ci-workflow.spec.ts 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703
  1. import { readFileSync } from 'node:fs'
  2. import { resolve } from 'node:path'
  3. import * as yaml from 'js-yaml'
  4. import { describe, expect, it } from 'vitest'
  5. const root = resolve(import.meta.dirname, '..')
  6. const runnerPrivatePnpmDestination = /^\$\{\{ runner\.temp \}\}\/setup-pnpm-\$\{\{ github\.run_id \}\}-\$\{\{ github\.run_attempt \}\}$/
  7. const nativeWindowsPnpmDestination = '${{ runner.temp }}/setup-pnpm-js-${{ github.run_id }}-${{ github.run_attempt }}-${{ github.job }}'
  8. describe('CI workflow', () => {
  9. it('isolates every pnpm action setup destination per runner', () => {
  10. const files = ['.github/workflows/ci.yml', '.github/workflows/ci-master.yml']
  11. const setups: Array<{ jobName: string; step: unknown }> = []
  12. for (const file of files) {
  13. const workflow: unknown = yaml.load(readFileSync(resolve(root, file), 'utf8'))
  14. if (!isRecord(workflow) || !isRecord(workflow.jobs)) throw new TypeError(`${file} must define jobs`)
  15. for (const [jobName, job] of Object.entries(workflow.jobs)) {
  16. if (!isRecord(job) || !Array.isArray(job.steps)) continue
  17. for (const step of job.steps) {
  18. if (!isRecord(step) || typeof step.uses !== 'string' || !step.uses.startsWith('pnpm/action-setup@')) continue
  19. setups.push({ jobName, step })
  20. }
  21. }
  22. }
  23. expect(setups.length).toBeGreaterThan(0)
  24. for (const { jobName, step } of setups) {
  25. const stepDest = (step as { with?: { dest?: unknown } }).with?.dest
  26. if (jobName.startsWith('windows-')) {
  27. expect(stepDest, `${jobName} must use the native Windows pnpm destination`).toBe(nativeWindowsPnpmDestination)
  28. expect(step).not.toMatchObject({ with: { standalone: true } })
  29. } else {
  30. expect(typeof stepDest, `${jobName} must use a runner-and-run-private pnpm destination`).toBe('string')
  31. expect(stepDest as string).toMatch(runnerPrivatePnpmDestination)
  32. }
  33. }
  34. })
  35. it('isolates the python SDK exe pnpm setup destination per job', () => {
  36. const workflow: unknown = yaml.load(readFileSync(resolve(root, '.github/workflows/build-exe-for-python-sdk.yml'), 'utf8'))
  37. if (!isRecord(workflow) || !isRecord(workflow.jobs)) throw new TypeError('build-exe-for-python-sdk.yml must define jobs')
  38. const setups: Array<{ step: unknown }> = []
  39. for (const job of Object.values(workflow.jobs)) {
  40. if (!isRecord(job) || !Array.isArray(job.steps)) continue
  41. for (const step of job.steps) {
  42. if (!isRecord(step) || typeof step.uses !== 'string' || !step.uses.startsWith('pnpm/action-setup@')) continue
  43. setups.push({ step })
  44. }
  45. }
  46. expect(setups.length).toBeGreaterThan(0)
  47. for (const { step } of setups) {
  48. expect(step).toMatchObject({
  49. with: { dest: nativeWindowsPnpmDestination },
  50. })
  51. }
  52. })
  53. it('keeps required Wine and split native Windows jobs with failover, plus a master-only standby', () => {
  54. const workflow = loadWorkflow('.github/workflows/ci.yml')
  55. const masterWorkflow = loadWorkflow('.github/workflows/ci-master.yml')
  56. if (!isRecord(workflow.jobs)
  57. || !isRecord(workflow.jobs.windows)
  58. || !isRecord(workflow.jobs['windows-build'])
  59. || !isRecord(workflow.jobs['windows-coverage'])
  60. || !isRecord(workflow.jobs['windows-native-tests'])
  61. || !isRecord(workflow.jobs['windows-observational'])
  62. || !isRecord(workflow.jobs['node-24'])
  63. || !isRecord(workflow.jobs['node-24-coverage'])
  64. || !isRecord(workflow.jobs['node-24-consumers'])
  65. || !isRecord(workflow.jobs['all-checks-passed'])
  66. || !isRecord(masterWorkflow.jobs)
  67. || !isRecord(masterWorkflow.jobs['wine-apt-cache'])
  68. || !isRecord(masterWorkflow.jobs['serial-windows'])) {
  69. throw new TypeError('CI workflow must define windows, windows-build, windows-coverage, windows-native-tests, windows-observational, node-24, node-24-coverage, node-24-consumers, and all-checks-passed; ci-master must define wine-apt-cache and serial-windows')
  70. }
  71. const windows = workflow.jobs.windows
  72. const windowsBuild = workflow.jobs['windows-build']
  73. const windowsCoverage = workflow.jobs['windows-coverage']
  74. const windowsNativeTests = workflow.jobs['windows-native-tests']
  75. const windowsObservational = workflow.jobs['windows-observational']
  76. const wineAptCache = masterWorkflow.jobs['wine-apt-cache']
  77. const serialWindows = masterWorkflow.jobs['serial-windows']
  78. const node24 = workflow.jobs['node-24']
  79. const node24Coverage = workflow.jobs['node-24-coverage']
  80. const node24Consumers = workflow.jobs['node-24-consumers']
  81. const aggregate = workflow.jobs['all-checks-passed']
  82. if (!Array.isArray(windows.steps) || !Array.isArray(aggregate.needs)) {
  83. throw new TypeError('Windows job must define steps and the aggregate must define needs')
  84. }
  85. const commandSteps = windows.steps.filter((step): step is Record<string, unknown> & { run: string } => (
  86. isRecord(step) && typeof step.run === 'string'
  87. ))
  88. // Required PR job: Wine on ubuntu-latest, runs wine-windows-gates.sh.
  89. expect(windows['runs-on']).toBe('ubuntu-latest')
  90. expect(windows.name).toBe('windows node 24 / wine blocking')
  91. expect(windows.if).toBe("github.event_name == 'pull_request'")
  92. expect(commandSteps.some(step => step.run.includes('wine-windows-gates.sh'))).toBe(true)
  93. // The split native jobs all resolve their pool through the Windows switch.
  94. for (const [jobName, job] of [['windows-build', windowsBuild], ['windows-coverage', windowsCoverage], ['windows-native-tests', windowsNativeTests], ['windows-observational', windowsObservational]] as const) {
  95. expect(typeof job['runs-on']).toBe('string')
  96. expect(job['runs-on'], `${jobName} runs-on must use the Windows failover switch`).toContain('DSH_CI_FAILOVER_WINDOWS')
  97. expect(job['runs-on'], `${jobName} runs-on must not use the Linux failover switch`).not.toContain('DSH_CI_FAILOVER_LINUX')
  98. expect(job['runs-on']).toContain('self-hosted')
  99. expect(job['runs-on']).toContain('dsh-win-ci')
  100. expect(job['runs-on']).toContain('dsh-windows-2025-16core')
  101. expect(job.if).toBe("github.event_name == 'pull_request'")
  102. }
  103. // windows-build runs the blocking build/site pair.
  104. expect(windowsBuild.name).toBe('windows node 24 / build')
  105. const buildSteps = windowsBuild.steps as unknown[]
  106. const buildCommands = buildSteps.filter((step): step is Record<string, unknown> & { run: string } => (
  107. isRecord(step) && typeof step.run === 'string'
  108. ))
  109. expect(buildCommands.map(step => step.run)).toContain('pnpm run check:ci:windows-blocking')
  110. // windows-coverage uses the lower 4-partition profile.
  111. expect(windowsCoverage.name).toBe('windows node 24 / coverage')
  112. expect(windowsCoverage.env).toMatchObject({ DSH_COVERAGE_PARTITIONS: '4' })
  113. const coverageSteps = windowsCoverage.steps as unknown[]
  114. const coverageCommands = coverageSteps.filter((step): step is Record<string, unknown> & { run: string } => (
  115. isRecord(step) && typeof step.run === 'string'
  116. ))
  117. expect(coverageCommands.map(step => step.run)).toContain('pnpm run check:ci:coverage')
  118. // windows-native-tests runs the Windows-specific specs.
  119. expect(windowsNativeTests.name).toBe('windows node 24 / native tests')
  120. const nativeTestSteps = windowsNativeTests.steps as unknown[]
  121. const nativeTestCommands = nativeTestSteps.filter((step): step is Record<string, unknown> & { run: string } => (
  122. isRecord(step) && typeof step.run === 'string'
  123. ))
  124. const nativeTestCommand = nativeTestCommands.map(step => step.run).join('\n')
  125. expect(nativeTestCommand).toContain('--no-file-parallelism')
  126. expect(nativeTestCommand).toContain('--testTimeout 90000')
  127. expect(nativeTestCommand).toContain('tool-pwsh/tests/loader.spec.ts')
  128. expect(nativeTestCommand).toContain('workflow-worker-thread.spec.ts')
  129. // windows-observational is non-blocking.
  130. expect(windowsObservational.name).toBe('windows node 24 / observational')
  131. expect(windowsObservational['continue-on-error']).toBe(true)
  132. // wine-apt-cache: master-only, seeds the Wine apt cache, lives in ci-master.
  133. expect(wineAptCache.if).toBe("github.event_name == 'push' && github.ref == 'refs/heads/master'")
  134. expect(wineAptCache['runs-on']).toBe('ubuntu-latest')
  135. // serial-windows: master-only standby, self-hosted, non-blocking, lives in ci-master.
  136. expect(serialWindows.if).toBe("github.event_name == 'push' && github.ref == 'refs/heads/master'")
  137. expect(serialWindows['runs-on']).toEqual(['self-hosted', 'dsh-win-ci', 'windows'])
  138. expect(serialWindows.name).toBe('serial / windows (self-hosted standby)')
  139. // Aggregate: Wine and the required split native jobs are needed;
  140. // windows-coverage is temporarily non-blocking while Windows ACP
  141. // half-close tests are stabilized; observational stays out too.
  142. expect(aggregate.needs).toContain('windows')
  143. expect(aggregate.needs).toContain('windows-build')
  144. expect(aggregate.needs).not.toContain('windows-coverage')
  145. expect(aggregate.needs).toContain('windows-native-tests')
  146. expect(aggregate.needs).not.toContain('windows-observational')
  147. expect(aggregate.needs).not.toContain('serial-windows')
  148. // Linux failover is a separate switch: the three required Linux workers
  149. // and the verdict job resolve their pool through DSH_CI_FAILOVER_LINUX,
  150. // never the Windows switch.
  151. for (const [jobName, job] of [['node-24', node24], ['node-24-coverage', node24Coverage], ['node-24-consumers', node24Consumers]] as const) {
  152. expect(typeof job['runs-on']).toBe('string')
  153. expect(job['runs-on'], `${jobName} runs-on must use the Linux failover switch`).toContain('DSH_CI_FAILOVER_LINUX')
  154. expect(job['runs-on'], `${jobName} runs-on must not use the Windows failover switch`).not.toContain('DSH_CI_FAILOVER_WINDOWS')
  155. expect(job['runs-on']).toContain('vm-backup')
  156. }
  157. expect(aggregate['runs-on']).toContain('DSH_CI_FAILOVER_LINUX')
  158. expect(aggregate['runs-on']).not.toContain('DSH_CI_FAILOVER_WINDOWS')
  159. expect(aggregate['runs-on']).toContain('vm-backup')
  160. })
  161. it('gives the Wine Host TypeScript compile the repository heap budget', () => {
  162. const wineGates = readFileSync(resolve(root, 'scripts/wine-windows-gates.sh'), 'utf8')
  163. expect(wineGates).toContain(
  164. 'wine_node "$scratch/logs/host-tsc.log" --max-old-space-size=4096 "$tsc_js" -b tsconfig.host.json --pretty false',
  165. )
  166. })
  167. it('exempts push from cancellation in ci-master, so one master merge does not cancel the running drill', () => {
  168. const workflow = loadWorkflow('.github/workflows/ci-master.yml')
  169. const prWorkflow = loadWorkflow('.github/workflows/ci.yml')
  170. if (!isRecord(workflow.jobs) || !isRecord(workflow.concurrency)) {
  171. throw new TypeError('ci-master workflow must define jobs and a workflow-level concurrency block')
  172. }
  173. if (!isRecord(prWorkflow.jobs)) {
  174. throw new TypeError('ci workflow must define jobs')
  175. }
  176. // Cancellation applies to the whole superseded RUN, so this has to be
  177. // decided at workflow level and gated on the event: a job-level group
  178. // cannot exempt its job from its run being cancelled. Only push is exempt —
  179. // a drill takes longer than the interval between master merges. The negated
  180. // form is load-bearing: `== 'pull_request'` would also stop cancelling
  181. // workflow_dispatch, and a re-dispatched runner benchmark holds up to 12
  182. // larger runners for 15 minutes in this same group on master.
  183. expect(workflow.concurrency['cancel-in-progress']).toBe("${{ github.event_name != 'push' }}")
  184. // The PR-only ci.yml still cancels a superseded run on a new push, so a
  185. // fresh head does not stack a second full 9-job run behind a stale one.
  186. // Unlike ci-master it has no push carve-out: every PR event supersedes.
  187. expect(prWorkflow.concurrency).toMatchObject({
  188. 'cancel-in-progress': true,
  189. })
  190. // The exact event sets are what keep master-only jobs out of the PR check
  191. // panel: ci-master triggers only on push(master) + workflow_dispatch and
  192. // never on pull_request; ci.yml is exactly pull_request-only. Assert the
  193. // full sets so losing the wrong event, or gaining an extra one, fails.
  194. if (!isRecord(workflow.on) || !isRecord(prWorkflow.on)) {
  195. throw new TypeError('both CI workflows must define on')
  196. }
  197. expect(Object.keys(workflow.on).sort()).toEqual(['push', 'workflow_dispatch'])
  198. expect(Object.keys(prWorkflow.on)).toEqual(['pull_request'])
  199. // Neither drill may carry a job-level group: it would not exempt the job
  200. // from run-scoped cancellation.
  201. for (const name of ['serial-linux-selfhosted', 'serial-windows']) {
  202. const job = workflow.jobs[name]
  203. if (!isRecord(job)) throw new TypeError(`${name} must be defined`)
  204. expect(job.concurrency).toBeUndefined()
  205. // Both stay master-push-only; that is what makes the push carve-out safe.
  206. expect(job.if).toBe("github.event_name == 'push' && github.ref == 'refs/heads/master'")
  207. }
  208. // What bounds the cost of exempting push: a master push may only carry the
  209. // cache seeder and the two drills. Any job reachable on push would start
  210. // accumulating uncancelled runs, so the set is pinned here.
  211. const NOT_PUSH_REACHABLE = new Set([
  212. "github.event_name == 'workflow_dispatch' && inputs.suite == 'larger-runner-benchmark'",
  213. "github.event_name == 'workflow_dispatch' && inputs.suite == 'consolidated-runner-benchmark'",
  214. ])
  215. const pushReachable = Object.entries(workflow.jobs)
  216. .filter(([, job]) => {
  217. if (!isRecord(job)) return false
  218. if (job.if === undefined) return true // unconditional: runs on every event
  219. if (job.if === false) return false // `if: false` parses as a boolean
  220. if (typeof job.if !== 'string') return true // unrecognized shape: surface it
  221. return !NOT_PUSH_REACHABLE.has(job.if.trim())
  222. })
  223. .map(([name]) => name)
  224. .sort()
  225. expect(pushReachable).toEqual(['serial-linux-selfhosted', 'serial-windows', 'wine-apt-cache'])
  226. // Why workflow_dispatch must keep cancelling: each benchmark fans out to a
  227. // dozen larger runners at once, in this same group on master. If it stopped
  228. // cancelling, a re-dispatch would queue ahead of a drill instead of
  229. // replacing the stale measurement.
  230. for (const name of ['larger-runner-benchmark', 'consolidated-runner-benchmark']) {
  231. const job = workflow.jobs[name]
  232. if (!isRecord(job) || !isRecord(job.strategy)) {
  233. throw new TypeError(`${name} must define a matrix strategy`)
  234. }
  235. expect(job.strategy['max-parallel']).toBe(12)
  236. expect(job['timeout-minutes']).toBe(15)
  237. }
  238. })
  239. it('keeps supported LSP source under native Windows coverage', () => {
  240. const config = readFileSync(resolve(root, 'vitest.config.ts'), 'utf8')
  241. expect(config).not.toContain('packages/lsp/lsp-stdio/src/connection.ts')
  242. expect(config).not.toContain('packages/lsp/lsp-stdio/src/index.ts')
  243. expect(config).not.toContain('packages/lsp/lsp-stdio/src/instance.ts')
  244. })
  245. it('requires release-shaped Python runtime validation on every published target', () => {
  246. const workflow = loadWorkflow('.github/workflows/ci.yml')
  247. const pythonRuntime = workflowJob(workflow, 'python-runtime')
  248. const aggregate = workflowJob(workflow, 'all-checks-passed')
  249. if (!Array.isArray(aggregate.needs)) {
  250. throw new TypeError('CI aggregate must define required job dependencies')
  251. }
  252. expect(pythonRuntime).toMatchObject({
  253. if: "github.event_name == 'pull_request'",
  254. name: 'python runtime / release-shaped matrix',
  255. uses: './.github/workflows/build-exe-for-python-sdk.yml',
  256. with: {
  257. targets: 'node24-linux-x64,node24-linux-arm64,node24-macos-arm64,node24-win-x64',
  258. ci: true,
  259. },
  260. secrets: {
  261. DEEPSEEK_API_KEY_EXTERNAL: '${{ secrets.DEEPSEEK_API_KEY_EXTERNAL }}',
  262. },
  263. })
  264. expect(aggregate.needs).toContain('python-runtime')
  265. })
  266. it('keeps every Vitest project process-isolated on native Windows', () => {
  267. const config = readFileSync(resolve(root, 'vitest.config.ts'), 'utf8')
  268. expect(config).not.toContain("pool: process.platform === 'win32' ? 'threads' : 'forks'")
  269. expect(config.match(/pool: 'forks'/g)).toHaveLength(2)
  270. })
  271. })
  272. describe('DeepSeek e2e workflow', () => {
  273. it('prepares bubblewrap from the pinned payload without a package transaction', () => {
  274. const workflow = loadWorkflow('.github/workflows/e2e.yml')
  275. const e2e = workflowJob(workflow, 'e2e')
  276. if (!Array.isArray(e2e.steps)) throw new TypeError('DeepSeek e2e workflow must define steps')
  277. const steps = e2e.steps.filter(isRecord)
  278. expect(steps.find(step => step.name === 'Prepare bubblewrap (unrestrict userns)')).toMatchObject({
  279. run: 'bash scripts/prepare-ci-bubblewrap.sh',
  280. })
  281. expect(JSON.stringify(steps)).not.toContain('apt-get')
  282. })
  283. it('bounds profile subprocess fan-out to the tested e2e default', () => {
  284. const workflow = loadWorkflow('.github/workflows/e2e.yml')
  285. const e2e = workflowJob(workflow, 'e2e')
  286. if (!Array.isArray(e2e.steps)) throw new TypeError('DeepSeek e2e workflow must define steps')
  287. const step = e2e.steps.filter(isRecord).find(candidate => candidate.name === 'E2E tests (real DeepSeek API)')
  288. expect(step).toMatchObject({ env: { DSH_E2E_MAX_WORKERS: 4 } })
  289. })
  290. })
  291. describe('E2B e2e workflow', () => {
  292. it('is manual-only and fails loud before running the focused live suite', () => {
  293. const workflow = loadWorkflow('.github/workflows/e2b-e2e.yml')
  294. expect(workflow.on).toEqual({ workflow_dispatch: null })
  295. if (!isRecord(workflow.jobs) || !isRecord(workflow.jobs.e2b) || !Array.isArray(workflow.jobs.e2b.steps)) {
  296. throw new TypeError('E2B e2e workflow must define the e2b job steps')
  297. }
  298. const steps = workflow.jobs.e2b.steps.filter(isRecord)
  299. const preflight = steps.find(step => step.name === 'Preflight (require E2B API key)')
  300. const e2b = steps.find(step => step.name === 'E2B tests (live sandbox)')
  301. expect(preflight).toMatchObject({
  302. env: { E2B_API_KEY: '${{ secrets.E2B_API_KEY_EXTERNAL }}' },
  303. })
  304. expect(preflight?.run).toContain('E2B_API_KEY_EXTERNAL repository secret')
  305. expect(e2b).toMatchObject({
  306. env: {
  307. E2B_API_KEY: '${{ secrets.E2B_API_KEY_EXTERNAL }}',
  308. DSH_E2E_MAX_WORKERS: '1',
  309. DSH_EXAMPLE_MODE: 'lib',
  310. },
  311. })
  312. expect(e2b?.run).toContain('packages/e2b/e2b/tests/composition.e2e.ts')
  313. })
  314. })
  315. describe('Python release workflows', () => {
  316. it('keeps complete wheel validation separate from protected public publication', () => {
  317. const workflow = loadWorkflow('.github/workflows/python-release.yml')
  318. const dispatch = workflowEvent(workflow, 'workflow_dispatch')
  319. const build = workflowJob(workflow, 'build')
  320. const pythonCompat = workflowJob(workflow, 'python-compat')
  321. const validate = workflowJob(workflow, 'validate')
  322. const publishRuntime = workflowJob(workflow, 'publish-runtime')
  323. const publishSdk = workflowJob(workflow, 'publish-sdk')
  324. if (!isRecord(dispatch.inputs)
  325. || !isRecord(dispatch.inputs.publish)
  326. || !Array.isArray(pythonCompat.steps)
  327. || !Array.isArray(validate.steps)
  328. || !Array.isArray(publishRuntime.steps)
  329. || !Array.isArray(publishSdk.steps)) {
  330. throw new TypeError('Python release workflow must define publish input and release steps')
  331. }
  332. expect(dispatch.inputs.publish).toMatchObject({ type: 'boolean', default: false })
  333. if (!isRecord(workflow.on)) throw new TypeError('python-release workflow must define on')
  334. expect(Object.keys(workflow.on)).toEqual(['workflow_dispatch'])
  335. expect(build).toMatchObject({
  336. uses: './.github/workflows/build-exe-for-python-sdk.yml',
  337. with: {
  338. targets: 'node24-linux-x64,node24-linux-arm64,node24-macos-arm64,node24-win-x64',
  339. release: true,
  340. },
  341. })
  342. expect(pythonCompat.strategy).toMatchObject({ matrix: { python: ['3.10', '3.14'] } })
  343. const pythonCompatSteps = JSON.stringify(pythonCompat.steps)
  344. expect(pythonCompatSteps).toContain('dist/deepseek_harness_sdk-$VERSION-py3-none-any.whl')
  345. expect(pythonCompatSteps).toContain('dist/deepseek_harness_runtime_bin-$VERSION-py3-none-manylinux_2_28_x86_64.whl')
  346. expect(pythonCompatSteps).not.toContain('--find-links')
  347. const validateSteps = JSON.stringify(validate.steps)
  348. const authorize = validate.steps.filter(isRecord).find(step => step.name === 'Authorize publication request')
  349. if (!isRecord(authorize) || typeof authorize.run !== 'string') {
  350. throw new TypeError('Python release validation must authorize publication requests')
  351. }
  352. expect(validateSteps).toContain('PUBLIC_PYPI_RELEASE_ENABLED')
  353. expect(authorize).toMatchObject({
  354. env: {
  355. PYPI_PUBLISHER_REPOSITORY: '${{ vars.PYPI_PUBLISHER_REPOSITORY }}',
  356. REPOSITORY: '${{ github.repository }}',
  357. },
  358. })
  359. expect(authorize.run).toContain('[ "$REPOSITORY" = "$PYPI_PUBLISHER_REPOSITORY" ]')
  360. expect(validateSteps).toContain('100000000')
  361. expect(publishRuntime).toMatchObject({
  362. if: "github.event_name == 'workflow_dispatch' && inputs.publish",
  363. needs: 'validate',
  364. environment: 'pypi-runtime',
  365. permissions: { contents: 'read', 'id-token': 'write' },
  366. })
  367. expect(publishSdk).toMatchObject({
  368. if: "github.event_name == 'workflow_dispatch' && inputs.publish",
  369. needs: ['validate', 'publish-runtime'],
  370. environment: 'pypi',
  371. permissions: { contents: 'read', 'id-token': 'write' },
  372. })
  373. const runtimeSteps = publishRuntime.steps.filter(isRecord)
  374. const sdkSteps = publishSdk.steps.filter(isRecord)
  375. const runtimePublish = runtimeSteps.find(step => step.name === 'Publish runtime wheels')
  376. const sdkPublish = sdkSteps.find(step => step.name === 'Publish SDK wheel')
  377. const runtimeHashes = runtimeSteps.find(step => step.name === 'Verify release artifact hashes')
  378. const sdkHashes = sdkSteps.find(step => step.name === 'Verify release artifact hashes')
  379. expect([...runtimeSteps, ...sdkSteps].some(
  380. step => typeof step.uses === 'string' && step.uses.startsWith('actions/checkout@'),
  381. )).toBe(false)
  382. expect([...runtimeSteps, ...sdkSteps].filter(
  383. step => step.uses === 'pypa/gh-action-pypi-publish@release/v1',
  384. )).toHaveLength(2)
  385. expect(runtimePublish).toMatchObject({
  386. with: { 'packages-dir': 'dist/runtime/', attestations: false },
  387. })
  388. expect(sdkPublish).toMatchObject({
  389. with: { 'packages-dir': 'dist/sdk/', attestations: false },
  390. })
  391. expect(runtimeHashes).toMatchObject({ run: 'cd dist && sha256sum -c SHA256SUMS' })
  392. expect(sdkHashes).toMatchObject({ run: 'cd dist && sha256sum -c SHA256SUMS' })
  393. })
  394. it('exposes the native wheel builder to the release caller with normalized versions', () => {
  395. const workflow = loadWorkflow('.github/workflows/build-exe-for-python-sdk.yml')
  396. expect(Object.keys(workflow.on as Record<string, unknown>).sort()).toEqual(['workflow_call', 'workflow_dispatch'])
  397. const call = workflowEvent(workflow, 'workflow_call')
  398. const plan = workflowJob(workflow, 'plan')
  399. const build = workflowJob(workflow, 'build')
  400. if (!isRecord(call.inputs) || !isRecord(call.secrets) || !Array.isArray(plan.steps) || !Array.isArray(build.steps)) {
  401. throw new TypeError('Python wheel builder must define workflow_call inputs and plan steps')
  402. }
  403. const buildSteps: unknown[] = build.steps
  404. const manylinuxAddon = buildSteps.find(step => isRecord(step) && step.name === 'Rebuild Linux node-pty against manylinux 2.28')
  405. const macosCheck = buildSteps.find(step => isRecord(step) && step.name === 'Check macOS deployment target')
  406. const manylinuxSmoke = buildSteps.find(step => isRecord(step) && step.name === 'Run wheel in a manylinux 2.28 container')
  407. const cleanVenvPosix = buildSteps.find(step => isRecord(step) && step.name === 'Install local SDK and runtime wheels into a clean venv (POSIX)')
  408. const cleanVenvWindows = buildSteps.find(step => isRecord(step) && step.name === 'Install local SDK and runtime wheels into a clean venv (Windows)')
  409. const installedKeylessPosix = buildSteps.find(step => isRecord(step) && step.name === 'Run installed-wheel keyless black-box tests (POSIX)')
  410. const installedKeylessWindows = buildSteps.find(step => isRecord(step) && step.name === 'Run installed-wheel keyless black-box tests (Windows)')
  411. const realApiPreflightPosix = buildSteps.find(step => isRecord(step) && step.name === 'Preflight installed-wheel real API test (POSIX)')
  412. const realApiPreflightWindows = buildSteps.find(step => isRecord(step) && step.name === 'Preflight installed-wheel real API test (Windows)')
  413. const installedRealApiPosix = buildSteps.find(step => isRecord(step) && step.name === 'Run installed-wheel real API black-box test (POSIX)')
  414. const installedRealApiWindows = buildSteps.find(step => isRecord(step) && step.name === 'Run installed-wheel real API black-box test (Windows)')
  415. if (!isRecord(cleanVenvPosix) || !isRecord(cleanVenvWindows)
  416. || !isRecord(installedKeylessPosix) || !isRecord(installedKeylessWindows)
  417. || !isRecord(realApiPreflightPosix) || !isRecord(realApiPreflightWindows)
  418. || !isRecord(installedRealApiPosix) || !isRecord(installedRealApiWindows)) {
  419. throw new TypeError('Python wheel builder must define native POSIX and Windows installed-wheel steps')
  420. }
  421. expect(call.inputs).toHaveProperty('targets')
  422. expect(call.inputs).toMatchObject({
  423. ci: { type: 'boolean', default: false },
  424. release: { type: 'boolean', default: false },
  425. })
  426. expect(call.secrets).toMatchObject({
  427. DEEPSEEK_API_KEY_EXTERNAL: { required: false },
  428. })
  429. expect(workflow.concurrency).toMatchObject({
  430. group: 'build-single-exe-${{ github.workflow }}-${{ github.ref }}',
  431. })
  432. expect(build.defaults).toBeUndefined()
  433. expect(plan.if).toContain('inputs.ci')
  434. expect(plan.if).toContain('inputs.release')
  435. expect(JSON.stringify(plan.steps)).toContain('pep440_version')
  436. const workflowJson = JSON.stringify(workflow)
  437. expect(workflowJson).toContain('macosx_14_0_arm64')
  438. expect(workflowJson).toContain('win_amd64')
  439. expect(workflowJson).toContain('node24-win-x64')
  440. expect(workflowJson).toContain('windows-2025')
  441. expect(workflowJson).toContain('dist-python/$SDK_WHEEL')
  442. expect(workflowJson).toContain('dist-python/$RUNTIME_WHEEL')
  443. expect(workflowJson).toContain('/work/dist-python/$SDK_WHEEL')
  444. expect(workflowJson).toContain('/work/dist-python/$RUNTIME_WHEEL')
  445. expect(workflowJson).not.toContain('--find-links dist-python')
  446. expect(workflowJson).not.toContain('--find-links /work/dist-python')
  447. expect(workflowJson).not.toContain('cygpath')
  448. expect(manylinuxAddon).toMatchObject({ if: "runner.os == 'Linux'" })
  449. expect(JSON.stringify(manylinuxAddon)).toContain('manylinux_2_28_x86_64')
  450. expect(JSON.stringify(manylinuxAddon)).toContain('manylinux_2_28_aarch64')
  451. expect(JSON.stringify(manylinuxAddon)).toContain('npm_config_build_from_source=true pnpm run install')
  452. expect(JSON.stringify(manylinuxAddon)).toContain('pnpm_setup_root')
  453. expect(JSON.stringify(manylinuxAddon)).toContain('$pnpm_setup_root:$pnpm_setup_root:ro')
  454. expect(JSON.stringify(manylinuxAddon)).toContain('node-pty-glibc-versions.txt')
  455. expect(JSON.stringify(manylinuxAddon)).toContain('le 2.28')
  456. expect(macosCheck).toMatchObject({ if: "runner.os == 'macOS'" })
  457. expect(JSON.stringify(macosCheck)).toContain('scripts/check-macos-deployment-target.py')
  458. expect(JSON.stringify(macosCheck)).toContain('$EXE-spawn-helper')
  459. expect(JSON.stringify(installedKeylessPosix)).toContain('--scenario all')
  460. expect(JSON.stringify(installedKeylessPosix)).toContain('env -u PYTHONPATH')
  461. expect(JSON.stringify(installedKeylessWindows)).toContain('--scenario all --installed-wheel')
  462. expect(installedKeylessWindows).toMatchObject({ if: "runner.os == 'Windows'", shell: 'pwsh' })
  463. expect(cleanVenvWindows).toMatchObject({ if: "runner.os == 'Windows'", shell: 'pwsh' })
  464. expect(JSON.stringify(cleanVenvWindows)).toContain('Scripts\\\\python.exe')
  465. expect(realApiPreflightPosix).toMatchObject({
  466. env: { DEEPSEEK_API_KEY: '${{ secrets.DEEPSEEK_API_KEY_EXTERNAL }}' },
  467. })
  468. expect(String(realApiPreflightPosix.if)).toContain('inputs.ci')
  469. expect(String(realApiPreflightPosix.if)).toContain('head.repo.fork')
  470. expect(String(realApiPreflightPosix.if)).toContain('dependabot[bot]')
  471. expect(realApiPreflightWindows).toMatchObject({ shell: 'pwsh' })
  472. expect(installedRealApiPosix).toMatchObject({
  473. env: {
  474. DEEPSEEK_API_KEY: '${{ secrets.DEEPSEEK_API_KEY_EXTERNAL }}',
  475. DEEPSEEK_BASE_URL: 'https://api.deepseek.com',
  476. },
  477. })
  478. expect(JSON.stringify(installedRealApiPosix)).toContain('--scenario sdk-live')
  479. expect(JSON.stringify(installedRealApiPosix)).toContain('-u DSH_RUNTIME_MODE')
  480. expect(installedRealApiWindows).toMatchObject({ shell: 'pwsh' })
  481. expect(JSON.stringify(installedRealApiWindows)).toContain('--scenario sdk-live --installed-wheel')
  482. expect(manylinuxSmoke).toMatchObject({ if: "runner.os == 'Linux'" })
  483. expect(JSON.stringify(manylinuxSmoke)).toContain('-e DSH_TELEMETRY_DISABLED')
  484. })
  485. it('uses the shared macOS deployment-target check in GitLab', () => {
  486. const workflow = loadWorkflow('.gitlab-ci.yml')
  487. const runtimeWheel = workflow['.runtime-wheel']
  488. if (!isRecord(runtimeWheel) || !Array.isArray(runtimeWheel.script)) {
  489. throw new TypeError('GitLab CI must define the runtime wheel script')
  490. }
  491. const runtimeScript: unknown[] = runtimeWheel.script
  492. const macosCheck = runtimeScript.find(
  493. step => typeof step === 'string' && step.includes('PLATFORM" = macos-arm64'),
  494. )
  495. if (typeof macosCheck !== 'string') {
  496. throw new TypeError('GitLab CI must check the macOS deployment target')
  497. }
  498. expect(macosCheck).toContain('scripts/check-macos-deployment-target.py')
  499. expect(macosCheck).toContain('"$EXE" "$EXE-spawn-helper"')
  500. })
  501. it('builds and black-box tests the Windows x64 wheel in GitLab', () => {
  502. const workflow = loadWorkflow('.gitlab-ci.yml')
  503. const windows = workflow['runtime-windows-x64']
  504. const publish = workflow['publish-python']
  505. if (!isRecord(windows) || !Array.isArray(windows.before_script) || !Array.isArray(windows.script)
  506. || !isRecord(publish) || !Array.isArray(publish.needs)) {
  507. throw new TypeError('GitLab CI must define the Windows runtime and aggregate publication jobs')
  508. }
  509. expect(windows.tags).toEqual(['windows-x64'])
  510. expect(windows.variables).toMatchObject({ PKG_TARGET: 'node24-win-x64', PLATFORM: 'win-x64' })
  511. expect(JSON.stringify(windows.before_script)).toContain('.ci-python\\\\Scripts')
  512. expect(JSON.stringify(windows.before_script)).toContain('[IO.Path]::PathSeparator')
  513. expect(JSON.stringify(windows.script)).toContain('win_amd64.whl')
  514. expect(JSON.stringify(windows.script)).toContain('--scenario all --installed-wheel')
  515. expect(publish.needs).toContainEqual({ job: 'runtime-windows-x64', artifacts: true })
  516. })
  517. })
  518. describe('Issue lifecycle workflow', () => {
  519. it('runs the lifecycle job on every PR/review event but gates token and board steps', () => {
  520. const lifecycle = loadWorkflow('.github/workflows/issue-lifecycle.yml')
  521. const policy = loadWorkflow('.github/workflows/issue-policy.yml')
  522. const lifecycleJob = workflowJob(lifecycle, 'lifecycle')
  523. if (!Array.isArray(lifecycleJob.steps)) throw new TypeError('Issue lifecycle job must define steps')
  524. // The job has no job-level `if`, so it is listed on every pull_request /
  525. // pull_request_review event and reports success instead of a gray skip. The
  526. // write-capable steps are gated at step level so approved/commented reviews
  527. // never mint a Project/Issue App token nor touch the board.
  528. expect(lifecycle.on).toHaveProperty('pull_request')
  529. expect(lifecycle.on).toHaveProperty('pull_request_review')
  530. expect(lifecycleJob.if).toBeUndefined()
  531. // Keep the subscription-type gates: issue-lifecycle does not re-subscribe
  532. // ready_for_review (issue-policy owns that) and only reacts to submitted
  533. // review events.
  534. const lifecyclePullRequest = workflowEvent(lifecycle, 'pull_request')
  535. const lifecycleReview = workflowEvent(lifecycle, 'pull_request_review')
  536. expect(lifecyclePullRequest.types).not.toContain('ready_for_review')
  537. expect(lifecyclePullRequest.types).toContain('review_requested')
  538. expect(lifecycleReview.types).toEqual(['submitted'])
  539. const gated = "${{ github.event_name != 'pull_request_review' || github.event.review.state == 'changes_requested' }}"
  540. const steps = lifecycleJob.steps.filter(isRecord)
  541. const tokenStep = steps.find(s => s.name === 'Create project token')
  542. const handleStep = steps.find(s => s.name === 'Handle repository event')
  543. expect(tokenStep).toMatchObject({ if: gated })
  544. expect(handleStep).toMatchObject({ if: gated })
  545. // issue-policy owns PR validation; it is read-only and a real gate.
  546. const policyPullRequest = workflowEvent(policy, 'pull_request')
  547. expect(policyPullRequest.types).toContain('ready_for_review')
  548. })
  549. })
  550. describe('npm release workflows', () => {
  551. it('keeps publication dispatch-only and pack in the PR workflow', () => {
  552. // pack stays in the PR/master release workflows so a PR proves the set packs.
  553. for (const file of ['release.yml', 'release-vendor.yml']) {
  554. const workflow = loadWorkflow(`.github/workflows/${file}`)
  555. if (!isRecord(workflow.jobs)) throw new TypeError(`${file} must define jobs`)
  556. expect(Object.keys(workflow.jobs).sort()).toEqual(['pack'])
  557. }
  558. // publication is workflow_dispatch-only (never a PR check) and keeps the
  559. // npm-publish environment plus the shared dist-tag group.
  560. for (const file of ['release-publish.yml', 'release-vendor-publish.yml']) {
  561. const workflow = loadWorkflow(`.github/workflows/${file}`)
  562. if (!isRecord(workflow.on) || !isRecord(workflow.jobs)) throw new TypeError(`${file} must define on and jobs`)
  563. expect(Object.keys(workflow.on)).toEqual(['workflow_dispatch'])
  564. const publish = workflow.jobs.publish
  565. if (!isRecord(publish)) throw new TypeError(`${file} must define a publish job`)
  566. expect(publish.environment).toBe('npm-publish')
  567. expect(publish.concurrency).toMatchObject({ group: 'Release-publish' })
  568. }
  569. })
  570. })
  571. describe('Documentation site publication', () => {
  572. it('keeps Pages deployment dispatch-only from a dsh-v* tag', () => {
  573. const workflow = loadWorkflow('.github/workflows/docs-pages.yml')
  574. const build = workflowJob(workflow, 'build')
  575. const deploy = workflowJob(workflow, 'deploy')
  576. if (!isRecord(workflow.on) || !isRecord(workflow.env) || !Array.isArray(build.steps)) {
  577. throw new TypeError('Documentation deployment must define on, env, and build steps')
  578. }
  579. // The site presents a released snapshot: a merge must never publish it, and
  580. // publication must never appear as a PR check.
  581. expect(Object.keys(workflow.on)).toEqual(['workflow_dispatch'])
  582. // RELEASE_PUBLISH makes release:verify reject every ref that is not a dsh-v*
  583. // tag naming this tree's version, so the site and the npm sequence share one
  584. // definition of a released version.
  585. const steps = build.steps.filter(isRecord)
  586. const verify = steps.find(step => step.name === 'Verify release version')
  587. const checkout = steps.find(
  588. step => typeof step.uses === 'string' && step.uses.startsWith('actions/checkout@'),
  589. )
  590. expect(verify).toMatchObject({
  591. env: { RELEASE_PUBLISH: 'true' },
  592. run: 'pnpm run release:verify --family dsh',
  593. })
  594. // Complete history: the release scripts read tags.
  595. expect(checkout).toMatchObject({ with: { 'fetch-depth': 0 } })
  596. // Projected source links stay on the public repository's master. That
  597. // repository advances only to each release commit, so its master never
  598. // carries unreleased work, while it retains only the most recent tags:
  599. // following the dispatched tag would leave every source link on a deploy
  600. // from an older tag unresolvable.
  601. expect(workflow.env.DOCS_REPOSITORY_REF).toBe('master')
  602. // The environment owns the deployment tag policy and the required reviewers.
  603. expect(deploy.environment).toMatchObject({ name: 'github-pages' })
  604. })
  605. })
  606. describe('Git hooks', () => {
  607. it('leaves frozen Agent Note sidecars to the archive verifier', () => {
  608. const lefthook = loadWorkflow('lefthook.yml')
  609. for (const hookName of ['pre-commit', 'pre-merge-commit']) {
  610. const hook = lefthook[hookName]
  611. if (!isRecord(hook) || !Array.isArray(hook.jobs)) {
  612. throw new TypeError(`lefthook must define ${hookName} jobs`)
  613. }
  614. const pairing: unknown = hook.jobs.find(
  615. (job: unknown) => isRecord(job) && job.name === 'translation pairing (staged records)',
  616. )
  617. expect(pairing).toMatchObject({ exclude: ['.agents/notes/archived/**'] })
  618. }
  619. })
  620. })
  621. function loadWorkflow(path: string): Record<string, unknown> {
  622. const workflow: unknown = yaml.load(readFileSync(resolve(root, path), 'utf8'))
  623. if (!isRecord(workflow)) throw new TypeError(`${path} must define a workflow`)
  624. return workflow
  625. }
  626. function workflowEvent(workflow: Record<string, unknown>, event: string): Record<string, unknown> {
  627. if (!isRecord(workflow.on) || !isRecord(workflow.on[event])) {
  628. throw new TypeError(`workflow must define the ${event} event`)
  629. }
  630. return workflow.on[event]
  631. }
  632. function workflowJob(workflow: Record<string, unknown>, job: string): Record<string, unknown> {
  633. if (!isRecord(workflow.jobs) || !isRecord(workflow.jobs[job])) {
  634. throw new TypeError(`workflow must define the ${job} job`)
  635. }
  636. return workflow.jobs[job]
  637. }
  638. function isRecord(value: unknown): value is Record<string, unknown> {
  639. return typeof value === 'object' && value !== null && !Array.isArray(value)
  640. }