[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:
219
electron/terminalWorker/process.test.cjs
Normal file
219
electron/terminalWorker/process.test.cjs
Normal file
@@ -0,0 +1,219 @@
|
||||
const assert = require("node:assert/strict");
|
||||
const crypto = require("node:crypto");
|
||||
const test = require("node:test");
|
||||
|
||||
const {
|
||||
createZmodemDownloadDirectorySelector,
|
||||
createZmodemUploadFileSelector,
|
||||
normalizeParentPortMessage,
|
||||
registerExternalSessionHandlers,
|
||||
} = require("./process.cjs");
|
||||
|
||||
function createParentPort() {
|
||||
const messages = [];
|
||||
const listeners = new Map();
|
||||
return {
|
||||
messages,
|
||||
on(channel, callback) {
|
||||
listeners.set(channel, callback);
|
||||
},
|
||||
postMessage(message) {
|
||||
messages.push(message);
|
||||
},
|
||||
emitMessage(message) {
|
||||
listeners.get("message")?.(message);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
test("normalizeParentPortMessage unwraps Electron utility process MessageEvent data", () => {
|
||||
assert.deepEqual(
|
||||
normalizeParentPortMessage({ data: { kind: "zmodem-upload-dialog-result" } }),
|
||||
{ kind: "zmodem-upload-dialog-result" },
|
||||
);
|
||||
assert.deepEqual(
|
||||
normalizeParentPortMessage({ kind: "request" }),
|
||||
{ kind: "request" },
|
||||
);
|
||||
});
|
||||
|
||||
test("terminal worker installs DH compatibility before SSH bridges load", () => {
|
||||
assert.equal(crypto.createDiffieHellmanGroup.__boringSslDhCompat, true);
|
||||
});
|
||||
|
||||
test("ZMODEM upload selector resolves dialog results delivered as MessageEvent data", async () => {
|
||||
const parentPort = createParentPort();
|
||||
const selectUploadFiles = createZmodemUploadFileSelector(parentPort, {
|
||||
randomUUID: () => "dialog-1",
|
||||
});
|
||||
|
||||
const promise = selectUploadFiles(7, "session-1");
|
||||
assert.deepEqual(parentPort.messages, [{
|
||||
kind: "zmodem-upload-dialog",
|
||||
requestId: "dialog-1",
|
||||
webContentsId: 7,
|
||||
sessionId: "session-1",
|
||||
}]);
|
||||
|
||||
parentPort.emitMessage({
|
||||
data: {
|
||||
kind: "zmodem-upload-dialog-result",
|
||||
requestId: "dialog-1",
|
||||
result: { canceled: false, filePaths: ["/tmp/upload.txt"] },
|
||||
},
|
||||
});
|
||||
|
||||
assert.deepEqual(await promise, {
|
||||
canceled: false,
|
||||
filePaths: ["/tmp/upload.txt"],
|
||||
});
|
||||
});
|
||||
|
||||
test("ZMODEM download selector resolves directory dialog results delivered as MessageEvent data", async () => {
|
||||
const parentPort = createParentPort();
|
||||
const selectDownloadDirectory = createZmodemDownloadDirectorySelector(parentPort, {
|
||||
randomUUID: () => "download-dialog-1",
|
||||
});
|
||||
|
||||
const promise = selectDownloadDirectory(7, "session-1");
|
||||
assert.deepEqual(parentPort.messages, [{
|
||||
kind: "zmodem-download-dialog",
|
||||
requestId: "download-dialog-1",
|
||||
webContentsId: 7,
|
||||
sessionId: "session-1",
|
||||
}]);
|
||||
|
||||
parentPort.emitMessage({
|
||||
data: {
|
||||
kind: "zmodem-download-dialog-result",
|
||||
requestId: "download-dialog-1",
|
||||
result: { canceled: false, filePaths: ["/tmp/downloads"] },
|
||||
},
|
||||
});
|
||||
|
||||
assert.deepEqual(await promise, {
|
||||
canceled: false,
|
||||
filePaths: ["/tmp/downloads"],
|
||||
});
|
||||
});
|
||||
|
||||
test("external plugin sessions stream auto-save logs through output and lifecycle cleanup", async () => {
|
||||
const handlers = new Map();
|
||||
const sessions = new Map();
|
||||
const parentPort = createParentPort();
|
||||
const observed = [];
|
||||
const token = Symbol("plugin-session-log");
|
||||
const sessionLogStreamManager = {
|
||||
startStream(sessionId, options) {
|
||||
observed.push(["start-log", sessionId, options]);
|
||||
return token;
|
||||
},
|
||||
appendData(sessionId, data) {
|
||||
observed.push(["append-log", sessionId, data]);
|
||||
},
|
||||
async stopStream(sessionId, expectedToken) {
|
||||
observed.push(["stop-log", sessionId, expectedToken]);
|
||||
},
|
||||
};
|
||||
registerExternalSessionHandlers({
|
||||
handle(channel, handler) {
|
||||
handlers.set(channel, handler);
|
||||
},
|
||||
}, {
|
||||
sessions,
|
||||
parentPort,
|
||||
sessionLogStreamManager,
|
||||
});
|
||||
const sender = {
|
||||
id: 7,
|
||||
send(channel, payload) {
|
||||
observed.push(["send", channel, payload]);
|
||||
},
|
||||
};
|
||||
|
||||
assert.deepEqual(await handlers.get("netcatty:external:start")({ sender }, {
|
||||
sessionId: "plugin-log-1",
|
||||
protocol: "plugin:com.example.transport.connection",
|
||||
hostLabel: "Example transport",
|
||||
hostname: "example.test",
|
||||
columns: 80,
|
||||
rows: 24,
|
||||
sessionLog: {
|
||||
enabled: true,
|
||||
directory: "/logs",
|
||||
format: "html",
|
||||
timestampsEnabled: true,
|
||||
},
|
||||
}), { sessionId: "plugin-log-1" });
|
||||
assert.equal(observed[0][0], "start-log");
|
||||
assert.deepEqual(observed[0].slice(1, 3), [
|
||||
"plugin-log-1",
|
||||
{
|
||||
hostLabel: "Example transport",
|
||||
hostname: "example.test",
|
||||
directory: "/logs",
|
||||
format: "html",
|
||||
timestampsEnabled: true,
|
||||
startTime: observed[0][2].startTime,
|
||||
},
|
||||
]);
|
||||
|
||||
await handlers.get("netcatty:external:output")({ sender }, {
|
||||
sessionId: "plugin-log-1",
|
||||
data: "provider output",
|
||||
});
|
||||
assert.deepEqual(observed.slice(1, 3), [
|
||||
["append-log", "plugin-log-1", "provider output"],
|
||||
["send", "netcatty:data", {
|
||||
sessionId: "plugin-log-1",
|
||||
data: "provider output",
|
||||
}],
|
||||
]);
|
||||
|
||||
await assert.rejects(
|
||||
handlers.get("netcatty:external:output")({ sender }, {
|
||||
sessionId: "plugin-log-1",
|
||||
data: Buffer.from("not a decoded provider string"),
|
||||
}),
|
||||
/output is invalid/,
|
||||
);
|
||||
assert.equal(observed.length, 3);
|
||||
|
||||
await handlers.get("netcatty:external:finish")({ sender }, {
|
||||
sessionId: "plugin-log-1",
|
||||
reason: "closed",
|
||||
diagnostics: [{ severity: "warning", message: "Provider closed after idle timeout" }],
|
||||
});
|
||||
assert.deepEqual(observed.slice(3), [
|
||||
["stop-log", "plugin-log-1", token],
|
||||
["send", "netcatty:exit", {
|
||||
sessionId: "plugin-log-1",
|
||||
exitCode: 0,
|
||||
reason: "closed",
|
||||
diagnostics: [{ severity: "warning", message: "Provider closed after idle timeout" }],
|
||||
}],
|
||||
]);
|
||||
assert.equal(sessions.has("plugin-log-1"), false);
|
||||
|
||||
await handlers.get("netcatty:external:start")({ sender }, {
|
||||
sessionId: "plugin-log-2",
|
||||
protocol: "plugin:com.example.transport.connection",
|
||||
hostLabel: "Example transport",
|
||||
hostname: "example.test",
|
||||
columns: 80,
|
||||
rows: 24,
|
||||
sessionLog: {
|
||||
enabled: true,
|
||||
directory: "/logs",
|
||||
format: "txt",
|
||||
},
|
||||
});
|
||||
sessions.get("plugin-log-2").stream.close();
|
||||
await new Promise((resolve) => setImmediate(resolve));
|
||||
assert.equal(
|
||||
observed.some((entry) => entry[0] === "stop-log"
|
||||
&& entry[1] === "plugin-log-2"
|
||||
&& entry[2] === token),
|
||||
true,
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user