Skip to content

The agent that grows with you

test: v2-marker delegate fixtures record the delegate's real creation time

Teknium927990dbb2f4
diff --git a/apps/desktop/electron/managed-ssh-update.test.ts b/apps/desktop/electron/managed-ssh-update.test.ts
index 64ef4b9d110..7a49f7a5887 100644
--- a/apps/desktop/electron/managed-ssh-update.test.ts
+++ b/apps/desktop/electron/managed-ssh-update.test.ts
@@ -1,5 +1,5 @@
import assert from 'node:assert/strict'
-import { exec as execCallback } from 'node:child_process'
+import { exec as execCallback, spawn } from 'node:child_process'
import { mkdir, mkdtemp, readdir, readFile, rm, stat, writeFile } from 'node:fs/promises'
import os from 'node:os'
import path from 'node:path'
@@ -629,15 +629,20 @@ test.runIf(process.platform !== 'win32')(
const exited = (await exec(`sh -c 'echo $$'`)).stdout.trim()
// The updater's v2 claim: pid, started_at, creation-time line (A2), then tagged lines.
const deadClaim = `${exited}\n${Math.floor(Date.now() / 1000)}\nct:1700000000.125\n`
+ // A delegate is live only at its real creation time (the judge checks pid AND ct, so a reused
+ // pid cannot impersonate it): record the spawn time, well inside the 2 s tolerance.
+ const delegateCt = (Date.now() / 1000).toFixed(3)
+ const delegate = spawn('sleep', ['30'], { stdio: 'ignore' })
try {
await writeFile(marker, deadClaim)
assert.equal((await observe()).marker, 'dead', 'a dead v2 claim is dead, never malformed')
- await writeFile(marker, `${deadClaim}delegate:${process.pid} ct:1700000001.500\n`)
+ await writeFile(marker, `${deadClaim}delegate:${delegate.pid} ct:${delegateCt}\n`)
const delegated = await observe()
assert.equal(delegated.marker, 'live', 'a live delegate keeps the update live')
- assert.equal(delegated.markerPid, process.pid)
+ assert.equal(delegated.markerPid, delegate.pid)
} finally {
+ delegate.kill()
await rm(home, { force: true, recursive: true })
}
}
diff --git a/apps/desktop/electron/remote-lifecycle-v2-marker.test.ts b/apps/desktop/electron/remote-lifecycle-v2-marker.test.ts
index 198ab69568e..dcc13d4a5b9 100644
--- a/apps/desktop/electron/remote-lifecycle-v2-marker.test.ts
+++ b/apps/desktop/electron/remote-lifecycle-v2-marker.test.ts
@@ -25,6 +25,9 @@ test.runIf(process.platform === 'linux')(
await new Promise(resolve => exited.once('exit', resolve))
// The updater's v2 claim: pid, started_at, creation-time line (A2), then tagged lines.
const deadClaim = `${exited.pid}\n${Math.floor(Date.now() / 1000)}\nct:1700000000.125\n`
+ // A delegate is live only at its real creation time (the judge checks pid AND ct, so a reused
+ // pid cannot impersonate it): record the spawn time, well inside the 2 s tolerance.
+ const delegateCt = (Date.now() / 1000).toFixed(3)
const delegate = spawn('sleep', ['30'], { argv0: 'hermes-update', stdio: 'ignore' })
let mutexHolder: ReturnType<typeof spawn> | undefined
@@ -35,7 +38,7 @@ test.runIf(process.platform === 'linux')(
await assertRemoteInstallUpdateClear(ssh, home)
await assert.rejects(readFile(marker), 'a confirmed-dead v2 claim is cleared, not left UNCERTAIN')
- const delegated = `${deadClaim}run:abc\ndelegate:${delegate.pid} ct:1700000001.500\n`
+ const delegated = `${deadClaim}run:abc\ndelegate:${delegate.pid} ct:${delegateCt}\n`
await writeFile(marker, delegated)
await assert.rejects(() => assertRemoteInstallUpdateClear(ssh, home), refused)
assert.equal(await readFile(marker, 'utf8'), delegated, 'a live delegate keeps the claim')
@@ -58,5 +61,7 @@ test.runIf(process.platform === 'linux')(
mutexHolder?.kill()
await rm(home, { force: true, recursive: true })
}
- }
+ },
+ // A held marker mutex makes the gate wait out its 10 s acquisition window before refusing.
+ 30_000
)