Skip to content

Commit d4bf8d3

Browse files
authored
test: record evidence from the Offing fix PR dogfood workflow (#1186)
1 parent 4319c96 commit d4bf8d3

3 files changed

Lines changed: 73 additions & 13 deletions

File tree

‎.github/workflows/offing-fix-pr.yml‎

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ concurrency:
1414

1515
jobs:
1616
acc-fix-pr:
17-
if: github.repository == 'velella-sh/offing' && github.ref_name == github.event.repository.default_branch
17+
if: >-
18+
github.repository == 'velella-sh/offing' &&
19+
(github.event_name == 'workflow_dispatch' || github.ref_name == github.event.repository.default_branch)
1820
runs-on: ubuntu-latest
1921
timeout-minutes: 10
2022
steps:
@@ -28,9 +30,41 @@ jobs:
2830
run: |
2931
npm run build
3032
npm run build:action
33+
- name: Plan fixes on Offing's tracked files without writing
34+
env:
35+
OFFING_DATA_VERSION: bundled
36+
run: |
37+
set -euo pipefail
38+
checkout="$RUNNER_TEMP/offing-dogfood"
39+
mkdir "$checkout"
40+
# These directories intentionally contain old versions and APIs for fixtures.
41+
git archive HEAD | tar --extract --directory "$checkout" \
42+
--exclude='examples' --exclude='tests/fixtures' --exclude='benchmarks/agent-staleness/outputs'
43+
node dist/src/cli.js fix "$checkout" --dry-run --json > "$RUNNER_TEMP/offing-dogfood-plan.json"
44+
{
45+
printf '### Offing fix plan at %s\n\n' "$GITHUB_SHA"
46+
printf 'Read-only snapshot of tracked files excluding examples/, tests/fixtures/ and benchmarks/agent-staleness/outputs/.\n\n'
47+
jq -er '
48+
select(.schemaVersion == "offing.fix.v1") |
49+
if (.patches | length) == 0 then "No deterministic patches were planned for the scanned files."
50+
else "Deterministic patches planned for review: " + (.patches | length | tostring) end,
51+
("Refusals: " + (.refusals | length | tostring))
52+
' "$RUNNER_TEMP/offing-dogfood-plan.json"
53+
printf '\nThis read-only workflow makes no GitHub branch or pull request writes.\n'
54+
} | tee -a "$GITHUB_STEP_SUMMARY"
3155
- name: Run the candidate Action against an isolated Git remote
3256
env:
3357
OFFING_FIX_PR_ACTION: ${{ github.workspace }}/dist/action/index.js
58+
OFFING_FIX_PR_EVIDENCE: ${{ runner.temp }}/acc-fix-pr-evidence
3459
run: |
3560
node --test dist/tests/action-fix-pr.test.js dist/tests/fix-pr-body.test.js
36-
printf '### acc-fix-pr\n\nCandidate Action exercised against local Git and a stubbed GitHub API. Live PR publication is disabled.\n' >> "$GITHUB_STEP_SUMMARY"
61+
{
62+
printf '### acc-fix-pr\n\nCandidate Action exercised against local Git and a stubbed GitHub API.\n'
63+
cat "$OFFING_FIX_PR_EVIDENCE/fixture-summary.md"
64+
} | tee -a "$GITHUB_STEP_SUMMARY"
65+
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7
66+
with:
67+
name: acc-fix-pr-evidence-${{ github.run_attempt }}
68+
path: ${{ runner.temp }}/acc-fix-pr-evidence
69+
if-no-files-found: error
70+
retention-days: 14

‎docs/FIX_PR.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ The pull request begins with its evidence table, then lists patches by fixer, re
1616

1717
A later run updates the bot branch only when all its extra commits match the bot's recorded author, committer and fix subject. An explicit Git lease rejects a branch changed after inspection. A human commit causes a notice on the open PR. Fork runs and rejected writes are explained in the job summary.
1818

19-
[Offing's dry-run workflow](https://github.com/velella-sh/offing/blob/main/.github/workflows/offing-fix-pr.yml) builds the candidate and exercises it with a local Git remote and stubbed GitHub responses.
19+
[Offing's dry-run workflow](https://github.com/velella-sh/offing/blob/main/.github/workflows/offing-fix-pr.yml) runs a read-only fix plan on Offing's tracked files and reports the result in the job summary. It excludes the intentionally outdated test fixtures, examples and benchmark outputs. In the same run, the candidate Action opens and updates one fixture PR through a local Git remote and stubbed GitHub responses. Download `acc-fix-pr-evidence-<attempt>` from the run's **Artifacts** section to inspect the fixture's verification result, patch, fix plan and summary.

‎tests/action-fix-pr.test.ts‎

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -228,19 +228,24 @@ test("a merged pull request is not reopened; the next run opens a new one", asyn
228228
});
229229

230230
/** Runs the compiled Action entry point against a checkout with a fake step summary. */
231-
async function runAction(root: string, inputs: Record<string, string>, status = 200) {
231+
async function runAction(root: string, inputs: Record<string, string>, status = 200, existingPull?: number) {
232232
const runner = await scratch("offing-fix-pr-runner-");
233233
const output = join(runner, "outputs.txt");
234234
const summary = join(runner, "summary.md");
235-
await Promise.all([writeFile(output, ""), writeFile(summary, "")]);
235+
const requests = join(runner, "requests.txt");
236+
await Promise.all([writeFile(output, ""), writeFile(summary, ""), writeFile(requests, "")]);
236237
const stub = join(runner, "api.mjs");
237238
await writeFile(
238239
stub,
239240
`
240-
globalThis.fetch = async (_url, options) => {
241+
import { appendFileSync } from "node:fs";
242+
globalThis.fetch = async (url, options) => {
243+
appendFileSync(${JSON.stringify(requests)}, options.method + " " + new URL(url).pathname + "\\n");
241244
if (${status} !== 200) return Response.json({}, { status: ${status} });
242-
if (options.method === "GET") return Response.json([]);
243-
return Response.json({ number: 7, html_url: "https://github.com/o/r/pull/7" });
245+
const number = ${existingPull ?? 7};
246+
const pull = { number, state: "open", head: { ref: "offing/fixes" }, html_url: "https://github.com/o/r/pull/" + number };
247+
if (options.method === "GET") return Response.json(${existingPull === undefined ? "[]" : "[pull]"});
248+
return Response.json(pull);
244249
};
245250
`,
246251
);
@@ -266,7 +271,13 @@ async function runAction(root: string, inputs: Record<string, string>, status =
266271
child.once("error", reject);
267272
child.once("close", (status) => resolveCode(status ?? 1));
268273
});
269-
return { code, stdout, outputs: await readFile(output, "utf8"), summary: await readFile(summary, "utf8") };
274+
return {
275+
code,
276+
stdout,
277+
outputs: await readFile(output, "utf8"),
278+
summary: await readFile(summary, "utf8"),
279+
requests: (await readFile(requests, "utf8")).trim().split("\n"),
280+
};
270281
}
271282

272283
test("the Action skips fix-pr on events other than schedule and workflow_dispatch", async () => {
@@ -333,7 +344,7 @@ test("the fix branch and the PR stay intact when any branch commit belongs to a
333344
}
334345
});
335346

336-
test("the Action summarizes fork, read-only, protected branch, and no-change outcomes", async () => {
347+
test("the Action publishes and refreshes the same fixture PR before producing a no-change summary", async () => {
337348
const { root, remote } = await repositoryWithFinding();
338349
const forkEvent = join(await scratch("offing-fix-fork-"), "event.json");
339350
await writeFile(forkEvent, JSON.stringify({ repository: { fork: true, default_branch: "main" } }));
@@ -356,21 +367,36 @@ test("the Action summarizes fork, read-only, protected branch, and no-change out
356367
assert.match(await readFile(join(artifactPath, "offing-fix-plan.json"), "utf8"), /github-actions/);
357368
assert.match(await readFile(join(artifactPath, "offing-fix.patch"), "utf8"), /actions\/checkout/);
358369
assert.match(first.summary, /opened fix pull request #7/);
359-
const evidenceDirectory = process.env.OFFING_FIX_PR_EVIDENCE;
360-
if (evidenceDirectory) await cp(artifactPath, evidenceDirectory, { recursive: true });
370+
assert.deepEqual(first.requests, ["GET /repos/o/r/pulls", "POST /repos/o/r/pulls"]);
371+
372+
git(root, ["checkout", "-q", "main"]);
373+
const rerun = await runAction(root, FIX_RUN, 200, 7);
374+
assert.equal(rerun.code, 0);
375+
assert.match(rerun.summary, /updated fix pull request #7/);
376+
assert.match(rerun.outputs, /fix-pr-number=7/);
377+
assert.deepEqual(rerun.requests, ["GET /repos/o/r/pulls", "PATCH /repos/o/r/pulls/7"]);
361378

362379
git(remote, ["config", "receive.denyNonFastForwards", "true"]);
363380
git(root, ["checkout", "-q", "main"]);
364381
git(root, ["commit", "--allow-empty", "-m", "Update default branch"]);
365-
const protectedBranch = await runAction(root, FIX_RUN);
382+
const protectedBranch = await runAction(root, FIX_RUN, 200, 7);
366383
assert.equal(protectedBranch.code, 0);
367384
assert.match(protectedBranch.summary, /Branch protection rejected/);
385+
assert.deepEqual(protectedBranch.requests, ["GET /repos/o/r/pulls"]);
368386

369387
git(root, ["checkout", "-q", "main"]);
370388
await rm(join(root, ".github", "workflows", "ci.yml"));
371389
const clean = await runAction(root, FIX_RUN);
372390
assert.equal(clean.code, 0);
373391
assert.match(clean.summary, /no deterministic fixes/);
392+
assert.deepEqual(clean.requests, ["GET /repos/o/r/pulls"]);
393+
394+
const evidenceDirectory = process.env.OFFING_FIX_PR_EVIDENCE;
395+
if (evidenceDirectory) {
396+
await cp(artifactPath, evidenceDirectory, { recursive: true });
397+
const summaries = [first, rerun, protectedBranch, clean].map(({ summary }) => summary.trim().split("\n").at(-1));
398+
await writeFile(join(evidenceDirectory, "fixture-summary.md"), summaries.map((line) => `- ${line}\n`).join(""));
399+
}
374400
});
375401

376402
test("existing bot PRs update with checkout's original shallow history default", async () => {

0 commit comments

Comments
 (0)