From 6c8d109d761efe91728bc58ade166bc0ef84423d Mon Sep 17 00:00:00 2001 From: CREDO23 Date: Wed, 22 Jul 2026 19:35:04 +0200 Subject: [PATCH] test: parse run citation tokens --- .../lib/citations/citation-parser.test.ts | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 surfsense_web/lib/citations/citation-parser.test.ts diff --git a/surfsense_web/lib/citations/citation-parser.test.ts b/surfsense_web/lib/citations/citation-parser.test.ts new file mode 100644 index 000000000..1f5749f2f --- /dev/null +++ b/surfsense_web/lib/citations/citation-parser.test.ts @@ -0,0 +1,35 @@ +import assert from "node:assert/strict"; +import { test } from "node:test"; +import { parseTextWithCitations } from "./citation-parser"; + +// Run with: pnpm exec tsx --test lib/citations/citation-parser.test.ts + +const NO_URLS = new Map(); + +test("parses a scraper-run handle into a run token", () => { + const segments = parseTextWithCitations( + "Price is $19 [citation:run_1b2c3d4e-5f60-7081-9abc-def012345678].", + NO_URLS + ); + + assert.deepEqual(segments, [ + "Price is $19 ", + { kind: "run", runId: "run_1b2c3d4e-5f60-7081-9abc-def012345678" }, + ".", + ]); +}); + +test("run handles do not collide with numeric chunk citations", () => { + const segments = parseTextWithCitations( + "chunk [citation:42] vs run [citation:run_ab-12].", + NO_URLS + ); + + assert.deepEqual(segments, [ + "chunk ", + { kind: "chunk", chunkId: 42, isDocsChunk: false }, + " vs run ", + { kind: "run", runId: "run_ab-12" }, + ".", + ]); +});