ci-workflow.spec.ts 63 KB

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