ReviewOS

also looking at this

craft-native/craft

Test the built native CLI startup in CI

#317
Merged glennmichael123 wants to merge codex/native-startup-rehearsal into main
3 files +54 -2
scripts/verify-native-startup.test.tsadded+27-0
Changes to scripts/verify-native-startup.test.ts
@@ -0,0 +1,27 @@
1import { afterEach, expect, test } from 'bun:test'
2import { chmodSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'
3import { tmpdir } from 'node:os'
4import { join } from 'node:path'
5import { verifyNativeStartup } from './verify-native-startup'
6
7const roots: string[] = []
8afterEach(() => { for (const root of roots.splice(0)) rmSync(root, { recursive: true, force: true }) })
9
10function executable(body: string): string {
11 const root = mkdtempSync(join(tmpdir(), 'craft-native-startup-test-'))
12 roots.push(root)
13 const path = join(root, 'craft')
14 writeFileSync(path, `#!/bin/sh\n${body}\n`)
15 chmodSync(path, 0o755)
16 return path
17}
18
19test('accepts a running native CLI with the requested version', () => {
20 expect(() => verifyNativeStartup(executable("printf 'craft version 1.2.3\\nBuilt with Zig\\n'"), '1.2.3')).not.toThrow()
21})
22
23test('rejects a stale binary, startup failure, and missing executable', () => {
24 expect(() => verifyNativeStartup(executable("printf 'craft version 1.2.2\\n'"), '1.2.3')).toThrow('reported')
25 expect(() => verifyNativeStartup(executable('exit 7'), '1.2.3')).toThrow('failed to start')
26 expect(() => verifyNativeStartup('/path/that/does/not/exist', '1.2.3')).toThrow()
27})