MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / main

Function main

cli/scripts/smoke-binary.ts:117–198  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

115}
116
117async 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

Callers 1

smoke-binary.tsFile · 0.70

Calls 6

runTreeSitterSmokeFunction · 0.85
setTimeoutFunction · 0.85
onceMethod · 0.80
failFunction · 0.70
onMethod · 0.65
resolveFunction · 0.50

Tested by

no test coverage detected