返回 DeepSeek-Reasonix
project-tree-session-archive.test.ts
根目录 / desktop / frontend / src / __tests__ / project-tree-session-archive.test.ts
1 // Run: tsx src/__tests__/project-tree-session-archive.test.ts
2
3 import assert from "node:assert/strict";
4 import { archiveProjectTreeSession } from "../lib/projectTreeArchive";
5
6 async function main() {
7 const transcript = { identity: {}, draft: "keep draft", scrollTop: 417 };
8 const selectors: Array<{ sessionPath: string }> = [];
9 let refreshes = 0;
10 let topicNotifications = 0;
11 let errors: unknown[] = [];
12
13 const committed = await archiveProjectTreeSession({
14 sessionPath: "/history/background.jsonl",
15 archiveTarget: async (selector) => {
16 selectors.push(selector);
17 return { committed: true };
18 },
19 refresh: async () => { refreshes += 1; },
20 topicsChanged: async () => { topicNotifications += 1; },
21 showError: (error) => { errors.push(error); },
22 });
23 assert.equal(committed, true);
24 assert.deepEqual(selectors, [{ sessionPath: "/history/background.jsonl" }]);
25 assert.equal(refreshes, 1);
26 assert.equal(topicNotifications, 1);
27 assert.equal(errors.length, 0);
28 assert.deepEqual(transcript, { identity: {}, draft: "keep draft", scrollTop: 417 });
29
30 const structured = { data: { sessionCode: "operation_busy" } };
31 const rejected = await archiveProjectTreeSession({
32 sessionPath: "/history/busy.jsonl",
33 archiveTarget: async () => { throw structured; },
34 refresh: async () => { refreshes += 1; },
35 showError: (error) => { errors.push(error); },
36 });
37 assert.equal(rejected, false);
38 assert.equal(refreshes, 2, "a rejected archive reconciles only the project tree");
39 assert.deepEqual(errors, [structured]);
40 assert.deepEqual(transcript, { identity: {}, draft: "keep draft", scrollTop: 417 });
41
42 process.stdout.write("PASS explicit session archive routing and current transcript stability\n");
43 }
44
45 void main();
46
46 lines TYPESCRIPT