|
9 | 9 | * 2. Its frontmatter advertises the documented trigger phrases (discoverability). |
10 | 10 | * 3. Its body still encodes every critical safety gate (allowlist, strict |
11 | 11 | * compile, never-auto-merge, read-only token, explicit staging). |
12 | | - * 4. The canonical source and both template mirrors are byte-for-byte identical |
| 12 | + * 4. The canonical source and all four mirrors are byte-for-byte identical |
13 | 13 | * (the sync invariant every canonical skill upholds). |
14 | 14 | */ |
15 | 15 |
|
@@ -42,6 +42,64 @@ function readLF(rel: string): string { |
42 | 42 | return readRaw(rel).replace(/\r\n/g, '\n'); |
43 | 43 | } |
44 | 44 |
|
| 45 | +const COMPILE_WARNINGS = [ |
| 46 | + '.github/workflows/squad-review.md: warning: pull_request_target is a very dangerous trigger.', |
| 47 | + ".github/workflows/squad.md: warning: Both slash_command and bots triggers are configured. If a bot listed in bots: posts a comment that starts with the slash command text (e.g., /command-name), it will trigger the workflow and occupy the concurrency slot, potentially blocking simultaneous manual invocations. To ensure the workflow only runs on explicit user commands, remove the 'bots:' field.", |
| 48 | +]; |
| 49 | + |
| 50 | +function assertCompileWarningContract(content: string): void { |
| 51 | + const regions = [...content.matchAll( |
| 52 | + /^<!-- compile-warning-allowlist-start -->\n```text\n([\s\S]*?)\n```\n<!-- compile-warning-allowlist-end -->$/gm, |
| 53 | + )]; |
| 54 | + expect(regions).toHaveLength(1); |
| 55 | + expect(regions[0][1].split('\n')).toEqual(COMPILE_WARNINGS); |
| 56 | + const flat = content.replace(/\s+/g, ' '); |
| 57 | + expect(flat).toContain('require exactly two warnings, one occurrence of each exact diagnostic header'); |
| 58 | + expect(flat).toContain('**STOP** on any error, or on **any additional warning** beyond these two exact documented diagnostics.'); |
| 59 | + expect(flat).toContain('Also STOP if either warning is missing, duplicated, changed, or attributed to another path'); |
| 60 | + expect(flat).toContain('Compiled 8 workflows: 8 succeeded, 2 warnings'); |
| 61 | + expect(flat).toContain('or if any required control is absent.'); |
| 62 | + expect(flat).toContain('Do not suppress warnings or use `--approve` to bypass this gate.'); |
| 63 | +} |
| 64 | + |
| 65 | +describe.each([CANONICAL, ...MIRRORS, GUIDE])('%s strict compile warning contract', path => { |
| 66 | + const content = readLF(path); |
| 67 | + |
| 68 | + it('allows exactly the native review advisory and bot-trigger diagnostic with hard-stop semantics', () => { |
| 69 | + assertCompileWarningContract(content); |
| 70 | + }); |
| 71 | + |
| 72 | + it('conditions the native review exception on every existing control', () => { |
| 73 | + const flat = content.replace(/\s+/g, ' '); |
| 74 | + expect(flat).toContain('**only while all existing controls remain**'); |
| 75 | + for (const control of [ |
| 76 | + 'same-repository head restriction', 'base-controlled workflow source', |
| 77 | + '`checkout: false` agent path', 'API-only inspection', 'exact run/head/attempt guard', |
| 78 | + 'least-privilege jobs', 'advisory verdict', 'independent human approval', |
| 79 | + ]) expect(flat).toContain(control); |
| 80 | + expect(flat).toContain('`pull_request_target` is not generally safe'); |
| 81 | + }); |
| 82 | + |
| 83 | + it.each([ |
| 84 | + ['unknown third warning', `${COMPILE_WARNINGS.join('\n')}\n.github/workflows/squad.md: warning: unknown diagnostic`], |
| 85 | + ['missing review warning', COMPILE_WARNINGS[1]], |
| 86 | + ['missing bot warning', COMPILE_WARNINGS[0]], |
| 87 | + ['duplicate warning', `${COMPILE_WARNINGS.join('\n')}\n${COMPILE_WARNINGS[0]}`], |
| 88 | + ['different workflow path', COMPILE_WARNINGS.join('\n').replace('squad-review.md', 'untrusted.md')], |
| 89 | + ['changed diagnostic', COMPILE_WARNINGS.join('\n').replace('very dangerous', 'safe')], |
| 90 | + ])('rejects a contract mutation allowing %s', (_label, replacement) => { |
| 91 | + const mutated = content.replace(COMPILE_WARNINGS.join('\n'), replacement); |
| 92 | + expect(mutated).not.toBe(content); |
| 93 | + expect(() => assertCompileWarningContract(mutated)).toThrow(); |
| 94 | + }); |
| 95 | + |
| 96 | + it('rejects removal of the error/additional-warning hard stop', () => { |
| 97 | + const mutated = content.replace('**STOP** on any error', 'Continue on any error'); |
| 98 | + expect(mutated).not.toBe(content); |
| 99 | + expect(() => assertCompileWarningContract(mutated)).toThrow(); |
| 100 | + }); |
| 101 | +}); |
| 102 | + |
45 | 103 | describe('gh-aw-enlistment skill', () => { |
46 | 104 | it('canonical SKILL.md exists', () => { |
47 | 105 | expect(existsSync(resolve(ROOT, CANONICAL)), `${CANONICAL} should exist`).toBe(true); |
@@ -169,22 +227,6 @@ describe('gh-aw-enlistment skill', () => { |
169 | 227 | expect(content).toMatch(/^gh aw compile --strict(\s+#[^\n]*)?$/m); |
170 | 228 | }); |
171 | 229 |
|
172 | | - it('permits only the documented bot-trigger warning', () => { |
173 | | - expect(content).toMatch(/bot-trigger warning|bot trigger/i); |
174 | | - }); |
175 | | - |
176 | | - // The permission above is only safe because it is paired with a hard halt |
177 | | - // on anything else. Asserting the allowance alone would keep passing if |
178 | | - // the STOP were deleted -- i.e. if the narrow exception silently became a |
179 | | - // blanket "warnings are fine". Assert the gate itself, not just the |
180 | | - // carve-out. Newlines are collapsed first because the sentence wraps. |
181 | | - it('halts on any error or any warning beyond the documented one', () => { |
182 | | - const flat = content.replace(/\s+/g, ' '); |
183 | | - expect(flat).toMatch( |
184 | | - /\*\*STOP\*\* on any error, or on \*\*any additional warning\*\* beyond that single documented one\./, |
185 | | - ); |
186 | | - }); |
187 | | - |
188 | 230 | it('keeps the default workflow token read-only', () => { |
189 | 231 | expect(content).toContain('default_workflow_permissions=read'); |
190 | 232 | }); |
|
0 commit comments