run-gates.ts 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567
  1. /**
  2. * Run local and CI quality gates with bounded in-process scheduling.
  3. *
  4. * The gate vocabulary stays in package.json; this runner only decides which
  5. * independent commands can overlap and which commands wait for built artifacts.
  6. */
  7. import { spawn } from 'node:child_process'
  8. import { readdir, rm } from 'node:fs/promises'
  9. import { availableParallelism } from 'node:os'
  10. import { join, resolve } from 'node:path'
  11. import { performance } from 'node:perf_hooks'
  12. type Mode =
  13. | 'ci-primary'
  14. | 'ci-static'
  15. | 'ci-lint'
  16. | 'ci-coverage'
  17. | 'ci-snapshot'
  18. | 'ci-artifacts'
  19. | 'node-compat'
  20. | 'pre-push'
  21. type GateStatus = 'pending' | 'running' | 'passed' | 'failed' | 'skipped'
  22. interface Gate {
  23. id: string
  24. label: string
  25. displayCommand: string
  26. command: string
  27. args: string[]
  28. needs?: string[]
  29. env?: Record<string, string | undefined>
  30. input?: string
  31. verify?: (result: GateResult) => Promise<void>
  32. }
  33. interface GateResult {
  34. gate: Gate
  35. status: GateStatus
  36. durationMs: number
  37. stdout: string
  38. stderr: string
  39. output: GateOutputChunk[]
  40. exitCode: number | null
  41. error?: string
  42. }
  43. interface GateOutputChunk {
  44. stream: 'stdout' | 'stderr'
  45. text: string
  46. }
  47. interface RunningGate {
  48. gate: Gate
  49. promise: Promise<GateResult>
  50. }
  51. interface ConcurrencyDefault {
  52. workers: number
  53. source: string
  54. }
  55. const root = resolve(import.meta.dirname, '..')
  56. const mode = parseMode(process.argv[2])
  57. const gates = gatesForMode(mode)
  58. const concurrencyDefault = defaultConcurrency(mode, gates.length)
  59. const concurrencyOverride = process.env.DSH_GATE_CONCURRENCY
  60. const maxConcurrency = concurrencyFromEnv('DSH_GATE_CONCURRENCY', concurrencyDefault.workers)
  61. const verbose = process.env.DSH_GATE_VERBOSE === '1'
  62. const startedAt = performance.now()
  63. const concurrencySource = concurrencyOverride === undefined || concurrencyOverride === ''
  64. ? concurrencyDefault.source
  65. : '$DSH_GATE_CONCURRENCY'
  66. console.log(`run-gates: ${mode} running ${gates.length} gate(s) with ${maxConcurrency} worker(s) from ${concurrencySource}.`)
  67. const results = await runGates(gates, maxConcurrency)
  68. printSummary(results, performance.now() - startedAt)
  69. if (results.some(result => result.status === 'failed' || result.status === 'skipped')) process.exit(1)
  70. function parseMode(raw: string | undefined): Mode {
  71. switch (raw) {
  72. case 'ci-primary':
  73. case 'ci-static':
  74. case 'ci-lint':
  75. case 'ci-coverage':
  76. case 'ci-snapshot':
  77. case 'ci-artifacts':
  78. case 'node-compat':
  79. case 'pre-push':
  80. return raw
  81. default:
  82. throw new Error(
  83. `run-gates: expected mode ci-primary | ci-static | ci-lint | ci-coverage | ci-snapshot | ci-artifacts | node-compat | pre-push, got ${JSON.stringify(raw)}.`,
  84. )
  85. }
  86. }
  87. function defaultConcurrency(selectedMode: Mode, total: number): ConcurrencyDefault {
  88. const available = availableParallelism()
  89. const modeLimit = selectedMode === 'pre-push' ? Math.min(4, available) : available
  90. return {
  91. workers: Math.min(total, modeLimit),
  92. source: selectedMode === 'pre-push'
  93. ? `${available} available CPU(s), pre-push cap 4`
  94. : `${available} available CPU(s)`,
  95. }
  96. }
  97. function concurrencyFromEnv(name: string, fallback: number): number {
  98. const raw = process.env[name]
  99. if (raw === undefined || raw === '') return fallback
  100. const parsed = Number.parseInt(raw, 10)
  101. if (!Number.isSafeInteger(parsed) || parsed < 1) {
  102. throw new Error(`run-gates: ${name} must be a positive integer, got ${JSON.stringify(raw)}.`)
  103. }
  104. return parsed
  105. }
  106. function pnpmScript(id: string, script: string, options: Partial<Gate> = {}): Gate {
  107. return {
  108. id,
  109. label: options.label ?? script,
  110. displayCommand: `pnpm run ${script}`,
  111. ...pnpmInvocation(['run', script]),
  112. ...options,
  113. }
  114. }
  115. function pnpmExec(id: string, args: string[], options: Partial<Gate> = {}): Gate {
  116. return {
  117. id,
  118. label: options.label ?? `pnpm exec ${args.join(' ')}`,
  119. displayCommand: `pnpm exec ${args.join(' ')}`,
  120. ...pnpmInvocation(['exec', ...args]),
  121. ...options,
  122. }
  123. }
  124. function pnpmInvocation(args: string[]): Pick<Gate, 'command' | 'args'> {
  125. const entrypoint = process.env.npm_execpath
  126. if (entrypoint === undefined || entrypoint === '') {
  127. throw new Error('run-gates: npm_execpath is unavailable; invoke the runner through a pnpm package script.')
  128. }
  129. // Windows cannot spawn the pnpm.cmd shim directly; the JavaScript entrypoint keeps every host shell-free.
  130. return { command: process.execPath, args: [entrypoint, ...args] }
  131. }
  132. function nodeOptions(...options: string[]): string {
  133. return [process.env.NODE_OPTIONS, ...options].filter(option => option !== undefined && option !== '').join(' ')
  134. }
  135. function gatesForMode(selected: Mode): Gate[] {
  136. switch (selected) {
  137. case 'ci-primary':
  138. return ciPrimaryGates()
  139. case 'ci-static':
  140. return ciStaticGates()
  141. case 'ci-lint':
  142. return [
  143. lintGate(),
  144. pnpmScript('duplication', 'duplication'),
  145. ]
  146. case 'ci-coverage':
  147. return [
  148. pnpmScript('build', 'build'),
  149. coverageGate(),
  150. ]
  151. case 'ci-snapshot':
  152. return [
  153. pnpmScript('build', 'build'),
  154. snapshotGate(),
  155. ]
  156. case 'ci-artifacts':
  157. return ciArtifactGates()
  158. case 'node-compat':
  159. return [
  160. pnpmScript('typecheck', 'typecheck'),
  161. pnpmExec('source-worker-smoke', [
  162. 'vitest',
  163. 'run',
  164. 'packages/workflow/workflow-workerthread/tests/source-worker.compat.spec.ts',
  165. ], { label: 'source worker smoke' }),
  166. ]
  167. case 'pre-push':
  168. return [
  169. pnpmScript('runtime-closure', 'verify-runtime-closure', { label: 'runtime closure' }),
  170. pnpmScript('cordis-config', 'verify-cordis-config', { label: 'Cordis config' }),
  171. pnpmScript('test', 'test'),
  172. pnpmScript('duplication', 'duplication'),
  173. snapshotGate(),
  174. pnpmScript('build', 'build'),
  175. ...hygieneLeafGates({ artifactNeeds: ['build'] }),
  176. ...docSyncLeafGates({
  177. docTypecheckNeeds: ['build'],
  178. docTypecheckEnv: { DSH_DOC_TYPECHECK_USE_BUILD_OUTPUT: '1' },
  179. }),
  180. pnpmScript('module-graph', 'verify-module-graph', { label: 'module graph' }),
  181. ]
  182. }
  183. }
  184. function ciPrimaryGates(): Gate[] {
  185. return [
  186. pnpmScript('runtime-closure', 'verify-runtime-closure', { label: 'runtime closure' }),
  187. pnpmScript('constraints', 'constraints'),
  188. pnpmScript('cordis-config', 'verify-cordis-config', { label: 'Cordis config' }),
  189. pnpmScript('typecheck', 'typecheck'),
  190. lintGate(),
  191. pnpmScript('duplication', 'duplication'),
  192. coverageGate(),
  193. snapshotGate(),
  194. demoSmokeGate({ needs: ['lint'] }),
  195. ...docSyncLeafGates(),
  196. pnpmScript('module-graph', 'verify-module-graph', { label: 'module graph' }),
  197. pnpmScript('knip', 'knip'),
  198. pnpmScript('website-build', 'website:build', { label: 'website build' }),
  199. pnpmScript('build', 'build', { needs: ['typecheck'] }),
  200. pnpmScript('publint', 'publint', { needs: ['build'] }),
  201. pnpmScript('node-next-types', 'verify-node-next-types', {
  202. label: 'node-next types',
  203. needs: ['build'],
  204. }),
  205. builtBinSmokeGate(),
  206. ]
  207. }
  208. function ciStaticGates(): Gate[] {
  209. return [
  210. pnpmScript('runtime-closure', 'verify-runtime-closure', { label: 'runtime closure' }),
  211. pnpmScript('constraints', 'constraints'),
  212. pnpmScript('cordis-config', 'verify-cordis-config', { label: 'Cordis config' }),
  213. ...staticDemoSmokeGates(),
  214. ...docSyncLeafGates(),
  215. pnpmScript('module-graph', 'verify-module-graph', { label: 'module graph' }),
  216. pnpmScript('knip', 'knip'),
  217. pnpmScript('website-build', 'website:build', { label: 'website build' }),
  218. ]
  219. }
  220. function staticDemoSmokeGates(): Gate[] {
  221. // Native Windows session persistence is outside the gates-only support scope.
  222. return process.platform === 'win32' ? [] : [demoSmokeGate()]
  223. }
  224. function ciArtifactGates(): Gate[] {
  225. return [
  226. pnpmScript('build', 'build'),
  227. pnpmScript('publint', 'publint', { needs: ['build'] }),
  228. pnpmScript('node-next-types', 'verify-node-next-types', {
  229. label: 'node-next types',
  230. needs: ['build'],
  231. }),
  232. builtBinSmokeGate(),
  233. ]
  234. }
  235. function lintGate(): Gate {
  236. if (process.env.DSH_ESLINT_CACHE === '1') {
  237. return pnpmExec('lint', [
  238. 'eslint',
  239. '.',
  240. '--cache',
  241. '--cache-location',
  242. '.cache/eslint/',
  243. '--cache-strategy',
  244. 'content',
  245. ], {
  246. label: 'lint',
  247. env: { NODE_OPTIONS: nodeOptions('--max-old-space-size=8192') },
  248. })
  249. }
  250. return pnpmScript('lint', 'lint', {
  251. env: { NODE_OPTIONS: nodeOptions('--max-old-space-size=8192') },
  252. })
  253. }
  254. function coverageGate(): Gate {
  255. return pnpmExec('coverage', [
  256. 'vitest',
  257. 'run',
  258. '--coverage',
  259. ...positiveIntArg('DSH_COVERAGE_MAX_WORKERS', '--maxWorkers'),
  260. ], {
  261. label: 'test:coverage',
  262. env: { DSH_EXAMPLE_MODE: 'lib' },
  263. needs: ['build'],
  264. })
  265. }
  266. // The snapshot suite boots the example bins in `lib` mode (built artifact under plain Node,
  267. // plugins via real exports) — CI and pre-push already build, so they exercise what ships rather
  268. // than the tsx/source path dev uses. It therefore waits on `build`.
  269. function snapshotGate(): Gate {
  270. return pnpmScript('snapshot', 'test:snapshot', {
  271. env: { DSH_EXAMPLE_MODE: 'lib' },
  272. needs: ['build'],
  273. })
  274. }
  275. function positiveIntArg(envName: string, flag: string): string[] {
  276. const raw = process.env[envName]
  277. if (raw === undefined || raw === '') return []
  278. const parsed = Number.parseInt(raw, 10)
  279. if (!Number.isSafeInteger(parsed) || parsed < 1 || String(parsed) !== raw) {
  280. throw new Error(`run-gates: ${envName} must be a positive integer, got ${JSON.stringify(raw)}.`)
  281. }
  282. return [`${flag}=${raw}`]
  283. }
  284. function hygieneLeafGates(options: { artifactNeeds?: string[] } = {}): Gate[] {
  285. const artifactOptions = options.artifactNeeds === undefined ? {} : { needs: options.artifactNeeds }
  286. return [
  287. pnpmScript('knip', 'knip'),
  288. pnpmScript('publint', 'publint', artifactOptions),
  289. pnpmScript('constraints', 'constraints'),
  290. pnpmScript('node-next-types', 'verify-node-next-types', {
  291. label: 'node-next types',
  292. ...artifactOptions,
  293. }),
  294. ]
  295. }
  296. function docSyncLeafGates(options: {
  297. docTypecheckNeeds?: string[]
  298. docTypecheckEnv?: Record<string, string | undefined>
  299. } = {}): Gate[] {
  300. const docTypecheckOptions: Partial<Gate> = {}
  301. if (options.docTypecheckNeeds !== undefined) docTypecheckOptions.needs = options.docTypecheckNeeds
  302. if (options.docTypecheckEnv !== undefined) docTypecheckOptions.env = options.docTypecheckEnv
  303. return [
  304. pnpmScript('doc-typecheck', 'doc-typecheck', docTypecheckOptions),
  305. pnpmScript('cordis-catalog', 'verify-cordis-catalog', { label: 'cordis catalog' }),
  306. pnpmScript('export-jsdoc', 'verify-export-jsdoc', { label: 'export jsdoc' }),
  307. pnpmScript('tool-catalog', 'verify-tool-catalog', { label: 'tool catalog' }),
  308. pnpmScript('config-catalog', 'verify-config-catalog', { label: 'config catalog' }),
  309. pnpmScript('persistence-catalog', 'verify-persistence-catalog', { label: 'persistence catalog' }),
  310. pnpmScript('doc-graphs', 'verify-doc-graphs', { label: 'doc graphs' }),
  311. pnpmScript('scoped-events', 'verify-scoped-events', { label: 'scoped events' }),
  312. pnpmScript('website-api', 'verify-website-api', { label: 'website api' }),
  313. pnpmScript('markdown-wrap', 'verify-md-wrap', { label: 'markdown wrap' }),
  314. pnpmScript('markdown-links', 'verify-md-links', { label: 'markdown links' }),
  315. pnpmScript('doc-refs', 'verify-doc-refs', { label: 'doc refs' }),
  316. pnpmScript('package-paths', 'verify-package-paths', { label: 'package paths' }),
  317. pnpmScript('package-readme-model-experience', 'verify-package-readme-model-experience', { label: 'package README model experience' }),
  318. pnpmScript('mermaid', 'verify-mermaid'),
  319. pnpmScript('rfc-classification', 'verify-rfc-classification', { label: 'rfc classification' }),
  320. pnpmScript('rfc-format', 'verify-rfc-format', { label: 'rfc format' }),
  321. pnpmScript('type-equivalence', 'verify-type-equiv', { label: 'type equivalence' }),
  322. pnpmScript('translation-prompt', 'verify-translation-prompt', { label: 'translation prompt' }),
  323. pnpmScript('translation-pairing', 'verify-translation-pairing', { label: 'translation pairing' }),
  324. pnpmScript('doc-budgets', 'verify-doc-budgets', { label: 'doc budgets' }),
  325. pnpmScript('package-readme-limitations', 'verify-package-readme-limitations', { label: 'package README limitations' }),
  326. pnpmScript('website-yaml', 'verify-website-yaml', { label: 'website yaml' }),
  327. ]
  328. }
  329. function demoSmokeGate(options: { needs?: string[] } = {}): Gate {
  330. const dependencyOptions = options.needs === undefined ? {} : { needs: options.needs }
  331. return {
  332. id: 'demo-smoke',
  333. label: 'demo smoke',
  334. displayCommand: 'pnpm run demo:echo',
  335. ...pnpmInvocation(['run', 'demo:echo']),
  336. input: 'echo ci smoke\n',
  337. ...dependencyOptions,
  338. verify: async (result) => {
  339. const output = result.stdout + result.stderr
  340. const sessionsRoot = join(root, '.sessions')
  341. try {
  342. if (!output.includes('[tool call] echo({"text":"ci smoke"})')) {
  343. throw new Error('demo smoke did not show the echo tool call.')
  344. }
  345. if (!output.includes('[tool result] ECHO: CI SMOKE')) {
  346. throw new Error('demo smoke did not show the echo tool result.')
  347. }
  348. const buckets = await readdir(sessionsRoot, { withFileTypes: true })
  349. let found = false
  350. for (const bucket of buckets) {
  351. if (!bucket.isDirectory() || !bucket.name.startsWith('cwd-')) continue
  352. const entries = await readdir(join(sessionsRoot, bucket.name))
  353. if (entries.some(entry => /^main-session-.+\.jsonl$/.test(entry))) {
  354. found = true
  355. break
  356. }
  357. }
  358. if (!found) throw new Error('demo smoke did not create a main-session JSONL log in a cwd bucket.')
  359. } finally {
  360. await rm(sessionsRoot, { recursive: true, force: true })
  361. }
  362. },
  363. }
  364. }
  365. function builtBinSmokeGate(): Gate {
  366. return pnpmExec('built-bin-smoke', [
  367. 'vitest',
  368. 'run',
  369. '--config',
  370. 'vitest.e2e.config.ts',
  371. 'packages/examples/stdio-demo/tests/built-bin.e2e.ts',
  372. 'packages/examples/acp-demo/tests/built-bin.e2e.ts',
  373. 'packages/ui/jsonrpc/tests/built-scope-carrier.e2e.ts',
  374. // The worker-entry packages' built bundles: the only automated proof
  375. // that lib/index.js resolves its sibling lib/worker.cjs under plain node
  376. // (the e2e lane runs unbuilt, so these files self-skip there).
  377. 'packages/workflow/workflow-workerthread/tests/built-worker.e2e.ts',
  378. 'packages/code-runtime/code-runtime-worker/tests/built-lib.e2e.ts',
  379. ], {
  380. label: 'built-bin smoke',
  381. needs: ['build'],
  382. })
  383. }
  384. async function runGates(allGates: Gate[], maxActive: number): Promise<GateResult[]> {
  385. const states = new Map<string, GateStatus>(allGates.map(gate => [gate.id, 'pending']))
  386. const results = new Map<string, GateResult>()
  387. const running: RunningGate[] = []
  388. for (;;) {
  389. let madeProgress = false
  390. while (running.length < maxActive) {
  391. const ready = allGates.find(gate => states.get(gate.id) === 'pending' && dependenciesPassed(gate, states))
  392. if (ready === undefined) break
  393. states.set(ready.id, 'running')
  394. running.push({ gate: ready, promise: runGate(ready) })
  395. console.log(`run-gates: start ${ready.label}`)
  396. madeProgress = true
  397. }
  398. if (running.length === 0) {
  399. const pending = allGates.filter(gate => states.get(gate.id) === 'pending')
  400. for (const gate of pending) {
  401. const failedDeps = (gate.needs ?? []).filter(id => states.get(id) !== 'passed')
  402. const result: GateResult = {
  403. gate,
  404. status: 'skipped',
  405. durationMs: 0,
  406. stdout: '',
  407. stderr: '',
  408. output: [],
  409. exitCode: null,
  410. error: `dependency failed or skipped: ${failedDeps.join(', ')}`,
  411. }
  412. states.set(gate.id, 'skipped')
  413. results.set(gate.id, result)
  414. printResult(result)
  415. }
  416. break
  417. }
  418. if (!madeProgress) {
  419. const settled = await Promise.race(running.map(async item => ({ item, result: await item.promise })))
  420. running.splice(running.indexOf(settled.item), 1)
  421. states.set(settled.item.gate.id, settled.result.status)
  422. results.set(settled.item.gate.id, settled.result)
  423. printResult(settled.result)
  424. }
  425. }
  426. return allGates.map((gate) => {
  427. const result = results.get(gate.id)
  428. if (result === undefined) throw new Error(`run-gates: missing result for ${gate.id}.`)
  429. return result
  430. })
  431. }
  432. function dependenciesPassed(gate: Gate, states: Map<string, GateStatus>): boolean {
  433. return (gate.needs ?? []).every(id => states.get(id) === 'passed')
  434. }
  435. async function runGate(gate: Gate): Promise<GateResult> {
  436. const started = performance.now()
  437. let stdout = ''
  438. let stderr = ''
  439. const output: GateOutputChunk[] = []
  440. let spawnError: string | undefined
  441. const exitCode = await new Promise<number | null>((resolveExit) => {
  442. const child = spawn(gate.command, gate.args, {
  443. cwd: root,
  444. env: { ...process.env, ...gate.env },
  445. stdio: ['pipe', 'pipe', 'pipe'],
  446. })
  447. child.stdout.setEncoding('utf8')
  448. child.stderr.setEncoding('utf8')
  449. child.stdout.on('data', (chunk: string) => {
  450. stdout += chunk
  451. output.push({ stream: 'stdout', text: chunk })
  452. })
  453. child.stderr.on('data', (chunk: string) => {
  454. stderr += chunk
  455. output.push({ stream: 'stderr', text: chunk })
  456. })
  457. child.on('error', (error) => {
  458. spawnError = `failed to start command: ${error.message}`
  459. resolveExit(null)
  460. })
  461. child.on('close', resolveExit)
  462. if (gate.input !== undefined) child.stdin.end(gate.input)
  463. else child.stdin.end()
  464. })
  465. let status: GateStatus = exitCode === 0 && spawnError === undefined ? 'passed' : 'failed'
  466. let error = spawnError
  467. if (status === 'passed' && gate.verify !== undefined) {
  468. try {
  469. await gate.verify({ gate, status, durationMs: performance.now() - started, stdout, stderr, output, exitCode })
  470. } catch (verifyError: unknown) {
  471. status = 'failed'
  472. error = verifyError instanceof Error ? verifyError.message : String(verifyError)
  473. }
  474. }
  475. const result: GateResult = {
  476. gate,
  477. status,
  478. durationMs: performance.now() - started,
  479. stdout,
  480. stderr,
  481. output,
  482. exitCode,
  483. }
  484. if (error !== undefined) result.error = error
  485. return result
  486. }
  487. function printResult(result: GateResult): void {
  488. const seconds = (result.durationMs / 1000).toFixed(2)
  489. if (result.status === 'passed' && !verbose) {
  490. console.log(`run-gates: PASS ${result.gate.label} (${seconds}s)`)
  491. return
  492. }
  493. const heading = `${result.status.toUpperCase()} ${result.gate.label} (${seconds}s)`
  494. const writeHeading = result.status === 'passed' ? console.log : console.error
  495. writeHeading(`\n== ${heading} ==`)
  496. if (result.status !== 'passed') console.error(`command: ${result.gate.displayCommand}`)
  497. printOutput(result.output)
  498. if (result.error !== undefined) console.error(result.error)
  499. }
  500. function printSummary(results: GateResult[], durationMs: number): void {
  501. const passed = results.filter(result => result.status === 'passed').length
  502. const failed = results.filter(result => result.status === 'failed').length
  503. const skipped = results.filter(result => result.status === 'skipped').length
  504. const seconds = (durationMs / 1000).toFixed(2)
  505. console.log(`\nrun-gates: ${passed} passed, ${failed} failed, ${skipped} skipped in ${seconds}s.`)
  506. const unsuccessful = results.filter(result => result.status === 'failed' || result.status === 'skipped')
  507. if (unsuccessful.length === 0) return
  508. console.error('run-gates: unsuccessful gates:')
  509. for (const result of unsuccessful) {
  510. const duration = (result.durationMs / 1000).toFixed(2)
  511. const reason = result.error ?? (result.exitCode === null ? 'no exit code' : `exit ${result.exitCode}`)
  512. console.error(` - ${result.status.toUpperCase()} ${result.gate.label} (${duration}s, ${reason})`)
  513. console.error(` ${result.gate.displayCommand}`)
  514. }
  515. }
  516. function printOutput(output: GateOutputChunk[]): void {
  517. for (const chunk of output) {
  518. if (chunk.stream === 'stdout') process.stdout.write(chunk.text)
  519. else process.stderr.write(chunk.text)
  520. }
  521. }