also looking at this
test: retain bounded browser launch evidence on failure
#70
18 files
+620
-23
| @@ -0,0 +1,62 @@ | ||
| 1 | import { expect, test } from 'bun:test' | |
| 2 | import { Buffer } from 'node:buffer' | |
| 3 | import process from 'node:process' | |
| 4 | import { captureColdBuild, coldBuildCaptureBytes, coldBuildQualificationTimeout } from '../helpers/runtime-cold-build-supervisor' | |
| 5 | ||
| 6 | const options = { cwd: process.cwd(), env: process.env, timeoutMs: 15000 } | |
| 7 | const run = (source: string, timeoutMs = options.timeoutMs) => captureColdBuild([process.execPath, '-e', source], { ...options, timeoutMs }) | |
| 8 | function groupExists(pid: number): boolean { | |
| 9 | try { process.kill(-pid, 0); return true } | |
| 10 | catch (error) { if ((error as NodeJS.ErrnoException).code === 'ESRCH') return false; throw error } | |
| 11 | } | |
| 12 | ||
| 13 | test.skipIf(process.platform === 'win32')('aggregate capture drains both real streams and preserves a native nonzero exit', async () => { | |
| 14 | const result = await run("await Promise.all([Bun.write(Bun.stdout, 'o'.repeat(262144)), Bun.write(Bun.stderr, 'e'.repeat(262144))]); process.exit(7)") | |
| 15 | expect(result.exitCode).toBe(7) | |
| 16 | expect(result.stdout).toBe('o'.repeat(262144)) | |
| 17 | expect(result.stderr).toBe('e'.repeat(262144)) | |
| 18 | expect(result.failure).toBeUndefined() | |
| 19 | expect(result.stopRequested).toBe(false) | |
| 20 | expect(result.rootCleanupRequired).toBe(false) | |
| 21 | expect(result.rootGroupRemaining).toBe(false) | |
| 22 | expect(groupExists(result.pid)).toBe(false) | |
| 23 | }, 25000) | |
| 24 | ||
| 25 | test.skipIf(process.platform === 'win32')('aggregate deadline retains actual child output and settles its owned group', async () => { | |
| 26 | const result = await run("await Bun.write(Bun.stdout, 'ready\\n'); setInterval(() => {}, 1000)", 2000) | |
| 27 | expect(result.stdout).toBe('ready\n') | |
| 28 | expect(result.exitCode).not.toBe(0) | |
| 29 | expect(result.deadlineReached).toBe(true) | |
| 30 | expect(result.stopRequested).toBe(true) | |
| 31 | expect(String(result.failure)).toContain('timed out') | |
| 32 | expect(result.rootGroupRemaining).toBe(false) | |
| 33 | expect(groupExists(result.pid)).toBe(false) | |
| 34 | }, 15000) | |
| 35 | ||
| 36 | test.skipIf(process.platform === 'win32')('actual output overflow retains the bounded prefix and terminates the writer', async () => { | |
| 37 | const result = await run("await Bun.write(Bun.stdout, 'x'.repeat(2000001)); setInterval(() => {}, 1000)") | |
| 38 | expect(Buffer.byteLength(result.stdout)).toBe(coldBuildCaptureBytes) | |
| 39 | expect(result.stdout).toBe('x'.repeat(coldBuildCaptureBytes)) | |
| 40 | expect(result.exitCode).not.toBe(0) | |
| 41 | expect(String(result.failure)).toContain('stdout exceeds byte limit') | |
| 42 | expect(result.deadlineReached).toBe(false) | |
| 43 | expect(result.rootGroupRemaining).toBe(false) | |
| 44 | expect(groupExists(result.pid)).toBe(false) | |
| 45 | }, 25000) | |
| 46 | ||
| 47 | test.skipIf(process.platform === 'win32')('exited parent with an actual inherited pipe is refused and its descendant group settles', async () => { | |
| 48 | const result = await run("const child = Bun.spawn([process.execPath, '-e', 'setInterval(() => {}, 1000)'], { stdout: 'inherit', stderr: 'inherit' }); console.log(child.pid); process.exit(0)") | |
| 49 | expect(result.exitCode).toBe(0) | |
| 50 | expect(result.stdout).toMatch(/^\d+\n$/) | |
| 51 | expect(result.deadlineReached).toBe(false) | |
| 52 | expect(result.stopRequested).toBe(true) | |
| 53 | expect(String(result.failure)).toContain('inherited output pipes did not settle') | |
| 54 | expect(result.rootGroupRemaining).toBe(false) | |
| 55 | expect(groupExists(result.pid)).toBe(false) | |
| 56 | }, 25000) | |
| 57 | ||
| 58 | test('qualification derives its aggregate budget without changing the individual command limit', () => { | |
| 59 | expect(coldBuildQualificationTimeout(120000, 5000)).toBe(390000) | |
| 60 | expect(coldBuildQualificationTimeout(120000, 20000)).toBe(405000) | |
| 61 | expect(() => coldBuildQualificationTimeout(120001, 5000)).toThrow('command budget') | |
| 62 | }) | |