Skip to content

Commit 3e167d8

Browse files
authored
test(gh-aw): prove plaintext resource delivery (#1983)
* feat(gh-aw): add resource delivery probe Closes #1982 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 083906de-529b-42f9-ae2d-36b0c911eaef * chore(gh-aw): keep resource probe scope focused Closes #1982 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 083906de-529b-42f9-ae2d-36b0c911eaef * test(gh-aw): exercise resource readability guard (#1982) Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 083906de-529b-42f9-ae2d-36b0c911eaef --------- Copilot-Session: 083906de-529b-42f9-ae2d-36b0c911eaef
1 parent 5ee4688 commit 3e167d8

5 files changed

Lines changed: 200 additions & 3 deletions

File tree

‎.gitattributes‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,8 @@ Dockerfile.* text eol=lf
5353
# perpetually dirty tree (#1788).
5454
*.snap text eol=lf
5555

56+
# Squad: the gh-aw resource probe is authenticated byte-for-byte before agent startup.
57+
workflows/shared/squad-gh-aw-resource-probe.txt text eol=lf
58+
5659
# Squad: union merge for append-only team state files
57-
.squad/fact-checker/audit-trail.md merge=union
60+
.squad/fact-checker/audit-trail.md merge=union

‎docs/src/content/docs/guide/gh-aw.md‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,28 @@ committed. If a `.gitignore` is missing from `.github/aw/logs/`, add one there:
242242
243243
Once pushed, the `/squad` slash command is live on your repo.
244244
245+
### Experimental gh-aw resource probe (`dev` test zone)
246+
247+
Issue #1982 adds a gh-aw-only plaintext probe to the `@dev` dispatcher. It tests
248+
whether a direct install delivers top-level `resources:` beside the installed
249+
workflow. The probe does not change Cast behavior or any CLI/SDK install path;
250+
the existing Base64 Cast validator remains authoritative.
251+
252+
In a disposable test repository, install or refresh only the dispatcher:
253+
254+
```bash
255+
gh aw add bradygaster/squad/workflows/squad.md@dev --force
256+
gh aw compile squad --strict
257+
test -r .github/workflows/shared/squad-gh-aw-resource-probe.txt
258+
```
259+
260+
Review the source, generated lockfile, and plaintext probe before committing the
261+
test-zone update. Then comment `/squad cast` on a test issue. A missing,
262+
unreadable, or modified probe fails the pre-agent assertion explicitly; a valid
263+
probe leaves the current Cast path unchanged. After updating `@dev`, rerun the
264+
same Cast issue to confirm the installed resource is used without changing the
265+
expected Cast PR contents.
266+
245267
### Optional: pin a CLI version
246268
247269
Activation downloads a self-contained GitHub Release bundle; it does not install

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

Lines changed: 145 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99
*/
1010

1111
import { afterAll, describe, it, expect } from 'vitest';
12-
import { cpSync, readFileSync, existsSync, mkdirSync, mkdtempSync, writeFileSync, rmSync } from 'node:fs';
12+
import { chmodSync, cpSync, readFileSync, existsSync, mkdirSync, mkdtempSync, writeFileSync, rmSync } from 'node:fs';
1313
import { join, dirname } from 'node:path';
1414
import { tmpdir } from 'node:os';
1515
import { execFileSync, execSync, spawnSync } from 'node:child_process';
16+
import { createHash } from 'node:crypto';
1617
import { minimatch } from 'minimatch';
1718
import { POSIX_SHELL, NO_POSIX_SHELL_MESSAGE, requirePosixShell } from './posix-shell';
1819
import {
@@ -167,6 +168,40 @@ function extractImports(frontmatter: string): string[] {
167168
return imports;
168169
}
169170

171+
/** Extract the resources list from frontmatter. */
172+
function extractResources(frontmatter: string): string[] {
173+
const resources: string[] = [];
174+
const lines = frontmatter.split('\n');
175+
let inResources = false;
176+
177+
for (const line of lines) {
178+
if (line.match(/^resources:\s*$/)) {
179+
inResources = true;
180+
continue;
181+
}
182+
183+
if (inResources) {
184+
const itemMatch = line.match(/^\s+-\s+(.+)$/);
185+
if (itemMatch) {
186+
resources.push(itemMatch[1].trim());
187+
} else if (line.match(/^\S/)) {
188+
break;
189+
}
190+
}
191+
}
192+
193+
return resources;
194+
}
195+
196+
function extractNamedStepScript(frontmatter: string, stepName: string): string {
197+
const escapedName = stepName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
198+
const match = frontmatter.match(
199+
new RegExp(`^ - name: ${escapedName}\\n shell: bash\\n run: \\|\\n([\\s\\S]*?)(?=^ - name:|\\n\\S)`, 'm'),
200+
);
201+
if (!match) throw new Error(`No bash step named "${stepName}" found`);
202+
return match[1].split('\n').map(line => line.replace(/^ {6}/, '')).join('\n').trim();
203+
}
204+
170205
function extractWorkflowDispatchInputs(frontmatter: string): Record<string, Record<string, string>> {
171206
const inputs: Record<string, Record<string, string>> = {};
172207
const lines = frontmatter.split('\n');
@@ -568,6 +603,111 @@ describe('gh-aw: shared component imports', () => {
568603
expect(imports.length).toBeGreaterThan(0);
569604
});
570605

606+
describe('#1982: experimental gh-aw resource delivery probe', () => {
607+
const frontmatter = extractFrontmatter(SQUAD_WORKFLOW);
608+
const probeResource = 'shared/squad-gh-aw-resource-probe.txt';
609+
const probePath = join(WORKFLOWS_DIR, probeResource);
610+
const expectedDigest = 'dba0c331c0b0fda06539bd9245dda72bd9c36cca6962726147b03168c1d97a73';
611+
const stepName = 'Assert experimental gh-aw resource delivery';
612+
613+
it('declares the plaintext probe on the top-level direct-install workflow only', () => {
614+
expect(extractResources(frontmatter)).toEqual([probeResource]);
615+
expect(existsSync(probePath)).toBe(true);
616+
expect(readText(probePath)).toContain('Experiment: bradygaster/squad#1982');
617+
expect(readText(probePath)).toContain('no executable or runtime behavior');
618+
619+
for (const sharedFile of [
620+
'squad.md',
621+
'squad-cast-validator.md',
622+
'squad-planning-ontology.md',
623+
'squad-planning-policy.md',
624+
]) {
625+
expect(readText(join(SHARED_DIR, sharedFile))).not.toMatch(/^resources:/m);
626+
}
627+
});
628+
629+
it('pins the exact plaintext bytes and checks missing, unreadable, and mismatched resources', () => {
630+
const actualDigest = createHash('sha256').update(readFileSync(probePath)).digest('hex');
631+
const script = extractNamedStepScript(frontmatter, stepName);
632+
633+
expect(actualDigest).toBe(expectedDigest);
634+
expect(script).toContain(`expected_sha256="${expectedDigest}"`);
635+
expect(script).toContain('if [ ! -f "$probe" ]');
636+
expect(script).toContain('if [ ! -r "$probe" ]');
637+
expect(script).toContain('Experimental gh-aw resource probe SHA-256 mismatch');
638+
});
639+
640+
it('fails closed before the agent for a missing or modified installed probe', () => {
641+
const script = extractNamedStepScript(frontmatter, stepName);
642+
const bash = process.platform === 'win32' ? requirePosixShell() : 'bash';
643+
const workspace = createTestWorkspace('gh-aw-resource-probe-');
644+
const installedProbe = join(workspace, '.github', 'workflows', probeResource);
645+
mkdirSync(dirname(installedProbe), { recursive: true });
646+
647+
const missing = spawnSync(bash, ['-c', script], {
648+
cwd: workspace,
649+
encoding: 'utf8',
650+
env: { ...process.env, GITHUB_WORKSPACE: workspace, RUNNER_TEMP: workspace },
651+
});
652+
expect(missing.status).not.toBe(0);
653+
expect(missing.stderr).toContain('Experimental gh-aw resource probe is missing');
654+
655+
writeFileSync(installedProbe, 'tampered\n');
656+
const modified = spawnSync(bash, ['-c', script], {
657+
cwd: workspace,
658+
encoding: 'utf8',
659+
env: { ...process.env, GITHUB_WORKSPACE: workspace, RUNNER_TEMP: workspace },
660+
});
661+
expect(modified.status).not.toBe(0);
662+
expect(modified.stderr).toContain('Experimental gh-aw resource probe SHA-256 mismatch');
663+
664+
cpSync(probePath, installedProbe);
665+
const verified = spawnSync(bash, ['-c', script], {
666+
cwd: workspace,
667+
encoding: 'utf8',
668+
env: { ...process.env, GITHUB_WORKSPACE: workspace, RUNNER_TEMP: workspace },
669+
});
670+
expect(verified.status).toBe(0);
671+
expect(verified.stdout).toContain('Experimental gh-aw resource delivery verified');
672+
});
673+
674+
it.skipIf(
675+
process.platform === 'win32' ||
676+
typeof process.getuid !== 'function' ||
677+
process.getuid() === 0,
678+
)('fails closed before the agent for an unreadable installed probe', () => {
679+
const script = extractNamedStepScript(frontmatter, stepName);
680+
const workspace = createTestWorkspace('gh-aw-resource-probe-unreadable-');
681+
const installedProbe = join(workspace, '.github', 'workflows', probeResource);
682+
const bash = 'bash';
683+
mkdirSync(dirname(installedProbe), { recursive: true });
684+
cpSync(probePath, installedProbe);
685+
686+
try {
687+
chmodSync(installedProbe, 0o000);
688+
const permissionCheck = spawnSync(
689+
bash,
690+
['-c', '[ ! -r "$1" ]', 'bash', installedProbe],
691+
{ encoding: 'utf8' },
692+
);
693+
expect(
694+
permissionCheck.status,
695+
'fixture must be unreadable to Bash before exercising the workflow branch',
696+
).toBe(0);
697+
698+
const unreadable = spawnSync(bash, ['-c', script], {
699+
cwd: workspace,
700+
encoding: 'utf8',
701+
env: { ...process.env, GITHUB_WORKSPACE: workspace, RUNNER_TEMP: workspace },
702+
});
703+
expect(unreadable.status).not.toBe(0);
704+
expect(unreadable.stderr).toContain('Experimental gh-aw resource probe is not readable');
705+
} finally {
706+
chmodSync(installedProbe, 0o600);
707+
}
708+
});
709+
});
710+
571711
it('each imported file exists in workflows/shared/', () => {
572712
for (const importPath of imports) {
573713
const fullPath = join(WORKFLOWS_DIR, importPath);
@@ -947,7 +1087,10 @@ describe('gh-aw: prompt budget & planning import regression', () => {
9471087
// moved from agent-transcribed prompt text into a deterministic pre-agent runner.
9481088
// The runner also emits a machine-readable factual failure record. The Cast skill
9491089
// shrank, and the ambient prompt remains below its independently enforced 40 KB cap.
950-
const SOURCE_GROWTH_BUDGET_KB = 194;
1090+
// Raised 194 -> 196 KB by #1982's gh-aw-only resource assertion. The deterministic
1091+
// step runs before the agent and does not enter its prompt; the separate ambient
1092+
// prompt budget remains the authoritative delivered-context guard.
1093+
const SOURCE_GROWTH_BUDGET_KB = 196;
9511094
const SOURCE_GROWTH_BUDGET_BYTES = SOURCE_GROWTH_BUDGET_KB * 1024;
9521095

9531096
it('squad-planning-ontology.md is in the imports list', () => {
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Squad gh-aw resource delivery probe.
2+
Experiment: bradygaster/squad#1982
3+
This plaintext file has no executable or runtime behavior.

‎workflows/squad.md‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,39 @@ imports:
4343
- shared/squad-cast-validator.md
4444
- shared/squad-planning-ontology.md
4545
- shared/squad-planning-policy.md
46+
resources:
47+
- shared/squad-gh-aw-resource-probe.txt
4648
tools:
4749
bash: true
4850
web-fetch:
4951
github:
5052
mode: gh-proxy
5153
toolsets: [default]
5254
steps:
55+
- name: Assert experimental gh-aw resource delivery
56+
shell: bash
57+
run: |
58+
set -euo pipefail
59+
probe="${GITHUB_WORKSPACE:?}/.github/workflows/shared/squad-gh-aw-resource-probe.txt"
60+
expected_sha256="dba0c331c0b0fda06539bd9245dda72bd9c36cca6962726147b03168c1d97a73"
61+
if [ ! -f "$probe" ]; then
62+
printf 'Experimental gh-aw resource probe is missing: %s\n' "$probe" >&2
63+
exit 1
64+
fi
65+
if [ ! -r "$probe" ]; then
66+
printf 'Experimental gh-aw resource probe is not readable: %s\n' "$probe" >&2
67+
exit 1
68+
fi
69+
actual_sha256="$(
70+
node -e 'const c=require("node:crypto"),f=require("node:fs");process.stdout.write(c.createHash("sha256").update(f.readFileSync(process.argv[1])).digest("hex"))' \
71+
"$probe"
72+
)"
73+
if [ "$actual_sha256" != "$expected_sha256" ]; then
74+
printf 'Experimental gh-aw resource probe SHA-256 mismatch: expected %s, got %s.\n' \
75+
"$expected_sha256" "$actual_sha256" >&2
76+
exit 1
77+
fi
78+
printf 'Experimental gh-aw resource delivery verified.\n'
5379
- name: Prepare deterministic Cast validator runner
5480
shell: bash
5581
run: |

0 commit comments

Comments
 (0)