ci-workflow.spec.ts 22 KB

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