1
0

ci-workflow.spec.ts 51 KB

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