- MCP
- code on this site's /mcp
- CLI
- none: the JSON below is the answer
- JSON
- /christopher/abso-core/files/worker/project/test/unseen.test.ts?format=json
54 linesengine 98% · rename 2%Last change rename in version 100, 4 versions changed it
1// Text the engine keeps and prints can't hold characters a reader can't see:
2// a version message with an escape sequence would run in
3// every terminal that shows `abso log` or news.
5import assert from "node:assert/strict";
6import { test } from "node:test";
7import { answer } from "../http.ts";
8import type { ProjectCalls } from "../project-api.ts";
9import { unseenIn } from "../unseen.ts";
11const ESC = String.fromCharCode(0x1b);
12const BEL = String.fromCharCode(0x07);
13const CSI = String.fromCharCode(0x9b);
14const RLO = String.fromCharCode(0x202e);
15const CR = String.fromCharCode(0x0d);
17test("unseenIn: ESC, C1, BEL and bidi overrides are found; newline, tab and CRLF pass", () => {
18 assert.equal(unseenIn(`Fix the parser\n\nDetails\twith a tab${CR}\nand CRLF.`), null);
19 assert.equal(unseenIn(`ok ${ESC}]52;c;aGk=${BEL}`), "a control character at character 4");
20 assert.equal(unseenIn(`${CSI}31m`), "a control character at character 1");
21 assert.equal(unseenIn(`a${CR}b`), "a control character at character 2");
22 assert.match(unseenIn(`abc${RLO}def`)!, /bidirectional embedding or override/);
23 assert.equal(unseenIn(`emoji 🎉 counts as one character ${ESC}`), "a control character at character 33");
24 assert.equal(unseenIn(`😀😀😀\nB${CR}X`), "a control character at character 6", "a lone CR after emoji is found");
25 assert.equal(unseenIn(`😀😀😀${CR}\nB`), null, "CRLF after emoji passes");
26});
28test("push, amend, land, starting notes and announcements refuse unseen characters before the engine sees them", () => {
29 // A stand-in for the engine: it records each call that gets through.
30 const calls: string[] = [];
31 const project = new Proxy({} as ProjectCalls, {
32 get:
33 (_, name) =>
34 (...args: unknown[]) => {
35 if (name === "exists") return true;
36 calls.push(`${String(name)} ${JSON.stringify(args[1])}`);
37 return { ok: true };
38 },
39 });
40 const osc8 = `Fix ${ESC}]8;;https://example.invalid${BEL}here${ESC}]8;;${BEL}`;
41 const refused = answer(project, "publish", "ann", { message: osc8 });
42 assert.equal(refused.status, 400);
43 assert.match(JSON.stringify(refused.body), /the message holds a control character at character 5/);
44 assert.equal(answer(project, "amend", "ann", { message: `Two ${ESC}[2J` }).status, 400);
45 assert.equal(answer(project, "land", "ann", { message: `Land ${CSI}1m` }).status, 400);
46 assert.equal(answer(project, "starting", "ann", { text: `on ${RLO}this` }).status, 400);
47 assert.equal(answer(project, "announce", "ann", { text: `hi ${BEL}` }).status, 400);
48 assert.deepEqual(calls, [], "none reached the engine");
50 const windows = `Two${CR}\n${CR}\nWritten on Windows.`;
51 assert.equal(answer(project, "publish", "ann", { message: windows }).status, 200);
52 assert.equal(answer(project, "starting", "ann", { text: "on the parser" }).status, 200);
53 assert.deepEqual(calls, [`publish ${JSON.stringify(windows)}`, 'starting "on the parser"']);
54});