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
117 lines
3.6 KiB
TypeScript
117 lines
3.6 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
import {
|
|
createTerminalEncodingStorageKey,
|
|
resolveInitialTerminalEncoding,
|
|
resolveTerminalEncodingFromCharset,
|
|
shouldSyncTerminalEncodingOnAttach,
|
|
terminalEncodingPreferenceToCharset,
|
|
} from "./terminalEncodingPreference";
|
|
|
|
test("resolves GB18030-compatible charset labels", () => {
|
|
assert.equal(resolveTerminalEncodingFromCharset("GB18030"), "gb18030");
|
|
assert.equal(resolveTerminalEncodingFromCharset("GBK"), "gb18030");
|
|
assert.equal(resolveTerminalEncodingFromCharset("zh_CN.GB18030"), "gb18030");
|
|
assert.equal(resolveTerminalEncodingFromCharset("zh_CN.GBK@variant"), "gb18030");
|
|
});
|
|
|
|
test("resolves UTF-8 charset labels", () => {
|
|
assert.equal(resolveTerminalEncodingFromCharset("UTF-8"), "utf-8");
|
|
assert.equal(resolveTerminalEncodingFromCharset("en_US.UTF-8"), "utf-8");
|
|
});
|
|
|
|
test("per-host remembered terminal encoding wins for supported or empty host charsets", () => {
|
|
assert.equal(resolveInitialTerminalEncoding("UTF-8", "gb18030"), "gb18030");
|
|
assert.equal(resolveInitialTerminalEncoding(undefined, "gb18030"), "gb18030");
|
|
});
|
|
|
|
test("missing per-host remembered encoding preserves configured GB18030 charset", () => {
|
|
assert.equal(resolveInitialTerminalEncoding("GB18030", null), "gb18030");
|
|
});
|
|
|
|
test("per-host remembered UTF-8 can override a supported GB18030 host charset", () => {
|
|
assert.equal(resolveInitialTerminalEncoding("GB18030", "utf-8"), "utf-8");
|
|
});
|
|
|
|
test("unsupported charsets ignore remembered encoding", () => {
|
|
assert.equal(resolveInitialTerminalEncoding("latin1", "gb18030"), "utf-8");
|
|
});
|
|
|
|
test("maps terminal encoding preferences back to host charset labels", () => {
|
|
assert.equal(terminalEncodingPreferenceToCharset("utf-8"), "UTF-8");
|
|
assert.equal(terminalEncodingPreferenceToCharset("gb18030"), "GB18030");
|
|
});
|
|
|
|
test("syncs remembered serial encoding preferences on attach", () => {
|
|
assert.equal(
|
|
shouldSyncTerminalEncodingOnAttach({
|
|
connection: "serial",
|
|
userPickedEncoding: false,
|
|
hasRememberedEncoding: true,
|
|
}),
|
|
true,
|
|
);
|
|
assert.equal(
|
|
shouldSyncTerminalEncodingOnAttach({
|
|
connection: "serial",
|
|
userPickedEncoding: false,
|
|
hasRememberedEncoding: false,
|
|
}),
|
|
false,
|
|
);
|
|
});
|
|
|
|
test("syncs SSH encoding on attach and leaves unrelated sessions alone", () => {
|
|
assert.equal(
|
|
shouldSyncTerminalEncodingOnAttach({
|
|
connection: "ssh",
|
|
userPickedEncoding: false,
|
|
hasRememberedEncoding: false,
|
|
}),
|
|
true,
|
|
);
|
|
assert.equal(
|
|
shouldSyncTerminalEncodingOnAttach({
|
|
connection: "other",
|
|
userPickedEncoding: true,
|
|
hasRememberedEncoding: true,
|
|
}),
|
|
false,
|
|
);
|
|
});
|
|
|
|
test("creates isolated terminal encoding storage keys per host", () => {
|
|
const prefix = "netcatty_terminal_encoding_by_host_v1:";
|
|
const first = createTerminalEncodingStorageKey(prefix, {
|
|
id: "host-a",
|
|
protocol: "ssh",
|
|
hostname: "10.0.0.1",
|
|
username: "root",
|
|
port: 22,
|
|
});
|
|
const second = createTerminalEncodingStorageKey(prefix, {
|
|
id: "host-b",
|
|
protocol: "ssh",
|
|
hostname: "10.0.0.2",
|
|
username: "root",
|
|
port: 22,
|
|
});
|
|
|
|
assert.notEqual(first, second);
|
|
assert.equal(first, `${prefix}host-a`);
|
|
assert.equal(second, `${prefix}host-b`);
|
|
});
|
|
|
|
test("falls back to a connection fingerprint when a host id is unavailable", () => {
|
|
const prefix = "netcatty_terminal_encoding_by_host_v1:";
|
|
assert.equal(
|
|
createTerminalEncodingStorageKey(prefix, {
|
|
protocol: "ssh",
|
|
hostname: "example.com",
|
|
username: "deploy",
|
|
port: 2222,
|
|
}),
|
|
`${prefix}ssh%7Cdeploy%7Cexample.com%7C2222`,
|
|
);
|
|
});
|