Skip to content

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.

test: isolate server validation from live host state

freshjuiceze295e01ad1f2
diff --git a/src/core/agents/hooks/opencode.test.ts b/src/core/agents/hooks/opencode.test.ts
index 7bc8e6267..cf8b3dc34 100644
--- a/src/core/agents/hooks/opencode.test.ts
+++ b/src/core/agents/hooks/opencode.test.ts
@@ -82,6 +82,9 @@ describe('generated plugin behavior (executed)', () => {
vi.stubEnv('NODETERM_HOOK_PORT', '43210')
vi.stubEnv('NODETERM_HOOK_TOKEN', 'tok')
vi.stubEnv('NODETERM_HOOK_ENDPOINT', '')
+ // A developer may be running this test from a live nodeterm PTY. Never let the
+ // generated plugin inherit that session's socket and post test events to it.
+ vi.stubEnv('NODETERM_HOOK_SOCK', '')
const file = path.join(tmp, `plugin-under-test-${Math.random().toString(36).slice(2)}.mjs`)
fs.writeFileSync(file, buildOpencodePlugin())
const mod = await import(/* @vite-ignore */ `file://${file}`)
diff --git a/src/core/git-service.worktree-remote.test.ts b/src/core/git-service.worktree-remote.test.ts
index 4534163a3..4556ee46d 100644
--- a/src/core/git-service.worktree-remote.test.ts
+++ b/src/core/git-service.worktree-remote.test.ts
@@ -23,7 +23,14 @@ const svc = new GitService()
/** Make the resolver claim exactly `repoPath` — i.e. "this repo lives on an SSH host". */
function claimAsRemote(repoPath: string): void {
setGitRemoteResolver((cwd) =>
- cwd === repoPath ? { conn: { host: 'h', user: 'u' }, controlPath: '/tmp/cm.sock' } : undefined
+ cwd === repoPath
+ ? {
+ // An invalid port makes any accidental SSH execution fail locally and immediately.
+ // Do not depend on DNS/network timeouts or contact an external host from this test.
+ conn: { host: '127.0.0.1', user: 'u', port: 65_536 },
+ controlPath: path.join(repoPath, 'missing-control.sock')
+ }
+ : undefined
)
}
@@ -119,7 +126,7 @@ describe('history routing', () => {
})
it('a remote-claimed repo never gets LOCAL git run against its (remote) path', async () => {
- claimAsRemote(repo) // bogus master socket → the remote git fails
+ claimAsRemote(repo) // invalid local-only SSH endpoint → the remote git fails
// The invariant is "the local repo's commits are never served as if they were the host's".
// With every remote call failing, the loader lands on its empty result (or throws) — either
// reads as a failed load; what it must NOT contain is the LOCAL repo's history.
diff --git a/test/server/headless-e2e.test.ts b/test/server/headless-e2e.test.ts
index 319751e15..2e9fba99b 100644
--- a/test/server/headless-e2e.test.ts
+++ b/test/server/headless-e2e.test.ts
@@ -5,15 +5,33 @@ import path from 'path'
import net from 'net'
import { startServer } from '../../src/server/index'
+async function unusedLoopbackPort(): Promise<number> {
+ const probe = net.createServer()
+ await new Promise<void>((resolve, reject) => {
+ probe.once('error', reject)
+ probe.listen(0, '127.0.0.1', resolve)
+ })
+ const address = probe.address()
+ if (address === null || typeof address === 'string') {
+ probe.close()
+ throw new Error('failed to reserve a loopback test port')
+ }
+ await new Promise<void>((resolve, reject) =>
+ probe.close((error) => (error ? reject(error) : resolve()))
+ )
+ return address.port
+}
+
// Headless notification-host boot smoke: every core service (incl. the loopback hook server) boots,
// but NO public HTTP/WS listener is bound. Follows the same startServer harness as server-e2e, minus
// tmux/pty (nothing is spawned here), so it runs everywhere.
describe('server headless mode: boots core services, binds no public listener', () => {
it('startServer with headless:true returns port 0 and closes cleanly', async () => {
const dataDir = fs.mkdtempSync(path.join(os.tmpdir(), 'nt-headless-'))
+ const sentinelPort = await unusedLoopbackPort()
try {
const srv = await startServer({
- port: 8443,
+ port: sentinelPort,
host: '127.0.0.1',
dataDir,
rendererDir: path.join(dataDir, 'no-renderer'),
@@ -25,10 +43,10 @@ describe('server headless mode: boots core services, binds no public listener',
})
// Nothing bound: the sentinel port is 0.
expect(srv.port).toBe(0)
- // And the configured port (8443) is NOT listening — a connect attempt is refused.
+ // And the configured ephemeral port is NOT listening — a connect attempt is refused.
const listening = await new Promise<boolean>((resolve) => {
const sock = net
- .connect({ host: '127.0.0.1', port: 8443 }, () => {
+ .connect({ host: '127.0.0.1', port: sentinelPort }, () => {
sock.destroy()
resolve(true)
})