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
162 lines
5.2 KiB
JavaScript
162 lines
5.2 KiB
JavaScript
"use strict";
|
|
|
|
const assert = require("node:assert/strict");
|
|
const test = require("node:test");
|
|
const terminalBridge = require("./terminalBridge.cjs");
|
|
|
|
test("renderer terminal input reports activity for the matching session", () => {
|
|
const writes = [];
|
|
const activity = [];
|
|
const sessions = new Map([
|
|
["session-1", {
|
|
proc: { write: (data) => writes.push(data) },
|
|
webContentsId: 1,
|
|
}],
|
|
]);
|
|
terminalBridge.init({
|
|
sessions,
|
|
electronModule: { webContents: { fromId: () => null } },
|
|
reportOpenedSessionActivity: (event) => activity.push(event),
|
|
});
|
|
|
|
terminalBridge.writeToSession({ sender: {} }, {
|
|
sessionId: "session-1",
|
|
data: "pwd\r",
|
|
});
|
|
|
|
assert.deepEqual(writes, ["pwd\r"]);
|
|
assert.deepEqual(activity, [
|
|
{ sessionId: "session-1", phase: "touch" },
|
|
]);
|
|
});
|
|
|
|
test("direct-mode close reports ownership cleanup after the backend already exited", () => {
|
|
const activity = [];
|
|
terminalBridge.init({
|
|
sessions: new Map(),
|
|
electronModule: {},
|
|
reportOpenedSessionActivity: (event) => activity.push(event),
|
|
});
|
|
|
|
const result = terminalBridge.closeSession({ sender: {} }, {
|
|
sessionId: "already-exited",
|
|
bootEpoch: 3,
|
|
});
|
|
|
|
assert.deepEqual(result, { closed: false, reason: "missing" });
|
|
assert.deepEqual(activity, [{ sessionId: "already-exited", phase: "closed" }]);
|
|
});
|
|
|
|
test("direct-mode disconnect close keeps host_open ownership for reconnect", () => {
|
|
const activity = [];
|
|
const sessions = new Map([
|
|
["session-keep", {
|
|
proc: { kill() {} },
|
|
webContentsId: 1,
|
|
}],
|
|
]);
|
|
terminalBridge.init({
|
|
sessions,
|
|
electronModule: { webContents: { fromId: () => ({ isDestroyed: () => true, send() {} }) } },
|
|
reportOpenedSessionActivity: (event) => activity.push(event),
|
|
});
|
|
|
|
const result = terminalBridge.closeSession({ sender: {} }, {
|
|
sessionId: "session-keep",
|
|
retainOwnership: true,
|
|
});
|
|
|
|
assert.deepEqual(result, { closed: true });
|
|
assert.equal(sessions.has("session-keep"), false);
|
|
assert.deepEqual(activity, []);
|
|
});
|
|
|
|
test("direct-mode disconnect close of an already-exited session keeps ownership", () => {
|
|
const activity = [];
|
|
terminalBridge.init({
|
|
sessions: new Map(),
|
|
electronModule: {},
|
|
reportOpenedSessionActivity: (event) => activity.push(event),
|
|
});
|
|
|
|
const result = terminalBridge.closeSession({ sender: {} }, {
|
|
sessionId: "already-exited",
|
|
bootEpoch: 3,
|
|
retainOwnership: true,
|
|
});
|
|
|
|
assert.deepEqual(result, { closed: false, reason: "missing" });
|
|
assert.deepEqual(activity, []);
|
|
});
|
|
|
|
test("stale direct-mode close cannot clean up a newer same-id boot", () => {
|
|
const activity = [];
|
|
const { claimSessionSlot } = require("./sessionBootEpoch.cjs");
|
|
const lifecycle = new Map();
|
|
claimSessionSlot(lifecycle, "reconnected", {}, 4);
|
|
lifecycle.delete("reconnected");
|
|
terminalBridge.init({
|
|
sessions: new Map(),
|
|
electronModule: {},
|
|
reportOpenedSessionActivity: (event) => activity.push(event),
|
|
});
|
|
|
|
const stale = terminalBridge.closeSession({ sender: {} }, {
|
|
sessionId: "reconnected",
|
|
bootEpoch: 3,
|
|
});
|
|
assert.deepEqual(stale, { skipped: true, reason: "boot-epoch-mismatch" });
|
|
assert.deepEqual(activity, []);
|
|
|
|
const current = terminalBridge.closeSession({ sender: {} }, {
|
|
sessionId: "reconnected",
|
|
bootEpoch: 4,
|
|
});
|
|
assert.deepEqual(current, { closed: false, reason: "missing" });
|
|
assert.deepEqual(activity, [{ sessionId: "reconnected", phase: "closed" }]);
|
|
});
|
|
|
|
test("only a submitted non-sensitive user command arms cwd recovery", () => {
|
|
const stream = { write() { return true; } };
|
|
const session = { stream, webContentsId: 1, blockUntargetedCwdProbe: true };
|
|
const sessions = new Map([["session-1", session]]);
|
|
terminalBridge.init({ sessions, electronModule: { webContents: { fromId: () => null } } });
|
|
|
|
terminalBridge.writeToSession({ sender: {} }, {
|
|
sessionId: "session-1", data: "pwd", automated: false,
|
|
});
|
|
assert.notEqual(session.pendingCwdRecoveryAfterUserCommand, true);
|
|
|
|
terminalBridge.writeToSession({ sender: {} }, {
|
|
sessionId: "session-1", data: "secret\r", sensitive: true,
|
|
});
|
|
assert.notEqual(session.pendingCwdRecoveryAfterUserCommand, true);
|
|
|
|
terminalBridge.writeToSession({ sender: {} }, {
|
|
sessionId: "session-1", data: "pwd\r", automated: false,
|
|
});
|
|
assert.equal(session.pendingCwdRecoveryAfterUserCommand, true);
|
|
});
|
|
|
|
test("blocked transfer input and failed writes do not arm cwd recovery", () => {
|
|
const blocked = {
|
|
stream: { write() { throw new Error("must not write during transfer"); } },
|
|
webContentsId: 1,
|
|
blockUntargetedCwdProbe: true,
|
|
zmodemSentry: { isActive: () => true, cancel() {} },
|
|
};
|
|
const failed = {
|
|
stream: { write() { throw Object.assign(new Error("closed"), { code: "EPIPE" }); } },
|
|
webContentsId: 1,
|
|
blockUntargetedCwdProbe: true,
|
|
};
|
|
const sessions = new Map([["blocked", blocked], ["failed", failed]]);
|
|
terminalBridge.init({ sessions, electronModule: { webContents: { fromId: () => null } } });
|
|
|
|
terminalBridge.writeToSession({ sender: {} }, { sessionId: "blocked", data: "pwd\r" });
|
|
terminalBridge.writeToSession({ sender: {} }, { sessionId: "failed", data: "pwd\r" });
|
|
|
|
assert.notEqual(blocked.pendingCwdRecoveryAfterUserCommand, true);
|
|
assert.notEqual(failed.pendingCwdRecoveryAfterUserCommand, true);
|
|
});
|