Skip to content

Commit 58f249b

Browse files
bradygasterCopilot
andauthored
fix(gh-aw): add dispatch job discriminators (#1981)
Refs #1958 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent aff26a0 commit 58f249b

5 files changed

Lines changed: 40 additions & 3 deletions

File tree

‎test/gh-aw-review-workflow.test.ts‎

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { afterAll, describe, expect, it } from 'vitest';
2-
import { cpSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync } from 'node:fs';
3-
import { execFileSync } from 'node:child_process';
2+
import { cpSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, writeFileSync } from 'node:fs';
3+
import { execFileSync, spawnSync } from 'node:child_process';
44
import { tmpdir } from 'node:os';
55
import { dirname, resolve } from 'node:path';
66
import { fileURLToPath } from 'node:url';
@@ -209,11 +209,18 @@ describe('gh-aw advisory Squad reviewer', () => {
209209
}
210210
execFileSync('git', ['init', '--quiet'], { cwd: workspace });
211211
for (const name of installOrder) {
212-
execFileSync(
212+
const result = spawnSync(
213213
'gh',
214214
['aw', 'compile', name.slice(0, -3), '--strict', '--approve', '--no-check-update'],
215215
{ cwd: workspace, encoding: 'utf8', stdio: 'pipe' },
216216
);
217+
const diagnostics = `${result.stdout}\n${result.stderr}`;
218+
expect(result.error, `failed to launch gh aw for ${name}`).toBeUndefined();
219+
expect(result.status, `strict compile failed for ${name}:\n${diagnostics}`).toBe(0);
220+
expect(
221+
diagnostics,
222+
`${name} must not emit the workflow_dispatch concurrency warning in a clean consumer install`,
223+
).not.toContain('concurrency.job-discriminator');
217224
}
218225

219226
const installed = readdirSync(workflowDir, { withFileTypes: true })
@@ -232,6 +239,32 @@ describe('gh-aw advisory Squad reviewer', () => {
232239
]);
233240
}, 30000);
234241

242+
it('detects a missing workflow_dispatch job discriminator during strict compilation', () => {
243+
const workspace = mkdtempSync(resolve(tmpdir(), 'squad-review-discriminator-mutation-'));
244+
compileWorkspaces.push(workspace);
245+
const workflowDir = resolve(workspace, '.github', 'workflows');
246+
mkdirSync(workflowDir, { recursive: true });
247+
cpSync(resolve(ROOT, 'workflows'), workflowDir, { recursive: true });
248+
249+
const workerPath = resolve(workflowDir, 'squad-deps-worker.md');
250+
const worker = readFileSync(workerPath, 'utf8').replace(/\r\n/g, '\n');
251+
expect(worker).toContain(' job-discriminator: ${{ github.run_id }}\n');
252+
writeFileSync(workerPath, worker.replace(' job-discriminator: ${{ github.run_id }}\n', ''));
253+
execFileSync('git', ['init', '--quiet'], { cwd: workspace });
254+
255+
const result = spawnSync(
256+
'gh',
257+
['aw', 'compile', 'squad-deps-worker', '--strict', '--no-check-update', '--no-emit'],
258+
{ cwd: workspace, encoding: 'utf8', stdio: 'pipe' },
259+
);
260+
const diagnostics = `${result.stdout}\n${result.stderr}`;
261+
expect(result.error, 'failed to launch gh aw for discriminator mutation').toBeUndefined();
262+
expect(result.status, `mutated workflow must remain compilable:\n${diagnostics}`).toBe(0);
263+
expect(diagnostics).toContain(
264+
'workflow_dispatch workflow has no concurrency.job-discriminator',
265+
);
266+
}, 20000);
267+
235268
it('keeps all consumer install surfaces on the coherent four-workflow order', () => {
236269
for (const surface of [GUIDE, README, AGENT_GUIDE, SHARED_BOOTSTRAP]) {
237270
const orders = installOrders(surface);

‎workflows/squad-deps-worker.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ permissions:
2525
concurrency:
2626
group: "squad-deps-${{ github.event.inputs.issue_number }}"
2727
cancel-in-progress: false
28+
job-discriminator: ${{ github.run_id }}
2829
network:
2930
allowed:
3031
- defaults

‎workflows/squad-implement-worker.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ permissions:
3131
concurrency:
3232
group: "squad-implement-${{ github.event.inputs.issue_number || github.event.pull_request.number }}"
3333
cancel-in-progress: false
34+
job-discriminator: ${{ github.run_id }}
3435
network:
3536
allowed:
3637
- defaults

‎workflows/squad-review.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ permissions:
3636
concurrency:
3737
group: "squad-review-${{ github.event.inputs.issue_number || github.event.pull_request.number || github.run_id }}"
3838
cancel-in-progress: true
39+
job-discriminator: ${{ github.run_id }}
3940
network:
4041
allowed:
4142
- defaults

‎workflows/squad.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ permissions:
3434
concurrency:
3535
group: "squad-${{ github.event.inputs.issue_number || github.event.issue.number || github.event.pull_request.number || github.run_id }}"
3636
cancel-in-progress: false
37+
job-discriminator: ${{ github.run_id }}
3738
network:
3839
allowed:
3940
- defaults

0 commit comments

Comments
 (0)