ci-workflow.spec.ts 60 KB

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