Files
orca/config/scripts/release/workflow-contracts/adhoc-build-pinned-commit.test.mjs
T
Neil 9bd6272fdf refactor(tooling): organize build, CI, and test owners (#38130)
* refactor(tooling): organize test runtime and maintenance owners

* test(tooling): preserve relocated runtime fixture dependency edges

* refactor(tooling): preserve xterm routing owner checks

* ci(tooling): include routing owner in sparse checkout

* test(tooling): preserve copied workflow dependency closures

* fix(tooling): normalize hashed JSON assets in release parity

* fix(tooling): distinguish asset aliases from literal references

* fix(tooling): frame normalized asset reference payloads

* fix(tooling): normalize decoded JSON asset references

* refactor(tooling): organize build, CI and release owners

* fix(tooling): align moved generator and workflow path contracts

* fix(tooling): update generated plugin bundle owner banners

* test(tooling): create relocated mobile verifier fixture directories

* test(tooling): copy headless detector dependency closure

* test(tooling): align native batch policy fixtures with owner path

* fix(tooling): link moved reliability command to historical evidence

* fix(tooling): preserve nested sandbox owners and canonical guide source

* fix(tooling): target release version owners in checkout fixture
2026-11-04 21:08:19 -08:00

88 lines
3.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Pin every job to dispatch’s resolved commit so mid-run pushes cannot mix artifacts.
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { pathToFileURL } from 'node:url'
import { afterAll, beforeAll, describe, expect, it } from 'vitest'
import { parse } from 'yaml'
import { runProcess } from '@orca/process-host'
const workflow = parse(readFileSync('.github/workflows/adhoc-mac-build.yml', 'utf8'))
const PINNED = '${{ needs.resolve-ref.outputs.sha }}'
const resolveStep = workflow.jobs['resolve-ref'].steps.find((step) => step.id === 'resolve')
const directory = mkdtempSync(join(tmpdir(), 'adhoc-pinned-commit-'))
const repository = join(directory, 'remote.git')
const identity = {
...process.env,
GIT_AUTHOR_NAME: 'Ref test',
GIT_AUTHOR_EMAIL: 'ref-test@example.com',
GIT_COMMITTER_NAME: 'Ref test',
GIT_COMMITTER_EMAIL: 'ref-test@example.com'
}
let branchTip, tagged
async function git(args) {
const result = await runProcess({ program: 'git', args, env: identity })
expect(result.code, result.stderr).toBe(0)
return result.stdout.trim()
}
async function resolve(ref) {
const scratch = mkdtempSync(join(directory, 'attempt-'))
const script = join(scratch, 'resolve.sh')
writeFileSync(script, resolveStep.run)
const output = join(scratch, 'output')
writeFileSync(output, '')
const result = await runProcess({
program: 'bash',
args: [script],
env: {
...identity,
REPO_URL: pathToFileURL(repository).href,
GITHUB_OUTPUT: output,
RUNNER_TEMP: scratch,
REQUESTED_REF: ref
}
})
return { code: result.code, output: readFileSync(output, 'utf8').trim() }
}
beforeAll(async () => {
await git(['init', '--bare', repository])
const tree = await git(['-C', repository, 'mktree'])
tagged = await git(['-C', repository, 'commit-tree', tree, '-m', 'tagged'])
branchTip = await git(['-C', repository, 'commit-tree', tree, '-p', tagged, '-m', 'tip'])
await git(['-C', repository, 'update-ref', 'refs/heads/feature/x', branchTip])
await git(['-C', repository, 'tag', '-a', 'v1', tagged, '-m', 'annotated'])
})
afterAll(() => rmSync(directory, { recursive: true, force: true }))
describe('adhoc build pins one commit for the whole run', () => {
it('checks out the pinned commit in every job that builds from the repo', () => {
const { jobs } = workflow
expect(jobs['orcad-template'].with.ref).toBe(PINNED)
const support = jobs['orcad-template-support'].steps.find((step) =>
step.uses?.startsWith('actions/checkout@')
)
expect(support.with.ref).toBe(PINNED)
const vet = jobs['build-adhoc-mac-arch'].steps.find((step) => step.id === 'vetted')
expect(vet.env.REQUESTED_REF).toBe(PINNED)
for (const name of ['orcad-template-support', 'orcad-template', 'build-adhoc-mac']) {
expect([jobs[name].needs].flat(), name).toContain('resolve-ref')
}
})
it('resolves a branch, an annotated tag to its commit, and passes a full SHA through', async () => {
expect(await resolve('feature/x')).toEqual({ code: 0, output: `sha=${branchTip}` })
expect(await resolve('v1')).toEqual({ code: 0, output: `sha=${tagged}` })
expect(await resolve(tagged)).toEqual({ code: 0, output: `sha=${tagged}` })
})
it('refuses PR refs and names it cannot resolve', async () => {
for (const ref of ['refs/pull/1/head', 'pull/1/head', 'missing', tagged.slice(0, 12)]) {
expect(await resolve(ref), ref).toEqual({ code: 1, output: '' })
}
})
})