run-gates.ts 20 KB

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