fix: filter codex subthreads during auto import

This commit is contained in:
kris
2026-03-30 14:25:25 +08:00
parent 03ac40f427
commit 40861c63da
7 changed files with 145 additions and 6 deletions

View File

@@ -537,7 +537,7 @@ test("existing bound production devices auto-sync suggested candidates into conv
assert.equal(payload.importDraft?.status, "applied");
assert.equal(payload.importDraft?.selectedCandidateIds.length, 2);
const nextState = await readState();
let nextState = await readState();
const yuandiProject = nextState.projects.find(
(project) => project.threadMeta.codexThreadRef === "session-yuandi-1",
);
@@ -551,4 +551,50 @@ test("existing bound production devices auto-sync suggested candidates into conv
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"],
);
});

View File

@@ -83,6 +83,21 @@ test("discoverCodexProjectCandidates prefers Codex sqlite indexes and session na
null,
null,
);
insertThread.run(
"019d3bossworker",
path.join(codexRoot, "sessions/2026/03/30/rollout-boss-worker.jsonl"),
1774845620,
1774845630,
"desktop",
"openai",
"/Users/kris/code/boss",
"你是只读分析子线程",
"workspace-write",
"never",
0,
"Sagan",
"explorer",
);
insertThread.run(
"019d3yuandiexplorer",
path.join(codexRoot, "sessions/2026/03/30/rollout-yuandi-explorer.jsonl"),
@@ -137,6 +152,7 @@ test("discoverCodexProjectCandidates prefers Codex sqlite indexes and session na
VALUES (?, 0, 'info', 'codex', ?, 0)
`);
insertLog.run(1774845618, "019d3bossmain");
insertLog.run(1774845630, "019d3bossworker");
insertLog.run(1774845776, "019d3yuandiexplorer");
logsDb.close();
@@ -183,8 +199,10 @@ test("discoverCodexProjectCandidates prefers Codex sqlite indexes and session na
assert.equal(discovered.projectCandidates.length, 2);
const bossSession = discovered.projectCandidates.find((item) => item.threadId === "019d3bossmain");
const bossWorker = discovered.projectCandidates.find((item) => item.threadId === "019d3bossworker");
const yuandiSession = discovered.projectCandidates.find((item) => item.threadId === "019d3yuandiexplorer");
assert.ok(bossSession);
assert.equal(bossWorker, undefined, "subagent/explorer threads should be filtered when a primary thread exists for the same folder");
assert.ok(yuandiSession);
assert.equal(bossSession?.folderName, "boss");
assert.equal(bossSession?.codexFolderRef, "/Users/kris/code/boss");