also looking at this
Test the built native CLI startup in CI
#317
3 files
+54
-2
| @@ -0,0 +1,20 @@ | ||
| 1 | import { resolve } from 'node:path' | |
| 2 | ||
| 3 | export function verifyNativeStartup(binary: string, version: string): void { | |
| 4 | const result = Bun.spawnSync([resolve(binary), '--version'], { | |
| 5 | stdout: 'pipe', stderr: 'pipe', timeout: 30_000, | |
| 6 | }) | |
| 7 | if (result.exitCode !== 0) | |
| 8 | throw new Error(`Native CLI failed to start (${result.signalCode ?? result.exitCode}): ${result.stderr.toString()}`) | |
| 9 | const firstLine = result.stdout.toString().trim().split('\n')[0] | |
| 10 | if (firstLine !== `craft version ${version}`) | |
| 11 | throw new Error(`Native CLI reported ${JSON.stringify(firstLine)}, expected craft version ${version}`) | |
| 12 | console.log(`Verified native CLI startup: craft version ${version}`) | |
| 13 | } | |
| 14 | ||
| 15 | if (import.meta.main) { | |
| 16 | const [binary, version] = Bun.argv.slice(2) | |
| 17 | if (!binary || !version) | |
| 18 | throw new Error('Usage: bun scripts/verify-native-startup.ts <binary> <version>') | |
| 19 | verifyNativeStartup(binary, version) | |
| 20 | } | |