ci-workflow.spec.ts 59 KB

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