Skip to content

Commit f88755c

Browse files
bradygasterCopilot
andcommitted
fix(gh-aw): normalize compiler setup pin
Closes #2103 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent f7dbff7 commit f88755c

5 files changed

Lines changed: 119 additions & 13 deletions

File tree

‎test/gh-aw-quality.test.ts‎

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3630,9 +3630,21 @@ describe('gh-aw: canonical package integrity contract', () => {
36303630
});
36313631

36323632
it('normalizes only compiler-declared repository-scattered schedules', () => {
3633-
const metadata = `# gh-aw-metadata: {"frontmatter_hash":"${'a'.repeat(64)}"}`;
3633+
const setupPin = '924af5fdc64061cfbf66fb584c8b07e2ac230c60';
3634+
const metadata = `# gh-aw-metadata: ${JSON.stringify({
3635+
frontmatter_hash: 'a'.repeat(64),
3636+
compiler_version: 'v0.89.21',
3637+
})}`;
36343638
const lock = [
36353639
metadata,
3640+
`# gh-aw-manifest: ${JSON.stringify({
3641+
actions: [{
3642+
repo: 'github/gh-aw-actions/setup',
3643+
sha: setupPin,
3644+
version: 'v0.89.21',
3645+
}],
3646+
})}`,
3647+
`uses: github/gh-aw-actions/setup@${setupPin}`,
36363648
`source_revision: ${revisionA}`,
36373649
' - cron: "17 4 * * 2" # Friendly format: weekly on Tuesday at 04:00 (scattered)',
36383650
' - cron: "0 4 * * 2" # Fixed schedule',
@@ -3646,6 +3658,59 @@ describe('gh-aw: canonical package integrity contract', () => {
36463658
expect(normalized).not.toContain(revisionA);
36473659
});
36483660

3661+
it('normalizes only the approved gh-aw setup tag to its exact compiler pin', () => {
3662+
const setupPin = '924af5fdc64061cfbf66fb584c8b07e2ac230c60';
3663+
const compiled = (setupRef: string, permissions = 'checks: read') => [
3664+
`# gh-aw-metadata: ${JSON.stringify({
3665+
schema_version: 'v4',
3666+
frontmatter_hash: 'a'.repeat(64),
3667+
body_hash: 'b'.repeat(64),
3668+
compiler_version: 'v0.89.21',
3669+
strict: true,
3670+
})}`,
3671+
`# gh-aw-manifest: ${JSON.stringify({
3672+
version: 1,
3673+
secrets: ['SQUAD_REVIEW_APP_PRIVATE_KEY'],
3674+
actions: [{
3675+
repo: 'github/gh-aw-actions/setup',
3676+
sha: setupRef,
3677+
version: 'v0.89.21',
3678+
}],
3679+
})}`,
3680+
`# - github/gh-aw-actions/setup@${setupRef}${setupRef === setupPin ? ' # v0.89.21' : ''}`,
3681+
`source_revision: ${revisionA}`,
3682+
'permissions:',
3683+
` ${permissions}`,
3684+
'environment: squad-review-authority',
3685+
'github-token: ${{ steps.squad-review-app-token.outputs.token }}',
3686+
`uses: github/gh-aw-actions/setup@${setupRef}${setupRef === setupPin ? ' # v0.89.21' : ''}`,
3687+
].join('\n');
3688+
const macOS = normalizeCompiledLock(compiled(setupPin), revisionA);
3689+
const linux = normalizeCompiledLock(compiled('v0.89.21'), revisionA);
3690+
3691+
expect(linux).toBe(macOS);
3692+
expect(linux).toContain(`github/gh-aw-actions/setup@${setupPin}`);
3693+
expect(linux).not.toContain('github/gh-aw-actions/setup@v0.89.21');
3694+
expect(() => normalizeCompiledLock(compiled('c'.repeat(40)), revisionA))
3695+
.toThrow(/approved compiler pin/);
3696+
expect(normalizeCompiledLock(compiled(setupPin, 'checks: write'), revisionA))
3697+
.not.toBe(macOS);
3698+
expect(normalizeCompiledLock(
3699+
compiled(setupPin).replace(
3700+
'environment: squad-review-authority',
3701+
'environment: unrestricted',
3702+
),
3703+
revisionA,
3704+
)).not.toBe(macOS);
3705+
expect(normalizeCompiledLock(
3706+
compiled(setupPin).replace(
3707+
'github-token: ${{ steps.squad-review-app-token.outputs.token }}',
3708+
'github-token: ${{ github.token }}',
3709+
),
3710+
revisionA,
3711+
)).not.toBe(macOS);
3712+
});
3713+
36493714
it('accepts only the deterministic retained bootstrap trigger sentinel', () => {
36503715
const root = makeConsumer();
36513716
const probePath = join(root, TRIGGER_PROBE_DESTINATION);

‎workflows/package/squad-bootstrap.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ pre-agent-steps:
151151
node --check "$path" >/dev/null
152152
}
153153
# BEGIN GENERATED RESOURCE DIGESTS
154-
check_hash "$install_verifier" "4f385df488cc65165e398e499663c015ce63851cb9c938f4c3dd0af38d25f991"
154+
check_hash "$install_verifier" "09f806f17c7ff2ddd207484a536e13f41071c4ed584ab37be415755979bec1c4"
155155
check_hash "$cast_validator" "0988e04aeef316f4d7a0107c902bbbcf6538b8899b9fffba5f62150717967685"
156156
check_hash "$bootstrap_validator" "d449b9204f7fad133ff7133c1a30c9381c87e3c0c9d481352819ca93ea1a1dad"
157157
# END GENERATED RESOURCE DIGESTS

‎workflows/shared/squad-install-verifier.mjs‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ export const TRIGGER_PROBE_DESTINATION =
3333
const SHA256_PATTERN = /^[0-9a-f]{64}$/;
3434
const REVISION_PATTERN = /^[0-9a-f]{40}$/;
3535
const LOCK_REVISION_PLACEHOLDER = 'f'.repeat(40);
36+
const GH_AW_SETUP_PINS = Object.freeze({
37+
'v0.89.21': '924af5fdc64061cfbf66fb584c8b07e2ac230c60',
38+
});
3639

3740
function deepFreeze(value) {
3841
if (value && typeof value === 'object' && !Object.isFrozen(value)) {
@@ -348,8 +351,46 @@ export function normalizeCompiledLock(content, revision) {
348351
/^(# gh-aw-metadata: \{[^\n]*"frontmatter_hash":")([0-9a-f]{64})("[^\n]*\})$/m,
349352
);
350353
if (!metadata) throw new Error('Compiled lock has missing or malformed gh-aw metadata.');
354+
const compilerVersion = JSON.parse(metadata[0].slice('# gh-aw-metadata: '.length))
355+
.compiler_version;
356+
const setupPin = GH_AW_SETUP_PINS[compilerVersion];
357+
if (!setupPin) {
358+
throw new Error(`Compiled lock uses unsupported gh-aw compiler version: ${compilerVersion}.`);
359+
}
360+
const manifest = text.match(/^(# gh-aw-manifest: )(\{[^\n]*\})$/m);
361+
if (!manifest) throw new Error('Compiled lock has missing or malformed gh-aw manifest.');
362+
const manifestValue = JSON.parse(manifest[2]);
363+
const setupActions = manifestValue.actions?.filter(
364+
action => action.repo === 'github/gh-aw-actions/setup',
365+
) ?? [];
366+
if (setupActions.length !== 1) {
367+
throw new Error('Compiled lock must declare exactly one gh-aw setup action.');
368+
}
369+
const setupAction = setupActions[0];
370+
if (setupAction.version !== compilerVersion) {
371+
throw new Error('Compiled lock gh-aw setup action version does not match its compiler.');
372+
}
373+
if (![compilerVersion, setupPin].includes(setupAction.sha)) {
374+
throw new Error('Compiled lock gh-aw setup action does not match the approved compiler pin.');
375+
}
376+
setupAction.sha = setupPin;
377+
const setupRefs = [
378+
...text.matchAll(/github\/gh-aw-actions\/setup@([^\s#'"]+)/g),
379+
].map(match => match[1]);
380+
if (setupRefs.some(ref => ![compilerVersion, setupPin].includes(ref))) {
381+
throw new Error('Compiled lock contains an unapproved gh-aw setup action reference.');
382+
}
351383
return text
352384
.replace(metadata[0], `${metadata[1]}${'0'.repeat(64)}${metadata[3]}`)
385+
.replace(manifest[0], `${manifest[1]}${JSON.stringify(manifestValue)}`)
386+
.replaceAll(
387+
`github/gh-aw-actions/setup@${compilerVersion}`,
388+
`github/gh-aw-actions/setup@${setupPin}`,
389+
)
390+
.replaceAll(
391+
`github/gh-aw-actions/setup@${setupPin} # ${compilerVersion}`,
392+
`github/gh-aw-actions/setup@${setupPin}`,
393+
)
353394
.replace(
354395
/^(\s*-\s+cron:\s+)"[^"]+"(\s+# Friendly format: .+ \(scattered\))$/gm,
355396
'$1"<repository-scattered>"$2',

‎workflows/squad-bootstrap.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ pre-agent-steps:
158158
node --check "$path" >/dev/null
159159
}
160160
# BEGIN GENERATED RESOURCE DIGESTS
161-
check_hash "$install_verifier" "4f385df488cc65165e398e499663c015ce63851cb9c938f4c3dd0af38d25f991"
161+
check_hash "$install_verifier" "09f806f17c7ff2ddd207484a536e13f41071c4ed584ab37be415755979bec1c4"
162162
check_hash "$cast_validator" "0988e04aeef316f4d7a0107c902bbbcf6538b8899b9fffba5f62150717967685"
163163
check_hash "$bootstrap_validator" "d449b9204f7fad133ff7133c1a30c9381c87e3c0c9d481352819ca93ea1a1dad"
164164
# END GENERATED RESOURCE DIGESTS

‎workflows/squad-workflows.manifest.json‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,63 +15,63 @@
1515
"destination": ".github/workflows/squad.md",
1616
"lock": ".github/workflows/squad.lock.yml",
1717
"source_sha256": "bb7f231c852dfb73c5d1a6ba5e9f23f9f7c9fc5af9e1f1021c4c5213fd9389f9",
18-
"lock_sha256": "f2e62f0ded2b937c99dcdab321f1ea2f886ff2f0537a324af4342908466a2bcf"
18+
"lock_sha256": "98b174e188340159ee581b02cf6463d5a0e3ad60ad16c0c59a53133e3ca65b3d"
1919
},
2020
{
2121
"name": "squad-implement-worker",
2222
"source": "workflows/package/squad-implement-worker.md",
2323
"destination": ".github/workflows/squad-implement-worker.md",
2424
"lock": ".github/workflows/squad-implement-worker.lock.yml",
2525
"source_sha256": "ae710dd5c89360af540576dac378a0d0df129cce5a9bbf16f0615dfd86d0b21c",
26-
"lock_sha256": "d6d2fa7f2bac5845c414cf42a9ea565d3663dba23d9208942fe142fca6b23bc3"
26+
"lock_sha256": "ff1d336b2ee99a51c7b7f1b87dcc03dbcaec069cde5fc962f1da30189a99f9d6"
2727
},
2828
{
2929
"name": "squad-review",
3030
"source": "workflows/package/squad-review.md",
3131
"destination": ".github/workflows/squad-review.md",
3232
"lock": ".github/workflows/squad-review.lock.yml",
3333
"source_sha256": "27adf384cbe16c11ec89f4ecd76c9087a409c911ab9760575a3254b1d21dfb56",
34-
"lock_sha256": "c3ed91988744077da65cbbc8a77a6d262bf4dca3bbfc593ab520283c3e9ced6b"
34+
"lock_sha256": "a29203c21a6af2c9ce4dbf838a8d61f0fe39f9d6fe08b371d54167c2f74177a4"
3535
},
3636
{
3737
"name": "squad-deps-worker",
3838
"source": "workflows/package/squad-deps-worker.md",
3939
"destination": ".github/workflows/squad-deps-worker.md",
4040
"lock": ".github/workflows/squad-deps-worker.lock.yml",
4141
"source_sha256": "37c4ba60b85c5fc07bef322bbfd0f713472924d55cff9481ae76af7ec0c91fac",
42-
"lock_sha256": "d5a8c0b1eb7933bb4bb74499fd9de872b6d55045665f918c831658f8baa20f71"
42+
"lock_sha256": "858c9247b26ff786cca81052ff3c6bb18168e8fb50cd72e8b0e5c4b42bfd38ad"
4343
},
4444
{
4545
"name": "squad-retro",
4646
"source": "workflows/package/squad-retro.md",
4747
"destination": ".github/workflows/squad-retro.md",
4848
"lock": ".github/workflows/squad-retro.lock.yml",
4949
"source_sha256": "92bcfa39cc5fd3087b11612125e314959237c5b79460825453d1e493727a2562",
50-
"lock_sha256": "00771decb93b93d04ea9c9e6173c2338eef615e49df0a8ca12729680fa15fc52"
50+
"lock_sha256": "03f31bf1cbe276c686ae7899307180b2231e1c0ff25edd1afc40151ec29c105d"
5151
},
5252
{
5353
"name": "squad-improvement-worker",
5454
"source": "workflows/package/squad-improvement-worker.md",
5555
"destination": ".github/workflows/squad-improvement-worker.md",
5656
"lock": ".github/workflows/squad-improvement-worker.lock.yml",
5757
"source_sha256": "01c89f8890f02c0ca884513aa10225787feaf3606ab604d5c0e85fbbccdb6c95",
58-
"lock_sha256": "880b7673b022d6155870d87b70e6d6a2489eb7eefec64fcf3515041d5ca5c42e"
58+
"lock_sha256": "583d505966d9591088c7a482f08d23c410b0c1e6bbf7396ae871c0a87c8ecba6"
5959
},
6060
{
6161
"name": "squad-bootstrap",
6262
"source": "workflows/package/squad-bootstrap.md",
6363
"destination": ".github/workflows/squad-bootstrap.md",
6464
"lock": ".github/workflows/squad-bootstrap.lock.yml",
65-
"source_sha256": "9df28d8e4094b66e7ddf4aed1ff3626efaa65c1dcd3815984d70573b40af640d",
66-
"lock_sha256": "9a23ee0bd51cd7dd69b91538872a3fce0fb2376423ce8ac56c7c9f6f5b7f4b1b"
65+
"source_sha256": "de21c6e2baed831a573596d85e2ccdd70a28fe5b1fe275797055c44609a999d0",
66+
"lock_sha256": "b46648d07dae93a51958349a052f85c900eb50075d1c0bbf841234493af93112"
6767
},
6868
{
6969
"name": "squad-command-router",
7070
"source": "workflows/package/squad-command-router.md",
7171
"destination": ".github/workflows/squad-command-router.md",
7272
"lock": ".github/workflows/squad-command-router.lock.yml",
7373
"source_sha256": "cbce466a6cfe64c194b17672ea3363fe7c22cb6b4258c195cc93a2d294d0bf88",
74-
"lock_sha256": "9c5bf2b28dc82a575c528ce73a75c38b54129d512341e10cdce2a6e12ceecb4b"
74+
"lock_sha256": "bb604c0fd7d061e37a5ac9bf1a39d5162e8e149ef25e061d5eee447447c3be1c"
7575
}
7676
],
7777
"shared_runtime": [
@@ -89,7 +89,7 @@
8989
"package_destination": ".github/workflows/shared/squad-install-verifier.mjs",
9090
"destination": ".github/workflows/shared/squad-install-verifier.mjs",
9191
"ownership": "manifest",
92-
"sha256": "4f385df488cc65165e398e499663c015ce63851cb9c938f4c3dd0af38d25f991"
92+
"sha256": "09f806f17c7ff2ddd207484a536e13f41071c4ed584ab37be415755979bec1c4"
9393
},
9494
{
9595
"path": "shared/squad-command-contract.mjs",

0 commit comments

Comments
 (0)