ci-workflow.spec.ts 34 KB

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