ci-workflow.spec.ts 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122
  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('E2B e2e workflow', () => {
  557. it('is manual-only and fails loud before running the focused live suite', () => {
  558. const workflow = loadWorkflow('.github/workflows/e2b-e2e.yml')
  559. expect(workflow.on).toEqual({ workflow_dispatch: null })
  560. if (!isRecord(workflow.jobs) || !isRecord(workflow.jobs.e2b) || !Array.isArray(workflow.jobs.e2b.steps)) {
  561. throw new TypeError('E2B e2e workflow must define the e2b job steps')
  562. }
  563. const steps = workflow.jobs.e2b.steps.filter(isRecord)
  564. const preflight = steps.find(step => step.name === 'Preflight (require E2B API key)')
  565. const e2b = steps.find(step => step.name === 'E2B tests (live sandbox)')
  566. expect(preflight).toMatchObject({
  567. env: { E2B_API_KEY: '${{ secrets.E2B_API_KEY_EXTERNAL }}' },
  568. })
  569. expect(preflight?.run).toContain('E2B_API_KEY_EXTERNAL repository secret')
  570. expect(e2b).toMatchObject({
  571. env: {
  572. E2B_API_KEY: '${{ secrets.E2B_API_KEY_EXTERNAL }}',
  573. DSH_E2E_MAX_WORKERS: '1',
  574. DSH_EXAMPLE_MODE: 'lib',
  575. },
  576. })
  577. expect(e2b?.run).toContain('packages/e2b/e2b/tests/composition.e2e.ts')
  578. })
  579. })
  580. describe('Python release workflows', () => {
  581. it('keeps complete wheel validation separate from protected public publication', () => {
  582. const workflow = loadWorkflow('.github/workflows/python-release.yml')
  583. const dispatch = workflowEvent(workflow, 'workflow_dispatch')
  584. const build = workflowJob(workflow, 'build')
  585. const pythonCompat = workflowJob(workflow, 'python-compat')
  586. const validate = workflowJob(workflow, 'validate')
  587. const publishRuntime = workflowJob(workflow, 'publish-runtime')
  588. const publishSdk = workflowJob(workflow, 'publish-sdk')
  589. if (!isRecord(dispatch.inputs)
  590. || !isRecord(dispatch.inputs.publish)
  591. || !Array.isArray(pythonCompat.steps)
  592. || !Array.isArray(validate.steps)
  593. || !Array.isArray(publishRuntime.steps)
  594. || !Array.isArray(publishSdk.steps)) {
  595. throw new TypeError('Python release workflow must define publish input and release steps')
  596. }
  597. expect(dispatch.inputs.publish).toMatchObject({ type: 'boolean', default: false })
  598. if (!isRecord(workflow.on)) throw new TypeError('python-release workflow must define on')
  599. expect(Object.keys(workflow.on)).toEqual(['workflow_dispatch'])
  600. expect(build).toMatchObject({
  601. uses: './.github/workflows/build-exe-for-python-sdk.yml',
  602. with: {
  603. targets: 'node24-linux-x64,node24-linux-arm64,node24-macos-arm64,node24-macos-x64,node24-win-x64',
  604. release: true,
  605. },
  606. })
  607. expect(pythonCompat.strategy).toMatchObject({ matrix: { python: ['3.10', '3.14'] } })
  608. const pythonCompatSteps = JSON.stringify(pythonCompat.steps)
  609. expect(pythonCompatSteps).toContain('dist/deepseek_harness_sdk-$VERSION-py3-none-any.whl')
  610. expect(pythonCompatSteps).toContain('dist/deepseek_harness_runtime_bin-$VERSION-py3-none-manylinux_2_28_x86_64.whl')
  611. expect(pythonCompatSteps).not.toContain('--find-links')
  612. const validateSteps = JSON.stringify(validate.steps)
  613. const authorize = validate.steps.filter(isRecord).find(step => step.name === 'Authorize publication request')
  614. if (!isRecord(authorize) || typeof authorize.run !== 'string') {
  615. throw new TypeError('Python release validation must authorize publication requests')
  616. }
  617. expect(validateSteps).toContain('PUBLIC_PYPI_RELEASE_ENABLED')
  618. expect(authorize).toMatchObject({
  619. env: {
  620. PYPI_PUBLISHER_REPOSITORY: '${{ vars.PYPI_PUBLISHER_REPOSITORY }}',
  621. REPOSITORY: '${{ github.repository }}',
  622. },
  623. })
  624. expect(authorize.run).toContain('[ "$REPOSITORY" = "$PYPI_PUBLISHER_REPOSITORY" ]')
  625. expect(validateSteps).toContain('100000000')
  626. expect(publishRuntime).toMatchObject({
  627. if: "github.event_name == 'workflow_dispatch' && inputs.publish",
  628. needs: 'validate',
  629. environment: 'pypi-runtime',
  630. permissions: { contents: 'read', 'id-token': 'write' },
  631. })
  632. expect(publishSdk).toMatchObject({
  633. if: "github.event_name == 'workflow_dispatch' && inputs.publish",
  634. needs: ['validate', 'publish-runtime'],
  635. environment: 'pypi',
  636. permissions: { contents: 'read', 'id-token': 'write' },
  637. })
  638. const runtimeSteps = publishRuntime.steps.filter(isRecord)
  639. const sdkSteps = publishSdk.steps.filter(isRecord)
  640. const runtimePublish = runtimeSteps.find(step => step.name === 'Publish runtime wheels')
  641. const sdkPublish = sdkSteps.find(step => step.name === 'Publish SDK wheel')
  642. const runtimeHashes = runtimeSteps.find(step => step.name === 'Verify release artifact hashes')
  643. const sdkHashes = sdkSteps.find(step => step.name === 'Verify release artifact hashes')
  644. expect([...runtimeSteps, ...sdkSteps].some(
  645. step => typeof step.uses === 'string' && step.uses.startsWith('actions/checkout@'),
  646. )).toBe(false)
  647. expect([...runtimeSteps, ...sdkSteps].filter(
  648. step => step.uses === 'pypa/gh-action-pypi-publish@release/v1',
  649. )).toHaveLength(2)
  650. expect(runtimePublish).toMatchObject({
  651. with: { 'packages-dir': 'dist/runtime/', attestations: false },
  652. })
  653. expect(sdkPublish).toMatchObject({
  654. with: { 'packages-dir': 'dist/sdk/', attestations: false },
  655. })
  656. expect(runtimeHashes).toMatchObject({ run: 'cd dist && sha256sum -c SHA256SUMS' })
  657. expect(sdkHashes).toMatchObject({ run: 'cd dist && sha256sum -c SHA256SUMS' })
  658. })
  659. it('exposes the native wheel builder to the release caller with normalized versions', () => {
  660. const workflow = loadWorkflow('.github/workflows/build-exe-for-python-sdk.yml')
  661. expect(Object.keys(workflow.on as Record<string, unknown>).sort()).toEqual(['workflow_call', 'workflow_dispatch'])
  662. const call = workflowEvent(workflow, 'workflow_call')
  663. const plan = workflowJob(workflow, 'plan')
  664. const build = workflowJob(workflow, 'build')
  665. if (!isRecord(call.inputs) || !isRecord(call.secrets) || !Array.isArray(plan.steps) || !Array.isArray(build.steps)) {
  666. throw new TypeError('Python wheel builder must define workflow_call inputs and plan steps')
  667. }
  668. const buildSteps: unknown[] = build.steps
  669. const manylinuxAddon = buildSteps.find(step => isRecord(step) && step.name === 'Rebuild Linux node-pty against manylinux 2.28')
  670. const macosCheck = buildSteps.find(step => isRecord(step) && step.name === 'Check macOS payload architecture and deployment target')
  671. const manylinuxSmoke = buildSteps.find(step => isRecord(step) && step.name === 'Run wheel in a manylinux 2.28 container')
  672. const cleanVenvPosix = buildSteps.find(step => isRecord(step) && step.name === 'Install local SDK and runtime wheels into a clean venv (POSIX)')
  673. const cleanVenvWindows = buildSteps.find(step => isRecord(step) && step.name === 'Install local SDK and runtime wheels into a clean venv (Windows)')
  674. const installedKeylessPosix = buildSteps.find(step => isRecord(step) && step.name === 'Run installed-wheel keyless black-box tests (POSIX)')
  675. const installedKeylessWindows = buildSteps.find(step => isRecord(step) && step.name === 'Run installed-wheel keyless black-box tests (Windows)')
  676. const realApiPreflightPosix = buildSteps.find(step => isRecord(step) && step.name === 'Preflight installed-wheel real API test (POSIX)')
  677. const realApiPreflightWindows = buildSteps.find(step => isRecord(step) && step.name === 'Preflight installed-wheel real API test (Windows)')
  678. const installedRealApiPosix = buildSteps.find(step => isRecord(step) && step.name === 'Run installed-wheel real API black-box test (POSIX)')
  679. const installedRealApiWindows = buildSteps.find(step => isRecord(step) && step.name === 'Run installed-wheel real API black-box test (Windows)')
  680. if (!isRecord(macosCheck) || typeof macosCheck.run !== 'string'
  681. || !isRecord(cleanVenvPosix) || !isRecord(cleanVenvWindows)
  682. || !isRecord(installedKeylessPosix) || !isRecord(installedKeylessWindows)
  683. || !isRecord(realApiPreflightPosix) || !isRecord(realApiPreflightWindows)
  684. || !isRecord(installedRealApiPosix) || !isRecord(installedRealApiWindows)) {
  685. throw new TypeError('Python wheel builder must define native POSIX and Windows installed-wheel steps')
  686. }
  687. expect(call.inputs).toHaveProperty('targets')
  688. expect(call.inputs).toMatchObject({
  689. ci: { type: 'boolean', default: false },
  690. release: { type: 'boolean', default: false },
  691. })
  692. expect(call.secrets).toMatchObject({
  693. DEEPSEEK_API_KEY_EXTERNAL: { required: false },
  694. })
  695. expect(workflow.concurrency).toMatchObject({
  696. group: 'build-single-exe-${{ github.workflow }}-${{ github.ref }}',
  697. })
  698. expect(build.defaults).toBeUndefined()
  699. expect(plan.if).toContain('inputs.ci')
  700. expect(plan.if).toContain('inputs.release')
  701. expect(JSON.stringify(plan.steps)).toContain('pep440_version')
  702. const workflowJson = JSON.stringify(workflow)
  703. expect(workflowJson).toContain('macosx_14_0_arm64')
  704. expect(workflowJson).toContain('macosx_14_0_x86_64')
  705. expect(workflowJson).toContain('node24-macos-x64')
  706. expect(workflowJson).toContain('macos-15-intel')
  707. expect(workflowJson).toContain('win_amd64')
  708. expect(workflowJson).toContain('node24-win-x64')
  709. expect(workflowJson).toContain('windows-2025')
  710. expect(workflowJson).toContain('dist-python/$SDK_WHEEL')
  711. expect(workflowJson).toContain('dist-python/$RUNTIME_WHEEL')
  712. expect(workflowJson).toContain('/work/dist-python/$SDK_WHEEL')
  713. expect(workflowJson).toContain('/work/dist-python/$RUNTIME_WHEEL')
  714. expect(workflowJson).not.toContain('--find-links dist-python')
  715. expect(workflowJson).not.toContain('--find-links /work/dist-python')
  716. expect(workflowJson).not.toContain('cygpath')
  717. expect(manylinuxAddon).toMatchObject({ if: "runner.os == 'Linux'" })
  718. expect(JSON.stringify(manylinuxAddon)).toContain('manylinux_2_28_x86_64')
  719. expect(JSON.stringify(manylinuxAddon)).toContain('manylinux_2_28_aarch64')
  720. expect(JSON.stringify(manylinuxAddon)).toContain('npm_config_build_from_source=true pnpm run install')
  721. expect(JSON.stringify(manylinuxAddon)).toContain('pnpm_setup_root')
  722. expect(JSON.stringify(manylinuxAddon)).toContain('$pnpm_setup_root:$pnpm_setup_root:ro')
  723. expect(JSON.stringify(manylinuxAddon)).toContain('node-pty-glibc-versions.txt')
  724. expect(JSON.stringify(manylinuxAddon)).toContain('le 2.28')
  725. expect(macosCheck).toMatchObject({ if: "runner.os == 'macOS'" })
  726. expect(macosCheck.run).toContain('scripts/check-macos-deployment-target.py')
  727. expect(macosCheck.run).toContain('lipo "$payload" -verify_arch')
  728. expect(macosCheck.run).toContain('$EXE-rg')
  729. expect(macosCheck.run).toContain('$EXE-spawn-helper')
  730. expect(JSON.stringify(installedKeylessPosix)).toContain('--scenario all')
  731. expect(JSON.stringify(installedKeylessPosix)).toContain('env -u PYTHONPATH')
  732. expect(JSON.stringify(installedKeylessWindows)).toContain('--scenario all --installed-wheel')
  733. expect(installedKeylessWindows).toMatchObject({ if: "runner.os == 'Windows'", shell: 'pwsh' })
  734. expect(cleanVenvWindows).toMatchObject({ if: "runner.os == 'Windows'", shell: 'pwsh' })
  735. expect(JSON.stringify(cleanVenvWindows)).toContain('Scripts\\\\python.exe')
  736. expect(realApiPreflightPosix).toMatchObject({
  737. env: { DEEPSEEK_API_KEY: '${{ secrets.DEEPSEEK_API_KEY_EXTERNAL }}' },
  738. })
  739. expect(String(realApiPreflightPosix.if)).toContain('inputs.ci')
  740. expect(String(realApiPreflightPosix.if)).toContain('head.repo.fork')
  741. expect(String(realApiPreflightPosix.if)).toContain('dependabot[bot]')
  742. expect(realApiPreflightWindows).toMatchObject({ shell: 'pwsh' })
  743. expect(installedRealApiPosix).toMatchObject({
  744. env: {
  745. DEEPSEEK_API_KEY: '${{ secrets.DEEPSEEK_API_KEY_EXTERNAL }}',
  746. DEEPSEEK_BASE_URL: 'https://api.deepseek.com',
  747. },
  748. })
  749. expect(JSON.stringify(installedRealApiPosix)).toContain('--scenario sdk-live')
  750. expect(JSON.stringify(installedRealApiPosix)).toContain('-u DSH_RUNTIME_MODE')
  751. expect(installedRealApiWindows).toMatchObject({ shell: 'pwsh' })
  752. expect(JSON.stringify(installedRealApiWindows)).toContain('--scenario sdk-live --installed-wheel')
  753. expect(manylinuxSmoke).toMatchObject({ if: "runner.os == 'Linux'" })
  754. expect(JSON.stringify(manylinuxSmoke)).toContain('-e DSH_TELEMETRY_DISABLED')
  755. })
  756. it('uses the shared macOS deployment-target check in GitLab', () => {
  757. const workflow = loadWorkflow('.gitlab-ci.yml')
  758. const runtimeWheel = workflow['.runtime-wheel']
  759. if (!isRecord(runtimeWheel) || !Array.isArray(runtimeWheel.script)) {
  760. throw new TypeError('GitLab CI must define the runtime wheel script')
  761. }
  762. const runtimeScript: unknown[] = runtimeWheel.script
  763. const macosCheck = runtimeScript.find(
  764. step => typeof step === 'string' && step.includes('${PLATFORM#macos-}'),
  765. )
  766. if (typeof macosCheck !== 'string') {
  767. throw new TypeError('GitLab CI must check the macOS deployment target')
  768. }
  769. expect(macosCheck).toContain('scripts/check-macos-deployment-target.py')
  770. expect(macosCheck).toContain('lipo "$payload" -verify_arch')
  771. expect(macosCheck).toContain('"$EXE" "$EXE-rg" "$EXE-spawn-helper"')
  772. })
  773. it('builds the macOS x64 wheel on the matching GitLab runner', () => {
  774. const workflow = loadWorkflow('.gitlab-ci.yml')
  775. const macosX64 = workflow['runtime-macos-x64']
  776. const publish = workflow['publish-python']
  777. if (!isRecord(macosX64) || !isRecord(publish) || !Array.isArray(publish.needs)) {
  778. throw new TypeError('GitLab CI must define the macOS x64 runtime and publication jobs')
  779. }
  780. expect(macosX64.tags).toEqual(['macos-x64'])
  781. expect(macosX64.variables).toMatchObject({ PKG_TARGET: 'node24-macos-x64', PLATFORM: 'macos-x64' })
  782. expect(publish.needs).toContainEqual({ job: 'runtime-macos-x64', artifacts: true })
  783. expect(JSON.stringify(publish.script)).toContain('macosx_14_0_x86_64.whl')
  784. })
  785. it('builds and black-box tests the Windows x64 wheel in GitLab', () => {
  786. const workflow = loadWorkflow('.gitlab-ci.yml')
  787. const windows = workflow['runtime-windows-x64']
  788. const publish = workflow['publish-python']
  789. if (!isRecord(windows) || !Array.isArray(windows.before_script) || !Array.isArray(windows.script)
  790. || !isRecord(publish) || !Array.isArray(publish.needs)) {
  791. throw new TypeError('GitLab CI must define the Windows runtime and aggregate publication jobs')
  792. }
  793. expect(windows.tags).toEqual(['windows-x64'])
  794. expect(windows.variables).toMatchObject({ PKG_TARGET: 'node24-win-x64', PLATFORM: 'win-x64' })
  795. expect(JSON.stringify(windows.before_script)).toContain('.ci-python\\\\Scripts')
  796. expect(JSON.stringify(windows.before_script)).toContain('[IO.Path]::PathSeparator')
  797. expect(JSON.stringify(windows.script)).toContain('win_amd64.whl')
  798. expect(JSON.stringify(windows.script)).toContain('--scenario all --installed-wheel')
  799. expect(publish.needs).toContainEqual({ job: 'runtime-windows-x64', artifacts: true })
  800. })
  801. })
  802. describe('Weighted approval workflow', () => {
  803. it('publishes from the trusted default branch after pull request and review updates', () => {
  804. const publisher = loadWorkflow('.github/workflows/weighted-approval.yml')
  805. const reviewEvent = loadWorkflow('.github/workflows/weighted-approval-review-event.yml')
  806. const pullRequest = workflowEvent(publisher, 'pull_request_target')
  807. const workflowRun = workflowEvent(publisher, 'workflow_run')
  808. const review = workflowEvent(reviewEvent, 'pull_request_review')
  809. const job = workflowJob(publisher, 'publish-status')
  810. const recordJob = workflowJob(reviewEvent, 'record-review-event')
  811. if (!isRecord(publisher.on)) throw new TypeError('weighted-approval workflow must define events')
  812. if (!isRecord(reviewEvent.on)) throw new TypeError('weighted-approval review event workflow must define events')
  813. if (!Array.isArray(job.steps)) throw new TypeError('weighted-approval job must define steps')
  814. if (!Array.isArray(recordJob.steps)) throw new TypeError('weighted-approval review event job must define steps')
  815. const steps = job.steps.filter(isRecord)
  816. const checkout = steps.find(step => step.name === 'Check out trusted approval policy')
  817. const publish = steps.find(step => step.name === 'Publish weighted approval status')
  818. const recordSteps = recordJob.steps.filter(isRecord)
  819. const record = recordSteps.find(step => step.name === 'Record review event')
  820. expect(publisher.name).toBe('weighted-approval')
  821. expect(Object.keys(publisher.on)).toEqual(['pull_request_target', 'workflow_run'])
  822. expect(pullRequest.types).toEqual(['opened', 'synchronize', 'reopened', 'ready_for_review', 'converted_to_draft'])
  823. expect(workflowRun).toEqual({ workflows: ['weighted-approval-review-event'], types: ['completed'] })
  824. expect(reviewEvent.name).toBe('weighted-approval-review-event')
  825. expect(reviewEvent['run-name']).toBe('weighted-approval-review-event:${{ github.event.pull_request.number }}')
  826. expect(Object.keys(reviewEvent.on)).toEqual(['pull_request_review'])
  827. expect(review.types).toEqual(['submitted', 'edited', 'dismissed'])
  828. expect(reviewEvent.permissions).toEqual({})
  829. expect(publisher.permissions).toEqual({
  830. contents: 'read',
  831. 'pull-requests': 'read',
  832. statuses: 'write',
  833. })
  834. expect(publisher.concurrency).toEqual({
  835. group: 'weighted-approval-${{ github.event.pull_request.number || github.event.workflow_run.head_sha }}',
  836. 'cancel-in-progress': false,
  837. })
  838. expect(job).toMatchObject({
  839. if: "github.event_name != 'workflow_run' || github.event.workflow_run.conclusion == 'success'",
  840. name: 'weighted approval publisher',
  841. 'runs-on': 'ubuntu-latest',
  842. 'timeout-minutes': 5,
  843. })
  844. expect(checkout).toMatchObject({
  845. uses: 'actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1',
  846. with: {
  847. ref: '${{ github.event.repository.default_branch }}',
  848. 'persist-credentials': false,
  849. },
  850. })
  851. expect(publish).toMatchObject({
  852. env: {
  853. GITHUB_TOKEN: '${{ github.token }}',
  854. GITHUB_RUN_URL: '${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}',
  855. },
  856. run: 'node .github/review-ownership/check-approval.mjs',
  857. })
  858. expect(recordJob).toMatchObject({
  859. name: 'record weighted approval review event',
  860. 'runs-on': 'ubuntu-latest',
  861. 'timeout-minutes': 2,
  862. })
  863. expect(record).toBeDefined()
  864. expect(record?.run).toBe("echo 'Recorded a weighted approval review event.'")
  865. expect(recordSteps).toHaveLength(1)
  866. expect(JSON.stringify(publisher)).not.toContain('github.event.pull_request.head')
  867. expect(JSON.stringify(publisher)).not.toContain('secrets.')
  868. expect(JSON.stringify(reviewEvent)).not.toContain('github.token')
  869. expect(JSON.stringify(reviewEvent)).not.toContain('secrets.')
  870. })
  871. })
  872. describe('Issue lifecycle workflow', () => {
  873. it('runs the lifecycle job on every PR/review event but gates token and board steps', () => {
  874. const lifecycle = loadWorkflow('.github/workflows/issue-lifecycle.yml')
  875. const policy = loadWorkflow('.github/workflows/issue-policy.yml')
  876. const lifecycleJob = workflowJob(lifecycle, 'lifecycle')
  877. if (!Array.isArray(lifecycleJob.steps)) throw new TypeError('Issue lifecycle job must define steps')
  878. // The job has no job-level `if`, so it is listed on every pull_request /
  879. // pull_request_review event and reports success instead of a gray skip. The
  880. // write-capable steps are gated at step level so approved/commented reviews
  881. // never mint a Project/Issue App token nor touch the board.
  882. expect(lifecycle.on).toHaveProperty('pull_request')
  883. expect(lifecycle.on).toHaveProperty('pull_request_review')
  884. expect(lifecycleJob.if).toBeUndefined()
  885. // Keep the subscription-type gates: issue-lifecycle does not re-subscribe
  886. // ready_for_review (issue-policy owns that) and only reacts to submitted
  887. // review events.
  888. const lifecyclePullRequest = workflowEvent(lifecycle, 'pull_request')
  889. const lifecycleReview = workflowEvent(lifecycle, 'pull_request_review')
  890. expect(lifecyclePullRequest.types).toContain('opened')
  891. expect(lifecyclePullRequest.types).not.toContain('ready_for_review')
  892. expect(lifecyclePullRequest.types).toContain('review_requested')
  893. expect(lifecycleReview.types).toEqual(['submitted'])
  894. const gated = "${{ github.event_name != 'pull_request_review' || github.event.review.state == 'changes_requested' }}"
  895. const steps = lifecycleJob.steps.filter(isRecord)
  896. const tokenStep = steps.find(s => s.name === 'Create project token')
  897. const handleStep = steps.find(s => s.name === 'Handle repository event')
  898. expect(tokenStep).toMatchObject({ if: gated })
  899. expect(handleStep).toMatchObject({ if: gated })
  900. // issue-policy owns PR validation; it is read-only and a real gate.
  901. const policyPullRequest = workflowEvent(policy, 'pull_request')
  902. expect(policyPullRequest.types).toContain('ready_for_review')
  903. })
  904. it('uses a read-only Project token only for human pull request policy metadata', () => {
  905. const policy = loadWorkflow('.github/workflows/issue-policy.yml')
  906. const policyJob = workflowJob(policy, 'policy')
  907. if (!Array.isArray(policyJob.steps)) throw new TypeError('Issue policy job must define steps')
  908. const steps = policyJob.steps.filter(isRecord)
  909. const tokenStep = steps.find(step => step.name === 'Create Project read token')
  910. const validateStep = steps.find(step => step.name === 'Validate pull request')
  911. const humanPullRequest =
  912. "${{ github.event.pull_request.user.type != 'Bot' && github.event.pull_request.user.type != 'App' }}"
  913. expect(tokenStep).toMatchObject({
  914. id: 'app-token',
  915. if: humanPullRequest,
  916. uses: 'actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1',
  917. with: {
  918. 'client-id': '${{ vars.DSH_ISSUE_APP_CLIENT_ID }}',
  919. 'private-key': '${{ secrets.DSH_ISSUE_APP_PRIVATE_KEY }}',
  920. owner: 'deepseek-harness',
  921. repositories: 'deepseek-harness',
  922. 'permission-issues': 'read',
  923. 'permission-organization-projects': 'read',
  924. },
  925. })
  926. expect(validateStep).toMatchObject({
  927. if: humanPullRequest,
  928. env: {
  929. GITHUB_TOKEN: '${{ github.token }}',
  930. PROJECT_TOKEN: '${{ steps.app-token.outputs.token }}',
  931. },
  932. })
  933. })
  934. })
  935. describe('npm release workflows', () => {
  936. it('keeps publication dispatch-only and pack in the PR workflow', () => {
  937. // pack stays in the PR/master release workflows so a PR proves the set packs.
  938. for (const file of ['release.yml', 'release-vendor.yml']) {
  939. const workflow = loadWorkflow(`.github/workflows/${file}`)
  940. if (!isRecord(workflow.jobs)) throw new TypeError(`${file} must define jobs`)
  941. expect(Object.keys(workflow.jobs).sort()).toEqual(file === 'release.yml' ? ['dependencies', 'pack'] : ['pack'])
  942. }
  943. // publication is workflow_dispatch-only (never a PR check) and keeps the
  944. // npm-publish environment plus the shared dist-tag group.
  945. for (const file of ['release-publish.yml', 'release-vendor-publish.yml']) {
  946. const workflow = loadWorkflow(`.github/workflows/${file}`)
  947. if (!isRecord(workflow.on) || !isRecord(workflow.jobs)) throw new TypeError(`${file} must define on and jobs`)
  948. expect(Object.keys(workflow.on)).toEqual(['workflow_dispatch'])
  949. const publish = workflow.jobs.publish
  950. if (!isRecord(publish)) throw new TypeError(`${file} must define a publish job`)
  951. expect(publish.environment).toBe('npm-publish')
  952. expect(publish.concurrency).toMatchObject({ group: 'Release-publish' })
  953. }
  954. })
  955. it('runs dependency policy and npm layout checks in the DSH release workflow', () => {
  956. const workflow = loadWorkflow('.github/workflows/release.yml')
  957. const dependencies = workflowJob(workflow, 'dependencies')
  958. if (!isRecord(workflow.on) || !Array.isArray(dependencies.steps)) {
  959. throw new TypeError('DSH release workflow must define triggers and dependency steps')
  960. }
  961. const commands = dependencies.steps.flatMap(step =>
  962. isRecord(step) && typeof step.run === 'string' ? [step.run] : [])
  963. expect(Object.keys(workflow.on).sort()).toEqual(['pull_request', 'push', 'workflow_dispatch'])
  964. expect(commands).toContain('pnpm run verify-package-dependencies')
  965. expect(commands).toContain('pnpm run verify-npm-install-layout')
  966. })
  967. })
  968. describe('Documentation site publication', () => {
  969. it('keeps Pages deployment dispatch-only from a dsh-v* tag', () => {
  970. const workflow = loadWorkflow('.github/workflows/docs-pages.yml')
  971. const build = workflowJob(workflow, 'build')
  972. const deploy = workflowJob(workflow, 'deploy')
  973. if (!isRecord(workflow.on) || !isRecord(workflow.env) || !Array.isArray(build.steps)) {
  974. throw new TypeError('Documentation deployment must define on, env, and build steps')
  975. }
  976. // The site presents a released snapshot: a merge must never publish it, and
  977. // publication must never appear as a PR check.
  978. expect(Object.keys(workflow.on)).toEqual(['workflow_dispatch'])
  979. // RELEASE_PUBLISH makes release:verify reject every ref that is not a dsh-v*
  980. // tag naming this tree's version, so the site and the npm sequence share one
  981. // definition of a released version.
  982. const steps = build.steps.filter(isRecord)
  983. const verify = steps.find(step => step.name === 'Verify release version')
  984. const checkout = steps.find(
  985. step => typeof step.uses === 'string' && step.uses.startsWith('actions/checkout@'),
  986. )
  987. expect(verify).toMatchObject({
  988. env: { RELEASE_PUBLISH: 'true' },
  989. run: 'pnpm run release:verify --family dsh',
  990. })
  991. // Complete history: the release scripts read tags.
  992. expect(checkout).toMatchObject({ with: { 'fetch-depth': 0 } })
  993. // Projected source links stay on the public repository's master. That
  994. // repository advances only to each release commit, so its master never
  995. // carries unreleased work, while it retains only the most recent tags:
  996. // following the dispatched tag would leave every source link on a deploy
  997. // from an older tag unresolvable.
  998. expect(workflow.env.DOCS_REPOSITORY_REF).toBe('master')
  999. // The environment owns the deployment tag policy and the required reviewers.
  1000. expect(deploy.environment).toMatchObject({ name: 'github-pages' })
  1001. })
  1002. })
  1003. describe('Git hooks', () => {
  1004. it('leaves frozen Agent Note sidecars to the archive verifier', () => {
  1005. const lefthook = loadWorkflow('lefthook.yml')
  1006. for (const hookName of ['pre-commit', 'pre-merge-commit']) {
  1007. const hook = lefthook[hookName]
  1008. if (!isRecord(hook) || !Array.isArray(hook.jobs)) {
  1009. throw new TypeError(`lefthook must define ${hookName} jobs`)
  1010. }
  1011. const pairing: unknown = hook.jobs.find(
  1012. (job: unknown) => isRecord(job) && job.name === 'translation pairing (staged records)',
  1013. )
  1014. expect(pairing).toMatchObject({ exclude: ['.agents/notes/archived/**'] })
  1015. }
  1016. })
  1017. })
  1018. function loadWorkflow(path: string): Record<string, unknown> {
  1019. const workflow: unknown = yaml.load(readFileSync(resolve(root, path), 'utf8'))
  1020. if (!isRecord(workflow)) throw new TypeError(`${path} must define a workflow`)
  1021. return workflow
  1022. }
  1023. function workflowEvent(workflow: Record<string, unknown>, event: string): Record<string, unknown> {
  1024. if (!isRecord(workflow.on) || !isRecord(workflow.on[event])) {
  1025. throw new TypeError(`workflow must define the ${event} event`)
  1026. }
  1027. return workflow.on[event]
  1028. }
  1029. function workflowJob(workflow: Record<string, unknown>, job: string): Record<string, unknown> {
  1030. if (!isRecord(workflow.jobs) || !isRecord(workflow.jobs[job])) {
  1031. throw new TypeError(`workflow must define the ${job} job`)
  1032. }
  1033. return workflow.jobs[job]
  1034. }
  1035. function isRecord(value: unknown): value is Record<string, unknown> {
  1036. return typeof value === 'object' && value !== null && !Array.isArray(value)
  1037. }