返回 DeepSeek-Reasonix
draft-credentials.test.ts
根目录 / desktop / frontend / src / __tests__ / draft-credentials.test.ts
1 // Run: tsx src/__tests__/draft-credentials.test.ts
2
3 import { draftIDsFromSubmit } from "../lib/draftCredentials";
4 import { readSessionAttachmentDataURL } from "../lib/sessionAttachmentRead";
5
6 let passed = 0;
7 let failed = 0;
8
9 function eq(a: unknown, b: unknown, label: string) {
10 if (JSON.stringify(a) === JSON.stringify(b)) {
11 process.stdout.write(` PASS ${label}\n`);
12 passed += 1;
13 } else {
14 process.stdout.write(` FAIL ${label}: expected ${JSON.stringify(b)}, got ${JSON.stringify(a)}\n`);
15 failed += 1;
16 }
17 }
18
19 console.log("\ndraft credentials");
20 eq(
21 draftIDsFromSubmit("inspect @[a.png](draft:0123456789abcdef0123456789abcdef) and @[b.png](draft:0123456789ABCDEF0123456789ABCDEF)"),
22 ["0123456789abcdef0123456789abcdef"],
23 "extracts unique lowercase draft credentials",
24 );
25 eq(draftIDsFromSubmit("no drafts here"), [], "returns no ids without draft credentials");
26
27 console.log("\nsession attachment read");
28 const png = Uint8Array.from([1, 2, 3, 4]);
29 const encoded = Buffer.from(png).toString("base64");
30 const url = await readSessionAttachmentDataURL("tab-1", "ab".repeat(32), "image/png", async (_tab, _digest, offset) => {
31 if (offset !== 0) throw new Error(`unexpected offset ${offset}`);
32 return { data: encoded, nextOffset: png.length, done: true };
33 });
34 eq(url, `data:image/png;base64,${encoded}`, "assembles a bounded attachment preview");
35
36 console.log(`\n${passed} passed, ${failed} failed, ${passed + failed} total`);
37 if (failed > 0) process.exit(1);
38
38 lines TYPESCRIPT