Files
orca/tests/e2e/helpers/docker-ssh-remote-shell-pid.ts
T
NeilandOrca 6b6a3b666a test(ssh): add MaxSessions, lazy-discovery and paired-skew oracles
Three journeys attempted; none promoted, and the reasons are recorded in
the ledger rather than rounded up.

MaxSessions=1 against real OpenSSH, with the cap read back from `sshd -T`
rather than assumed, and remote pids read on the container two
independent ways that must agree, each carrying its kernel start time.
Two disjoint mutations discriminate — one reddens only the reconnect
clause, the other only the two restart clauses. But the disconnect clause
is a forward guard: four separate guard removals left it green, so
nothing shipped is load-bearing for it.

Lazy discovery samples sshd's own accept log and live session census
across a 22s window with the in-use host as a positive control. No
mutation reddens its third clause alone — the real cross-host lease
scoping is load-bearing, but removing it breaks the sibling host during
setup, so the failure carries no clause information.

The paired-runtime skew spec pairs two real processes at different
versions and refuses to run rather than degrade into a same-version
pairing that would look green and prove nothing.

No production code changes.

Co-authored-by: Orca <help@stably.ai>
2026-08-08 19:11:54 -07:00

65 lines
2.2 KiB
TypeScript

/**
* Asks a remote pane's own shell for its pid, through the production write path.
*
* Why not read it from app state: a pane id, a leaf id and a PTY id can all
* match while a different process runs underneath. The shell answers on the
* container's filesystem, so the pid is observed where the process actually
* lives — and a pane that no longer reaches its shell cannot answer at all.
*/
import type { Page } from '@stablyai/playwright-test'
import { expect } from '@stablyai/playwright-test'
import { sendToTerminal } from './terminal'
import {
execDockerSshRelayTargetCommand,
shellQuote,
type DockerSshRelayTarget
} from './docker-ssh-relay-target'
function readRemoteFile(target: DockerSshRelayTarget, remotePath: string): string | null {
try {
return execDockerSshRelayTargetCommand(target, `cat ${shellQuote(remotePath)}`)
} catch {
return null
}
}
/**
* `probePath` must be unique per probe: a stale file from an earlier phase would
* answer for a shell that is no longer there.
*/
export async function readRemoteShellPid(
page: Page,
target: DockerSshRelayTarget,
args: { ptyId: string; probePath: string; timeoutMs?: number }
): Promise<number> {
if (readRemoteFile(target, args.probePath) !== null) {
throw new Error(`Remote shell pid probe path already exists: ${args.probePath}`)
}
// Write-then-rename: the redirect creates the file before printf fills it, and
// a poll that caught it empty would read pid 0.
await sendToTerminal(
page,
args.ptyId,
`printf '%s\\n' "$$" > ${args.probePath}.part && mv ${args.probePath}.part ${args.probePath}\r`
)
let pid: number | null = null
await expect
.poll(
() => {
const raw = readRemoteFile(target, args.probePath)
const parsed = raw === null ? Number.NaN : Number(raw.trim())
pid = Number.isInteger(parsed) && parsed > 0 ? parsed : null
return pid
},
{
timeout: args.timeoutMs ?? 60_000,
message: `Remote pane ${args.ptyId} never reported its shell pid to ${args.probePath}`
}
)
.not.toBeNull()
if (pid === null) {
throw new Error(`Remote pane ${args.ptyId} reported no shell pid`)
}
return pid
}