Files
NetMesh/scripts/patch-xterm-macos-column-selection.test.cjs
zhaolei 3c72efcb7f
Some checks failed
build-packages / resolve bundled mosh-client (push) Has been cancelled
build-packages / resolve bundled et-client (push) Has been cancelled
build-packages / build-macos (push) Has been cancelled
build-packages / build-windows (push) Has been cancelled
build-packages / build-linux-x64 (push) Has been cancelled
build-packages / build-linux-arm64 (push) Has been cancelled
build-packages / release (push) Has been cancelled
build-packages / update Nix release metadata (push) Has been cancelled
build-packages / bump homebrew tap (push) Has been cancelled
test / lint-and-test (push) Has been cancelled
AI automation / Route event (push) Has been cancelled
AI automation / Hand reopened issue to maintainers (push) Has been cancelled
AI automation / Clean source issue state (push) Has been cancelled
AI automation / Reconcile handoffs (push) Has been cancelled
AI automation / Classify issue (push) Has been cancelled
AI automation / Claude Code smoke (push) Has been cancelled
AI automation / Review issue follow-up (push) Has been cancelled
AI automation / Publish issue follow-up (push) Has been cancelled
AI automation / Implement with Claude Code (push) Has been cancelled
AI automation / Publish implement PR (push) Has been cancelled
AI automation / Continue queued issue comments (push) Has been cancelled
AI automation / Codex review loop (push) Has been cancelled
AI automation / Publish Codex fix (push) Has been cancelled
AI automation / Clear Codex dispatch marker (push) Has been cancelled
AI automation / Own PR re-request Codex (push) Has been cancelled
AI automation / External PR re-request Codex (push) Has been cancelled
AI automation / Poll Codex reaction / retry (push) Has been cancelled
build-et-binaries / build-linux-x64 (push) Has been cancelled
build-et-binaries / build-linux-arm64 (push) Has been cancelled
build-et-binaries / build-macos-universal (push) Has been cancelled
build-et-binaries / build-windows-x64 (push) Has been cancelled
build-et-binaries / release (push) Has been cancelled
[Init] Initial commit - NetMesh terminal manager
2026-09-13 18:24:01 +08:00

87 lines
2.8 KiB
JavaScript

"use strict";
const assert = require("node:assert/strict");
const path = require("node:path");
const test = require("node:test");
const {
PATCHES,
invalidateViteCache,
patchXtermSource,
replacementForPatch,
sameLengthExpression,
} = require("./patch-xterm-macos-column-selection.cjs");
test("patches both distributed bundles without shifting source-map offsets", () => {
for (const patch of PATCHES.filter((entry) => entry.preserveLength)) {
const input = `before:${patch.original}:after`;
const result = patchXtermSource(input, patch);
assert.equal(result.changed, true);
assert.equal(result.source.length, input.length);
assert.equal(result.source.includes(patch.original), false);
assert.equal(
result.source.includes(sameLengthExpression(patch.replacement, patch.original.length)),
true,
);
}
});
test("patches readable xterm sources and source-map content", () => {
for (const patch of PATCHES.filter((entry) => !entry.preserveLength)) {
const input = `before:${patch.original}:after`;
const result = patchXtermSource(input, patch);
assert.equal(result.changed, true);
assert.equal(result.source, `before:${replacementForPatch(patch)}:after`);
assert.equal(result.source.length, input.length);
}
});
test("keeps source-map token columns stable inside every patched expression", () => {
for (const patch of PATCHES) {
const replacement = replacementForPatch(patch);
for (const token of ["this", "_optionsService", "rawOptions", ")", ";"]) {
assert.equal(
replacement.lastIndexOf(token),
patch.original.lastIndexOf(token),
`${patch.file}: ${token} moved to a different generated column`,
);
}
}
});
test("is idempotent and fails closed on an unknown package shape", () => {
for (const patch of PATCHES) {
const replacement = replacementForPatch(patch);
assert.deepEqual(patchXtermSource(`before:${replacement}:after`, patch), {
source: `before:${replacement}:after`,
changed: false,
});
assert.throws(
() => patchXtermSource("unrecognized source", patch),
/expected exactly one original or patched selection predicate/,
);
}
});
test("fails closed when a generated-bundle replacement would shift offsets", () => {
assert.throws(
() => sameLengthExpression("replacement is longer", 4),
/replacement expression is too long/,
);
});
test("invalidates Vite's optimized dependency cache after patching xterm", () => {
const calls = [];
const cachePath = invalidateViteCache("/repo", {
rmSync(target, options) {
calls.push({ target, options });
},
});
assert.equal(cachePath, path.resolve("/repo/node_modules/.vite"));
assert.deepEqual(calls, [{
target: cachePath,
options: { recursive: true, force: true },
}]);
});