Files
Netcatty/components/terminal/programmaticCommandLog.test.ts
T
陈大猫 bd3491a3e4 revert(terminal): remove auto-run snippet stty protection (#1594) (#1599)
* fix(terminal): narrow snippet terminal restore to RHEL-family hosts

Limit auto-run snippet stty protection to distros affected by #1498 and
suppress wrapper echo so Ubuntu, Rocky, and macOS users see their raw
commands again.

Fixes #1594

Co-authored-by: Cursor <cursoragent@cursor.com>

* revert(terminal): remove auto-run snippet stty protection (#1594)

The wrapper added in #1498 caused visible preamble noise for all snippet
executions. Revert to inserting the original command directly; the underlying
CentOS 7 terminal issue reproduces when running the script manually too.

Co-authored-by: Cursor <cursoragent@cursor.com>

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-23 20:25:16 +08:00

50 lines
1.6 KiB
TypeScript

import assert from "node:assert/strict";
import test from "node:test";
import { createProgrammaticCommandLogRewriter } from "./programmaticCommandLog.ts";
test("rewrites a protected snippet echo to the readable command", () => {
const rewriter = createProgrammaticCommandLogRewriter();
rewriter.queueRewrite({
sentCommand: "sh -c 'private setup' && eval 'wrapped command'",
displayCommand: "sudo apt update && sudo apt upgrade -y",
});
const output = rewriter.append("sh -c 'private setup' && eval 'wrapped command'\r\nDone\r\n");
assert.equal(output, "sudo apt update && sudo apt upgrade -y\r\nDone\r\n");
});
test("rewrites a protected snippet echo split across terminal data chunks", () => {
const rewriter = createProgrammaticCommandLogRewriter();
rewriter.queueRewrite({
sentCommand: "sh -c 'private setup' && eval 'wrapped command'",
displayCommand: "uptime",
});
const first = rewriter.append("before\r\nsh -c 'private");
const second = rewriter.append(" setup' && eval 'wrapped command'\r\nafter\r\n");
assert.equal(first, "before\r\n");
assert.equal(second, "uptime\r\nafter\r\n");
});
test("finish returns an unmatched partial echo and clears stale rewrites", () => {
const rewriter = createProgrammaticCommandLogRewriter();
rewriter.queueRewrite({
sentCommand: "wrapped-one",
displayCommand: "one",
});
assert.equal(rewriter.append("wrapped-"), "");
assert.equal(rewriter.finish(), "wrapped-");
rewriter.queueRewrite({
sentCommand: "wrapped-two",
displayCommand: "two",
});
assert.equal(rewriter.append("wrapped-two\r\n"), "two\r\n");
});