also looking at this
feat: add scoped cargo receiving mission tasks
#102
21 files
+1186
-15
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | import { expect, test } from 'bun:test' |
| 2 | import { mkdir, mkdtemp, readFile, rm, writeFile } from 'node:fs/promises' | |
| 2 | import { mkdir, mkdtemp, readFile, rm, stat, writeFile } from 'node:fs/promises' | |
| 3 | 3 | import { tmpdir } from 'node:os' |
| 4 | 4 | import { join } from 'node:path' |
| 5 | 5 | import process from 'node:process' |
| @@ -25,6 +25,11 @@ test.skipIf(process.platform === 'win32')('failed native launch retains startup | ||
| 25 | 25 | expect(report.launch.cleanupRequested).toBe(true) |
| 26 | 26 | expect(report.portProbe.attempts).toBe(400) |
| 27 | 27 | expect(report.portProbe.lastReadError).toBe('ENOENT') |
| 28 | expect(report.startup.platform).toBe(process.platform) | |
| 29 | expect(report.startup.method).toBe('startup-only-process-observation-v1') | |
| 30 | expect(report.startup.snapshots.at(-1).label).toBe('cleanup-ended') | |
| 31 | expect(report.startup.snapshots.at(-1).root.pid).toBe(actualPid) | |
| 32 | expect(report.startup.snapshots.at(-1).root.probe).toBe('missing') | |
| 28 | 33 | expect(report.stderr.status).toBe('retained') |
| 29 | 34 | expect(report.stderr.retainedBytes).toBeLessThanOrEqual(65536) |
| 30 | 35 | expect(await readFile(join(root, 'chrome-startup-stderr.log'), 'utf8')).toContain('controlled native browser startup refusal') |
| @@ -46,3 +51,57 @@ test.skipIf(process.platform === 'win32')('failed native launch retains startup | ||
| 46 | 51 | else console.log(JSON.stringify({ evidence: 'controlled-native-launch', retainedRoot: root, passed })) |
| 47 | 52 | } |
| 48 | 53 | }, 30000) |
| 54 | ||
| 55 | // The existing native launch seam checks observed processes, not the cause of a Chrome failure. | |
| 56 | test.skipIf(process.platform === 'win32')('a live native launcher and child remain observable until cleanup without exporting argv or environment', async () => { | |
| 57 | const supplied = process.env.BROWSER_LAUNCH_LIVE_EVIDENCE | |
| 58 | const root = supplied ? (await mkdir(supplied), supplied) : await mkdtemp(join(tmpdir(), 'drone-browser-live-')) | |
| 59 | const executable = join(root, 'launch.ts'), pidPath = join(root, 'pids.json') | |
| 60 | const original = process.env.BROWSE_BROWSER | |
| 61 | let passed = false | |
| 62 | try { | |
| 63 | await writeFile(executable, `#!${process.execPath}\nimport { writeFileSync } from 'node:fs'\nconst child=Bun.spawn([process.execPath,'-e','setInterval(()=>{},1000)','PRIVATE_CHILD_ARG_SENTINEL'],{stdout:'ignore',stderr:'ignore',env:{...process.env,PRIVATE_FIXTURE_TOKEN:'PRIVATE_CHILD_ENV_SENTINEL'}})\nwriteFileSync(${JSON.stringify(pidPath)},JSON.stringify([process.pid,child.pid]))\nprocess.on('SIGTERM',async()=>{child.kill();await child.exited;process.exit(0)})\nconsole.error('controlled live browser startup fixture')\nsetInterval(()=>{},1000)\n`, { mode: 0o700 }) | |
| 64 | process.env.BROWSE_BROWSER = executable | |
| 65 | await expect(startWorkspaceBrowser(root)).rejects.toThrow('Fresh browser must start') | |
| 66 | const [pid, childPid] = JSON.parse(await readFile(pidPath, 'utf8')) as [number, number] | |
| 67 | const text = await readFile(join(root, 'browser-launch.json'), 'utf8'), report = JSON.parse(text) | |
| 68 | expect(text).not.toContain('PRIVATE_CHILD_ARG_SENTINEL') | |
| 69 | expect(text).not.toContain('PRIVATE_CHILD_ENV_SENTINEL') | |
| 70 | expect(report.portProbe.attempts).toBe(400) | |
| 71 | expect(report.launch.exitObservedBeforeCleanup).toBe(false) | |
| 72 | expect(report.launch.exitObserved).toBe(true) | |
| 73 | const before = report.startup.snapshots.find((s: any) => s.label === 'discovery-ended') | |
| 74 | expect(before.root.pid).toBe(pid) | |
| 75 | expect(before.root.probe).toBe('present') | |
| 76 | expect(report.startup.snapshots.at(-1).root.probe).toBe('missing') | |
| 77 | expect(report.startup.executables).toBeArray() | |
| 78 | if (process.platform === 'linux') { | |
| 79 | expect(before.linux.status).toBe('observed') | |
| 80 | expect(before.linux.root.startTicks).toMatch(/^\d+$/) | |
| 81 | expect(before.linux.root.rssKiB).toBeGreaterThan(0) | |
| 82 | expect(before.linux.descendants.some((p: any) => p.pid === childPid && p.parentPid === pid)).toBe(true) | |
| 83 | const identity = report.startup.executables.find((e: any) => e.observedPids.includes(pid) && e.sha256 !== null) | |
| 84 | expect(identity).toBeDefined() | |
| 85 | expect(identity.byteLength).toBe((await stat(process.execPath)).size) | |
| 86 | expect(identity.sha256).toBe(new Bun.CryptoHasher('sha256').update(await Bun.file(process.execPath).arrayBuffer()).digest('hex')) | |
| 87 | expect(identity.hashedAfterDiscovery).toBe(true) | |
| 88 | } | |
| 89 | else expect(before.linux.status).toBe('unsupported') | |
| 90 | expect(() => process.kill(pid, 0)).toThrow() | |
| 91 | expect(() => process.kill(childPid, 0)).toThrow() | |
| 92 | passed = true | |
| 93 | } | |
| 94 | finally { | |
| 95 | if (original === undefined) delete process.env.BROWSE_BROWSER | |
| 96 | else process.env.BROWSE_BROWSER = original | |
| 97 | const pids: number[] = JSON.parse(await readFile(pidPath, 'utf8').catch(() => '[]')) | |
| 98 | for (const pid of pids) { | |
| 99 | let gone = false | |
| 100 | try { process.kill(pid, 0) } | |
| 101 | catch (error) { gone = (error as NodeJS.ErrnoException).code === 'ESRCH' } | |
| 102 | expect(gone).toBe(true) | |
| 103 | } | |
| 104 | if (passed && !supplied) await rm(root, { recursive: true, force: true }) | |
| 105 | else console.log(JSON.stringify({ evidence: 'controlled-live-native-launch', retainedRoot: root, passed })) | |
| 106 | } | |
| 107 | }, 35000) | |