ci-workflow.spec.ts 55 KB

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