run-gates.ts 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  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('package-invariants', 'verify-package-invariants', { label: 'package invariants' }),
  189. pnpmScript('cordis-config', 'verify-cordis-config', { label: 'Cordis config' }),
  190. pnpmScript('typecheck', 'typecheck'),
  191. lintGate(),
  192. pnpmScript('duplication', 'duplication'),
  193. coverageGate(),
  194. snapshotGate(),
  195. demoSmokeGate({ needs: ['lint'] }),
  196. ...docSyncLeafGates(),
  197. pnpmScript('module-graph', 'verify-module-graph', { label: 'module graph' }),
  198. pnpmScript('knip', 'knip'),
  199. pnpmScript('website-build', 'website:build', { label: 'website build' }),
  200. pnpmScript('build', 'build', { needs: ['typecheck'] }),
  201. pnpmScript('publint', 'publint', { needs: ['build'] }),
  202. pnpmScript('node-next-types', 'verify-node-next-types', {
  203. label: 'node-next types',
  204. needs: ['build'],
  205. }),
  206. builtBinSmokeGate(),
  207. ]
  208. }
  209. function ciStaticGates(): Gate[] {
  210. return [
  211. pnpmScript('runtime-closure', 'verify-runtime-closure', { label: 'runtime closure' }),
  212. pnpmScript('constraints', 'constraints'),
  213. pnpmScript('package-invariants', 'verify-package-invariants', { label: 'package invariants' }),
  214. pnpmScript('cordis-config', 'verify-cordis-config', { label: 'Cordis config' }),
  215. ...staticDemoSmokeGates(),
  216. ...docSyncLeafGates(),
  217. pnpmScript('module-graph', 'verify-module-graph', { label: 'module graph' }),
  218. pnpmScript('knip', 'knip'),
  219. pnpmScript('website-build', 'website:build', { label: 'website build' }),
  220. ]
  221. }
  222. function staticDemoSmokeGates(): Gate[] {
  223. // Native Windows session persistence is outside the gates-only support scope.
  224. return process.platform === 'win32' ? [] : [demoSmokeGate()]
  225. }
  226. function ciArtifactGates(): Gate[] {
  227. return [
  228. pnpmScript('build', 'build'),
  229. pnpmScript('publint', 'publint', { needs: ['build'] }),
  230. pnpmScript('node-next-types', 'verify-node-next-types', {
  231. label: 'node-next types',
  232. needs: ['build'],
  233. }),
  234. builtBinSmokeGate(),
  235. ]
  236. }
  237. function lintGate(): Gate {
  238. if (process.env.DSH_ESLINT_CACHE === '1') {
  239. return pnpmExec('lint', [
  240. 'eslint',
  241. '.',
  242. '--cache',
  243. '--cache-location',
  244. '.cache/eslint/',
  245. '--cache-strategy',
  246. 'content',
  247. ], {
  248. label: 'lint',
  249. env: { NODE_OPTIONS: nodeOptions('--max-old-space-size=8192') },
  250. })
  251. }
  252. return pnpmScript('lint', 'lint', {
  253. env: { NODE_OPTIONS: nodeOptions('--max-old-space-size=8192') },
  254. })
  255. }
  256. function coverageGate(): Gate {
  257. return pnpmExec('coverage', [
  258. 'vitest',
  259. 'run',
  260. '--coverage',
  261. ...positiveIntArg('DSH_COVERAGE_MAX_WORKERS', '--maxWorkers'),
  262. ], {
  263. label: 'test:coverage',
  264. env: { DSH_EXAMPLE_MODE: 'lib' },
  265. needs: ['build'],
  266. })
  267. }
  268. // The snapshot suite boots the example bins in `lib` mode (built artifact under plain Node,
  269. // plugins via real exports) — CI and pre-push already build, so they exercise what ships rather
  270. // than the tsx/source path dev uses. It therefore waits on `build`.
  271. function snapshotGate(): Gate {
  272. return pnpmScript('snapshot', 'test:snapshot', {
  273. env: { DSH_EXAMPLE_MODE: 'lib' },
  274. needs: ['build'],
  275. })
  276. }
  277. function positiveIntArg(envName: string, flag: string): string[] {
  278. const raw = process.env[envName]
  279. if (raw === undefined || raw === '') return []
  280. const parsed = Number.parseInt(raw, 10)
  281. if (!Number.isSafeInteger(parsed) || parsed < 1 || String(parsed) !== raw) {
  282. throw new Error(`run-gates: ${envName} must be a positive integer, got ${JSON.stringify(raw)}.`)
  283. }
  284. return [`${flag}=${raw}`]
  285. }
  286. function hygieneLeafGates(options: { artifactNeeds?: string[] } = {}): Gate[] {
  287. const artifactOptions = options.artifactNeeds === undefined ? {} : { needs: options.artifactNeeds }
  288. return [
  289. pnpmScript('knip', 'knip'),
  290. pnpmScript('publint', 'publint', artifactOptions),
  291. pnpmScript('constraints', 'constraints'),
  292. pnpmScript('package-invariants', 'verify-package-invariants', { label: 'package invariants' }),
  293. pnpmScript('node-next-types', 'verify-node-next-types', {
  294. label: 'node-next types',
  295. ...artifactOptions,
  296. }),
  297. ]
  298. }
  299. function docSyncLeafGates(options: {
  300. docTypecheckNeeds?: string[]
  301. docTypecheckEnv?: Record<string, string | undefined>
  302. } = {}): Gate[] {
  303. const docTypecheckOptions: Partial<Gate> = {}
  304. if (options.docTypecheckNeeds !== undefined) docTypecheckOptions.needs = options.docTypecheckNeeds
  305. if (options.docTypecheckEnv !== undefined) docTypecheckOptions.env = options.docTypecheckEnv
  306. return [
  307. pnpmScript('doc-typecheck', 'doc-typecheck', docTypecheckOptions),
  308. pnpmScript('cordis-catalog', 'verify-cordis-catalog', { label: 'cordis catalog' }),
  309. pnpmScript('export-jsdoc', 'verify-export-jsdoc', { label: 'export jsdoc' }),
  310. pnpmScript('tool-catalog', 'verify-tool-catalog', { label: 'tool catalog' }),
  311. pnpmScript('config-catalog', 'verify-config-catalog', { label: 'config catalog' }),
  312. pnpmScript('persistence-catalog', 'verify-persistence-catalog', { label: 'persistence catalog' }),
  313. pnpmScript('doc-graphs', 'verify-doc-graphs', { label: 'doc graphs' }),
  314. pnpmScript('scoped-events', 'verify-scoped-events', { label: 'scoped events' }),
  315. pnpmScript('website-api', 'verify-website-api', { label: 'website api' }),
  316. pnpmScript('markdown-wrap', 'verify-md-wrap', { label: 'markdown wrap' }),
  317. pnpmScript('markdown-links', 'verify-md-links', { label: 'markdown links' }),
  318. pnpmScript('doc-refs', 'verify-doc-refs', { label: 'doc refs' }),
  319. pnpmScript('package-paths', 'verify-package-paths', { label: 'package paths' }),
  320. pnpmScript('package-readme-model-experience', 'verify-package-readme-model-experience', { label: 'package README model experience' }),
  321. pnpmScript('mermaid', 'verify-mermaid'),
  322. pnpmScript('agent-note-classification', 'verify-agent-note-classification', { label: 'agent note classification' }),
  323. pnpmScript('agent-note-format', 'verify-agent-note-format', { label: 'agent note format' }),
  324. pnpmScript('type-equivalence', 'verify-type-equiv', { label: 'type equivalence' }),
  325. pnpmScript('translation-prompt', 'verify-translation-prompt', { label: 'translation prompt' }),
  326. pnpmScript('translation-pairing', 'verify-translation-pairing', { label: 'translation pairing' }),
  327. pnpmScript('doc-budgets', 'verify-doc-budgets', { label: 'doc budgets' }),
  328. pnpmScript('package-readme-limitations', 'verify-package-readme-limitations', { label: 'package README limitations' }),
  329. pnpmScript('website-yaml', 'verify-website-yaml', { label: 'website yaml' }),
  330. ]
  331. }
  332. function demoSmokeGate(options: { needs?: string[] } = {}): Gate {
  333. const dependencyOptions = options.needs === undefined ? {} : { needs: options.needs }
  334. return {
  335. id: 'demo-smoke',
  336. label: 'demo smoke',
  337. displayCommand: 'pnpm run demo:echo',
  338. ...pnpmInvocation(['run', 'demo:echo']),
  339. input: 'echo ci smoke\n',
  340. ...dependencyOptions,
  341. verify: async (result) => {
  342. const output = result.stdout + result.stderr
  343. const sessionsRoot = join(root, '.sessions')
  344. try {
  345. if (!output.includes('[tool call] echo({"text":"ci smoke"})')) {
  346. throw new Error('demo smoke did not show the echo tool call.')
  347. }
  348. if (!output.includes('[tool result] ECHO: CI SMOKE')) {
  349. throw new Error('demo smoke did not show the echo tool result.')
  350. }
  351. const buckets = await readdir(sessionsRoot, { withFileTypes: true })
  352. let found = false
  353. for (const bucket of buckets) {
  354. if (!bucket.isDirectory() || !bucket.name.startsWith('cwd-')) continue
  355. const entries = await readdir(join(sessionsRoot, bucket.name))
  356. if (entries.some(entry => /^main-session-.+\.jsonl$/.test(entry))) {
  357. found = true
  358. break
  359. }
  360. }
  361. if (!found) throw new Error('demo smoke did not create a main-session JSONL log in a cwd bucket.')
  362. } finally {
  363. await rm(sessionsRoot, { recursive: true, force: true })
  364. }
  365. },
  366. }
  367. }
  368. function builtBinSmokeGate(): Gate {
  369. return pnpmExec('built-bin-smoke', [
  370. 'vitest',
  371. 'run',
  372. '--config',
  373. 'vitest.e2e.config.ts',
  374. 'packages/examples/stdio-demo/tests/built-bin.e2e.ts',
  375. 'packages/examples/cli-demo/tests/built-bin.e2e.ts',
  376. 'packages/examples/acp-demo/tests/built-bin.e2e.ts',
  377. 'packages/ui/jsonrpc/tests/built-scope-carrier.e2e.ts',
  378. // The worker-entry packages' built bundles: the only automated proof
  379. // that lib/index.js resolves its sibling lib/worker.cjs under plain node
  380. // (the e2e lane runs unbuilt, so these files self-skip there).
  381. 'packages/workflow/workflow-workerthread/tests/built-worker.e2e.ts',
  382. 'packages/code-runtime/code-runtime-worker/tests/built-lib.e2e.ts',
  383. ], {
  384. label: 'built-bin smoke',
  385. needs: ['build'],
  386. })
  387. }
  388. async function runGates(allGates: Gate[], maxActive: number): Promise<GateResult[]> {
  389. const states = new Map<string, GateStatus>(allGates.map(gate => [gate.id, 'pending']))
  390. const results = new Map<string, GateResult>()
  391. const running: RunningGate[] = []
  392. for (;;) {
  393. let madeProgress = false
  394. while (running.length < maxActive) {
  395. const ready = allGates.find(gate => states.get(gate.id) === 'pending' && dependenciesPassed(gate, states))
  396. if (ready === undefined) break
  397. states.set(ready.id, 'running')
  398. running.push({ gate: ready, promise: runGate(ready) })
  399. console.log(`run-gates: start ${ready.label}`)
  400. madeProgress = true
  401. }
  402. if (running.length === 0) {
  403. const pending = allGates.filter(gate => states.get(gate.id) === 'pending')
  404. for (const gate of pending) {
  405. const failedDeps = (gate.needs ?? []).filter(id => states.get(id) !== 'passed')
  406. const result: GateResult = {
  407. gate,
  408. status: 'skipped',
  409. durationMs: 0,
  410. stdout: '',
  411. stderr: '',
  412. output: [],
  413. exitCode: null,
  414. error: `dependency failed or skipped: ${failedDeps.join(', ')}`,
  415. }
  416. states.set(gate.id, 'skipped')
  417. results.set(gate.id, result)
  418. printResult(result)
  419. }
  420. break
  421. }
  422. if (!madeProgress) {
  423. const settled = await Promise.race(running.map(async item => ({ item, result: await item.promise })))
  424. running.splice(running.indexOf(settled.item), 1)
  425. states.set(settled.item.gate.id, settled.result.status)
  426. results.set(settled.item.gate.id, settled.result)
  427. printResult(settled.result)
  428. }
  429. }
  430. return allGates.map((gate) => {
  431. const result = results.get(gate.id)
  432. if (result === undefined) throw new Error(`run-gates: missing result for ${gate.id}.`)
  433. return result
  434. })
  435. }
  436. function dependenciesPassed(gate: Gate, states: Map<string, GateStatus>): boolean {
  437. return (gate.needs ?? []).every(id => states.get(id) === 'passed')
  438. }
  439. async function runGate(gate: Gate): Promise<GateResult> {
  440. const started = performance.now()
  441. let stdout = ''
  442. let stderr = ''
  443. const output: GateOutputChunk[] = []
  444. let spawnError: string | undefined
  445. const exitCode = await new Promise<number | null>((resolveExit) => {
  446. const child = spawn(gate.command, gate.args, {
  447. cwd: root,
  448. env: { ...process.env, ...gate.env },
  449. stdio: ['pipe', 'pipe', 'pipe'],
  450. })
  451. child.stdout.setEncoding('utf8')
  452. child.stderr.setEncoding('utf8')
  453. child.stdout.on('data', (chunk: string) => {
  454. stdout += chunk
  455. output.push({ stream: 'stdout', text: chunk })
  456. })
  457. child.stderr.on('data', (chunk: string) => {
  458. stderr += chunk
  459. output.push({ stream: 'stderr', text: chunk })
  460. })
  461. child.on('error', (error) => {
  462. spawnError = `failed to start command: ${error.message}`
  463. resolveExit(null)
  464. })
  465. child.on('close', resolveExit)
  466. if (gate.input !== undefined) child.stdin.end(gate.input)
  467. else child.stdin.end()
  468. })
  469. let status: GateStatus = exitCode === 0 && spawnError === undefined ? 'passed' : 'failed'
  470. let error = spawnError
  471. if (status === 'passed' && gate.verify !== undefined) {
  472. try {
  473. await gate.verify({ gate, status, durationMs: performance.now() - started, stdout, stderr, output, exitCode })
  474. } catch (verifyError: unknown) {
  475. status = 'failed'
  476. error = verifyError instanceof Error ? verifyError.message : String(verifyError)
  477. }
  478. }
  479. const result: GateResult = {
  480. gate,
  481. status,
  482. durationMs: performance.now() - started,
  483. stdout,
  484. stderr,
  485. output,
  486. exitCode,
  487. }
  488. if (error !== undefined) result.error = error
  489. return result
  490. }
  491. function printResult(result: GateResult): void {
  492. const seconds = (result.durationMs / 1000).toFixed(2)
  493. if (result.status === 'passed' && !verbose) {
  494. console.log(`run-gates: PASS ${result.gate.label} (${seconds}s)`)
  495. return
  496. }
  497. const heading = `${result.status.toUpperCase()} ${result.gate.label} (${seconds}s)`
  498. const writeHeading = result.status === 'passed' ? console.log : console.error
  499. writeHeading(`\n== ${heading} ==`)
  500. if (result.status !== 'passed') console.error(`command: ${result.gate.displayCommand}`)
  501. printOutput(result.output)
  502. if (result.error !== undefined) console.error(result.error)
  503. }
  504. function printSummary(results: GateResult[], durationMs: number): void {
  505. const passed = results.filter(result => result.status === 'passed').length
  506. const failed = results.filter(result => result.status === 'failed').length
  507. const skipped = results.filter(result => result.status === 'skipped').length
  508. const seconds = (durationMs / 1000).toFixed(2)
  509. console.log(`\nrun-gates: ${passed} passed, ${failed} failed, ${skipped} skipped in ${seconds}s.`)
  510. const unsuccessful = results.filter(result => result.status === 'failed' || result.status === 'skipped')
  511. if (unsuccessful.length === 0) return
  512. console.error('run-gates: unsuccessful gates:')
  513. for (const result of unsuccessful) {
  514. const duration = (result.durationMs / 1000).toFixed(2)
  515. const reason = result.error ?? (result.exitCode === null ? 'no exit code' : `exit ${result.exitCode}`)
  516. console.error(` - ${result.status.toUpperCase()} ${result.gate.label} (${duration}s, ${reason})`)
  517. console.error(` ${result.gate.displayCommand}`)
  518. }
  519. }
  520. function printOutput(output: GateOutputChunk[]): void {
  521. for (const chunk of output) {
  522. if (chunk.stream === 'stdout') process.stdout.write(chunk.text)
  523. else process.stderr.write(chunk.text)
  524. }
  525. }