()
| 115 | } |
| 116 | |
| 117 | async function main(): Promise<void> { |
| 118 | const binary = process.argv[2] |
| 119 | const runSeconds = Number(process.argv[3] ?? DEFAULT_RUN_SECONDS) |
| 120 | |
| 121 | if (!binary) { |
| 122 | console.error('Usage: bun smoke-binary.ts <path-to-binary> [seconds]') |
| 123 | process.exit(2) |
| 124 | } |
| 125 | if (!existsSync(binary)) { |
| 126 | console.error(`smoke-binary: binary not found: ${binary}`) |
| 127 | process.exit(2) |
| 128 | } |
| 129 | if (!Number.isFinite(runSeconds) || runSeconds <= 0) { |
| 130 | console.error(`smoke-binary: bad seconds arg: ${process.argv[3]}`) |
| 131 | process.exit(2) |
| 132 | } |
| 133 | |
| 134 | console.log(`smoke-binary: spawning ${binary} for ${runSeconds}s…`) |
| 135 | |
| 136 | await runTreeSitterSmoke(binary) |
| 137 | console.log('smoke-binary: tree-sitter init OK.') |
| 138 | |
| 139 | const proc = spawn(binary, [], { |
| 140 | stdio: ['ignore', 'pipe', 'pipe'], |
| 141 | env: { ...process.env, NO_COLOR: '1', TERM: 'dumb' }, |
| 142 | }) |
| 143 | |
| 144 | let captured = '' |
| 145 | const append = (chunk: Buffer): void => { |
| 146 | captured += chunk.toString('utf8') |
| 147 | } |
| 148 | proc.stdout?.on('data', append) |
| 149 | proc.stderr?.on('data', append) |
| 150 | |
| 151 | let earlyExitCode: number | null = null |
| 152 | const exited = new Promise<void>((resolve) => { |
| 153 | proc.once('exit', (code) => { |
| 154 | earlyExitCode = code |
| 155 | resolve() |
| 156 | }) |
| 157 | }) |
| 158 | |
| 159 | const killTimer = setTimeout(() => { |
| 160 | // SIGKILL is the only signal that's portable across Linux/macOS/Windows |
| 161 | // here; SIGTERM may be ignored by the renderer on some platforms. |
| 162 | proc.kill('SIGKILL') |
| 163 | }, runSeconds * 1_000) |
| 164 | |
| 165 | await exited |
| 166 | clearTimeout(killTimer) |
| 167 | |
| 168 | const fail = (reason: string): never => { |
| 169 | console.error(`smoke-binary: FAIL — ${reason} (exit code ${earlyExitCode}).`) |
| 170 | console.error('--- captured output (truncated to 8KB) ---') |
| 171 | console.error(captured.slice(0, 8 * 1024)) |
| 172 | process.exit(1) |
| 173 | } |
| 174 |
no test coverage detected