| 1 | // Run: tsx src/__tests__/memory-citation-visibility.test.ts |
| 2 | |
| 3 | import { visibleTranscriptMemoryCitations } from "../lib/memoryCitationVisibility"; |
| 4 | import type { MemoryCitation } from "../lib/types"; |
| 5 | |
| 6 | let passed = 0; |
| 7 | let failed = 0; |
| 8 | |
| 9 | function eq(a: unknown, b: unknown, label: string) { |
| 10 | if (a === 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("\nmemory citation visibility"); |
| 20 | |
| 21 | const compilerCitations: MemoryCitation[] = [ |
| 22 | { kind: "compiler_reference", source: "Memory v5", note: "evidence: bash succeeded" }, |
| 23 | { kind: "constraint", source: "Memory v5", note: "must_use: verify source" }, |
| 24 | { kind: "risk_note", source: "Memory v5", note: "risk: avoid failed strategy" }, |
| 25 | ]; |
| 26 | eq(visibleTranscriptMemoryCitations(compilerCitations).length, 0, "compiler-only citations stay out of the transcript"); |
| 27 | |
| 28 | const regularCitation: MemoryCitation = { id: "mem-1", source: "MEMORY.md", lineStart: 12, note: "workflow" }; |
| 29 | eq(visibleTranscriptMemoryCitations([regularCitation])[0]?.source, "MEMORY.md", "regular memory citations remain visible"); |
| 30 | |
| 31 | const mixed = visibleTranscriptMemoryCitations([...compilerCitations, regularCitation]); |
| 32 | eq(mixed.length, 1, "mixed citations keep only user-facing memory references"); |
| 33 | eq(mixed[0]?.id, "mem-1", "mixed citations preserve the regular memory citation"); |
| 34 | |
| 35 | const compilerWithOtherSource: MemoryCitation = { kind: "compiler_reference", source: "MEMORY.md", note: "explicit memory file reference" }; |
| 36 | eq(visibleTranscriptMemoryCitations([compilerWithOtherSource]).length, 1, "non-Memory-v5 compiler kind is not hidden by kind alone"); |
| 37 | |
| 38 | console.log(`\n${passed} passed, ${failed} failed`); |
| 39 | if (failed > 0) process.exit(1); |
| 40 |