1
0

ci-workflow.spec.ts 23 KB

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