Skip to content

abso-core

Public

abso is version control for agents: the client, the engine and a server you can run on your own Cloudflare account.

Check passed

Versions 73 to 74

Compare

+78 −0 in 1 place
new file, 78 lines
1+// What the client prints can't drive the terminal: colors pass to a terminal
2+// with NO_COLOR unset, and every other control character shows as text.
3+
4+import assert from "node:assert/strict";
5+import { execFile } from "node:child_process";
6+import { mkdtempSync, rmSync } from "node:fs";
7+import { tmpdir } from "node:os";
8+import { join, resolve } from "node:path";
9+import { describe, it } from "node:test";
10+import { colorsPass, terminalText } from "../src/terminal-text.ts";
12+const ESC = "\x1b";
14+describe("terminalText", () => {
15+ it("leaves plain text, tabs, newlines and CRLF alone", () => {
16+ const plain = "abso 72\tpublished\nnext line: ü, 中文, 🙂\r\n";
17+ assert.equal(terminalText(plain, true), plain);
18+ assert.equal(terminalText(plain, false), plain);
19+ });
21+ it("keeps colors only when they pass, and drops them quietly otherwise", () => {
22+ const red = `${ESC}[31mfailed${ESC}[0m and ${ESC}[1;38;5;208mbold${ESC}[m`;
23+ assert.equal(terminalText(red, true), red);
24+ assert.equal(terminalText(red, false), "failed and bold");
25+ });
27+ it("shows OSC 52 (the clipboard) and OSC 8 (links) as text, with or without colors", () => {
28+ const clip = `${ESC}]52;c;ZWNobyBoaQ==\x07`;
29+ assert.equal(terminalText(clip, true), "\\x1b]52;c;ZWNobyBoaQ==\\x07");
30+ const link = `${ESC}]8;;https://evil.example${ESC}\\click${ESC}]8;;${ESC}\\`;
31+ assert.equal(terminalText(link, true), "\\x1b]8;;https://evil.example\\x1b\\click\\x1b]8;;\\x1b\\");
32+ });
34+ it("shows other CSI, DCS and the rest of C0 and C1 as text", () => {
35+ assert.equal(terminalText(`${ESC}[2J${ESC}[H`, true), "\\x1b[2J\\x1b[H");
36+ assert.equal(terminalText(`${ESC}P1$r${ESC}\\`, true), "\\x1bP1$r\\x1b\\");
37+ assert.equal(terminalText("over\rwrite\b\x00\x7f", true), "over\\x0dwrite\\x08\\x00\\x7f");
38+ assert.equal(terminalText("\u009b31m\u0090x\u009c", true), "\\u009b31m\\u0090x\\u009c");
39+ // An SGR with anything but digits, ; and : isn't one.
40+ assert.equal(terminalText(`${ESC}[31;"m`, true), '\\x1b[31;"m');
41+ });
43+ it("colors pass to a terminal only, and never with NO_COLOR set", () => {
44+ assert.equal(colorsPass({ isTTY: true }, {}), true);
45+ assert.equal(colorsPass({ isTTY: true }, { NO_COLOR: "1" }), false);
46+ assert.equal(colorsPass({ isTTY: true }, { NO_COLOR: "" }), true);
47+ assert.equal(colorsPass({ isTTY: false }, {}), false);
48+ assert.equal(colorsPass({}, {}), false);
49+ });
51+ it("the client's own output goes through it: an error naming text with escapes prints them as text", async () => {
52+ const home = mkdtempSync(join(tmpdir(), "abso-test-terminal-"));
53+ try {
54+ // An unknown command: the error names it, escape and all.
55+ const dir = mkdtempSync(join(home, "x"));
56+ const env: Record<string, string> = {
57+ PATH: process.env.PATH ?? "",
58+ HOME: home,
59+ USERPROFILE: home,
60+ AVCS_SERVERS_FILE: "no-servers.json",
61+ };
62+ if (process.env.SystemRoot) env.SystemRoot = process.env.SystemRoot;
63+ const client = resolve(import.meta.dirname, "..", "abso.ts");
64+ const run = await new Promise<{ stdout: string; stderr: string }>((done) =>
65+ execFile(
66+ process.execPath,
67+ [client, `frob${ESC}]52;c;aGk=\x07`],
68+ { cwd: dir, env },
69+ (_e, stdout, stderr) => done({ stdout, stderr }),
70+ ),
71+ );
72+ assert.doesNotMatch(run.stdout + run.stderr, /\x1b/);
73+ assert.match(run.stderr, /frob\\x1b\]52;c;aGk=\\x07/);
74+ } finally {
75+ rmSync(home, { recursive: true, force: true });
76+ }
77+ });
78+});
MCP
compare on this site's /mcp
CLI
abso diff 73 74 client/test/terminal-text.test.ts --json
JSON
/christopher/abso-core/compare/73..74?file=client%2Ftest%2Fterminal-text.test.ts&format=json