test(terminal): make the restart identity spec run on Windows too

Both probes were POSIX-only and unconditional: `echo ...=\$\$` for the
shell's own pid, and `ps -o lstart=` for its start time. Running the spec
on a real Windows host proved it dies before reaching either guard, so
Journey 1's Windows half was unprovable rather than merely unproven.

PowerShell exposes the same two facts as `$PID` and `Get-Process`
StartTime. The start time still matters on both platforms for the same
reason: a PID alone cannot separate a survivor from a reused number.

Still green on macOS. The Windows path is written from the host probe and
has not itself been executed end to end — that is the next thing to run
there, not a claim being made here.

Co-authored-by: Orca <help@stably.ai>
This commit is contained in:
Neil
2026-08-08 19:11:54 -07:00
co-authored by Orca
parent 482ca59282
commit 56beffe5d4
@@ -74,9 +74,21 @@ function seededRepoPathOrSkip(): string {
/** Kernel-reported start time; distinguishes a survivor from a recycled PID. */
function readOsProcessIdentity(pid: number): OsProcessIdentity {
const startedAt = execFileSync('ps', ['-o', 'lstart=', '-p', String(pid)], {
encoding: 'utf8'
})
// Why two probes: `ps` does not exist on Windows, and a PID alone cannot tell
// a survivor from a reused number — both platforms must report a start time.
const startedAt = (
process.platform === 'win32'
? execFileSync(
'powershell.exe',
[
'-NoProfile',
'-Command',
`(Get-Process -Id ${pid} -ErrorAction SilentlyContinue).StartTime.ToString('o')`
],
{ encoding: 'utf8' }
)
: execFileSync('ps', ['-o', 'lstart=', '-p', String(pid)], { encoding: 'utf8' })
)
.trim()
.replace(/\s+/g, ' ')
if (!startedAt) {
@@ -118,7 +130,12 @@ async function readShellProcessIdentity(
// Why: the echoed command line also contains the marker, so match the
// *expanded* value — only the shell's own output carries digits.
const reported = new RegExp(`${marker}=(\\d+)`)
await execInTerminal(page, ptyId, `echo ${marker}=$$`)
// `$$` is POSIX; PowerShell exposes the same thing as `$PID`.
await execInTerminal(
page,
ptyId,
process.platform === 'win32' ? `echo ${marker}=$PID` : `echo ${marker}=$$`
)
let pid: number | null = null
await expect
.poll(