1
0

ci-workflow.spec.ts 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517
  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. describe('CI workflow', () => {
  8. it('isolates every pnpm action setup destination per runner', () => {
  9. const files = ['.github/workflows/ci.yml', '.github/workflows/ci-master.yml']
  10. const setups: Array<{ jobName: string; step: unknown }> = []
  11. for (const file of files) {
  12. const workflow: unknown = yaml.load(readFileSync(resolve(root, file), 'utf8'))
  13. if (!isRecord(workflow) || !isRecord(workflow.jobs)) throw new TypeError(`${file} must define jobs`)
  14. for (const [jobName, job] of Object.entries(workflow.jobs)) {
  15. if (!isRecord(job) || !Array.isArray(job.steps)) continue
  16. for (const step of job.steps) {
  17. if (!isRecord(step) || typeof step.uses !== 'string' || !step.uses.startsWith('pnpm/action-setup@')) continue
  18. setups.push({ jobName, step })
  19. }
  20. }
  21. }
  22. expect(setups.length).toBeGreaterThan(0)
  23. for (const { jobName, step } of setups) {
  24. expect(step, `${jobName} must not share pnpm/action-setup's default destination`).toMatchObject({
  25. with: { dest: runnerPrivatePnpmDestination },
  26. })
  27. }
  28. })
  29. it('keeps a required Wine Windows job, a non-blocking native Windows job with failover, and a master-only standby', () => {
  30. const workflow = loadWorkflow('.github/workflows/ci.yml')
  31. const masterWorkflow = loadWorkflow('.github/workflows/ci-master.yml')
  32. if (!isRecord(workflow.jobs)
  33. || !isRecord(workflow.jobs.windows)
  34. || !isRecord(workflow.jobs['windows-native'])
  35. || !isRecord(workflow.jobs['node-24'])
  36. || !isRecord(workflow.jobs['node-24-coverage'])
  37. || !isRecord(workflow.jobs['node-24-consumers'])
  38. || !isRecord(workflow.jobs['all-checks-passed'])
  39. || !isRecord(masterWorkflow.jobs)
  40. || !isRecord(masterWorkflow.jobs['wine-apt-cache'])
  41. || !isRecord(masterWorkflow.jobs['serial-windows'])) {
  42. 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')
  43. }
  44. const windows = workflow.jobs.windows
  45. const windowsNative = workflow.jobs['windows-native']
  46. const wineAptCache = masterWorkflow.jobs['wine-apt-cache']
  47. const serialWindows = masterWorkflow.jobs['serial-windows']
  48. const node24 = workflow.jobs['node-24']
  49. const node24Coverage = workflow.jobs['node-24-coverage']
  50. const node24Consumers = workflow.jobs['node-24-consumers']
  51. const aggregate = workflow.jobs['all-checks-passed']
  52. if (!Array.isArray(windows.steps) || !Array.isArray(aggregate.needs)) {
  53. throw new TypeError('Windows job must define steps and the aggregate must define needs')
  54. }
  55. const commandSteps = windows.steps.filter((step): step is Record<string, unknown> & { run: string } => (
  56. isRecord(step) && typeof step.run === 'string'
  57. ))
  58. // Required PR job: Wine on ubuntu-latest, runs wine-windows-gates.sh.
  59. expect(windows['runs-on']).toBe('ubuntu-latest')
  60. expect(windows.name).toBe('windows node 24 / wine blocking')
  61. expect(windows.if).toBe("github.event_name == 'pull_request'")
  62. expect(commandSteps.some(step => step.run.includes('wine-windows-gates.sh'))).toBe(true)
  63. // windows-native: non-blocking native job with failover, runs windows-complete.
  64. // Its pool is resolved by the Windows-specific switch.
  65. expect(typeof windowsNative['runs-on']).toBe('string')
  66. expect(windowsNative['runs-on']).toContain('DSH_CI_FAILOVER_WINDOWS')
  67. expect(windowsNative['runs-on']).not.toContain('DSH_CI_FAILOVER_LINUX')
  68. expect(windowsNative['runs-on']).toContain('self-hosted')
  69. expect(windowsNative['runs-on']).toContain('dsh-win-ci')
  70. expect(windowsNative['runs-on']).toContain('dsh-windows-2025-16core')
  71. expect(windowsNative.name).toBe('windows node 24 / native complete')
  72. expect(windowsNative.if).toBe("github.event_name == 'pull_request'")
  73. expect(windowsNative.env).toMatchObject({
  74. DSH_COVERAGE_TEST_TIMEOUT_MS: '30000',
  75. })
  76. const nativeCommandSteps = (windowsNative.steps as unknown[]).filter((step): step is Record<string, unknown> & { run: string } => (
  77. isRecord(step) && typeof step.run === 'string'
  78. ))
  79. expect(nativeCommandSteps.map(step => step.run)).toContain('pnpm run check:ci:windows-complete')
  80. // wine-apt-cache: master-only, seeds the Wine apt cache, lives in ci-master.
  81. expect(wineAptCache.if).toBe("github.event_name == 'push' && github.ref == 'refs/heads/master'")
  82. expect(wineAptCache['runs-on']).toBe('ubuntu-latest')
  83. // serial-windows: master-only standby, self-hosted, non-blocking, lives in ci-master.
  84. expect(serialWindows.if).toBe("github.event_name == 'push' && github.ref == 'refs/heads/master'")
  85. expect(serialWindows['runs-on']).toEqual(['self-hosted', 'dsh-win-ci', 'windows'])
  86. expect(serialWindows.name).toBe('serial / windows (self-hosted standby)')
  87. // Aggregate: Wine `windows` required, native `windows-native` excluded.
  88. expect(aggregate.needs).toContain('windows')
  89. expect(aggregate.needs).not.toContain('windows-native')
  90. expect(aggregate.needs).not.toContain('serial-windows')
  91. // Linux failover is a separate switch: the three required Linux workers
  92. // and the verdict job resolve their pool through DSH_CI_FAILOVER_LINUX,
  93. // never the Windows switch.
  94. for (const [jobName, job] of [['node-24', node24], ['node-24-coverage', node24Coverage], ['node-24-consumers', node24Consumers]] as const) {
  95. expect(typeof job['runs-on']).toBe('string')
  96. expect(job['runs-on'], `${jobName} runs-on must use the Linux failover switch`).toContain('DSH_CI_FAILOVER_LINUX')
  97. expect(job['runs-on'], `${jobName} runs-on must not use the Windows failover switch`).not.toContain('DSH_CI_FAILOVER_WINDOWS')
  98. expect(job['runs-on']).toContain('vm-backup')
  99. }
  100. expect(aggregate['runs-on']).toContain('DSH_CI_FAILOVER_LINUX')
  101. expect(aggregate['runs-on']).not.toContain('DSH_CI_FAILOVER_WINDOWS')
  102. expect(aggregate['runs-on']).toContain('vm-backup')
  103. })
  104. it('exempts push from cancellation in ci-master, so one master merge does not cancel the running drill', () => {
  105. const workflow = loadWorkflow('.github/workflows/ci-master.yml')
  106. const prWorkflow = loadWorkflow('.github/workflows/ci.yml')
  107. if (!isRecord(workflow.jobs) || !isRecord(workflow.concurrency)) {
  108. throw new TypeError('ci-master workflow must define jobs and a workflow-level concurrency block')
  109. }
  110. if (!isRecord(prWorkflow.jobs)) {
  111. throw new TypeError('ci workflow must define jobs')
  112. }
  113. // Cancellation applies to the whole superseded RUN, so this has to be
  114. // decided at workflow level and gated on the event: a job-level group
  115. // cannot exempt its job from its run being cancelled. Only push is exempt —
  116. // a drill takes longer than the interval between master merges. The negated
  117. // form is load-bearing: `== 'pull_request'` would also stop cancelling
  118. // workflow_dispatch, and a re-dispatched runner benchmark holds up to 12
  119. // larger runners for 15 minutes in this same group on master.
  120. expect(workflow.concurrency['cancel-in-progress']).toBe("${{ github.event_name != 'push' }}")
  121. // The PR-only ci.yml still cancels a superseded run on a new push, so a
  122. // fresh head does not stack a second full 9-job run behind a stale one.
  123. // Unlike ci-master it has no push carve-out: every PR event supersedes.
  124. expect(prWorkflow.concurrency).toMatchObject({
  125. 'cancel-in-progress': true,
  126. })
  127. // The exact event sets are what keep master-only jobs out of the PR check
  128. // panel: ci-master triggers only on push(master) + workflow_dispatch and
  129. // never on pull_request; ci.yml is exactly pull_request-only. Assert the
  130. // full sets so losing the wrong event, or gaining an extra one, fails.
  131. if (!isRecord(workflow.on) || !isRecord(prWorkflow.on)) {
  132. throw new TypeError('both CI workflows must define on')
  133. }
  134. expect(Object.keys(workflow.on).sort()).toEqual(['push', 'workflow_dispatch'])
  135. expect(Object.keys(prWorkflow.on)).toEqual(['pull_request'])
  136. // Neither drill may carry a job-level group: it would not exempt the job
  137. // from run-scoped cancellation.
  138. for (const name of ['serial-linux-selfhosted', 'serial-windows']) {
  139. const job = workflow.jobs[name]
  140. if (!isRecord(job)) throw new TypeError(`${name} must be defined`)
  141. expect(job.concurrency).toBeUndefined()
  142. // Both stay master-push-only; that is what makes the push carve-out safe.
  143. expect(job.if).toBe("github.event_name == 'push' && github.ref == 'refs/heads/master'")
  144. }
  145. // What bounds the cost of exempting push: a master push may only carry the
  146. // cache seeder and the two drills. Any job reachable on push would start
  147. // accumulating uncancelled runs, so the set is pinned here.
  148. const NOT_PUSH_REACHABLE = new Set([
  149. "github.event_name == 'workflow_dispatch' && inputs.suite == 'larger-runner-benchmark'",
  150. "github.event_name == 'workflow_dispatch' && inputs.suite == 'consolidated-runner-benchmark'",
  151. ])
  152. const pushReachable = Object.entries(workflow.jobs)
  153. .filter(([, job]) => {
  154. if (!isRecord(job)) return false
  155. if (job.if === undefined) return true // unconditional: runs on every event
  156. if (job.if === false) return false // `if: false` parses as a boolean
  157. if (typeof job.if !== 'string') return true // unrecognized shape: surface it
  158. return !NOT_PUSH_REACHABLE.has(job.if.trim())
  159. })
  160. .map(([name]) => name)
  161. .sort()
  162. expect(pushReachable).toEqual(['serial-linux-selfhosted', 'serial-windows', 'wine-apt-cache'])
  163. // Why workflow_dispatch must keep cancelling: each benchmark fans out to a
  164. // dozen larger runners at once, in this same group on master. If it stopped
  165. // cancelling, a re-dispatch would queue ahead of a drill instead of
  166. // replacing the stale measurement.
  167. for (const name of ['larger-runner-benchmark', 'consolidated-runner-benchmark']) {
  168. const job = workflow.jobs[name]
  169. if (!isRecord(job) || !isRecord(job.strategy)) {
  170. throw new TypeError(`${name} must define a matrix strategy`)
  171. }
  172. expect(job.strategy['max-parallel']).toBe(12)
  173. expect(job['timeout-minutes']).toBe(15)
  174. }
  175. })
  176. it('keeps supported LSP source under native Windows coverage', () => {
  177. const config = readFileSync(resolve(root, 'vitest.config.ts'), 'utf8')
  178. expect(config).not.toContain('packages/lsp/lsp-stdio/src/connection.ts')
  179. expect(config).not.toContain('packages/lsp/lsp-stdio/src/index.ts')
  180. expect(config).not.toContain('packages/lsp/lsp-stdio/src/instance.ts')
  181. })
  182. it('requires one release-shaped Python runtime target on every pull request', () => {
  183. const workflow = loadWorkflow('.github/workflows/ci.yml')
  184. const pythonRuntime = workflowJob(workflow, 'python-runtime')
  185. const aggregate = workflowJob(workflow, 'all-checks-passed')
  186. if (!Array.isArray(aggregate.needs)) {
  187. throw new TypeError('CI aggregate must define required job dependencies')
  188. }
  189. expect(pythonRuntime).toMatchObject({
  190. if: "github.event_name == 'pull_request'",
  191. name: 'python runtime / release-shaped Linux x64',
  192. uses: './.github/workflows/build-exe-for-python-sdk.yml',
  193. with: {
  194. targets: 'node24-linux-x64',
  195. ci: true,
  196. },
  197. })
  198. expect(aggregate.needs).toContain('python-runtime')
  199. })
  200. it('keeps every Vitest project process-isolated on native Windows', () => {
  201. const config = readFileSync(resolve(root, 'vitest.config.ts'), 'utf8')
  202. expect(config).not.toContain("pool: process.platform === 'win32' ? 'threads' : 'forks'")
  203. expect(config.match(/pool: 'forks'/g)).toHaveLength(2)
  204. })
  205. })
  206. describe('DeepSeek e2e workflow', () => {
  207. it('prepares bubblewrap from the pinned payload without a package transaction', () => {
  208. const workflow = loadWorkflow('.github/workflows/e2e.yml')
  209. const e2e = workflowJob(workflow, 'e2e')
  210. if (!Array.isArray(e2e.steps)) throw new TypeError('DeepSeek e2e workflow must define steps')
  211. const steps = e2e.steps.filter(isRecord)
  212. expect(steps.find(step => step.name === 'Prepare bubblewrap (unrestrict userns)')).toMatchObject({
  213. run: 'bash scripts/prepare-ci-bubblewrap.sh',
  214. })
  215. expect(JSON.stringify(steps)).not.toContain('apt-get')
  216. })
  217. })
  218. describe('E2B e2e workflow', () => {
  219. it('is manual-only and fails loud before running the focused live suite', () => {
  220. const workflow = loadWorkflow('.github/workflows/e2b-e2e.yml')
  221. expect(workflow.on).toEqual({ workflow_dispatch: null })
  222. if (!isRecord(workflow.jobs) || !isRecord(workflow.jobs.e2b) || !Array.isArray(workflow.jobs.e2b.steps)) {
  223. throw new TypeError('E2B e2e workflow must define the e2b job steps')
  224. }
  225. const steps = workflow.jobs.e2b.steps.filter(isRecord)
  226. const preflight = steps.find(step => step.name === 'Preflight (require E2B API key)')
  227. const e2b = steps.find(step => step.name === 'E2B tests (live sandbox)')
  228. expect(preflight).toMatchObject({
  229. env: { E2B_API_KEY: '${{ secrets.E2B_API_KEY_EXTERNAL }}' },
  230. })
  231. expect(preflight?.run).toContain('E2B_API_KEY_EXTERNAL repository secret')
  232. expect(e2b).toMatchObject({
  233. env: {
  234. E2B_API_KEY: '${{ secrets.E2B_API_KEY_EXTERNAL }}',
  235. DSH_E2E_MAX_WORKERS: '1',
  236. DSH_EXAMPLE_MODE: 'lib',
  237. },
  238. })
  239. expect(e2b?.run).toContain('packages/e2b/e2b/tests/composition.e2e.ts')
  240. })
  241. })
  242. describe('Python release workflows', () => {
  243. it('keeps complete wheel validation separate from protected public publication', () => {
  244. const workflow = loadWorkflow('.github/workflows/python-release.yml')
  245. const dispatch = workflowEvent(workflow, 'workflow_dispatch')
  246. const pullRequest = workflowEvent(workflow, 'pull_request')
  247. const build = workflowJob(workflow, 'build')
  248. const pythonCompat = workflowJob(workflow, 'python-compat')
  249. const validate = workflowJob(workflow, 'validate')
  250. const publishRuntime = workflowJob(workflow, 'publish-runtime')
  251. const publishSdk = workflowJob(workflow, 'publish-sdk')
  252. if (!isRecord(dispatch.inputs)
  253. || !isRecord(dispatch.inputs.publish)
  254. || !Array.isArray(pythonCompat.steps)
  255. || !Array.isArray(validate.steps)
  256. || !Array.isArray(publishRuntime.steps)
  257. || !Array.isArray(publishSdk.steps)) {
  258. throw new TypeError('Python release workflow must define publish input and release steps')
  259. }
  260. expect(dispatch.inputs.publish).toMatchObject({ type: 'boolean', default: false })
  261. expect(pullRequest).toEqual({ types: ['labeled'] })
  262. expect(build).toMatchObject({
  263. if: "github.event_name == 'workflow_dispatch' || github.event.label.name == 'python-release-dry-run'",
  264. uses: './.github/workflows/build-exe-for-python-sdk.yml',
  265. with: {
  266. targets: 'node24-linux-x64,node24-linux-arm64,node24-macos-arm64',
  267. release: true,
  268. },
  269. })
  270. expect(pythonCompat.strategy).toMatchObject({ matrix: { python: ['3.10', '3.14'] } })
  271. const pythonCompatSteps = JSON.stringify(pythonCompat.steps)
  272. expect(pythonCompatSteps).toContain('dist/deepseek_harness_sdk-$VERSION-py3-none-any.whl')
  273. expect(pythonCompatSteps).toContain('dist/deepseek_harness_runtime_bin-$VERSION-py3-none-manylinux_2_28_x86_64.whl')
  274. expect(pythonCompatSteps).not.toContain('--find-links')
  275. const validateSteps = JSON.stringify(validate.steps)
  276. const authorize = validate.steps.filter(isRecord).find(step => step.name === 'Authorize publication request')
  277. if (!isRecord(authorize) || typeof authorize.run !== 'string') {
  278. throw new TypeError('Python release validation must authorize publication requests')
  279. }
  280. expect(validateSteps).toContain('PUBLIC_PYPI_RELEASE_ENABLED')
  281. expect(authorize).toMatchObject({
  282. env: {
  283. PYPI_PUBLISHER_REPOSITORY: '${{ vars.PYPI_PUBLISHER_REPOSITORY }}',
  284. REPOSITORY: '${{ github.repository }}',
  285. },
  286. })
  287. expect(authorize.run).toContain('[ "$REPOSITORY" = "$PYPI_PUBLISHER_REPOSITORY" ]')
  288. expect(validateSteps).toContain('100000000')
  289. expect(publishRuntime).toMatchObject({
  290. if: "github.event_name == 'workflow_dispatch' && inputs.publish",
  291. needs: 'validate',
  292. environment: 'pypi-runtime',
  293. permissions: { contents: 'read', 'id-token': 'write' },
  294. })
  295. expect(publishSdk).toMatchObject({
  296. if: "github.event_name == 'workflow_dispatch' && inputs.publish",
  297. needs: ['validate', 'publish-runtime'],
  298. environment: 'pypi',
  299. permissions: { contents: 'read', 'id-token': 'write' },
  300. })
  301. const runtimeSteps = publishRuntime.steps.filter(isRecord)
  302. const sdkSteps = publishSdk.steps.filter(isRecord)
  303. const runtimePublish = runtimeSteps.find(step => step.name === 'Publish runtime wheels')
  304. const sdkPublish = sdkSteps.find(step => step.name === 'Publish SDK wheel')
  305. const runtimeHashes = runtimeSteps.find(step => step.name === 'Verify release artifact hashes')
  306. const sdkHashes = sdkSteps.find(step => step.name === 'Verify release artifact hashes')
  307. expect([...runtimeSteps, ...sdkSteps].some(
  308. step => typeof step.uses === 'string' && step.uses.startsWith('actions/checkout@'),
  309. )).toBe(false)
  310. expect([...runtimeSteps, ...sdkSteps].filter(
  311. step => step.uses === 'pypa/gh-action-pypi-publish@release/v1',
  312. )).toHaveLength(2)
  313. expect(runtimePublish).toMatchObject({
  314. with: { 'packages-dir': 'dist/runtime/', attestations: false },
  315. })
  316. expect(sdkPublish).toMatchObject({
  317. with: { 'packages-dir': 'dist/sdk/', attestations: false },
  318. })
  319. expect(runtimeHashes).toMatchObject({ run: 'cd dist && sha256sum -c SHA256SUMS' })
  320. expect(sdkHashes).toMatchObject({ run: 'cd dist && sha256sum -c SHA256SUMS' })
  321. })
  322. it('exposes the native wheel builder to the release caller with normalized versions', () => {
  323. const workflow = loadWorkflow('.github/workflows/build-exe-for-python-sdk.yml')
  324. const call = workflowEvent(workflow, 'workflow_call')
  325. const plan = workflowJob(workflow, 'plan')
  326. const build = workflowJob(workflow, 'build')
  327. if (!isRecord(call.inputs) || !Array.isArray(plan.steps) || !Array.isArray(build.steps)) {
  328. throw new TypeError('Python wheel builder must define workflow_call inputs and plan steps')
  329. }
  330. const buildSteps: unknown[] = build.steps
  331. const manylinuxAddon = buildSteps.find(step => isRecord(step) && step.name === 'Rebuild Linux node-pty against manylinux 2.28')
  332. const macosCheck = buildSteps.find(step => isRecord(step) && step.name === 'Check macOS deployment target')
  333. const manylinuxSmoke = buildSteps.find(step => isRecord(step) && step.name === 'Run wheel in a manylinux 2.28 container')
  334. expect(call.inputs).toHaveProperty('targets')
  335. expect(call.inputs).toMatchObject({
  336. ci: { type: 'boolean', default: false },
  337. release: { type: 'boolean', default: false },
  338. })
  339. expect(workflow.concurrency).toMatchObject({
  340. group: 'build-single-exe-${{ github.workflow }}-${{ github.ref }}',
  341. })
  342. expect(plan.if).toContain('inputs.ci')
  343. expect(plan.if).toContain('inputs.release')
  344. expect(JSON.stringify(plan.steps)).toContain('pep440_version')
  345. const workflowJson = JSON.stringify(workflow)
  346. expect(workflowJson).toContain('macosx_14_0_arm64')
  347. expect(workflowJson).toContain('dist-python/$SDK_WHEEL')
  348. expect(workflowJson).toContain('dist-python/$RUNTIME_WHEEL')
  349. expect(workflowJson).toContain('/work/dist-python/$SDK_WHEEL')
  350. expect(workflowJson).toContain('/work/dist-python/$RUNTIME_WHEEL')
  351. expect(workflowJson).not.toContain('--find-links dist-python')
  352. expect(workflowJson).not.toContain('--find-links /work/dist-python')
  353. expect(manylinuxAddon).toMatchObject({ if: "runner.os == 'Linux'" })
  354. expect(JSON.stringify(manylinuxAddon)).toContain('manylinux_2_28_x86_64')
  355. expect(JSON.stringify(manylinuxAddon)).toContain('manylinux_2_28_aarch64')
  356. expect(JSON.stringify(manylinuxAddon)).toContain('npm_config_build_from_source=true pnpm run install')
  357. expect(JSON.stringify(manylinuxAddon)).toContain('$HOME/setup-pnpm:$HOME/setup-pnpm:ro')
  358. expect(JSON.stringify(manylinuxAddon)).toContain('node-pty-glibc-versions.txt')
  359. expect(JSON.stringify(manylinuxAddon)).toContain('le 2.28')
  360. expect(macosCheck).toMatchObject({ if: "runner.os == 'macOS'" })
  361. expect(JSON.stringify(macosCheck)).toContain('scripts/check-macos-deployment-target.py')
  362. expect(JSON.stringify(macosCheck)).toContain('$EXE-spawn-helper')
  363. expect(manylinuxSmoke).toMatchObject({ if: "runner.os == 'Linux'" })
  364. expect(JSON.stringify(manylinuxSmoke)).toContain('-e DSH_TELEMETRY_DISABLED')
  365. })
  366. it('uses the shared macOS deployment-target check in GitLab', () => {
  367. const workflow = loadWorkflow('.gitlab-ci.yml')
  368. const runtimeWheel = workflow['.runtime-wheel']
  369. if (!isRecord(runtimeWheel) || !Array.isArray(runtimeWheel.script)) {
  370. throw new TypeError('GitLab CI must define the runtime wheel script')
  371. }
  372. const runtimeScript: unknown[] = runtimeWheel.script
  373. const macosCheck = runtimeScript.find(
  374. step => typeof step === 'string' && step.includes('PLATFORM" = macos-arm64'),
  375. )
  376. if (typeof macosCheck !== 'string') {
  377. throw new TypeError('GitLab CI must check the macOS deployment target')
  378. }
  379. expect(macosCheck).toContain('scripts/check-macos-deployment-target.py')
  380. expect(macosCheck).toContain('"$EXE" "$EXE-spawn-helper"')
  381. })
  382. })
  383. describe('Issue lifecycle workflow', () => {
  384. it('runs the lifecycle job on every PR/review event but gates token and board steps', () => {
  385. const lifecycle = loadWorkflow('.github/workflows/issue-lifecycle.yml')
  386. const policy = loadWorkflow('.github/workflows/issue-policy.yml')
  387. const lifecycleJob = workflowJob(lifecycle, 'lifecycle')
  388. if (!Array.isArray(lifecycleJob.steps)) throw new TypeError('Issue lifecycle job must define steps')
  389. // The job has no job-level `if`, so it is listed on every pull_request /
  390. // pull_request_review event and reports success instead of a gray skip. The
  391. // write-capable steps are gated at step level so approved/commented reviews
  392. // never mint a Project/Issue App token nor touch the board.
  393. expect(lifecycle.on).toHaveProperty('pull_request')
  394. expect(lifecycle.on).toHaveProperty('pull_request_review')
  395. expect(lifecycleJob.if).toBeUndefined()
  396. // Keep the subscription-type gates: issue-lifecycle does not re-subscribe
  397. // ready_for_review (issue-policy owns that) and only reacts to submitted
  398. // review events.
  399. const lifecyclePullRequest = workflowEvent(lifecycle, 'pull_request')
  400. const lifecycleReview = workflowEvent(lifecycle, 'pull_request_review')
  401. expect(lifecyclePullRequest.types).not.toContain('ready_for_review')
  402. expect(lifecyclePullRequest.types).toContain('review_requested')
  403. expect(lifecycleReview.types).toEqual(['submitted'])
  404. const gated = "${{ github.event_name != 'pull_request_review' || github.event.review.state == 'changes_requested' }}"
  405. const steps = lifecycleJob.steps.filter(isRecord)
  406. const tokenStep = steps.find(s => s.name === 'Create project token')
  407. const handleStep = steps.find(s => s.name === 'Handle repository event')
  408. expect(tokenStep).toMatchObject({ if: gated })
  409. expect(handleStep).toMatchObject({ if: gated })
  410. // issue-policy owns PR validation; it is read-only and a real gate.
  411. const policyPullRequest = workflowEvent(policy, 'pull_request')
  412. expect(policyPullRequest.types).toContain('ready_for_review')
  413. })
  414. })
  415. describe('npm release workflows', () => {
  416. it('keeps publication dispatch-only and pack in the PR workflow', () => {
  417. // pack stays in the PR/master release workflows so a PR proves the set packs.
  418. for (const file of ['release.yml', 'release-vendor.yml']) {
  419. const workflow = loadWorkflow(`.github/workflows/${file}`)
  420. if (!isRecord(workflow.jobs)) throw new TypeError(`${file} must define jobs`)
  421. expect(Object.keys(workflow.jobs).sort()).toEqual(['pack'])
  422. }
  423. // publication is workflow_dispatch-only (never a PR check) and keeps the
  424. // npm-publish environment plus the shared dist-tag group.
  425. for (const file of ['release-publish.yml', 'release-vendor-publish.yml']) {
  426. const workflow = loadWorkflow(`.github/workflows/${file}`)
  427. if (!isRecord(workflow.on) || !isRecord(workflow.jobs)) throw new TypeError(`${file} must define on and jobs`)
  428. expect(Object.keys(workflow.on)).toEqual(['workflow_dispatch'])
  429. const publish = workflow.jobs.publish
  430. if (!isRecord(publish)) throw new TypeError(`${file} must define a publish job`)
  431. expect(publish.environment).toBe('npm-publish')
  432. expect(publish.concurrency).toMatchObject({ group: 'Release-publish' })
  433. }
  434. })
  435. })
  436. describe('Git hooks', () => {
  437. it('leaves frozen Agent Note sidecars to the archive verifier', () => {
  438. const lefthook = loadWorkflow('lefthook.yml')
  439. for (const hookName of ['pre-commit', 'pre-merge-commit']) {
  440. const hook = lefthook[hookName]
  441. if (!isRecord(hook) || !Array.isArray(hook.jobs)) {
  442. throw new TypeError(`lefthook must define ${hookName} jobs`)
  443. }
  444. const pairing: unknown = hook.jobs.find(
  445. (job: unknown) => isRecord(job) && job.name === 'translation pairing (staged records)',
  446. )
  447. expect(pairing).toMatchObject({ exclude: ['.agents/notes/archived/**'] })
  448. }
  449. })
  450. })
  451. function loadWorkflow(path: string): Record<string, unknown> {
  452. const workflow: unknown = yaml.load(readFileSync(resolve(root, path), 'utf8'))
  453. if (!isRecord(workflow)) throw new TypeError(`${path} must define a workflow`)
  454. return workflow
  455. }
  456. function workflowEvent(workflow: Record<string, unknown>, event: string): Record<string, unknown> {
  457. if (!isRecord(workflow.on) || !isRecord(workflow.on[event])) {
  458. throw new TypeError(`workflow must define the ${event} event`)
  459. }
  460. return workflow.on[event]
  461. }
  462. function workflowJob(workflow: Record<string, unknown>, job: string): Record<string, unknown> {
  463. if (!isRecord(workflow.jobs) || !isRecord(workflow.jobs[job])) {
  464. throw new TypeError(`workflow must define the ${job} job`)
  465. }
  466. return workflow.jobs[job]
  467. }
  468. function isRecord(value: unknown): value is Record<string, unknown> {
  469. return typeof value === 'object' && value !== null && !Array.isArray(value)
  470. }