601 lines
21 KiB
TypeScript
601 lines
21 KiB
TypeScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import os from "node:os";
|
|
import path from "node:path";
|
|
import { mkdtemp, rm } from "node:fs/promises";
|
|
import { NextRequest } from "next/server";
|
|
|
|
let runtimeRoot = "";
|
|
let createEnrollmentRoute: (typeof import("../src/app/api/v1/devices/enrollments/route"))["POST"];
|
|
let deviceHeartbeatRoute: (typeof import("../src/app/api/device-heartbeat/route"))["POST"];
|
|
let getImportDraftRoute: (typeof import("../src/app/api/v1/devices/[deviceId]/import-draft/route"))["GET"];
|
|
let selectImportDraftRoute: (typeof import("../src/app/api/v1/devices/[deviceId]/import-draft/select/route"))["POST"];
|
|
let reviewImportDraftRoute: (typeof import("../src/app/api/v1/devices/[deviceId]/import-draft/review/route"))["POST"];
|
|
let applyImportDraftRoute: (typeof import("../src/app/api/v1/devices/[deviceId]/import-draft/apply/route"))["POST"];
|
|
let createAuthSession: (typeof import("../src/lib/boss-data"))["createAuthSession"];
|
|
let readState: (typeof import("../src/lib/boss-data"))["readState"];
|
|
let AUTH_SESSION_COOKIE = "";
|
|
|
|
async function setup() {
|
|
if (runtimeRoot) return;
|
|
|
|
runtimeRoot = await mkdtemp(path.join(os.tmpdir(), "boss-device-import-"));
|
|
process.env.BOSS_RUNTIME_ROOT = runtimeRoot;
|
|
process.env.BOSS_STATE_FILE = path.join(runtimeRoot, "boss-state.json");
|
|
|
|
const [enrollmentModule, heartbeatModule, importDraftModule, selectModule, reviewModule, applyModule, data, auth] =
|
|
await Promise.all([
|
|
import("../src/app/api/v1/devices/enrollments/route.ts"),
|
|
import("../src/app/api/device-heartbeat/route.ts"),
|
|
import("../src/app/api/v1/devices/[deviceId]/import-draft/route.ts"),
|
|
import("../src/app/api/v1/devices/[deviceId]/import-draft/select/route.ts"),
|
|
import("../src/app/api/v1/devices/[deviceId]/import-draft/review/route.ts"),
|
|
import("../src/app/api/v1/devices/[deviceId]/import-draft/apply/route.ts"),
|
|
import("../src/lib/boss-data.ts"),
|
|
import("../src/lib/boss-auth.ts"),
|
|
]);
|
|
|
|
createEnrollmentRoute = enrollmentModule.POST;
|
|
deviceHeartbeatRoute = heartbeatModule.POST;
|
|
getImportDraftRoute = importDraftModule.GET;
|
|
selectImportDraftRoute = selectModule.POST;
|
|
reviewImportDraftRoute = reviewModule.POST;
|
|
applyImportDraftRoute = applyModule.POST;
|
|
createAuthSession = data.createAuthSession;
|
|
readState = data.readState;
|
|
AUTH_SESSION_COOKIE = auth.AUTH_SESSION_COOKIE;
|
|
}
|
|
|
|
test.after(async () => {
|
|
if (runtimeRoot) {
|
|
await rm(runtimeRoot, { recursive: true, force: true });
|
|
}
|
|
});
|
|
|
|
async function createAuthedRequest(url: string, method: "GET" | "POST", body?: unknown) {
|
|
return createAuthedRequestFor("17600003315", "highest_admin", url, method, body);
|
|
}
|
|
|
|
async function createAuthedRequestFor(
|
|
account: string,
|
|
role: "member" | "admin" | "highest_admin",
|
|
url: string,
|
|
method: "GET" | "POST",
|
|
body?: unknown,
|
|
) {
|
|
const session = await createAuthSession({
|
|
account,
|
|
role,
|
|
displayName: "Boss 超级管理员",
|
|
loginMethod: "password",
|
|
});
|
|
|
|
return new NextRequest(url, {
|
|
method,
|
|
headers: {
|
|
cookie: `${AUTH_SESSION_COOKIE}=${session.sessionToken}`,
|
|
...(body ? { "content-type": "application/json" } : {}),
|
|
},
|
|
body: body ? JSON.stringify(body) : undefined,
|
|
});
|
|
}
|
|
|
|
test("device import draft flow scans candidates, selects imports, resolves suggestions, and creates real chat windows", async () => {
|
|
await setup();
|
|
|
|
const enrollmentResponse = await createEnrollmentRoute(
|
|
await createAuthedRequest("http://127.0.0.1:3000/api/v1/devices/enrollments", "POST", {
|
|
name: "MacBook Pro",
|
|
avatar: "P",
|
|
account: "17600003315",
|
|
endpoint: "mac://mbp.local",
|
|
note: "待导入新设备",
|
|
}),
|
|
);
|
|
assert.equal(enrollmentResponse.status, 200);
|
|
const enrollmentPayload = (await enrollmentResponse.json()) as {
|
|
enrollment: { deviceId: string; pairingCode: string };
|
|
device: { id: string };
|
|
};
|
|
|
|
const heartbeatResponse = await deviceHeartbeatRoute(
|
|
new NextRequest("http://127.0.0.1:3000/api/device-heartbeat", {
|
|
method: "POST",
|
|
headers: { "content-type": "application/json" },
|
|
body: JSON.stringify({
|
|
deviceId: enrollmentPayload.device.id,
|
|
pairingCode: enrollmentPayload.enrollment.pairingCode,
|
|
name: "MacBook Pro",
|
|
avatar: "P",
|
|
account: "17600003315",
|
|
status: "online",
|
|
quota5h: 72,
|
|
quota7d: 88,
|
|
projects: [],
|
|
endpoint: "mac://mbp.local",
|
|
projectCandidates: [
|
|
{
|
|
folderName: "北区试产线",
|
|
folderRef: "north-line",
|
|
threadId: "thread-north-regression",
|
|
threadDisplayName: "北区试产线回归",
|
|
codexFolderRef: "north-line",
|
|
codexThreadRef: "thread-north-regression",
|
|
lastActiveAt: "2026-03-30T10:18:00+08:00",
|
|
suggestedImport: true,
|
|
},
|
|
{
|
|
folderName: "北区试产线",
|
|
folderRef: "north-line",
|
|
threadId: "thread-north-audit",
|
|
threadDisplayName: "北区试产线审计",
|
|
codexFolderRef: "north-line",
|
|
codexThreadRef: "thread-north-audit",
|
|
lastActiveAt: "2026-03-30T10:20:00+08:00",
|
|
suggestedImport: true,
|
|
},
|
|
],
|
|
}),
|
|
}),
|
|
);
|
|
assert.equal(heartbeatResponse.status, 200);
|
|
|
|
const draftResponse = await getImportDraftRoute(
|
|
await createAuthedRequest(
|
|
`http://127.0.0.1:3000/api/v1/devices/${enrollmentPayload.device.id}/import-draft`,
|
|
"GET",
|
|
),
|
|
{ params: Promise.resolve({ deviceId: enrollmentPayload.device.id }) },
|
|
);
|
|
assert.equal(draftResponse.status, 200);
|
|
const draftPayload = (await draftResponse.json()) as {
|
|
draft: { draftId: string; candidates: Array<{ candidateId: string; threadDisplayName: string }> } | null;
|
|
};
|
|
assert.ok(draftPayload.draft, "expected an import draft after heartbeat candidates");
|
|
assert.equal(draftPayload.draft.candidates.length, 2);
|
|
|
|
const selectedCandidateIds = draftPayload.draft.candidates
|
|
.filter((candidate) => candidate.threadDisplayName === "北区试产线回归")
|
|
.map((candidate) => candidate.candidateId);
|
|
assert.equal(selectedCandidateIds.length, 1);
|
|
|
|
const selectResponse = await selectImportDraftRoute(
|
|
await createAuthedRequest(
|
|
`http://127.0.0.1:3000/api/v1/devices/${enrollmentPayload.device.id}/import-draft/select`,
|
|
"POST",
|
|
{ selectedCandidateIds },
|
|
),
|
|
{ params: Promise.resolve({ deviceId: enrollmentPayload.device.id }) },
|
|
);
|
|
assert.equal(selectResponse.status, 200);
|
|
|
|
const reviewResponse = await reviewImportDraftRoute(
|
|
await createAuthedRequest(
|
|
`http://127.0.0.1:3000/api/v1/devices/${enrollmentPayload.device.id}/import-draft/review`,
|
|
"POST",
|
|
{},
|
|
),
|
|
{ params: Promise.resolve({ deviceId: enrollmentPayload.device.id }) },
|
|
);
|
|
assert.equal(reviewResponse.status, 200);
|
|
const reviewPayload = (await reviewResponse.json()) as {
|
|
resolution: { summary: string; items: Array<{ action: string; threadDisplayName: string }> };
|
|
};
|
|
assert.match(reviewPayload.resolution.summary, /MacBook Pro 导入建议/);
|
|
assert.deepEqual(
|
|
reviewPayload.resolution.items.map((item) => item.action),
|
|
["create_thread_conversation"],
|
|
);
|
|
|
|
const reviewedState = await readState();
|
|
const resolutionTask = reviewedState.masterAgentTasks.find(
|
|
(task) =>
|
|
task.taskType === "device_import_resolution" &&
|
|
task.deviceImportDraftId &&
|
|
task.status === "completed",
|
|
);
|
|
assert.ok(resolutionTask, "expected import review to leave a master-agent task trace");
|
|
|
|
const applyResponse = await applyImportDraftRoute(
|
|
await createAuthedRequest(
|
|
`http://127.0.0.1:3000/api/v1/devices/${enrollmentPayload.device.id}/import-draft/apply`,
|
|
"POST",
|
|
{},
|
|
),
|
|
{ params: Promise.resolve({ deviceId: enrollmentPayload.device.id }) },
|
|
);
|
|
assert.equal(applyResponse.status, 200);
|
|
|
|
const nextState = await readState();
|
|
const importedProject = nextState.projects.find(
|
|
(project) => project.threadMeta.codexThreadRef === "thread-north-regression",
|
|
);
|
|
assert.ok(importedProject, "expected selected candidate to become a real chat window");
|
|
assert.equal(importedProject?.threadMeta.threadDisplayName, "北区试产线回归");
|
|
assert.equal(importedProject?.threadMeta.folderName, "北区试产线");
|
|
|
|
const device = nextState.devices.find((item) => item.id === enrollmentPayload.device.id);
|
|
assert.deepEqual(device?.projects, ["北区试产线"]);
|
|
|
|
const appliedDraft = nextState.deviceImportDrafts.find(
|
|
(draft) => draft.deviceId === enrollmentPayload.device.id,
|
|
);
|
|
const appliedResolution = nextState.deviceImportResolutions.find(
|
|
(resolution) => resolution.deviceId === enrollmentPayload.device.id,
|
|
);
|
|
assert.equal(appliedDraft?.status, "applied");
|
|
assert.equal(appliedResolution?.status, "applied");
|
|
});
|
|
|
|
test("heartbeat candidates no longer auto-create chat windows from legacy projects when import draft is present", async () => {
|
|
await setup();
|
|
|
|
const enrollmentResponse = await createEnrollmentRoute(
|
|
await createAuthedRequest("http://127.0.0.1:3000/api/v1/devices/enrollments", "POST", {
|
|
name: "ThinkPad",
|
|
avatar: "T",
|
|
account: "17600003315",
|
|
endpoint: "pc://thinkpad.local",
|
|
note: "legacy projects should not auto import",
|
|
}),
|
|
);
|
|
assert.equal(enrollmentResponse.status, 200);
|
|
const enrollmentPayload = (await enrollmentResponse.json()) as {
|
|
enrollment: { pairingCode: string };
|
|
device: { id: string };
|
|
};
|
|
|
|
const beforeState = await readState();
|
|
const beforeCount = beforeState.projects.filter((project) => project.name === "Legacy Folder").length;
|
|
|
|
const heartbeatResponse = await deviceHeartbeatRoute(
|
|
new NextRequest("http://127.0.0.1:3000/api/device-heartbeat", {
|
|
method: "POST",
|
|
headers: { "content-type": "application/json" },
|
|
body: JSON.stringify({
|
|
deviceId: enrollmentPayload.device.id,
|
|
pairingCode: enrollmentPayload.enrollment.pairingCode,
|
|
name: "ThinkPad",
|
|
avatar: "T",
|
|
account: "17600003315",
|
|
status: "online",
|
|
quota5h: 60,
|
|
quota7d: 75,
|
|
projects: ["Legacy Folder"],
|
|
endpoint: "pc://thinkpad.local",
|
|
projectCandidates: [
|
|
{
|
|
folderName: "Legacy Folder",
|
|
folderRef: "legacy-folder",
|
|
threadId: "thread-legacy-1",
|
|
threadDisplayName: "Legacy 线程",
|
|
codexFolderRef: "legacy-folder",
|
|
codexThreadRef: "thread-legacy-1",
|
|
lastActiveAt: "2026-03-30T10:30:00+08:00",
|
|
suggestedImport: true,
|
|
},
|
|
],
|
|
}),
|
|
}),
|
|
);
|
|
assert.equal(heartbeatResponse.status, 200);
|
|
|
|
const nextState = await readState();
|
|
const afterCount = nextState.projects.filter((project) => project.name === "Legacy Folder").length;
|
|
assert.equal(afterCount, beforeCount, "legacy project folders should wait for import apply");
|
|
|
|
const draft = nextState.deviceImportDrafts.find((item) => item.deviceId === enrollmentPayload.device.id);
|
|
assert.ok(draft, "expected import draft to be created");
|
|
});
|
|
|
|
test("device import apply is idempotent and heartbeat preserves applied status", async () => {
|
|
await setup();
|
|
|
|
const enrollmentResponse = await createEnrollmentRoute(
|
|
await createAuthedRequest("http://127.0.0.1:3000/api/v1/devices/enrollments", "POST", {
|
|
name: "Studio Mac",
|
|
avatar: "S",
|
|
account: "17600003315",
|
|
endpoint: "mac://studio.local",
|
|
note: "idempotent import apply",
|
|
}),
|
|
);
|
|
assert.equal(enrollmentResponse.status, 200);
|
|
const enrollmentPayload = (await enrollmentResponse.json()) as {
|
|
enrollment: { pairingCode: string };
|
|
device: { id: string };
|
|
};
|
|
|
|
const heartbeatPayload = {
|
|
deviceId: enrollmentPayload.device.id,
|
|
pairingCode: enrollmentPayload.enrollment.pairingCode,
|
|
name: "Studio Mac",
|
|
avatar: "S",
|
|
account: "17600003315",
|
|
status: "online" as const,
|
|
quota5h: 68,
|
|
quota7d: 82,
|
|
projects: [],
|
|
endpoint: "mac://studio.local",
|
|
projectCandidates: [
|
|
{
|
|
folderName: "导入目录",
|
|
folderRef: "import-folder",
|
|
threadId: "thread-import-1",
|
|
threadDisplayName: "导入线程一",
|
|
codexFolderRef: "import-folder",
|
|
codexThreadRef: "thread-import-1",
|
|
lastActiveAt: "2026-03-30T10:40:00+08:00",
|
|
suggestedImport: true,
|
|
},
|
|
],
|
|
};
|
|
|
|
assert.equal(
|
|
(
|
|
await deviceHeartbeatRoute(
|
|
new NextRequest("http://127.0.0.1:3000/api/device-heartbeat", {
|
|
method: "POST",
|
|
headers: { "content-type": "application/json" },
|
|
body: JSON.stringify(heartbeatPayload),
|
|
}),
|
|
)
|
|
).status,
|
|
200,
|
|
);
|
|
|
|
const draftResponse = await getImportDraftRoute(
|
|
await createAuthedRequest(
|
|
`http://127.0.0.1:3000/api/v1/devices/${enrollmentPayload.device.id}/import-draft`,
|
|
"GET",
|
|
),
|
|
{ params: Promise.resolve({ deviceId: enrollmentPayload.device.id }) },
|
|
);
|
|
const draftPayload = (await draftResponse.json()) as {
|
|
draft: { candidates: Array<{ candidateId: string }> };
|
|
};
|
|
const selectedCandidateIds = draftPayload.draft.candidates.map((candidate) => candidate.candidateId);
|
|
|
|
assert.equal(
|
|
(
|
|
await selectImportDraftRoute(
|
|
await createAuthedRequest(
|
|
`http://127.0.0.1:3000/api/v1/devices/${enrollmentPayload.device.id}/import-draft/select`,
|
|
"POST",
|
|
{ selectedCandidateIds },
|
|
),
|
|
{ params: Promise.resolve({ deviceId: enrollmentPayload.device.id }) },
|
|
)
|
|
).status,
|
|
200,
|
|
);
|
|
assert.equal(
|
|
(
|
|
await reviewImportDraftRoute(
|
|
await createAuthedRequest(
|
|
`http://127.0.0.1:3000/api/v1/devices/${enrollmentPayload.device.id}/import-draft/review`,
|
|
"POST",
|
|
{},
|
|
),
|
|
{ params: Promise.resolve({ deviceId: enrollmentPayload.device.id }) },
|
|
)
|
|
).status,
|
|
200,
|
|
);
|
|
|
|
const applyUrl = `http://127.0.0.1:3000/api/v1/devices/${enrollmentPayload.device.id}/import-draft/apply`;
|
|
const firstApply = await applyImportDraftRoute(
|
|
await createAuthedRequest(applyUrl, "POST", {}),
|
|
{ params: Promise.resolve({ deviceId: enrollmentPayload.device.id }) },
|
|
);
|
|
assert.equal(firstApply.status, 200);
|
|
|
|
const secondApply = await applyImportDraftRoute(
|
|
await createAuthedRequest(applyUrl, "POST", {}),
|
|
{ params: Promise.resolve({ deviceId: enrollmentPayload.device.id }) },
|
|
);
|
|
assert.equal(secondApply.status, 200);
|
|
|
|
let nextState = await readState();
|
|
const importedProjects = nextState.projects.filter(
|
|
(project) => project.threadMeta.codexThreadRef === "thread-import-1",
|
|
);
|
|
assert.equal(importedProjects.length, 1, "replaying apply should not duplicate imported thread windows");
|
|
|
|
assert.equal(
|
|
(
|
|
await deviceHeartbeatRoute(
|
|
new NextRequest("http://127.0.0.1:3000/api/device-heartbeat", {
|
|
method: "POST",
|
|
headers: { "content-type": "application/json" },
|
|
body: JSON.stringify(heartbeatPayload),
|
|
}),
|
|
)
|
|
).status,
|
|
200,
|
|
);
|
|
|
|
nextState = await readState();
|
|
const appliedDraft = nextState.deviceImportDrafts.find((item) => item.deviceId === enrollmentPayload.device.id);
|
|
assert.equal(appliedDraft?.status, "applied", "later heartbeats should not regress applied drafts");
|
|
});
|
|
|
|
test("device import routes reject unrelated logged-in members", async () => {
|
|
await setup();
|
|
|
|
const enrollmentResponse = await createEnrollmentRoute(
|
|
await createAuthedRequest("http://127.0.0.1:3000/api/v1/devices/enrollments", "POST", {
|
|
name: "Build Mac",
|
|
avatar: "B",
|
|
account: "17600003315",
|
|
endpoint: "mac://build.local",
|
|
note: "route auth test",
|
|
}),
|
|
);
|
|
assert.equal(enrollmentResponse.status, 200);
|
|
const enrollmentPayload = (await enrollmentResponse.json()) as {
|
|
enrollment: { pairingCode: string };
|
|
device: { id: string };
|
|
};
|
|
|
|
assert.equal(
|
|
(
|
|
await deviceHeartbeatRoute(
|
|
new NextRequest("http://127.0.0.1:3000/api/device-heartbeat", {
|
|
method: "POST",
|
|
headers: { "content-type": "application/json" },
|
|
body: JSON.stringify({
|
|
deviceId: enrollmentPayload.device.id,
|
|
pairingCode: enrollmentPayload.enrollment.pairingCode,
|
|
name: "Build Mac",
|
|
avatar: "B",
|
|
account: "17600003315",
|
|
status: "online",
|
|
quota5h: 71,
|
|
quota7d: 80,
|
|
projects: [],
|
|
endpoint: "mac://build.local",
|
|
projectCandidates: [
|
|
{
|
|
folderName: "受控目录",
|
|
folderRef: "secured-folder",
|
|
threadId: "thread-secured",
|
|
threadDisplayName: "受控线程",
|
|
codexFolderRef: "secured-folder",
|
|
codexThreadRef: "thread-secured",
|
|
lastActiveAt: "2026-03-30T10:50:00+08:00",
|
|
suggestedImport: true,
|
|
},
|
|
],
|
|
}),
|
|
}),
|
|
)
|
|
).status,
|
|
200,
|
|
);
|
|
|
|
const outsiderRequest = await createAuthedRequestFor(
|
|
"15500001111",
|
|
"member",
|
|
`http://127.0.0.1:3000/api/v1/devices/${enrollmentPayload.device.id}/import-draft`,
|
|
"GET",
|
|
);
|
|
const getResponse = await getImportDraftRoute(outsiderRequest, {
|
|
params: Promise.resolve({ deviceId: enrollmentPayload.device.id }),
|
|
});
|
|
assert.equal(getResponse.status, 403);
|
|
});
|
|
|
|
test("existing bound production devices auto-sync suggested candidates into conversations on heartbeat", async () => {
|
|
await setup();
|
|
|
|
const heartbeatResponse = await deviceHeartbeatRoute(
|
|
new NextRequest("http://127.0.0.1:3000/api/device-heartbeat", {
|
|
method: "POST",
|
|
headers: { "content-type": "application/json" },
|
|
body: JSON.stringify({
|
|
deviceId: "mac-studio",
|
|
token: "boss-mac-studio-token",
|
|
name: "Mac Studio",
|
|
avatar: "M",
|
|
account: "17600003315",
|
|
status: "online",
|
|
quota5h: 68,
|
|
quota7d: 81,
|
|
projects: ["Boss 移动控制台", "硬件审计协作"],
|
|
endpoint: "mac://kris.local",
|
|
projectCandidates: [
|
|
{
|
|
folderName: "yuandi",
|
|
folderRef: "/Users/kris/code/yuandi",
|
|
threadId: "session-yuandi-1",
|
|
threadDisplayName: "Epicurus",
|
|
codexFolderRef: "/Users/kris/code/yuandi",
|
|
codexThreadRef: "session-yuandi-1",
|
|
lastActiveAt: "2026-03-30T12:42:56+08:00",
|
|
suggestedImport: true,
|
|
},
|
|
{
|
|
folderName: "wenshenapp",
|
|
folderRef: "/Users/kris/code/wenshenapp",
|
|
threadId: "session-wenshenapp-1",
|
|
threadDisplayName: "wenshenapp · ea5f",
|
|
codexFolderRef: "/Users/kris/code/wenshenapp",
|
|
codexThreadRef: "session-wenshenapp-1",
|
|
lastActiveAt: "2026-03-30T12:34:51+08:00",
|
|
suggestedImport: true,
|
|
},
|
|
],
|
|
}),
|
|
}),
|
|
);
|
|
assert.equal(heartbeatResponse.status, 200);
|
|
|
|
const payload = (await heartbeatResponse.json()) as {
|
|
importDraft?: { status: string; selectedCandidateIds: string[] } | null;
|
|
};
|
|
assert.equal(payload.importDraft?.status, "applied");
|
|
assert.equal(payload.importDraft?.selectedCandidateIds.length, 2);
|
|
|
|
let nextState = await readState();
|
|
const yuandiProject = nextState.projects.find(
|
|
(project) => project.threadMeta.codexThreadRef === "session-yuandi-1",
|
|
);
|
|
const wenshenProject = nextState.projects.find(
|
|
(project) => project.threadMeta.codexThreadRef === "session-wenshenapp-1",
|
|
);
|
|
assert.ok(yuandiProject, "expected a discovered yuandi session to become a real chat window");
|
|
assert.ok(wenshenProject, "expected a discovered wenshenapp session to become a real chat window");
|
|
assert.equal(yuandiProject?.threadMeta.folderName, "yuandi");
|
|
assert.equal(wenshenProject?.threadMeta.folderName, "wenshenapp");
|
|
|
|
const device = nextState.devices.find((item) => item.id === "mac-studio");
|
|
assert.deepEqual(device?.projects, ["yuandi", "wenshenapp"]);
|
|
|
|
const followupHeartbeat = await deviceHeartbeatRoute(
|
|
new NextRequest("http://127.0.0.1:3000/api/device-heartbeat", {
|
|
method: "POST",
|
|
headers: { "content-type": "application/json" },
|
|
body: JSON.stringify({
|
|
deviceId: "mac-studio",
|
|
token: "boss-mac-studio-token",
|
|
name: "Mac Studio",
|
|
avatar: "M",
|
|
account: "17600003315",
|
|
status: "online",
|
|
quota5h: 68,
|
|
quota7d: 81,
|
|
projects: ["Boss 移动控制台", "硬件审计协作"],
|
|
endpoint: "mac://kris.local",
|
|
projectCandidates: [
|
|
{
|
|
folderName: "yuandi",
|
|
folderRef: "/Users/kris/code/yuandi",
|
|
threadId: "session-yuandi-1",
|
|
threadDisplayName: "Epicurus",
|
|
codexFolderRef: "/Users/kris/code/yuandi",
|
|
codexThreadRef: "session-yuandi-1",
|
|
lastActiveAt: "2026-03-30T12:55:56+08:00",
|
|
suggestedImport: true,
|
|
},
|
|
],
|
|
}),
|
|
}),
|
|
);
|
|
assert.equal(followupHeartbeat.status, 200);
|
|
|
|
nextState = await readState();
|
|
const remainingYuandi = nextState.projects.find(
|
|
(project) => project.threadMeta.codexThreadRef === "session-yuandi-1",
|
|
);
|
|
const removedWenshen = nextState.projects.find(
|
|
(project) => project.threadMeta.codexThreadRef === "session-wenshenapp-1",
|
|
);
|
|
assert.ok(remainingYuandi, "expected still-selected candidate to stay imported");
|
|
assert.equal(removedWenshen, undefined, "auto-sync should prune stale imported threads that disappeared from candidates");
|
|
assert.deepEqual(
|
|
nextState.devices.find((item) => item.id === "mac-studio")?.projects,
|
|
["yuandi"],
|
|
);
|
|
});
|