The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop-e2e): the reaper unit test reaps only its own fixtures
Teknium9b26e63d9d48
diff --git a/apps/desktop/e2e/run-tmp-reaper.ts b/apps/desktop/e2e/run-tmp-reaper.tsindex 1db0f43569b..07993294f99 100644--- a/apps/desktop/e2e/run-tmp-reaper.ts+++ b/apps/desktop/e2e/run-tmp-reaper.ts@@ -181,7 +181,10 @@ export function reapRunBackends(shouldReap: (root: string) => boolean): string[]return roots}-/** Reap the backends of every run whose runner is dead. */-export function reapAbandonedRuns(): string[] {- return reapRunBackends(root => !runnerAlive(root))+/**+ * Reap the backends of every run whose runner is dead: host-wide, or only the runs whose root+ * lies under `scope` (a test reaps its own fixtures, never another abandoned run on the host).+ */+export function reapAbandonedRuns(scope?: string): string[] {+ return reapRunBackends(root => (scope === undefined || root.startsWith(scope + path.sep)) && !runnerAlive(root))}diff --git a/apps/desktop/e2e/run-tmp-reaper.unit.test.ts b/apps/desktop/e2e/run-tmp-reaper.unit.test.tsindex 146ded5733a..b2b29db5d78 100644--- a/apps/desktop/e2e/run-tmp-reaper.unit.test.ts+++ b/apps/desktop/e2e/run-tmp-reaper.unit.test.ts@@ -38,32 +38,52 @@ function backendUnder(root: string): ChildProcess {return child}+/** The pid and kernel start time of a runner that no longer exists: a killed run's `.runner.json`. */+async function deadRunnerRecord(): Promise<string> {+ const runner = spawn('sleep', ['300'], { stdio: 'ignore' })+ const stat = fs.readFileSync(`/proc/${runner.pid}/stat`, 'utf8')+ const start = stat.slice(stat.lastIndexOf(')') + 2).split(' ')[19]+ runner.kill('SIGKILL')+ await exited(runner)++ return JSON.stringify({ pid: runner.pid, start })+}++function tmpBase(): string {+ const base = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), 'reaper-')))+ dirs.push(base)++ return base+}+describe.runIf(process.platform === 'linux')('reapAbandonedRuns', () => {- it("stops a killed runner's backends and removes its root; a live runner's backends are untouched", async () => {- const base = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), 'reaper-')))- dirs.push(base)+ it("stops a killed runner's backends and removes its root; a live runner's and an out-of-scope run's are untouched", async () => {+ const base = tmpBase()const deadRoot = fs.mkdtempSync(path.join(base, 'pw-'))const liveRoot = fs.mkdtempSync(path.join(base, 'pw-'))+ // Another abandoned run on the same host, outside the scope this reap is given.+ const outsideRoot = fs.mkdtempSync(path.join(tmpBase(), 'pw-'))- // The killed run's record: the pid and kernel start time of a runner that no longer exists.- const runner = spawn('sleep', ['300'], { stdio: 'ignore' })- const stat = fs.readFileSync(`/proc/${runner.pid}/stat`, 'utf8')- const start = stat.slice(stat.lastIndexOf(')') + 2).split(' ')[19]- runner.kill('SIGKILL')- await exited(runner)- fs.writeFileSync(path.join(deadRoot, '.runner.json'), JSON.stringify({ pid: runner.pid, start }))+ fs.writeFileSync(path.join(deadRoot, '.runner.json'), await deadRunnerRecord())+ fs.writeFileSync(path.join(outsideRoot, '.runner.json'), await deadRunnerRecord())recordRunOwner(liveRoot)const orphan = backendUnder(deadRoot)const concurrent = backendUnder(liveRoot)+ const outside = backendUnder(outsideRoot)- expect(reapAbandonedRuns()).toContain(deadRoot)+ expect(reapAbandonedRuns(base)).toEqual([deadRoot])expect(await exited(orphan)).toBe('SIGTERM')expect(fs.existsSync(deadRoot)).toBe(false)- expect(concurrent.exitCode).toBeNull()- expect(concurrent.signalCode).toBeNull()- expect(() => process.kill(concurrent.pid!, 0)).not.toThrow()- expect(fs.existsSync(liveRoot)).toBe(true)+ for (const [survivor, root] of [+ [concurrent, liveRoot],+ [outside, outsideRoot]+ ] as const) {+ expect(survivor.exitCode).toBeNull()+ expect(survivor.signalCode).toBeNull()+ expect(() => process.kill(survivor.pid!, 0)).not.toThrow()+ expect(fs.existsSync(root)).toBe(true)+ }})})