[Init] Initial commit - NetMesh terminal manager
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
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
This commit is contained in:
140
electron/bridges/terminalOutputChannel.test.cjs
Normal file
140
electron/bridges/terminalOutputChannel.test.cjs
Normal file
@@ -0,0 +1,140 @@
|
||||
const assert = require("node:assert/strict");
|
||||
const test = require("node:test");
|
||||
|
||||
const { createTerminalOutputChannel } = require("./terminalOutputChannel.cjs");
|
||||
|
||||
class FakePort {
|
||||
constructor(label) {
|
||||
this.label = label;
|
||||
this.messages = [];
|
||||
this.closed = false;
|
||||
}
|
||||
|
||||
postMessage(message) {
|
||||
this.messages.push(message);
|
||||
}
|
||||
|
||||
close() {
|
||||
this.closed = true;
|
||||
}
|
||||
}
|
||||
|
||||
class FakeMessageChannelMain {
|
||||
constructor() {
|
||||
this.port1 = new FakePort("port1");
|
||||
this.port2 = new FakePort("port2");
|
||||
}
|
||||
}
|
||||
|
||||
test("openSession posts a dedicated output port to the target webContents", () => {
|
||||
const posted = [];
|
||||
const channel = createTerminalOutputChannel({
|
||||
MessageChannelMain: FakeMessageChannelMain,
|
||||
});
|
||||
const webContents = {
|
||||
id: 42,
|
||||
postMessage(channelName, payload, ports) {
|
||||
posted.push({ channelName, payload, ports });
|
||||
},
|
||||
};
|
||||
|
||||
channel.openSession("session-1", webContents);
|
||||
|
||||
assert.equal(posted.length, 1);
|
||||
assert.equal(posted[0].channelName, "netcatty:terminal-output-port");
|
||||
assert.deepEqual(posted[0].payload, { sessionId: "session-1" });
|
||||
assert.equal(posted[0].ports.length, 1);
|
||||
assert.equal(posted[0].ports[0].label, "port2");
|
||||
});
|
||||
|
||||
test("send posts terminal output over the dedicated port", () => {
|
||||
const channel = createTerminalOutputChannel({
|
||||
MessageChannelMain: FakeMessageChannelMain,
|
||||
});
|
||||
channel.openSession("session-1", { id: 42, postMessage() {} });
|
||||
|
||||
assert.equal(channel.send("session-1", "hello"), true);
|
||||
|
||||
const entry = channel.getSessionForTest("session-1");
|
||||
assert.deepEqual(entry.port.messages, [
|
||||
{ sessionId: "session-1", data: "hello" },
|
||||
]);
|
||||
});
|
||||
|
||||
test("send includes terminal output metadata when present", () => {
|
||||
const channel = createTerminalOutputChannel({
|
||||
MessageChannelMain: FakeMessageChannelMain,
|
||||
});
|
||||
channel.openSession("session-1", { id: 42, postMessage() {} });
|
||||
|
||||
assert.equal(channel.send("session-1", "hello", { droppedOutputMayAffectTerminalState: true }), true);
|
||||
|
||||
const entry = channel.getSessionForTest("session-1");
|
||||
assert.deepEqual(entry.port.messages, [
|
||||
{
|
||||
sessionId: "session-1",
|
||||
data: "hello",
|
||||
meta: { droppedOutputMayAffectTerminalState: true },
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
test("openSession can reserve the output port for transfer to a worker", () => {
|
||||
const channel = createTerminalOutputChannel({
|
||||
MessageChannelMain: FakeMessageChannelMain,
|
||||
});
|
||||
const workerPort = channel.openSession("session-1", { id: 42, postMessage() {} }, {
|
||||
transferToWorker: true,
|
||||
});
|
||||
|
||||
assert.equal(workerPort.label, "port1");
|
||||
assert.equal(channel.send("session-1", "hello"), false);
|
||||
});
|
||||
|
||||
test("closeSession closes the output port and drops later output", () => {
|
||||
const channel = createTerminalOutputChannel({
|
||||
MessageChannelMain: FakeMessageChannelMain,
|
||||
});
|
||||
channel.openSession("session-1", { id: 42, postMessage() {} });
|
||||
const entry = channel.getSessionForTest("session-1");
|
||||
|
||||
channel.closeSession("session-1");
|
||||
|
||||
assert.equal(entry.port.closed, true);
|
||||
assert.equal(channel.send("session-1", "late"), false);
|
||||
assert.equal(channel.getSessionForTest("session-1"), undefined);
|
||||
});
|
||||
|
||||
test("opening a replacement session closes the stale output port", () => {
|
||||
const channel = createTerminalOutputChannel({
|
||||
MessageChannelMain: FakeMessageChannelMain,
|
||||
});
|
||||
channel.openSession("session-1", { id: 42, postMessage() {} });
|
||||
const stale = channel.getSessionForTest("session-1");
|
||||
|
||||
channel.openSession("session-1", { id: 42, postMessage() {} });
|
||||
|
||||
assert.equal(stale.port.closed, true);
|
||||
assert.notEqual(channel.getSessionForTest("session-1"), stale);
|
||||
});
|
||||
|
||||
test("a failed replacement transfer preserves the existing output route", () => {
|
||||
const channel = createTerminalOutputChannel({
|
||||
MessageChannelMain: FakeMessageChannelMain,
|
||||
});
|
||||
channel.openSession("session-1", { id: 42, postMessage() {} });
|
||||
const existing = channel.getSessionForTest("session-1");
|
||||
|
||||
assert.throws(() => {
|
||||
channel.openSession("session-1", {
|
||||
id: 43,
|
||||
postMessage() {
|
||||
throw new Error("renderer transfer failed");
|
||||
},
|
||||
});
|
||||
}, /renderer transfer failed/u);
|
||||
|
||||
assert.equal(channel.getSessionForTest("session-1"), existing);
|
||||
assert.equal(existing.port.closed, false);
|
||||
assert.equal(channel.send("session-1", "still-routed"), true);
|
||||
});
|
||||
Reference in New Issue
Block a user