{"draft":null,"from":7,"to":318,"files":[{"path":"worker/project/test/unseen.test.ts","added":54,"removed":0,"diff":"--- /dev/null\n+++ b/worker/project/test/unseen.test.ts\n@@ -0,0 +1,54 @@\n+// Text the engine keeps and prints can't hold characters a reader can't see:\n+// a version message with an escape sequence would run in\n+// every terminal that shows `abso log` or news.\n+\n+import assert from \"node:assert/strict\";\n+import { test } from \"node:test\";\n+import { answer } from \"../http.ts\";\n+import type { ProjectCalls } from \"../project-api.ts\";\n+import { unseenIn } from \"../unseen.ts\";\n+\n+const ESC = String.fromCharCode(0x1b);\n+const BEL = String.fromCharCode(0x07);\n+const CSI = String.fromCharCode(0x9b);\n+const RLO = String.fromCharCode(0x202e);\n+const CR = String.fromCharCode(0x0d);\n+\n+test(\"unseenIn: ESC, C1, BEL and bidi overrides are found; newline, tab and CRLF pass\", () => {\n+\tassert.equal(unseenIn(`Fix the parser\\n\\nDetails\\twith a tab${CR}\\nand CRLF.`), null);\n+\tassert.equal(unseenIn(`ok ${ESC}]52;c;aGk=${BEL}`), \"a control character at character 4\");\n+\tassert.equal(unseenIn(`${CSI}31m`), \"a control character at character 1\");\n+\tassert.equal(unseenIn(`a${CR}b`), \"a control character at character 2\");\n+\tassert.match(unseenIn(`abc${RLO}def`)!, /bidirectional embedding or override/);\n+\tassert.equal(unseenIn(`emoji 🎉 counts as one character ${ESC}`), \"a control character at character 33\");\n+\tassert.equal(unseenIn(`😀😀😀\\nB${CR}X`), \"a control character at character 6\", \"a lone CR after emoji is found\");\n+\tassert.equal(unseenIn(`😀😀😀${CR}\\nB`), null, \"CRLF after emoji passes\");\n+});\n+\n+test(\"push, amend, land, starting notes and announcements refuse unseen characters before the engine sees them\", () => {\n+\t// A stand-in for the engine: it records each call that gets through.\n+\tconst calls: string[] = [];\n+\tconst project = new Proxy({} as ProjectCalls, {\n+\t\tget:\n+\t\t\t(_, name) =>\n+\t\t\t(...args: unknown[]) => {\n+\t\t\t\tif (name === \"exists\") return true;\n+\t\t\t\tcalls.push(`${String(name)} ${JSON.stringify(args[1])}`);\n+\t\t\t\treturn { ok: true };\n+\t\t\t},\n+\t});\n+\tconst osc8 = `Fix ${ESC}]8;;https://example.invalid${BEL}here${ESC}]8;;${BEL}`;\n+\tconst refused = answer(project, \"publish\", \"ann\", { message: osc8 });\n+\tassert.equal(refused.status, 400);\n+\tassert.match(JSON.stringify(refused.body), /the message holds a control character at character 5/);\n+\tassert.equal(answer(project, \"amend\", \"ann\", { message: `Two ${ESC}[2J` }).status, 400);\n+\tassert.equal(answer(project, \"land\", \"ann\", { message: `Land ${CSI}1m` }).status, 400);\n+\tassert.equal(answer(project, \"starting\", \"ann\", { text: `on ${RLO}this` }).status, 400);\n+\tassert.equal(answer(project, \"announce\", \"ann\", { text: `hi ${BEL}` }).status, 400);\n+\tassert.deepEqual(calls, [], \"none reached the engine\");\n+\n+\tconst windows = `Two${CR}\\n${CR}\\nWritten on Windows.`;\n+\tassert.equal(answer(project, \"publish\", \"ann\", { message: windows }).status, 200);\n+\tassert.equal(answer(project, \"starting\", \"ann\", { text: \"on the parser\" }).status, 200);\n+\tassert.deepEqual(calls, [`publish ${JSON.stringify(windows)}`, 'starting \"on the parser\"']);\n+});"}],"unmatched":[]}