ci-workflow.spec.ts 63 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162
  1. import { readFileSync } from 'node:fs'
  2. import { resolve } from 'node:path'
  3. import { runInNewContext } from 'node:vm'
  4. import * as yaml from 'js-yaml'
  5. import { describe, expect, it } from 'vitest'
  6. function evaluateRunsOn(selector: unknown, context: Record<string, unknown>): unknown {
  7. if (typeof selector !== 'string') throw new TypeError('Runner selector must be a string')
  8. return runInNewContext(selector.trim().slice(3, -2), context, { timeout: 1000 })
  9. }
  10. const root = resolve(import.meta.dirname, '..')
  11. const runnerPrivatePnpmDestination = /^\$\{\{ runner\.temp \}\}\/setup-pnpm-\$\{\{ github\.run_id \}\}-\$\{\{ github\.run_attempt \}\}$/
  12. const nativeWindowsPnpmDestination = '${{ runner.temp }}/setup-pnpm-js-${{ github.run_id }}-${{ github.run_attempt }}-${{ github.job }}'
  13. describe('CI workflow', () => {
  14. it('prepares confinement before Node compatibility smokes', () => {
  15. const job = workflowJob(loadWorkflow('.github/workflows/ci.yml'), 'node-compat')
  16. if (!Array.isArray(job.steps)) throw new TypeError('Node compatibility job must define steps')
  17. const steps = job.steps.filter(isRecord)
  18. const preparation = steps.findIndex(step => step.run === 'bash scripts/prepare-ci-bubblewrap.sh')
  19. const smoke = steps.findIndex(step => step.run === 'pnpm run check:node-compat')
  20. expect(preparation).toBeGreaterThanOrEqual(0)
  21. expect(smoke).toBeGreaterThan(preparation)
  22. expect(steps[preparation]).not.toHaveProperty('continue-on-error', true)
  23. })
  24. it.each(['ci.yml', 'ci-master.yml', 'e2e.yml', 'release.yml', 'release-vendor.yml'])(
  25. '%s cancels superseded validation runs without crossing workflow or ref boundaries', (name) => {
  26. const workflow = loadWorkflow('.github/workflows/' + name)
  27. expect(workflow.concurrency).toEqual({
  28. group: '${{ github.workflow }}-${{ github.ref }}',
  29. 'cancel-in-progress': true,
  30. })
  31. },
  32. )
  33. it('cancels reusable CI builds without cancelling release-owned builds', () => {
  34. const workflow = loadWorkflow('.github/workflows/build-exe-for-python-sdk.yml')
  35. expect(workflow.concurrency).toEqual({
  36. group: 'build-single-exe-${{ github.workflow }}-${{ github.ref }}',
  37. 'cancel-in-progress': '${{ !inputs.release }}',
  38. })
  39. })
  40. it('does not cancel protected publication or deployment transactions', () => {
  41. for (const name of ['release-publish.yml', 'release-vendor-publish.yml']) {
  42. const publish = workflowJob(loadWorkflow('.github/workflows/' + name), 'publish')
  43. expect(publish.concurrency).toMatchObject({ 'cancel-in-progress': false })
  44. }
  45. for (const name of ['python-release.yml', 'node-addon-system-release.yml', 'docs-pages.yml']) {
  46. expect(loadWorkflow('.github/workflows/' + name).concurrency).toMatchObject({ 'cancel-in-progress': false })
  47. }
  48. })
  49. it('skips coverage-history uploads on cancellation but retains Wine cleanup', () => {
  50. const coverage = workflowJob(loadWorkflow('.github/workflows/ci.yml'), 'windows-coverage')
  51. const wine = workflowJob(loadWorkflow('.github/workflows/ci-master.yml'), 'windows')
  52. expect(coverage.steps).toContainEqual(expect.objectContaining({
  53. name: 'Save coverage duration history', if: '${{ !cancelled() }}',
  54. }))
  55. expect(wine.steps).toContainEqual(expect.objectContaining({ name: 'Shut down wineserver', if: 'always()' }))
  56. })
  57. it('isolates every pnpm action setup destination per runner', () => {
  58. const files = ['.github/workflows/ci.yml', '.github/workflows/ci-master.yml']
  59. const setups: Array<{ jobName: string; step: unknown }> = []
  60. for (const file of files) {
  61. const workflow: unknown = yaml.load(readFileSync(resolve(root, file), 'utf8'))
  62. if (!isRecord(workflow) || !isRecord(workflow.jobs)) throw new TypeError(`${file} must define jobs`)
  63. for (const [jobName, job] of Object.entries(workflow.jobs)) {
  64. if (!isRecord(job) || !Array.isArray(job.steps)) continue
  65. for (const step of job.steps) {
  66. if (!isRecord(step) || typeof step.uses !== 'string' || !step.uses.startsWith('pnpm/action-setup@')) continue
  67. setups.push({ jobName, step })
  68. }
  69. }
  70. }
  71. expect(setups.length).toBeGreaterThan(0)
  72. for (const { jobName, step } of setups) {
  73. const stepDest = (step as { with?: { dest?: unknown } }).with?.dest
  74. if (jobName.startsWith('windows-')) {
  75. expect(stepDest, `${jobName} must use the native Windows pnpm destination`).toBe(nativeWindowsPnpmDestination)
  76. expect(step).not.toMatchObject({ with: { standalone: true } })
  77. } else {
  78. expect(typeof stepDest, `${jobName} must use a runner-and-run-private pnpm destination`).toBe('string')
  79. expect(stepDest as string).toMatch(runnerPrivatePnpmDestination)
  80. }
  81. }
  82. })
  83. it.each(['node-24', 'node-24-coverage', 'node-24-consumers'])(
  84. '%s keeps tool and fixture temporary files under runner cleanup',
  85. (jobName) => {
  86. const job = workflowJob(loadWorkflow('.github/workflows/ci.yml'), jobName)
  87. if (!Array.isArray(job.steps)) throw new TypeError(`${jobName} must define steps`)
  88. expect(job.steps[0]).toEqual({
  89. name: 'Use runner-owned temporary storage',
  90. run: [
  91. 'echo "TMPDIR=${{ runner.temp }}" >> "$GITHUB_ENV"',
  92. ...(jobName === 'node-24-consumers'
  93. ? ['echo "PLAYWRIGHT_BROWSERS_PATH=${RUNNER_TEMP%/*}/ms-playwright" >> "$GITHUB_ENV"']
  94. : []),
  95. '',
  96. ].join('\n'),
  97. })
  98. if (jobName === 'node-24-consumers') {
  99. const browserCache: unknown = job.steps.find(step => isRecord(step) && isRecord(step.with)
  100. && step.with.path === '${{ env.PLAYWRIGHT_BROWSERS_PATH }}')
  101. expect(browserCache).toMatchObject({ uses: 'actions/cache/restore@v4' })
  102. }
  103. const store: unknown = job.steps.find(step => isRecord(step) && step.name === 'Configure pnpm store path')
  104. expect(store).toMatchObject({
  105. run: [
  106. 'store_root="$HOME/.local/share/pnpm/store"',
  107. 'echo "PNPM_CONFIG_STORE_DIR=$store_root" >> "$GITHUB_ENV"',
  108. 'store_path=$(PNPM_CONFIG_STORE_DIR="$store_root" pnpm store path --silent)',
  109. 'echo "path=$store_path" >> "$GITHUB_OUTPUT"',
  110. '',
  111. ].join('\n'),
  112. })
  113. for (const step of job.steps) {
  114. if (isRecord(step) && isRecord(step.env)) {
  115. expect(step.env.TMPDIR).toBeUndefined()
  116. expect(step.env.npm_config_cache).toBeUndefined()
  117. }
  118. }
  119. },
  120. )
  121. it('isolates the python SDK exe pnpm setup destination per job', () => {
  122. const workflow: unknown = yaml.load(readFileSync(resolve(root, '.github/workflows/build-exe-for-python-sdk.yml'), 'utf8'))
  123. if (!isRecord(workflow) || !isRecord(workflow.jobs)) throw new TypeError('build-exe-for-python-sdk.yml must define jobs')
  124. const setups: Array<{ step: unknown }> = []
  125. for (const job of Object.values(workflow.jobs)) {
  126. if (!isRecord(job) || !Array.isArray(job.steps)) continue
  127. for (const step of job.steps) {
  128. if (!isRecord(step) || typeof step.uses !== 'string' || !step.uses.startsWith('pnpm/action-setup@')) continue
  129. setups.push({ step })
  130. }
  131. }
  132. expect(setups.length).toBeGreaterThan(0)
  133. for (const { step } of setups) {
  134. expect(step).toMatchObject({
  135. with: { dest: nativeWindowsPnpmDestination },
  136. })
  137. }
  138. })
  139. it('keeps split native Windows PR jobs with failover, plus a master-only standby', () => {
  140. const workflow = loadWorkflow('.github/workflows/ci.yml')
  141. const masterWorkflow = loadWorkflow('.github/workflows/ci-master.yml')
  142. if (!isRecord(workflow.jobs)
  143. || !isRecord(workflow.jobs['windows-build'])
  144. || !isRecord(workflow.jobs['windows-coverage'])
  145. || !isRecord(workflow.jobs['windows-native-tests'])
  146. || !isRecord(workflow.jobs['windows-observational'])
  147. || !isRecord(workflow.jobs['node-24'])
  148. || !isRecord(workflow.jobs['node-24-coverage'])
  149. || !isRecord(workflow.jobs['node-24-bench'])
  150. || !isRecord(workflow.jobs['node-24-consumers'])
  151. || !isRecord(workflow.jobs['node-compat'])
  152. || !isRecord(workflow.jobs['all-checks-passed'])
  153. || !isRecord(masterWorkflow.jobs)
  154. || !isRecord(masterWorkflow.jobs['serial-windows'])) {
  155. throw new TypeError('CI workflow must define windows-build, windows-coverage, windows-native-tests, windows-observational, node-24, node-24-coverage, node-24-bench, node-24-consumers, node-compat, and all-checks-passed; ci-master must define serial-windows')
  156. }
  157. const windowsBuild = workflow.jobs['windows-build']
  158. const windowsCoverage = workflow.jobs['windows-coverage']
  159. const windowsNativeTests = workflow.jobs['windows-native-tests']
  160. const windowsObservational = workflow.jobs['windows-observational']
  161. const serialWindows = masterWorkflow.jobs['serial-windows']
  162. const node24 = workflow.jobs['node-24']
  163. const node24Coverage = workflow.jobs['node-24-coverage']
  164. const node24Bench = workflow.jobs['node-24-bench']
  165. const node24Consumers = workflow.jobs['node-24-consumers']
  166. const nodeCompat = workflow.jobs['node-compat']
  167. const aggregate = workflow.jobs['all-checks-passed']
  168. if (!Array.isArray(aggregate.needs)) {
  169. throw new TypeError('CI aggregate must define needs')
  170. }
  171. // The split native jobs all resolve their pool through the Windows switch.
  172. for (const [jobName, job] of [['windows-build', windowsBuild], ['windows-coverage', windowsCoverage], ['windows-native-tests', windowsNativeTests], ['windows-observational', windowsObservational]] as const) {
  173. expect(typeof job['runs-on']).toBe('string')
  174. expect(job['runs-on'], `${jobName} runs-on must use the Windows failover switch`).toContain('DSH_CI_FAILOVER_WINDOWS')
  175. expect(job['runs-on'], `${jobName} runs-on must not use the Linux failover switch`).not.toContain('DSH_CI_FAILOVER_LINUX')
  176. expect(job['runs-on']).toContain('self-hosted')
  177. expect(job['runs-on']).toContain('dsh-win-ci')
  178. expect(job['runs-on']).toContain('dsh-windows-2025-16core')
  179. expect(job['runs-on']).toContain('blacksmith-16vcpu-windows-2025')
  180. expect(job.if).toBe("github.event_name == 'pull_request'")
  181. }
  182. // windows-build runs the blocking build/site pair.
  183. expect(windowsBuild.name).toBe('windows node 24 / build')
  184. const buildSteps = windowsBuild.steps as unknown[]
  185. const buildCommands = buildSteps.filter((step): step is Record<string, unknown> & { run: string } => (
  186. isRecord(step) && typeof step.run === 'string'
  187. ))
  188. expect(buildCommands.map(step => step.run)).toContain('pnpm run check:ci:windows-blocking')
  189. // The four native Windows installs branch on the workspace filesystem:
  190. // clone (ReFS block clone) only on ReFS, plain install elsewhere. This
  191. // keeps the TS6231 store-path leak (see the Windows ReFS store note) out
  192. // of the self-hosted pool without forcing clone onto hosted NTFS, which
  193. // rejects copy-on-write. The branch must stay, or a hosted fallback would
  194. // fail installs with ERR_PNPM_LINKING_FAILED.
  195. for (const [jobName, job] of [['windows-build', windowsBuild], ['windows-coverage', windowsCoverage], ['windows-native-tests', windowsNativeTests], ['windows-observational', windowsObservational]] as const) {
  196. const steps = job.steps as unknown[]
  197. const install = steps.find((step): step is Record<string, unknown> & { run: string } => (
  198. isRecord(step) && step.name === 'Install (immutable)' && typeof step.run === 'string'
  199. ))
  200. expect(install, `${jobName} must define the filesystem-branched install`).toBeDefined()
  201. expect(install!.run).toContain("$fs -eq 'ReFS'")
  202. expect(install!.run).toContain('--package-import-method=clone')
  203. expect(install!.run).toContain('corepack pnpm install')
  204. // The else branch must keep the plain hosted install as a distinct line
  205. // (not the corepack clone line, which contains the same substring);
  206. // dropping it or making both branches clone would force clone onto
  207. // NTFS, which rejects copy-on-write (ERR_PNPM_LINKING_FAILED). The
  208. // YAML folded block keeps the first statement on line 1 and folds the
  209. // rest with leading two-space indents.
  210. const installLines = install!.run.split('\n').map(line => line.trim())
  211. expect(installLines).toContain('} else {')
  212. expect(installLines.some(line => line === 'pnpm install --frozen-lockfile'), `${jobName} else branch must keep the plain hosted install`).toBe(true)
  213. // The ReFS branch must not use the interpolated empty-flag form, which
  214. // passes a stray "" positional argument to pnpm.
  215. expect(install!.run).not.toContain('$cloneFlag')
  216. }
  217. // windows-coverage uses the lower 4-partition profile.
  218. expect(windowsCoverage.name).toBe('windows node 24 / coverage')
  219. expect(windowsCoverage.env).toMatchObject({ DSH_COVERAGE_PARTITIONS: '4' })
  220. const coverageSteps = windowsCoverage.steps as unknown[]
  221. const coverageCommands = coverageSteps.filter((step): step is Record<string, unknown> & { run: string } => (
  222. isRecord(step) && typeof step.run === 'string'
  223. ))
  224. expect(coverageCommands.map(step => step.run)).toContain('pnpm run check:ci:coverage')
  225. // Windows coverage runs zero-build like the Linux lane: workspace imports
  226. // resolve to src through the tsconfig paths map, and the lib-consuming
  227. // suites (webworker-packer image-loadable, webworker-runtime
  228. // transform-corpus, client ui-trajectory client-bundle) self-skip on
  229. // unbuilt checkouts. The regex catches a regression spelled as
  230. // 'corepack pnpm run build' or folded into a multi-line run block, which
  231. // an exact string match would miss.
  232. expect(coverageCommands.every(step => !/\bpnpm\s+run\s+build(?:\s|$)/.test(step.run))).toBe(true)
  233. // windows-native-tests runs the Windows-specific specs.
  234. expect(windowsNativeTests.name).toBe('windows node 24 / native tests')
  235. const nativeTestSteps = windowsNativeTests.steps as unknown[]
  236. const nativeTestCommands = nativeTestSteps.filter((step): step is Record<string, unknown> & { run: string } => (
  237. isRecord(step) && typeof step.run === 'string'
  238. ))
  239. const nativeTestCommand = nativeTestCommands.map(step => step.run).join('\n')
  240. expect(nativeTestCommand).toContain('--no-file-parallelism')
  241. expect(nativeTestCommand).toContain('--testTimeout 90000')
  242. expect(nativeTestCommand).toContain('tool-pwsh/tests/loader.spec.ts')
  243. expect(nativeTestCommand).toContain('workflow-ptc.spec.ts')
  244. // windows-observational is non-blocking.
  245. expect(windowsObservational.name).toBe('windows node 24 / observational')
  246. expect(windowsObservational['continue-on-error']).toBe(true)
  247. // serial-windows: master-only standby, self-hosted, non-blocking, lives in ci-master.
  248. expect(serialWindows.if).toBe("github.event_name == 'push' && github.ref == 'refs/heads/master'")
  249. expect(serialWindows['runs-on']).toEqual(['self-hosted', 'dsh-win-ci', 'windows'])
  250. expect(serialWindows.name).toBe('serial / windows (self-hosted standby)')
  251. // Its store must share the ReFS workspace volume for clone; the install
  252. // must carry the same filesystem branch as the PR jobs.
  253. const serialSteps = serialWindows.steps as unknown[]
  254. const serialStore = serialSteps.find((step): step is Record<string, unknown> & { run: string } => (
  255. isRecord(step) && step.name === 'Configure persistent pnpm store' && typeof step.run === 'string'
  256. ))
  257. expect(serialStore).toBeDefined()
  258. expect(serialStore!.run).toContain('[IO.Path]::GetPathRoot($env:GITHUB_WORKSPACE)')
  259. expect(serialStore!.run).toContain("'.pnpm-store'")
  260. const serialInstall = serialSteps.find((step): step is Record<string, unknown> & { run: string } => (
  261. isRecord(step) && step.name === 'Install (immutable)' && typeof step.run === 'string'
  262. ))
  263. expect(serialInstall).toBeDefined()
  264. expect(serialInstall!.run).toContain("$fs -eq 'ReFS'")
  265. expect(serialInstall!.run).toContain('--package-import-method=clone')
  266. expect(serialInstall!.run).toContain('corepack pnpm install')
  267. // Distinct else-branch line, as for the PR jobs: the corepack clone line
  268. // contains the plain-install substring too.
  269. expect(serialInstall!.run.split('\n').map(line => line.trim())).toContain('} else {')
  270. expect(serialInstall!.run.split('\n').map(line => line.trim())).toContain('pnpm install --frozen-lockfile')
  271. expect(serialInstall!.run).not.toContain('$cloneFlag')
  272. // The unsharded reference runs the whole coverage inventory at the same
  273. // per-test budget the PR coverage lane grants; the default 5000ms times
  274. // out load-sensitive store scans (e.g. gen-third-party-notices).
  275. const serialGate = serialSteps.find((step): step is Record<string, unknown> & { env?: Record<string, unknown> } => (
  276. isRecord(step) && step.name === 'Run complete unsharded Windows gate inventory serially'
  277. ))
  278. expect(serialGate).toBeDefined()
  279. expect(serialGate!.env).toMatchObject({ DSH_COVERAGE_TEST_TIMEOUT_MS: '90000' })
  280. // windows-coverage is temporarily non-blocking while Windows ACP
  281. // half-close tests are stabilized; observational stays out too.
  282. expect(aggregate.needs).not.toContain('windows')
  283. expect(aggregate.needs).toContain('windows-build')
  284. // The benchmark lane is a required verdict input and runs alone so its
  285. // wall-clock budgets never share a runner with a concurrent aggregate.
  286. expect(aggregate.needs).toContain('node-24-bench')
  287. expect(node24Bench.name).toBe('node 24 / benchmarks')
  288. expect(node24Bench.env).toBeUndefined()
  289. expect(node24Bench.steps).toContainEqual({
  290. name: 'Install benchmark browser and hosted dependencies',
  291. run: 'pnpm --filter @deepseek-ai/dsh-benchmarks exec playwright install --with-deps chromium',
  292. })
  293. expect(JSON.stringify(node24Bench.steps)).not.toContain('DSH_CI_FAILOVER_LINUX')
  294. expect(node24Bench.steps).toContainEqual({
  295. name: 'Run performance benchmarks',
  296. env: { DSH_GATE_VERBOSE: '1' },
  297. run: 'pnpm run check:ci:bench',
  298. })
  299. expect(aggregate.needs).not.toContain('windows-coverage')
  300. expect(aggregate.needs).toContain('windows-native-tests')
  301. expect(aggregate.needs).not.toContain('windows-observational')
  302. expect(aggregate.needs).not.toContain('serial-windows')
  303. // Linux failover is a separate switch: the three enterprise Linux workers
  304. // and the verdict job resolve their pool through DSH_CI_FAILOVER_LINUX,
  305. // never the Windows switch.
  306. for (const [jobName, job] of [['node-24', node24], ['node-24-coverage', node24Coverage], ['node-24-consumers', node24Consumers]] as const) {
  307. expect(typeof job['runs-on']).toBe('string')
  308. expect(job['runs-on'], `${jobName} runs-on must use the Linux failover switch`).toContain('DSH_CI_FAILOVER_LINUX')
  309. expect(job['runs-on'], `${jobName} runs-on must not use the Windows failover switch`).not.toContain('DSH_CI_FAILOVER_WINDOWS')
  310. expect(job['runs-on']).toContain('vm-backup')
  311. expect(job['runs-on']).toContain('blacksmith-16vcpu-ubuntu-2404')
  312. }
  313. expect(aggregate['runs-on']).toContain('DSH_CI_FAILOVER_LINUX')
  314. expect(aggregate['runs-on']).not.toContain('DSH_CI_FAILOVER_WINDOWS')
  315. expect(aggregate['runs-on']).toContain('vm-backup')
  316. expect(aggregate['runs-on']).toContain('blacksmith-4vcpu-ubuntu-2404')
  317. // Evaluating the full selector, not just substring containment, proves the
  318. // blacksmith branch is standalone: it must not fall through to the
  319. // self-hosted pool when the two values are mutually exclusive.
  320. const selectors = {
  321. linux: node24['runs-on'] as string,
  322. linuxAggregate: aggregate['runs-on'] as string,
  323. windows: windowsBuild['runs-on'] as string,
  324. }
  325. const evaluate = (expression: string, vars: Record<string, string>, login = 'maintainer'): unknown => {
  326. return evaluateRunsOn(expression, {
  327. vars,
  328. fromJSON: JSON.parse,
  329. github: { event: { pull_request: { user: { login } } } },
  330. })
  331. }
  332. for (const [name, selector, variable, pool, hosted] of [
  333. ['linux gates', selectors.linux, 'DSH_CI_FAILOVER_LINUX', ['self-hosted', 'linux', 'x64', 'vm-backup'], 'dsh-ubuntu-24-04-16core'],
  334. ['linux aggregate', selectors.linuxAggregate, 'DSH_CI_FAILOVER_LINUX', ['self-hosted', 'linux', 'x64', 'vm-backup'], 'ubuntu-latest'],
  335. ['windows lanes', selectors.windows, 'DSH_CI_FAILOVER_WINDOWS', ['self-hosted', 'dsh-win-ci', 'windows'], 'dsh-windows-2025-16core'],
  336. ] as const) {
  337. expect(evaluate(selector, { [variable]: 'blacksmith' }), `${name} blacksmith value`).toMatch(/^blacksmith-/)
  338. expect(evaluate(selector, { [variable]: 'selfhosted' }), `${name} selfhosted value`).toEqual(pool)
  339. // The blacksmith branch must not capture the selfhosted pool, and the
  340. // dependabot exclusion applies to the pool, not to the blacksmith tier.
  341. expect(evaluate(selector, { [variable]: 'selfhosted' }, 'dependabot[bot]'), `${name} dependabot on selfhosted`).toBe(hosted)
  342. for (const mode of ['', 'hosted', 'unexpected']) {
  343. expect(evaluate(selector, { [variable]: mode }), `${name} default on ${mode}`).toBe(hosted)
  344. }
  345. }
  346. // The run-gates aggregate lanes stop at the first blocking gate failure so
  347. // a red aggregate does not keep burning runner time on the remaining
  348. // gates. Removing the flag silently reverts to running every independent
  349. // gate to completion.
  350. for (const [jobName, job] of [['node-24', node24], ['node-24-coverage', node24Coverage], ['node-24-consumers', node24Consumers], ['node-compat', nodeCompat]] as const) {
  351. expect(job.env, `${jobName} must enable fail-fast`).toMatchObject({ DSH_GATE_FAIL_FAST: '1' })
  352. }
  353. // The native Windows lanes with run-gates aggregates fail fast for the
  354. // same reason: a failing gate aborts the sibling gate instead of waiting
  355. // out the multi-minute instrumented coverage run.
  356. expect(windowsBuild.env, 'windows-build must enable fail-fast').toMatchObject({ DSH_GATE_FAIL_FAST: '1' })
  357. expect(windowsCoverage.env, 'windows-coverage must enable fail-fast').toMatchObject({ DSH_GATE_FAIL_FAST: '1' })
  358. // The observational lane stays complete: it is continue-on-error by design
  359. // and exists to collect as much Windows-native evidence per run as
  360. // possible, so the first failure must not truncate the rest.
  361. expect(windowsObservational.env).toBeDefined()
  362. expect(windowsObservational.env).not.toMatchObject({ DSH_GATE_FAIL_FAST: '1' })
  363. })
  364. it('gates standalone keyless blacksmith jobs and benchmark tiers on the failover variables', () => {
  365. const expectedFilenames = workflowJob(loadWorkflow('.github/workflows/expected-filenames.yml'), 'expected-filenames')
  366. const sandbox = workflowJob(loadWorkflow('.github/workflows/sandbox.yml'), 'sandbox-e2e')
  367. expect(expectedFilenames['runs-on']).toContain('DSH_CI_FAILOVER_LINUX')
  368. expect(expectedFilenames['runs-on']).toContain("== 'blacksmith'")
  369. expect(expectedFilenames['runs-on']).toContain('blacksmith-4vcpu-ubuntu-2404')
  370. expect(expectedFilenames['runs-on']).toContain("'ubuntu-latest'")
  371. expect(sandbox['runs-on']).toContain("matrix.runner == 'bwrap'")
  372. expect(sandbox['runs-on']).toContain('DSH_CI_FAILOVER_LINUX')
  373. expect(sandbox['runs-on']).toContain('blacksmith-4vcpu-ubuntu-2404')
  374. for (const name of ['larger-runner-benchmark', 'consolidated-runner-benchmark'] as const) {
  375. const benchmark = workflowJob(loadWorkflow('.github/workflows/ci-master.yml'), name)
  376. if (!isRecord(benchmark.strategy) || !isRecord(benchmark.strategy.matrix) || !Array.isArray(benchmark.strategy.matrix.include)) {
  377. throw new TypeError(`${name} must define a matrix include list`)
  378. }
  379. expect(benchmark['runs-on']).toContain('matrix.blacksmith')
  380. expect(benchmark['runs-on']).toContain('DSH_CI_FAILOVER_LINUX')
  381. expect(benchmark['runs-on']).toContain('DSH_CI_FAILOVER_WINDOWS')
  382. for (const row of benchmark.strategy.matrix.include as Array<Record<string, string>>) {
  383. expect(typeof row.blacksmith, `${name} ${row.cores}-core row must declare a blacksmith label`).toBe('string')
  384. if (row.cores === '64' || row.cores === '96') {
  385. expect(row.blacksmith, `${name} ${row.cores}-core row has no Blacksmith tier`).toBe('')
  386. } else {
  387. expect(row.blacksmith).toContain(`blacksmith-${row.cores}vcpu`)
  388. }
  389. }
  390. }
  391. })
  392. it('runs required benchmarks on standard hosted Linux independently of failover', () => {
  393. const workflow = loadWorkflow('.github/workflows/ci.yml')
  394. const benchmark = workflowJob(workflow, 'node-24-bench')
  395. const aggregate = workflowJob(workflow, 'all-checks-passed')
  396. expect(benchmark['runs-on']).toBe('ubuntu-24.04')
  397. expect(benchmark.if).toBe("github.event_name == 'pull_request'")
  398. expect(benchmark.needs).toBeUndefined()
  399. expect(benchmark['continue-on-error']).toBeUndefined()
  400. expect(benchmark.env).toBeUndefined()
  401. expect(aggregate.needs).toContain('node-24-bench')
  402. })
  403. it('always restores the hosted benchmark pnpm cache', () => {
  404. const benchmark = workflowJob(loadWorkflow('.github/workflows/ci.yml'), 'node-24-bench')
  405. if (!Array.isArray(benchmark.steps)) throw new TypeError('benchmark job must define steps')
  406. const caches = benchmark.steps.filter(step => isRecord(step) && step.uses === 'actions/cache/restore@v4')
  407. expect(caches).toHaveLength(1)
  408. expect(caches[0]).not.toHaveProperty('if')
  409. expect(caches[0]).toMatchObject({
  410. with: {
  411. path: '${{ steps.pnpm-store.outputs.path }}',
  412. key: "${{ runner.os }}-node-${{ env.PRIMARY_NODE_VERSION }}-pnpm-${{ hashFiles('pnpm-lock.yaml') }}",
  413. },
  414. })
  415. })
  416. it('bounds the complete benchmark job to fifteen minutes', () => {
  417. const benchmark = workflowJob(loadWorkflow('.github/workflows/ci.yml'), 'node-24-bench')
  418. expect(benchmark['timeout-minutes']).toBe(15)
  419. expect(benchmark.steps).toContainEqual({
  420. name: 'Run performance benchmarks',
  421. env: { DSH_GATE_VERBOSE: '1' },
  422. run: 'pnpm run check:ci:bench',
  423. })
  424. })
  425. it('gives the Wine Host TypeScript compile the repository heap budget', () => {
  426. const wineGates = readFileSync(resolve(root, 'scripts/wine-windows-gates.sh'), 'utf8')
  427. expect(wineGates).toContain(
  428. 'wine_node "$scratch/logs/host-tsc.log" --max-old-space-size=4096 "$tsc_js" -b tsconfig.host.json --pretty false',
  429. )
  430. })
  431. it('cancels superseded master runs without changing the post-merge job inventory', () => {
  432. const workflow = loadWorkflow('.github/workflows/ci-master.yml')
  433. const prWorkflow = loadWorkflow('.github/workflows/ci.yml')
  434. if (!isRecord(workflow.jobs) || !isRecord(workflow.concurrency)) {
  435. throw new TypeError('ci-master workflow must define jobs and a workflow-level concurrency block')
  436. }
  437. if (!isRecord(prWorkflow.jobs)) {
  438. throw new TypeError('ci workflow must define jobs')
  439. }
  440. expect(workflow.concurrency).toEqual({
  441. group: '${{ github.workflow }}-${{ github.ref }}',
  442. 'cancel-in-progress': true,
  443. })
  444. expect(prWorkflow.concurrency).toEqual(workflow.concurrency)
  445. // The exact event sets are what keep master-only jobs out of the PR check
  446. // panel: ci-master triggers only on push(master) + workflow_dispatch and
  447. // never on pull_request; ci.yml is exactly pull_request-only. Assert the
  448. // full sets so losing the wrong event, or gaining an extra one, fails.
  449. if (!isRecord(workflow.on) || !isRecord(prWorkflow.on)) {
  450. throw new TypeError('both CI workflows must define on')
  451. }
  452. expect(Object.keys(workflow.on).sort()).toEqual(['push', 'workflow_dispatch'])
  453. expect(Object.keys(prWorkflow.on)).toEqual(['pull_request'])
  454. // Drills share the parent run’s supersession policy.
  455. for (const name of ['serial-linux-selfhosted', 'serial-windows']) {
  456. const job = workflow.jobs[name]
  457. if (!isRecord(job)) throw new TypeError(`${name} must be defined`)
  458. expect(job.concurrency).toBeUndefined()
  459. // Standby drills remain post-merge work, but share run cancellation.
  460. expect(job.if).toBe("github.event_name == 'push' && github.ref == 'refs/heads/master'")
  461. }
  462. // Pin the post-merge runtime, Wine, and standby inventory.
  463. const NOT_PUSH_REACHABLE = new Set([
  464. "github.event_name == 'workflow_dispatch' && inputs.suite == 'larger-runner-benchmark'",
  465. "github.event_name == 'workflow_dispatch' && inputs.suite == 'consolidated-runner-benchmark'",
  466. ])
  467. const pushReachable = Object.entries(workflow.jobs)
  468. .filter(([, job]) => {
  469. if (!isRecord(job)) return false
  470. if (job.if === undefined) return true // unconditional: runs on every event
  471. if (job.if === false) return false // `if: false` parses as a boolean
  472. if (typeof job.if !== 'string') return true // unrecognized shape: surface it
  473. return !NOT_PUSH_REACHABLE.has(job.if.trim())
  474. })
  475. .map(([name]) => name)
  476. .sort()
  477. expect(pushReachable).toEqual(['python-runtime', 'serial-linux-selfhosted', 'serial-windows', 'windows'])
  478. // Manual benchmarks retain their bounded fan-out.
  479. for (const name of ['larger-runner-benchmark', 'consolidated-runner-benchmark']) {
  480. const job = workflow.jobs[name]
  481. if (!isRecord(job) || !isRecord(job.strategy)) {
  482. throw new TypeError(`${name} must define a matrix strategy`)
  483. }
  484. expect(job.strategy['max-parallel']).toBe(12)
  485. expect(job['timeout-minutes']).toBe(15)
  486. }
  487. })
  488. it('redirects the Node compile cache to the data-volume runner temp before the first pnpm call', () => {
  489. const prWorkflow = loadWorkflow('.github/workflows/ci.yml')
  490. const masterWorkflow = loadWorkflow('.github/workflows/ci-master.yml')
  491. const redirectLanes = [
  492. [prWorkflow, 'node-24'],
  493. [prWorkflow, 'node-24-coverage'],
  494. [prWorkflow, 'node-24-consumers'],
  495. [masterWorkflow, 'serial-linux-selfhosted'],
  496. ] as const
  497. for (const [workflow, jobKey] of redirectLanes) {
  498. const job = workflowJob(workflow, jobKey)
  499. if (!Array.isArray(job.steps)) throw new TypeError(`${jobKey} must define steps`)
  500. const redirectStepIndex = job.steps.findIndex((step): step is Record<string, unknown> & { run: string } => (
  501. isRecord(step) && typeof step.run === 'string'
  502. && step.run.includes('NODE_COMPILE_CACHE=${{ runner.temp }}/node-compile-cache')
  503. && step.run.includes('"$GITHUB_ENV"')
  504. ))
  505. // Removing this injection would send every pnpm call in the lane (setup,
  506. // store-path probe, install, and the gate) back to the root partition's
  507. // /tmp; rationale in
  508. // .agents/notes/implemented/process/2026-08-28-ci-node-compile-cache-data-disk.md.
  509. expect(redirectStepIndex, `${jobKey} must inject NODE_COMPILE_CACHE into GITHUB_ENV`).toBeGreaterThan(-1)
  510. const pnpmSetupIndex = job.steps.findIndex((step): step is Record<string, unknown> & { uses: string } => (
  511. isRecord(step) && typeof step.uses === 'string' && step.uses.includes('pnpm/action-setup')
  512. ))
  513. expect(pnpmSetupIndex, `${jobKey} must run pnpm/action-setup`).toBeGreaterThan(-1)
  514. expect(redirectStepIndex, `${jobKey} must redirect before pnpm/action-setup runs pnpm`).toBeLessThan(pnpmSetupIndex)
  515. }
  516. })
  517. it('keeps supported LSP source under native Windows coverage', () => {
  518. const config = readFileSync(resolve(root, 'vitest.config.ts'), 'utf8')
  519. expect(config).not.toContain('packages/lsp/lsp-stdio/src/connection.ts')
  520. expect(config).not.toContain('packages/lsp/lsp-stdio/src/index.ts')
  521. expect(config).not.toContain('packages/lsp/lsp-stdio/src/instance.ts')
  522. })
  523. it('requires release-shaped Python runtime validation on Linux and Windows x64', () => {
  524. const workflow = loadWorkflow('.github/workflows/ci.yml')
  525. const pythonRuntime = workflowJob(workflow, 'python-runtime')
  526. const aggregate = workflowJob(workflow, 'all-checks-passed')
  527. if (!Array.isArray(aggregate.needs)) {
  528. throw new TypeError('CI aggregate must define required job dependencies')
  529. }
  530. expect(pythonRuntime).toMatchObject({
  531. if: "github.event_name == 'pull_request'",
  532. name: 'python runtime / release-shaped matrix',
  533. uses: './.github/workflows/build-exe-for-python-sdk.yml',
  534. with: {
  535. targets: 'node24-linux-x64,node24-win-x64',
  536. ci: true,
  537. },
  538. secrets: {
  539. DEEPSEEK_API_KEY_EXTERNAL: '${{ secrets.DEEPSEEK_API_KEY_EXTERNAL }}',
  540. },
  541. })
  542. expect(aggregate.needs).toContain('python-runtime')
  543. })
  544. it('keeps every Vitest project process-isolated on native Windows', () => {
  545. const config = readFileSync(resolve(root, 'vitest.config.ts'), 'utf8')
  546. expect(config).not.toContain("pool: process.platform === 'win32' ? 'threads' : 'forks'")
  547. expect(config.match(/pool: 'forks'/g)).toHaveLength(2)
  548. })
  549. })
  550. describe('Runtime and LLM e2e Blacksmith routing', () => {
  551. it('routes DeepSeek e2e only through the Linux Blacksmith switch', () => {
  552. const job = workflowJob(loadWorkflow('.github/workflows/e2e.yml'), 'e2e')
  553. for (const mode of ['', 'selfhosted', 'unexpected', 'blacksmith']) {
  554. expect(evaluateRunsOn(job['runs-on'], { vars: { DSH_CI_FAILOVER_LINUX: mode, DSH_CI_FAILOVER_WINDOWS: 'blacksmith' } }))
  555. .toBe(mode === 'blacksmith' ? 'blacksmith-4vcpu-ubuntu-2404' : 'ubuntu-latest')
  556. }
  557. })
  558. it('keeps native release and dispatch builders hosted while routing x64 CI by platform', () => {
  559. const workflow = loadWorkflow('.github/workflows/build-exe-for-python-sdk.yml')
  560. const build = workflowJob(workflow, 'build')
  561. for (const [target, runner, variable, blacksmith] of [
  562. ['node24-linux-x64', 'ubuntu-latest', 'DSH_CI_FAILOVER_LINUX', 'blacksmith-16vcpu-ubuntu-2404'],
  563. ['node24-win-x64', 'windows-2025', 'DSH_CI_FAILOVER_WINDOWS', 'blacksmith-16vcpu-windows-2025'],
  564. ['node24-linux-arm64', 'ubuntu-24.04-arm', 'DSH_CI_FAILOVER_LINUX', 'ubuntu-24.04-arm'],
  565. ['node24-macos-arm64', 'macos-latest', 'DSH_CI_FAILOVER_LINUX', 'macos-latest'],
  566. ['node24-macos-x64', 'macos-15-intel', 'DSH_CI_FAILOVER_LINUX', 'macos-15-intel'],
  567. ] as const) {
  568. for (const ci of [false, true]) {
  569. for (const release of [false, true]) {
  570. for (const mode of ['', 'selfhosted', 'unexpected', 'blacksmith']) {
  571. const vars = { DSH_CI_FAILOVER_LINUX: 'blacksmith', DSH_CI_FAILOVER_WINDOWS: 'blacksmith', [variable]: mode }
  572. expect(evaluateRunsOn(build['runs-on'], { inputs: { ci, release }, vars, matrix: { target, runner } }), `${target} ci=${ci} release=${release} mode=${mode}`)
  573. .toBe(ci && !release && mode === 'blacksmith' ? blacksmith : runner)
  574. }
  575. }
  576. }
  577. }
  578. })
  579. it.each(['plan', 'sdk-wheel'])('routes runtime %s only for non-release CI', (name) => {
  580. const job = workflowJob(loadWorkflow('.github/workflows/build-exe-for-python-sdk.yml'), name)
  581. for (const ci of [false, true]) {
  582. for (const release of [false, true]) {
  583. for (const mode of ['', 'selfhosted', 'unexpected', 'blacksmith']) {
  584. expect(evaluateRunsOn(job['runs-on'], { inputs: { ci, release }, vars: { DSH_CI_FAILOVER_LINUX: mode } }))
  585. .toBe(ci && !release && mode === 'blacksmith' ? 'blacksmith-4vcpu-ubuntu-2404' : 'ubuntu-latest')
  586. }
  587. }
  588. }
  589. })
  590. })
  591. describe('DeepSeek e2e workflow', () => {
  592. it('prepares bubblewrap from the pinned payload without a package transaction', () => {
  593. const workflow = loadWorkflow('.github/workflows/e2e.yml')
  594. const e2e = workflowJob(workflow, 'e2e')
  595. if (!Array.isArray(e2e.steps)) throw new TypeError('DeepSeek e2e workflow must define steps')
  596. const steps = e2e.steps.filter(isRecord)
  597. expect(steps.find(step => step.name === 'Prepare bubblewrap (unrestrict userns)')).toMatchObject({
  598. run: 'bash scripts/prepare-ci-bubblewrap.sh',
  599. })
  600. expect(JSON.stringify(steps)).not.toContain('apt-get')
  601. })
  602. it('bounds profile subprocess fan-out to the tested e2e default', () => {
  603. const workflow = loadWorkflow('.github/workflows/e2e.yml')
  604. const e2e = workflowJob(workflow, 'e2e')
  605. if (!Array.isArray(e2e.steps)) throw new TypeError('DeepSeek e2e workflow must define steps')
  606. const step = e2e.steps.filter(isRecord).find(candidate => candidate.name === 'E2E tests (real DeepSeek API)')
  607. expect(step).toMatchObject({ env: { DSH_E2E_MAX_WORKERS: 4 } })
  608. })
  609. })
  610. describe('Python release workflows', () => {
  611. it('keeps complete wheel validation separate from protected public publication', () => {
  612. const workflow = loadWorkflow('.github/workflows/python-release.yml')
  613. const dispatch = workflowEvent(workflow, 'workflow_dispatch')
  614. const build = workflowJob(workflow, 'build')
  615. const pythonCompat = workflowJob(workflow, 'python-compat')
  616. const validate = workflowJob(workflow, 'validate')
  617. const publishRuntime = workflowJob(workflow, 'publish-runtime')
  618. const publishSdk = workflowJob(workflow, 'publish-sdk')
  619. if (!isRecord(dispatch.inputs)
  620. || !isRecord(dispatch.inputs.publish)
  621. || !Array.isArray(pythonCompat.steps)
  622. || !Array.isArray(validate.steps)
  623. || !Array.isArray(publishRuntime.steps)
  624. || !Array.isArray(publishSdk.steps)) {
  625. throw new TypeError('Python release workflow must define publish input and release steps')
  626. }
  627. expect(dispatch.inputs.publish).toMatchObject({ type: 'boolean', default: false })
  628. if (!isRecord(workflow.on)) throw new TypeError('python-release workflow must define on')
  629. expect(Object.keys(workflow.on)).toEqual(['workflow_dispatch'])
  630. expect(build).toMatchObject({
  631. uses: './.github/workflows/build-exe-for-python-sdk.yml',
  632. with: {
  633. targets: 'node24-linux-x64,node24-linux-arm64,node24-macos-arm64,node24-macos-x64,node24-win-x64',
  634. release: true,
  635. },
  636. })
  637. expect(pythonCompat.strategy).toMatchObject({ matrix: { python: ['3.10', '3.14'] } })
  638. const pythonCompatSteps = JSON.stringify(pythonCompat.steps)
  639. expect(pythonCompatSteps).toContain('dist/deepseek_harness_sdk-$VERSION-py3-none-any.whl')
  640. expect(pythonCompatSteps).toContain('dist/deepseek_harness_runtime_bin-$VERSION-py3-none-manylinux_2_28_x86_64.whl')
  641. expect(pythonCompatSteps).not.toContain('--find-links')
  642. const validateSteps = JSON.stringify(validate.steps)
  643. const authorize = validate.steps.filter(isRecord).find(step => step.name === 'Authorize publication request')
  644. if (!isRecord(authorize) || typeof authorize.run !== 'string') {
  645. throw new TypeError('Python release validation must authorize publication requests')
  646. }
  647. expect(validateSteps).toContain('PUBLIC_PYPI_RELEASE_ENABLED')
  648. expect(authorize).toMatchObject({
  649. env: {
  650. PYPI_PUBLISHER_REPOSITORY: '${{ vars.PYPI_PUBLISHER_REPOSITORY }}',
  651. REPOSITORY: '${{ github.repository }}',
  652. },
  653. })
  654. expect(authorize.run).toContain('[ "$REPOSITORY" = "$PYPI_PUBLISHER_REPOSITORY" ]')
  655. expect(validateSteps).toContain('100000000')
  656. expect(publishRuntime).toMatchObject({
  657. if: "github.event_name == 'workflow_dispatch' && inputs.publish",
  658. needs: 'validate',
  659. environment: 'pypi-runtime',
  660. permissions: { contents: 'read', 'id-token': 'write' },
  661. })
  662. expect(publishSdk).toMatchObject({
  663. if: "github.event_name == 'workflow_dispatch' && inputs.publish",
  664. needs: ['validate', 'publish-runtime'],
  665. environment: 'pypi',
  666. permissions: { contents: 'read', 'id-token': 'write' },
  667. })
  668. const runtimeSteps = publishRuntime.steps.filter(isRecord)
  669. const sdkSteps = publishSdk.steps.filter(isRecord)
  670. const runtimePublish = runtimeSteps.find(step => step.name === 'Publish runtime wheels')
  671. const sdkPublish = sdkSteps.find(step => step.name === 'Publish SDK wheel')
  672. const runtimeHashes = runtimeSteps.find(step => step.name === 'Verify release artifact hashes')
  673. const sdkHashes = sdkSteps.find(step => step.name === 'Verify release artifact hashes')
  674. expect([...runtimeSteps, ...sdkSteps].some(
  675. step => typeof step.uses === 'string' && step.uses.startsWith('actions/checkout@'),
  676. )).toBe(false)
  677. expect([...runtimeSteps, ...sdkSteps].filter(
  678. step => step.uses === 'pypa/gh-action-pypi-publish@release/v1',
  679. )).toHaveLength(2)
  680. expect(runtimePublish).toMatchObject({
  681. with: { 'packages-dir': 'dist/runtime/', attestations: false },
  682. })
  683. expect(sdkPublish).toMatchObject({
  684. with: { 'packages-dir': 'dist/sdk/', attestations: false },
  685. })
  686. expect(runtimeHashes).toMatchObject({ run: 'cd dist && sha256sum -c SHA256SUMS' })
  687. expect(sdkHashes).toMatchObject({ run: 'cd dist && sha256sum -c SHA256SUMS' })
  688. })
  689. it('exposes the native wheel builder to the release caller with normalized versions', () => {
  690. const workflow = loadWorkflow('.github/workflows/build-exe-for-python-sdk.yml')
  691. expect(Object.keys(workflow.on as Record<string, unknown>).sort()).toEqual(['workflow_call', 'workflow_dispatch'])
  692. const call = workflowEvent(workflow, 'workflow_call')
  693. const plan = workflowJob(workflow, 'plan')
  694. const build = workflowJob(workflow, 'build')
  695. if (!isRecord(call.inputs) || !isRecord(call.secrets) || !Array.isArray(plan.steps) || !Array.isArray(build.steps)) {
  696. throw new TypeError('Python wheel builder must define workflow_call inputs and plan steps')
  697. }
  698. const buildSteps: unknown[] = build.steps
  699. const manylinuxAddon = buildSteps.find(step => isRecord(step) && step.name === 'Rebuild Linux node-pty against manylinux 2.28')
  700. const macosCheck = buildSteps.find(step => isRecord(step) && step.name === 'Check macOS payload architecture and deployment target')
  701. const manylinuxSmoke = buildSteps.find(step => isRecord(step) && step.name === 'Run wheel in a manylinux 2.28 container')
  702. const cleanVenvPosix = buildSteps.find(step => isRecord(step) && step.name === 'Install local SDK and runtime wheels into a clean venv (POSIX)')
  703. const cleanVenvWindows = buildSteps.find(step => isRecord(step) && step.name === 'Install local SDK and runtime wheels into a clean venv (Windows)')
  704. const installedKeylessPosix = buildSteps.find(step => isRecord(step) && step.name === 'Run installed-wheel keyless black-box tests (POSIX)')
  705. const installedKeylessWindows = buildSteps.find(step => isRecord(step) && step.name === 'Run installed-wheel keyless black-box tests (Windows)')
  706. const realApiPreflightPosix = buildSteps.find(step => isRecord(step) && step.name === 'Preflight installed-wheel real API test (POSIX)')
  707. const realApiPreflightWindows = buildSteps.find(step => isRecord(step) && step.name === 'Preflight installed-wheel real API test (Windows)')
  708. const installedRealApiPosix = buildSteps.find(step => isRecord(step) && step.name === 'Run installed-wheel real API black-box test (POSIX)')
  709. const installedRealApiWindows = buildSteps.find(step => isRecord(step) && step.name === 'Run installed-wheel real API black-box test (Windows)')
  710. if (!isRecord(macosCheck) || typeof macosCheck.run !== 'string'
  711. || !isRecord(cleanVenvPosix) || !isRecord(cleanVenvWindows)
  712. || !isRecord(installedKeylessPosix) || !isRecord(installedKeylessWindows)
  713. || !isRecord(realApiPreflightPosix) || !isRecord(realApiPreflightWindows)
  714. || !isRecord(installedRealApiPosix) || !isRecord(installedRealApiWindows)) {
  715. throw new TypeError('Python wheel builder must define native POSIX and Windows installed-wheel steps')
  716. }
  717. expect(call.inputs).toHaveProperty('targets')
  718. expect(call.inputs).toMatchObject({
  719. ci: { type: 'boolean', default: false },
  720. release: { type: 'boolean', default: false },
  721. })
  722. expect(call.secrets).toMatchObject({
  723. DEEPSEEK_API_KEY_EXTERNAL: { required: false },
  724. })
  725. expect(workflow.concurrency).toMatchObject({
  726. group: 'build-single-exe-${{ github.workflow }}-${{ github.ref }}',
  727. })
  728. expect(build.defaults).toBeUndefined()
  729. expect(plan.if).toContain('inputs.ci')
  730. expect(plan.if).toContain('inputs.release')
  731. expect(JSON.stringify(plan.steps)).toContain('pep440_version')
  732. const workflowJson = JSON.stringify(workflow)
  733. expect(workflowJson).toContain('macosx_14_0_arm64')
  734. expect(workflowJson).toContain('macosx_14_0_x86_64')
  735. expect(workflowJson).toContain('node24-macos-x64')
  736. expect(workflowJson).toContain('macos-15-intel')
  737. expect(workflowJson).toContain('win_amd64')
  738. expect(workflowJson).toContain('node24-win-x64')
  739. expect(workflowJson).toContain('windows-2025')
  740. expect(workflowJson).toContain('dist-python/$SDK_WHEEL')
  741. expect(workflowJson).toContain('dist-python/$RUNTIME_WHEEL')
  742. expect(workflowJson).toContain('/work/dist-python/$SDK_WHEEL')
  743. expect(workflowJson).toContain('/work/dist-python/$RUNTIME_WHEEL')
  744. expect(workflowJson).not.toContain('--find-links dist-python')
  745. expect(workflowJson).not.toContain('--find-links /work/dist-python')
  746. expect(workflowJson).not.toContain('cygpath')
  747. expect(manylinuxAddon).toMatchObject({ if: "runner.os == 'Linux'" })
  748. expect(JSON.stringify(manylinuxAddon)).toContain('manylinux_2_28_x86_64')
  749. expect(JSON.stringify(manylinuxAddon)).toContain('manylinux_2_28_aarch64')
  750. expect(JSON.stringify(manylinuxAddon)).toContain('npm_config_build_from_source=true pnpm run install')
  751. expect(JSON.stringify(manylinuxAddon)).toContain('pnpm_setup_root')
  752. expect(JSON.stringify(manylinuxAddon)).toContain('$pnpm_setup_root:$pnpm_setup_root:ro')
  753. expect(JSON.stringify(manylinuxAddon)).toContain('node-pty-glibc-versions.txt')
  754. expect(JSON.stringify(manylinuxAddon)).toContain('le 2.28')
  755. expect(macosCheck).toMatchObject({ if: "runner.os == 'macOS'" })
  756. expect(macosCheck.run).toContain('scripts/check-macos-deployment-target.py')
  757. expect(macosCheck.run).toContain('lipo "$payload" -verify_arch')
  758. expect(macosCheck.run).toContain('$EXE-rg')
  759. expect(macosCheck.run).toContain('$EXE-spawn-helper')
  760. expect(JSON.stringify(installedKeylessPosix)).toContain('--scenario all')
  761. expect(JSON.stringify(installedKeylessPosix)).toContain('env -u PYTHONPATH')
  762. expect(JSON.stringify(installedKeylessWindows)).toContain('--scenario all --installed-wheel')
  763. expect(installedKeylessWindows).toMatchObject({ if: "runner.os == 'Windows'", shell: 'pwsh' })
  764. expect(cleanVenvWindows).toMatchObject({ if: "runner.os == 'Windows'", shell: 'pwsh' })
  765. expect(JSON.stringify(cleanVenvWindows)).toContain('Scripts\\\\python.exe')
  766. expect(realApiPreflightPosix).toMatchObject({
  767. env: { DEEPSEEK_API_KEY: '${{ secrets.DEEPSEEK_API_KEY_EXTERNAL }}' },
  768. })
  769. expect(String(realApiPreflightPosix.if)).toContain('inputs.ci')
  770. expect(String(realApiPreflightPosix.if)).toContain('head.repo.fork')
  771. expect(String(realApiPreflightPosix.if)).toContain('dependabot[bot]')
  772. expect(realApiPreflightWindows).toMatchObject({ shell: 'pwsh' })
  773. expect(installedRealApiPosix).toMatchObject({
  774. env: {
  775. DEEPSEEK_API_KEY: '${{ secrets.DEEPSEEK_API_KEY_EXTERNAL }}',
  776. DEEPSEEK_BASE_URL: 'https://api.deepseek.com',
  777. },
  778. })
  779. expect(JSON.stringify(installedRealApiPosix)).toContain('--scenario sdk-live')
  780. expect(JSON.stringify(installedRealApiPosix)).toContain('-u DSH_RUNTIME_MODE')
  781. expect(installedRealApiWindows).toMatchObject({ shell: 'pwsh' })
  782. expect(JSON.stringify(installedRealApiWindows)).toContain('--scenario sdk-live --installed-wheel')
  783. expect(manylinuxSmoke).toMatchObject({ if: "runner.os == 'Linux'" })
  784. expect(JSON.stringify(manylinuxSmoke)).toContain('-e DSH_TELEMETRY_DISABLED')
  785. })
  786. it('uses the shared macOS deployment-target check in GitLab', () => {
  787. const workflow = loadWorkflow('.gitlab-ci.yml')
  788. const runtimeWheel = workflow['.runtime-wheel']
  789. if (!isRecord(runtimeWheel) || !Array.isArray(runtimeWheel.script)) {
  790. throw new TypeError('GitLab CI must define the runtime wheel script')
  791. }
  792. const runtimeScript: unknown[] = runtimeWheel.script
  793. const macosCheck = runtimeScript.find(
  794. step => typeof step === 'string' && step.includes('${PLATFORM#macos-}'),
  795. )
  796. if (typeof macosCheck !== 'string') {
  797. throw new TypeError('GitLab CI must check the macOS deployment target')
  798. }
  799. expect(macosCheck).toContain('scripts/check-macos-deployment-target.py')
  800. expect(macosCheck).toContain('lipo "$payload" -verify_arch')
  801. expect(macosCheck).toContain('"$EXE" "$EXE-rg" "$EXE-spawn-helper"')
  802. })
  803. it('builds the macOS x64 wheel on the matching GitLab runner', () => {
  804. const workflow = loadWorkflow('.gitlab-ci.yml')
  805. const macosX64 = workflow['runtime-macos-x64']
  806. const publish = workflow['publish-python']
  807. if (!isRecord(macosX64) || !isRecord(publish) || !Array.isArray(publish.needs)) {
  808. throw new TypeError('GitLab CI must define the macOS x64 runtime and publication jobs')
  809. }
  810. expect(macosX64.tags).toEqual(['macos-x64'])
  811. expect(macosX64.variables).toMatchObject({ PKG_TARGET: 'node24-macos-x64', PLATFORM: 'macos-x64' })
  812. expect(publish.needs).toContainEqual({ job: 'runtime-macos-x64', artifacts: true })
  813. expect(JSON.stringify(publish.script)).toContain('macosx_14_0_x86_64.whl')
  814. })
  815. it('builds and black-box tests the Windows x64 wheel in GitLab', () => {
  816. const workflow = loadWorkflow('.gitlab-ci.yml')
  817. const windows = workflow['runtime-windows-x64']
  818. const publish = workflow['publish-python']
  819. if (!isRecord(windows) || !Array.isArray(windows.before_script) || !Array.isArray(windows.script)
  820. || !isRecord(publish) || !Array.isArray(publish.needs)) {
  821. throw new TypeError('GitLab CI must define the Windows runtime and aggregate publication jobs')
  822. }
  823. expect(windows.tags).toEqual(['windows-x64'])
  824. expect(windows.variables).toMatchObject({ PKG_TARGET: 'node24-win-x64', PLATFORM: 'win-x64' })
  825. expect(JSON.stringify(windows.before_script)).toContain('.ci-python\\\\Scripts')
  826. expect(JSON.stringify(windows.before_script)).toContain('[IO.Path]::PathSeparator')
  827. expect(JSON.stringify(windows.script)).toContain('win_amd64.whl')
  828. expect(JSON.stringify(windows.script)).toContain('--scenario all --installed-wheel')
  829. expect(publish.needs).toContainEqual({ job: 'runtime-windows-x64', artifacts: true })
  830. })
  831. })
  832. describe('Weighted approval workflow', () => {
  833. it('publishes from the trusted default branch after pull request and review updates', () => {
  834. const publisher = loadWorkflow('.github/workflows/weighted-approval.yml')
  835. const reviewEvent = loadWorkflow('.github/workflows/weighted-approval-review-event.yml')
  836. const pullRequest = workflowEvent(publisher, 'pull_request_target')
  837. const workflowRun = workflowEvent(publisher, 'workflow_run')
  838. const review = workflowEvent(reviewEvent, 'pull_request_review')
  839. const job = workflowJob(publisher, 'publish-status')
  840. const recordJob = workflowJob(reviewEvent, 'record-review-event')
  841. if (!isRecord(publisher.on)) throw new TypeError('weighted-approval workflow must define events')
  842. if (!isRecord(reviewEvent.on)) throw new TypeError('weighted-approval review event workflow must define events')
  843. if (!Array.isArray(job.steps)) throw new TypeError('weighted-approval job must define steps')
  844. if (!Array.isArray(recordJob.steps)) throw new TypeError('weighted-approval review event job must define steps')
  845. const steps = job.steps.filter(isRecord)
  846. const checkout = steps.find(step => step.name === 'Check out trusted approval policy')
  847. const publish = steps.find(step => step.name === 'Publish weighted approval status')
  848. const recordSteps = recordJob.steps.filter(isRecord)
  849. const record = recordSteps.find(step => step.name === 'Record review event')
  850. expect(publisher.name).toBe('weighted-approval')
  851. expect(Object.keys(publisher.on)).toEqual(['pull_request_target', 'workflow_run'])
  852. expect(pullRequest.types).toEqual(['opened', 'synchronize', 'reopened', 'ready_for_review', 'converted_to_draft'])
  853. expect(workflowRun).toEqual({ workflows: ['weighted-approval-review-event'], types: ['completed'] })
  854. expect(reviewEvent.name).toBe('weighted-approval-review-event')
  855. expect(reviewEvent['run-name']).toBe('weighted-approval-review-event:${{ github.event.pull_request.number }}')
  856. expect(Object.keys(reviewEvent.on)).toEqual(['pull_request_review'])
  857. expect(review.types).toEqual(['submitted', 'edited', 'dismissed'])
  858. expect(reviewEvent.permissions).toEqual({})
  859. expect(publisher.permissions).toEqual({
  860. contents: 'read',
  861. 'pull-requests': 'read',
  862. statuses: 'write',
  863. })
  864. expect(publisher.concurrency).toEqual({
  865. group: 'weighted-approval-${{ github.event.pull_request.number || github.event.workflow_run.head_sha }}',
  866. 'cancel-in-progress': false,
  867. })
  868. expect(job).toMatchObject({
  869. if: "github.event_name != 'workflow_run' || github.event.workflow_run.conclusion == 'success'",
  870. name: 'weighted approval publisher',
  871. 'runs-on': 'ubuntu-latest',
  872. 'timeout-minutes': 5,
  873. })
  874. expect(checkout).toMatchObject({
  875. uses: 'actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1',
  876. with: {
  877. ref: '${{ github.event.repository.default_branch }}',
  878. 'persist-credentials': false,
  879. },
  880. })
  881. expect(publish).toMatchObject({
  882. env: {
  883. GITHUB_TOKEN: '${{ github.token }}',
  884. GITHUB_RUN_URL: '${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}',
  885. },
  886. run: 'node .github/review-ownership/check-approval.mjs',
  887. })
  888. expect(recordJob).toMatchObject({
  889. name: 'record weighted approval review event',
  890. 'runs-on': 'ubuntu-latest',
  891. 'timeout-minutes': 2,
  892. })
  893. expect(record).toBeDefined()
  894. expect(record?.run).toBe("echo 'Recorded a weighted approval review event.'")
  895. expect(recordSteps).toHaveLength(1)
  896. expect(JSON.stringify(publisher)).not.toContain('github.event.pull_request.head')
  897. expect(JSON.stringify(publisher)).not.toContain('secrets.')
  898. expect(JSON.stringify(reviewEvent)).not.toContain('github.token')
  899. expect(JSON.stringify(reviewEvent)).not.toContain('secrets.')
  900. })
  901. })
  902. describe('Issue lifecycle workflow', () => {
  903. it('allocates lifecycle runners only for events that can change the board', () => {
  904. const lifecycle = loadWorkflow('.github/workflows/issue-lifecycle.yml')
  905. const policy = loadWorkflow('.github/workflows/issue-policy.yml')
  906. const lifecycleJob = workflowJob(lifecycle, 'lifecycle')
  907. if (!Array.isArray(lifecycleJob.steps)) throw new TypeError('Issue lifecycle job must define steps')
  908. expect(lifecycle.on).toHaveProperty('pull_request')
  909. expect(lifecycle.on).toHaveProperty('pull_request_review')
  910. expect(lifecycleJob.if).toContain("github.event.review.state == 'changes_requested'")
  911. expect(lifecycleJob.if).toContain('github.event.changes.body != null')
  912. // Keep the subscription-type gates: issue-lifecycle does not re-subscribe
  913. // ready_for_review (issue-policy owns that) and only reacts to submitted
  914. // review events.
  915. const lifecyclePullRequest = workflowEvent(lifecycle, 'pull_request')
  916. const lifecycleReview = workflowEvent(lifecycle, 'pull_request_review')
  917. expect(lifecyclePullRequest.types).toContain('opened')
  918. expect(lifecyclePullRequest.types).not.toContain('ready_for_review')
  919. expect(lifecyclePullRequest.types).toContain('review_requested')
  920. expect(lifecycleReview.types).toEqual(['submitted'])
  921. expect(lifecyclePullRequest.types).not.toContain('synchronize')
  922. expect(lifecyclePullRequest.types).not.toContain('labeled')
  923. expect(lifecyclePullRequest.types).not.toContain('unlabeled')
  924. const issueEvents = workflowEvent(lifecycle, 'issues')
  925. expect(issueEvents.types).not.toContain('assigned')
  926. expect(issueEvents.types).not.toContain('unassigned')
  927. expect(issueEvents.types).toContain('typed')
  928. expect(issueEvents.types).toContain('untyped')
  929. const steps = lifecycleJob.steps.filter(isRecord)
  930. const tokenStep = steps.find(s => s.name === 'Create project token')
  931. const handleStep = steps.find(s => s.name === 'Handle repository event')
  932. expect(tokenStep?.if).toBeUndefined()
  933. expect(handleStep?.if).toBeUndefined()
  934. // issue-policy owns PR validation; it is read-only and a real gate.
  935. const policyPullRequest = workflowEvent(policy, 'pull_request')
  936. expect(policyPullRequest.types).toContain('ready_for_review')
  937. })
  938. it('mints Project credentials only after preflight and always revalidates current metadata', () => {
  939. const policy = loadWorkflow('.github/workflows/issue-policy.yml')
  940. const policyJob = workflowJob(policy, 'policy')
  941. if (!Array.isArray(policyJob.steps)) throw new TypeError('Issue policy job must define steps')
  942. const steps = policyJob.steps.filter(isRecord)
  943. const tokenStep = steps.find(step => step.name === 'Create Project read token')
  944. const validateStep = steps.find(step => step.name === 'Validate pull request')
  945. const preflightStep = steps.find(step => step.id === 'preflight')
  946. expect(preflightStep).toMatchObject({ shell: 'bash' })
  947. expect(preflightStep?.run).toContain('if [ -f .github/issue-management/selective-preflight.json ]; then')
  948. expect(preflightStep?.run).toContain('node .github/issue-management/policy.mjs pr-preflight')
  949. expect(preflightStep?.if).toBeUndefined()
  950. expect(policyJob.if).toBeUndefined()
  951. expect(validateStep?.if).toBe("${{ steps.preflight.outputs.legacy-automated != 'true' }}")
  952. expect(tokenStep).toMatchObject({
  953. id: 'app-token',
  954. if: "${{ steps.preflight.outputs.needs-project == 'true' }}",
  955. uses: 'actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1',
  956. with: {
  957. 'client-id': '${{ vars.DSH_ISSUE_APP_CLIENT_ID }}',
  958. 'private-key': '${{ secrets.DSH_ISSUE_APP_PRIVATE_KEY }}',
  959. owner: 'deepseek-harness',
  960. repositories: 'deepseek-harness',
  961. 'permission-issues': 'read',
  962. 'permission-organization-projects': 'read',
  963. },
  964. })
  965. expect(validateStep).toMatchObject({
  966. env: {
  967. GITHUB_TOKEN: '${{ github.token }}',
  968. PROJECT_TOKEN: '${{ steps.app-token.outputs.token }}',
  969. },
  970. })
  971. })
  972. })
  973. describe('npm release workflows', () => {
  974. it('keeps publication dispatch-only and pack in the PR workflow', () => {
  975. // pack stays in the PR/master release workflows so a PR proves the set packs.
  976. for (const file of ['release.yml', 'release-vendor.yml']) {
  977. const workflow = loadWorkflow(`.github/workflows/${file}`)
  978. if (!isRecord(workflow.jobs)) throw new TypeError(`${file} must define jobs`)
  979. expect(Object.keys(workflow.jobs).sort()).toEqual(file === 'release.yml' ? ['dependencies', 'pack'] : ['pack'])
  980. }
  981. // publication is workflow_dispatch-only (never a PR check) and keeps the
  982. // npm-publish environment plus the shared dist-tag group.
  983. for (const file of ['release-publish.yml', 'release-vendor-publish.yml']) {
  984. const workflow = loadWorkflow(`.github/workflows/${file}`)
  985. if (!isRecord(workflow.on) || !isRecord(workflow.jobs)) throw new TypeError(`${file} must define on and jobs`)
  986. expect(Object.keys(workflow.on)).toEqual(['workflow_dispatch'])
  987. const publish = workflow.jobs.publish
  988. if (!isRecord(publish)) throw new TypeError(`${file} must define a publish job`)
  989. expect(publish.environment).toBe('npm-publish')
  990. expect(publish.concurrency).toMatchObject({ group: 'Release-publish' })
  991. }
  992. })
  993. it('runs dependency policy and npm layout checks in the DSH release workflow', () => {
  994. const workflow = loadWorkflow('.github/workflows/release.yml')
  995. const dependencies = workflowJob(workflow, 'dependencies')
  996. if (!isRecord(workflow.on) || !Array.isArray(dependencies.steps)) {
  997. throw new TypeError('DSH release workflow must define triggers and dependency steps')
  998. }
  999. const commands = dependencies.steps.flatMap(step =>
  1000. isRecord(step) && typeof step.run === 'string' ? [step.run] : [])
  1001. expect(Object.keys(workflow.on).sort()).toEqual(['pull_request', 'push', 'workflow_dispatch'])
  1002. expect(commands).toContain('pnpm run verify-package-dependencies')
  1003. expect(commands).toContain('pnpm run verify-npm-install-layout')
  1004. })
  1005. })
  1006. describe('Documentation site publication', () => {
  1007. it('keeps Pages deployment dispatch-only from a dsh-v* tag', () => {
  1008. const workflow = loadWorkflow('.github/workflows/docs-pages.yml')
  1009. const build = workflowJob(workflow, 'build')
  1010. const deploy = workflowJob(workflow, 'deploy')
  1011. if (!isRecord(workflow.on) || !isRecord(workflow.env) || !Array.isArray(build.steps)) {
  1012. throw new TypeError('Documentation deployment must define on, env, and build steps')
  1013. }
  1014. // The site presents a released snapshot: a merge must never publish it, and
  1015. // publication must never appear as a PR check.
  1016. expect(Object.keys(workflow.on)).toEqual(['workflow_dispatch'])
  1017. // RELEASE_PUBLISH makes release:verify reject every ref that is not a dsh-v*
  1018. // tag naming this tree's version, so the site and the npm sequence share one
  1019. // definition of a released version.
  1020. const steps = build.steps.filter(isRecord)
  1021. const verify = steps.find(step => step.name === 'Verify release version')
  1022. const checkout = steps.find(
  1023. step => typeof step.uses === 'string' && step.uses.startsWith('actions/checkout@'),
  1024. )
  1025. expect(verify).toMatchObject({
  1026. env: { RELEASE_PUBLISH: 'true' },
  1027. run: 'pnpm run release:verify --family dsh',
  1028. })
  1029. // Complete history: the release scripts read tags.
  1030. expect(checkout).toMatchObject({ with: { 'fetch-depth': 0 } })
  1031. // Projected source links stay on the public repository's master. That
  1032. // repository advances only to each release commit, so its master never
  1033. // carries unreleased work, while it retains only the most recent tags:
  1034. // following the dispatched tag would leave every source link on a deploy
  1035. // from an older tag unresolvable.
  1036. expect(workflow.env.DOCS_REPOSITORY_REF).toBe('master')
  1037. // The environment owns the deployment tag policy and the required reviewers.
  1038. expect(deploy.environment).toMatchObject({ name: 'github-pages' })
  1039. })
  1040. })
  1041. describe('Git hooks', () => {
  1042. it('leaves frozen Agent Note sidecars to the archive verifier', () => {
  1043. const lefthook = loadWorkflow('lefthook.yml')
  1044. for (const hookName of ['pre-commit', 'pre-merge-commit']) {
  1045. const hook = lefthook[hookName]
  1046. if (!isRecord(hook) || !Array.isArray(hook.jobs)) {
  1047. throw new TypeError(`lefthook must define ${hookName} jobs`)
  1048. }
  1049. const pairing: unknown = hook.jobs.find(
  1050. (job: unknown) => isRecord(job) && job.name === 'translation pairing (staged records)',
  1051. )
  1052. expect(pairing).toMatchObject({ exclude: ['.agents/notes/archived/**'] })
  1053. }
  1054. })
  1055. })
  1056. function loadWorkflow(path: string): Record<string, unknown> {
  1057. const workflow: unknown = yaml.load(readFileSync(resolve(root, path), 'utf8'))
  1058. if (!isRecord(workflow)) throw new TypeError(`${path} must define a workflow`)
  1059. return workflow
  1060. }
  1061. function workflowEvent(workflow: Record<string, unknown>, event: string): Record<string, unknown> {
  1062. if (!isRecord(workflow.on) || !isRecord(workflow.on[event])) {
  1063. throw new TypeError(`workflow must define the ${event} event`)
  1064. }
  1065. return workflow.on[event]
  1066. }
  1067. function workflowJob(workflow: Record<string, unknown>, job: string): Record<string, unknown> {
  1068. if (!isRecord(workflow.jobs) || !isRecord(workflow.jobs[job])) {
  1069. throw new TypeError(`workflow must define the ${job} job`)
  1070. }
  1071. return workflow.jobs[job]
  1072. }
  1073. function isRecord(value: unknown): value is Record<string, unknown> {
  1074. return typeof value === 'object' && value !== null && !Array.isArray(value)
  1075. }