Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.
TypeScript adhdagent-orchestrationai-agentscanvasclaude-codecodexcoding-agentsdeveloper-toolselectrongeminilinuxmacosmultiplexeropencodeparallel-agentsterminalterminal-emulatorterminal-multiplexertmuxworkspace-manager
test: remove three sources of random CI failures
Fabricio Casali940059755cac
diff --git a/src/core/agent-launch.test.ts b/src/core/agent-launch.test.tsindex b2b996a1e..71ceb5ad6 100644--- a/src/core/agent-launch.test.ts+++ b/src/core/agent-launch.test.ts@@ -714,7 +714,12 @@ function executeWindowsPlan(return JSON.parse(result.stdout) as string[];}-describe.runIf(WINDOWS)("real Windows shell argv behavior", () => {+// Each case spawns a real shell (and Git Bash a node child) once per prompt; on a loaded+// windows-latest runner that sat right at the 5 s default and timed out at random. Same+// Windows-sized budget as remote-atomic-write's real-shell cases.+const REAL_SHELL_TIMEOUT_MS = 30_000++describe.runIf(WINDOWS)("real Windows shell argv behavior", { timeout: REAL_SHELL_TIMEOUT_MS }, () => {const windowsCases: Array<[AgentLaunchDialect, string | null]> = [["pwsh", PWSH],["windows-powershell", WINDOWS_POWERSHELL],@@ -821,6 +826,7 @@ describe.runIf(WINDOWS)("real Windows shell argv behavior", () => {describe.runIf(WINDOWS && WSL_DISTROS.length > 0)("real WSL POSIX argv behavior",+ { timeout: REAL_SHELL_TIMEOUT_MS },() => {it.each(WSL_DISTROS)("%s delivers the metacharacter and Unicode matrix exactly",diff --git a/src/core/remote-ssh/native/agent-add.test.ts b/src/core/remote-ssh/native/agent-add.test.tsindex 96e893bcd..cbd7e24c3 100644--- a/src/core/remote-ssh/native/agent-add.test.ts+++ b/src/core/remote-ssh/native/agent-add.test.ts@@ -25,6 +25,7 @@ import {SSH_AGENT_SUCCESS} from './agent-add'import { findExecutableSync } from '../../exec-path'+import { ed25519KeyPair } from './test-keys'function parsed(k: string, pass?: string): ParsedKey {const p = utils.parseKey(k, pass)@@ -35,7 +36,7 @@ function parsed(k: string, pass?: string): ParsedKey {const PASS = 'pw'const KEYS: Record<string, ParsedKey> = {- ed25519: parsed(utils.generateKeyPairSync('ed25519', { passphrase: PASS, cipher: 'aes256-ctr', rounds: 4 }).private, PASS),+ ed25519: parsed(ed25519KeyPair({ passphrase: PASS, cipher: 'aes256-ctr', rounds: 4 }).private, PASS),ecdsa256: parsed(utils.generateKeyPairSync('ecdsa', { bits: 256, passphrase: PASS, cipher: 'aes256-ctr', rounds: 4 }).private, PASS),ecdsa384: parsed(utils.generateKeyPairSync('ecdsa', { bits: 384 }).private),ecdsa521: parsed(utils.generateKeyPairSync('ecdsa', { bits: 521 }).private),diff --git a/src/core/remote-ssh/native/native-invoke.test.ts b/src/core/remote-ssh/native/native-invoke.test.tsindex ab04ed29a..700dbe9f4 100644--- a/src/core/remote-ssh/native/native-invoke.test.ts+++ b/src/core/remote-ssh/native/native-invoke.test.ts@@ -3,7 +3,7 @@ import fs from 'fs'import os from 'os'import net, { type AddressInfo } from 'net'import path from 'path'-import { Server, utils, type Connection } from 'ssh2'+import { Server, type Connection } from 'ssh2'import { NativeMux } from './native-mux'import { runSshArgv, spawnSshArgvStream, startNativeMaster, useNativeSsh } from './native-invoke'import {@@ -15,9 +15,10 @@ import {masterArgs} from '../control-master'import type { SshConnection } from '../../../shared/ssh'+import { ed25519KeyPair } from './test-keys'-const hostKey = utils.generateKeyPairSync('ed25519')-const clientKey = utils.generateKeyPairSync('ed25519')+const hostKey = ed25519KeyPair()+const clientKey = ed25519KeyPair()let dir: stringlet server: Serverdiff --git a/src/core/remote-ssh/native/native-jump.test.ts b/src/core/remote-ssh/native/native-jump.test.tsindex 56107881c..26d48026c 100644--- a/src/core/remote-ssh/native/native-jump.test.ts+++ b/src/core/remote-ssh/native/native-jump.test.ts@@ -14,10 +14,11 @@ import { parseSshArgv } from './ssh-argv'import { childArgs } from '../control-master'import { parseProxyJump, sshGArgs, type HostQuery, type ResolvedHost } from './ssh-config'import type { SshConnection } from '../../../shared/ssh'+import { ed25519KeyPair } from './test-keys'-const clientKey = utils.generateKeyPairSync('ed25519') // the target accepts only this-const jumpKey = utils.generateKeyPairSync('ed25519') // the jumps accept only this-const strangerKey = utils.generateKeyPairSync('ed25519')+const clientKey = ed25519KeyPair() // the target accepts only this+const jumpKey = ed25519KeyPair() // the jumps accept only this+const strangerKey = ed25519KeyPair()interface Peer {name: string@@ -39,7 +40,7 @@ function pubMatches(offered: { algo: string; data: Buffer }, pub: string): boole}function startPeer(name: string, acceptKey: string, isJump: boolean): Promise<Peer> {- const hostKey = utils.generateKeyPairSync('ed25519')+ const hostKey = ed25519KeyPair()const peer: Peer = { name, server: null as unknown as Server, port: 0, hostKey, logins: 0, live: [], forwards: [], limit: Infinity }peer.server = new Server({ hostKeys: [hostKey.private] }, (client) => {peer.live.push(client)@@ -187,7 +188,7 @@ describe('NativeMux over a ProxyJump chain', () => {})it('refuses a CHANGED host key on the jump, before the target is ever reached', async () => {- fs.writeFileSync(kh(), `[127.0.0.1]:${jump1.port} ${utils.generateKeyPairSync('ed25519').public}\n`)+ fs.writeFileSync(kh(), `[127.0.0.1]:${jump1.port} ${ed25519KeyPair().public}\n`)const r = await mux().exec(exec('echo hi'))expect(r.code).toBe(255)expect(r.stderr.toString()).toMatch(/jump host jump1: .*REMOTE HOST IDENTIFICATION HAS CHANGED/)diff --git a/src/core/remote-ssh/native/native-mux.test.ts b/src/core/remote-ssh/native/native-mux.test.tsindex f9c3e306c..fa9d82e43 100644--- a/src/core/remote-ssh/native/native-mux.test.ts+++ b/src/core/remote-ssh/native/native-mux.test.ts@@ -13,11 +13,12 @@ import { parseSshArgv } from './ssh-argv'import { childArgs, masterRoundTripArgs, remoteTmuxPtyArgs } from '../control-master'import type { ResolvedHost } from './ssh-config'import type { SshConnection } from '../../../shared/ssh'+import { ed25519KeyPair } from './test-keys'-const hostKey = utils.generateKeyPairSync('ed25519')-const otherHostKey = utils.generateKeyPairSync('ed25519')-const clientKey = utils.generateKeyPairSync('ed25519')-const lockedKey = utils.generateKeyPairSync('ed25519', { passphrase: 'open sesame', cipher: 'aes256-cbc', rounds: 4 })+const hostKey = ed25519KeyPair()+const otherHostKey = ed25519KeyPair()+const clientKey = ed25519KeyPair()+const lockedKey = ed25519KeyPair({ passphrase: 'open sesame', cipher: 'aes256-cbc', rounds: 4 })let dir: stringlet server: Serverdiff --git a/src/core/remote-ssh/native/native-overflow.test.ts b/src/core/remote-ssh/native/native-overflow.test.tsindex 2fe891df6..f464f890f 100644--- a/src/core/remote-ssh/native/native-overflow.test.ts+++ b/src/core/remote-ssh/native/native-overflow.test.ts@@ -9,15 +9,16 @@ import fs from 'fs'import os from 'os'import path from 'path'import type { AddressInfo } from 'net'-import { Server, utils, type Connection } from 'ssh2'+import { Server, type Connection } from 'ssh2'import { NativeMux } from './native-mux'import { parseSshArgv } from './ssh-argv'import { childArgs, remoteTmuxPtyArgs } from '../control-master'import type { SshConnection } from '../../../shared/ssh'+import { ed25519KeyPair } from './test-keys'const LIMIT = 3-const hostKey = utils.generateKeyPairSync('ed25519')-const clientKey = utils.generateKeyPairSync('ed25519')+const hostKey = ed25519KeyPair()+const clientKey = ed25519KeyPair()let dir: stringlet server: Serverlet port: numberdiff --git a/src/core/remote-ssh/native/native-pty.test.ts b/src/core/remote-ssh/native/native-pty.test.tsindex 330a63d32..02976204a 100644--- a/src/core/remote-ssh/native/native-pty.test.ts+++ b/src/core/remote-ssh/native/native-pty.test.ts@@ -3,14 +3,15 @@ import fs from 'fs'import os from 'os'import path from 'path'import type { AddressInfo } from 'net'-import { Server, utils, type Connection, type ServerChannel } from 'ssh2'+import { Server, type Connection, type ServerChannel } from 'ssh2'import { NativeMux } from './native-mux'import { NativeSshPty } from './native-pty'import { remoteTmuxPtyArgs } from '../control-master'import type { SshConnection } from '../../../shared/ssh'+import { ed25519KeyPair } from './test-keys'-const hostKey = utils.generateKeyPairSync('ed25519')-const clientKey = utils.generateKeyPairSync('ed25519')+const hostKey = ed25519KeyPair()+const clientKey = ed25519KeyPair()let dir: stringlet server: Serverlet port: numberdiff --git a/src/core/remote-ssh/native/test-keys.ts b/src/core/remote-ssh/native/test-keys.tsnew file mode 100644index 000000000..cd8c0ff62--- /dev/null+++ b/src/core/remote-ssh/native/test-keys.ts@@ -0,0 +1,24 @@+// Test helper: an Ed25519 key pair that ssh2 can read back.+//+// ssh2 1.17's `utils.generateKeyPairSync('ed25519')` strips every leading zero byte from the+// public key's DER BIT STRING, so a public key that itself starts with 0x00 (1 in 256) comes out+// 31 bytes long and the private key fails to parse ("Malformed OpenSSH private key"). MEASURED on+// this repo's ssh2: 67 of 20,000 generated keys. The native-SSH suites generate ~20 keys per run,+// which made roughly one CI run in 15 fail at random. Nothing outside tests generates keys this+// way. Same workaround as https://github.com/arjitc/ElectroSSH/pull/15: generate, parse back,+// retry.++import { utils } from 'ssh2'++type Ed25519Options = Parameters<typeof utils.generateKeyPairSync<'ed25519'>>[1]++export function ed25519KeyPair(opts?: Ed25519Options): utils.KeyPairReturn {+ const passphrase = opts && 'passphrase' in opts ? opts.passphrase : undefined+ for (let attempt = 0; attempt < 10; attempt++) {+ const pair = utils.generateKeyPairSync('ed25519', opts)+ if (!(utils.parseKey(pair.private, passphrase) instanceof Error) && !(utils.parseKey(pair.public) instanceof Error)) {+ return pair+ }+ }+ throw new Error('ssh2 produced 10 unreadable Ed25519 keys in a row')+}diff --git a/src/server/headless-node-factory.test.ts b/src/server/headless-node-factory.test.tsindex eab324aaf..9447b8982 100644--- a/src/server/headless-node-factory.test.ts+++ b/src/server/headless-node-factory.test.ts@@ -1610,10 +1610,16 @@ describe('HeadlessNodeFactory', () => {const pending = factory.openAgent('term-source', { agent: 'claude', prompt: 'x'.repeat(1100) }, true).finally(() => (settled = true))- for (let i = 0; i < 400 && !settled; i++) {+ // Bounded by REAL time, not by a turn count: on a loaded CI runner the store's file I/O can+ // need more turns than any fixed count, and a loop that gave up early left `await pending`+ // waiting on faked timers nothing advances: a hang until the 5 s test timeout, with the fake+ // timers then leaking into the next test (two red tests per run). `Date` is not faked here.+ const deadline = Date.now() + 4000+ while (!settled && Date.now() < deadline) {await new Promise((r) => setImmediate(r))await vi.advanceTimersByTimeAsync(100)}+ if (!settled) throw new Error('openAgent did not settle within 4 s of real time')reply = await pending} finally {vi.useRealTimers()