ReviewOS

also looking at this

stacks/drone

feat: model one point-load intake with conserved momentum

#99
Merged chris wants to merge codex/cargo-fleet-custody into main
45 files +3133 -169
tests/unit/cargo-qualification-process.test.tsadded+43-0
Changes to tests/unit/cargo-qualification-process.test.ts
@@ -0,0 +1,43 @@
1import { expect, test } from 'bun:test'
2import { chmod, mkdtemp, readFile, rm } from 'node:fs/promises'
3import { tmpdir } from 'node:os'
4import { join, resolve } from 'node:path'
5import { runBoundedHostProcess } from '../../resources/functions/host/process'
6
7// The real qualifier/child seam catches unbounded capture and leaked processes;
8// it does not qualify the modeled vehicle or CI runner memory consumption.
9for (const stream of ['stdout', 'stderr'] as const) {
10 test(`the cargo qualifier rejects ${stream} overflow and reaps its executable`, async () => {
11 const root = await mkdtemp(join(tmpdir(), 'drone-cargo-qualifier-'))
12 const binary = join(root, 'fixture'), pidFile = join(root, 'child.pid')
13 try {
14 await Bun.write(binary, `#!/usr/bin/env bun\nawait Bun.write(${JSON.stringify(pidFile)}, String(process.pid));\nprocess.${stream}.write('x'.repeat(32768)); await Bun.sleep(60000)\n`)
15 await chmod(binary, 0o755)
16 const result = await runBoundedHostProcess([process.execPath, resolve('scripts/qualify-cargo-cli.ts'), binary, join(root, 'output')], { timeoutMs: 5000, stdoutBytes: 4096, stderrBytes: 16384, label: 'Cargo qualifier fixture' })
17 expect(result.exitCode).not.toBe(0)
18 expect(result.stderr).toContain(`${stream} exceeds byte limit`)
19 const pid = Number(await readFile(pidFile, 'utf8'))
20 expect(Number.isSafeInteger(pid)).toBe(true)
21 expect(() => process.kill(pid, 0)).toThrow()
22 expect(await Bun.file(join(root, 'output/receipt.json')).exists()).toBe(false)
23 expect(await Bun.file(join(root, 'output/nominal.stdout')).exists()).toBe(false)
24 }
25 finally { await rm(root, { recursive: true, force: true }) }
26 }, 10000)
27}
28
29test('strict bounded process capture rejects malformed UTF8 after reaping the child and preserves valid bytes', async () => {
30 const root = await mkdtemp(join(tmpdir(), 'drone-cargo-encoding-')), pidFile = join(root, 'child.pid')
31 const options = { timeoutMs: 5000, stdoutBytes: 16384, stderrBytes: 1024, strictUtf8: true, label: 'Cargo encoding fixture' }
32 try {
33 await expect(runBoundedHostProcess([process.execPath, '-e', `await Bun.write(${JSON.stringify(pidFile)}, String(process.pid)); await Bun.write(Bun.stdout, new Uint8Array([255]))`], options)).rejects.toThrow()
34 const pid = Number(await readFile(pidFile, 'utf8'))
35 expect(Number.isSafeInteger(pid)).toBe(true)
36 expect(() => process.kill(pid, 0)).toThrow()
37 const result = await runBoundedHostProcess([process.execPath, '-e', `await Bun.write(Bun.stdout, new Uint8Array([239,187,191,195,169,10]))`], options)
38 expect(result.exitCode).toBe(0)
39 expect(Buffer.from(result.stdout, 'utf8')).toEqual(Buffer.from([239, 187, 191, 195, 169, 10]))
40 expect(result.stderr).toBe('')
41 }
42 finally { await rm(root, { recursive: true, force: true }) }
43}, 15000)