diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6951ed35b..1ddc4a200 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -82,4 +82,5 @@ jobs: NETCATTY_TEST_MOSH_SSH_EXE: ${{ runner.temp }}\netcatty-mosh-conpty\ssh.exe NETCATTY_TEST_MOSH_CLIENT_EXE: ${{ runner.temp }}\netcatty-mosh-conpty\mosh-client.exe run: | - node --test electron/bridges/moshHandshake.test.cjs electron/bridges/terminalBridge.moshConpty.integration.test.cjs + node --test electron/bridges/moshHandshake.test.cjs + node electron/bridges/terminalBridge.moshConpty.integration.cjs diff --git a/electron/bridges/terminalBridge.moshConpty.integration.test.cjs b/electron/bridges/terminalBridge.moshConpty.integration.cjs similarity index 51% rename from electron/bridges/terminalBridge.moshConpty.integration.test.cjs rename to electron/bridges/terminalBridge.moshConpty.integration.cjs index 0b144756e..e36bde2aa 100644 --- a/electron/bridges/terminalBridge.moshConpty.integration.test.cjs +++ b/electron/bridges/terminalBridge.moshConpty.integration.cjs @@ -1,6 +1,5 @@ "use strict"; -const test = require("node:test"); const assert = require("node:assert/strict"); const fs = require("node:fs"); const os = require("node:os"); @@ -24,9 +23,8 @@ function waitFor(predicate, description, timeoutMs = 15_000) { }); } -test("Windows ConPTY completes password handshake and switches to mosh-client", { - skip: process.platform !== "win32" ? "Windows ConPTY only" : false, -}, async (t) => { +async function main() { + assert.equal(process.platform, "win32", "Windows ConPTY only"); const fakeSsh = process.env.NETCATTY_TEST_MOSH_SSH_EXE; const fakeClient = process.env.NETCATTY_TEST_MOSH_CLIENT_EXE; assert.ok(fakeSsh && fs.existsSync(fakeSsh), "compiled fake ssh executable is required"); @@ -60,62 +58,70 @@ test("Windows ConPTY completes password handshake and switches to mosh-client", }, }); - t.after(() => { + try { + const sessionId = "mosh-conpty-integration"; + await bridge.startMoshSession( + { sender: { id: 77 } }, + { + sessionId, + hostname: "example.com", + username: "alice", + authMethod: "password", + password: "netcatty-test-password", + cols: 80, + rows: 24, + env: { PATH: process.env.PATH }, + }, + { + moshClientLookup: { + platform: "win32", + arch: "x64", + projectRoot: path.join(tmp, "project"), + resourcesPath, + }, + }, + ); + + await waitFor( + () => sent.some((entry) => entry.channel === "netcatty:mosh:ready"), + "mosh ready event", + ); + await waitFor( + () => sent.some((entry) => entry.channel === "netcatty:data" + && String(entry.payload?.data).includes("MOSHCATTY_TEST_READY")), + "mosh-client output", + ); + + const output = sent + .filter((entry) => entry.channel === "netcatty:data") + .map((entry) => String(entry.payload?.data || "")) + .join(""); + assert.match(output, /key=ABCDEFGHIJKLMNOPQRSTUV==/); + assert.match(output, /args=127\.0\.0\.1\|60002/); + assert.match(output, /fallback=example\.com/); + assert.equal(sessions.get(sessionId)?.moshHandshakePhase, "mosh-client"); + + bridge.writeToSession(null, { sessionId, data: "hello-from-conpty\r" }); + await waitFor( + () => sent.some((entry) => entry.channel === "netcatty:data" + && String(entry.payload?.data).includes("MOSHCATTY_TEST_ECHO=hello-from-conpty")), + "input routed to mosh-client", + ); + + bridge.writeToSession(null, { sessionId, data: "quit\r" }); + await waitFor(() => !sessions.has(sessionId), "mosh-client exit"); + } finally { bridge.cleanupAllSessions(); process.env.PATH = oldPath; delete require.cache[bridgePath]; fs.rmSync(tmp, { recursive: true, force: true }); - }); + } +} - const sessionId = "mosh-conpty-integration"; - await bridge.startMoshSession( - { sender: { id: 77 } }, - { - sessionId, - hostname: "example.com", - username: "alice", - authMethod: "password", - password: "netcatty-test-password", - cols: 80, - rows: 24, - env: { PATH: process.env.PATH }, - }, - { - moshClientLookup: { - platform: "win32", - arch: "x64", - projectRoot: path.join(tmp, "project"), - resourcesPath, - }, - }, - ); - - await waitFor( - () => sent.some((entry) => entry.channel === "netcatty:mosh:ready"), - "mosh ready event", - ); - await waitFor( - () => sent.some((entry) => entry.channel === "netcatty:data" - && String(entry.payload?.data).includes("MOSHCATTY_TEST_READY")), - "mosh-client output", - ); - - const output = sent - .filter((entry) => entry.channel === "netcatty:data") - .map((entry) => String(entry.payload?.data || "")) - .join(""); - assert.match(output, /key=ABCDEFGHIJKLMNOPQRSTUV==/); - assert.match(output, /args=127\.0\.0\.1\|60002/); - assert.match(output, /fallback=example\.com/); - assert.equal(sessions.get(sessionId)?.moshHandshakePhase, "mosh-client"); - - bridge.writeToSession(null, { sessionId, data: "hello-from-conpty\r" }); - await waitFor( - () => sent.some((entry) => entry.channel === "netcatty:data" - && String(entry.payload?.data).includes("MOSHCATTY_TEST_ECHO=hello-from-conpty")), - "input routed to mosh-client", - ); - - bridge.writeToSession(null, { sessionId, data: "quit\r" }); - await waitFor(() => !sessions.has(sessionId), "mosh-client exit"); +main().then(() => { + console.log("Windows ConPTY Mosh handoff passed"); + process.exit(0); +}).catch((err) => { + console.error(err); + process.exit(1); });