Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
bump: minor
---

### Changed

- pr-merge's merge job reads through the lanes App's installation allowance instead of the repository's shared `GITHUB_TOKEN` pool (owner decision D398). `lane-rules.json` gives the `merge-pr` grant `actions: read`, which the token broker allows to that activity alone. The candidate listing, the carried artifact reads (cursor, head-ref map, verdict reads, lane records), the post-merge check, the skip filter, the gate's verdict and review-evidence reads and the sweep-count read use the lane token, named `lanes-app` to the rate guard. Commit-status reads, the who and superseded reads before the mint, and the re-fire and escalation-clear steps stay on `GITHUB_TOKEN`. No read moves to the other token when its own pool runs low.
12 changes: 12 additions & 0 deletions .changes/source-control/feat-pr-merge-app-token-reads-69d513d8.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
bump: minor
---

### Added

- The babysit scripts' gh seam sends a REST read of a commit's statuses under `BABYSIT_JOB_GH_TOKEN` when a job sets it (`babysit_gh.job_token_env`), so a job whose process and verdict-reader token is an App token without the Commit statuses permission reads them with its own `GITHUB_TOKEN`. Writes and every other read keep their token.

### Changed

- A call whose `GH_TOKEN` override equals the process's own `GH_TOKEN` is named to the rate guard as `API_BUDGET_TOKEN`, not `API_BUDGET_OVERRIDE_TOKEN`, so a verdict reader set to the process token budgets against that token's pool.
- The whole-review request reads the job bucket and the running jobs with `BABYSIT_JOB_GH_TOKEN` when it is set, else with `BABYSIT_VERIFY_GH_TOKEN` as before.
3 changes: 2 additions & 1 deletion .github/actions/resolve-config/lane-rules.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@
"pr-merge": {
"stage": "merge",
"forbidden-effects": [],
"never": "Merges above the rung, past a hold, or a PR that touches a denied path"
"never": "Merges above the rung, past a hold, or a PR that touches a denied path",
"activity-grants": { "merge-pr": { "actions": "read" } }
},
"post-merge-verify": {
"stage": "post-merge",
Expand Down
12 changes: 9 additions & 3 deletions .github/actions/resolve-config/live-config.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -860,16 +860,22 @@ test("live config: the shipped patch rules pass against the live activities", ()
assert.equal(checkPatchRules(rules, json("./patch-rules.schema.json"), parse(FILES.config).activities), rules);
});

test("live config: no live slot resolves an actions permission", () => {
test("live config: only pr-merge's merge-pr grant carries actions, and only read", () => {
const doc = parse(FILES.config);
const holders = [];
for (const lane of Object.keys(doc.lanes)) {
const { lane: resolved } = resolve(FILES, { lane, configPath: CONFIG_PATH, basePath: ".base", facts: FACTS });
for (const slot of resolved.slots) {
assert.equal(slot.grant.actions, undefined, `${lane}/${slot.name}`);
if (slot.grant.actions !== undefined) holders.push(`${lane}/${slot.name}`);
}
}
assert.ok(holders.every((holder) => holder.startsWith("pr-merge/")), JSON.stringify(holders));
assert.deepEqual(resolveGrant(FILES, { lane: "pr-merge", activity: "merge-pr", configPath: CONFIG_PATH }), {
effect: "merge",
grant: { contents: "write", "pull-requests": "write", issues: "write", actions: "read" },
});
assert.equal(
resolveGrant(FILES, { lane: "pr-merge", activity: "merge-pr", configPath: CONFIG_PATH }).grant.actions,
resolveGrant(FILES, { lane: "pr-merge", activity: "enable-auto-merge", configPath: CONFIG_PATH }).grant.actions,
undefined,
);
});
Expand Down
2 changes: 1 addition & 1 deletion .github/scripts/pr-merge/carry-run-cache.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
// CARRY_BRANCH the branch the verdicts are judged on (main)
// GITHUB_OUTPUT gets carried=true once CARRY_TO is written, and
// kept=true when it holds a read
// ACTIONS_TOKEN read: the job's GITHUB_TOKEN (actions: read)
// ACTIONS_TOKEN read: a token with Actions read (https://docs.github.com/en/rest/authentication/permissions-required-for-github-apps)
// GITHUB_RUN_ID read: this run, which has no file yet
// RUNNER_TEMP read: where the artifact is downloaded
// PR_MERGE_READS_PATH read: the job's shared GET answers
Expand Down
2 changes: 1 addition & 1 deletion .github/scripts/pr-merge/head-ref-map.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
// untied FAIL, which costs requests, never a decision.
//
// Environment:
// ACTIONS_TOKEN read: the job's GITHUB_TOKEN (actions: read)
// ACTIONS_TOKEN read: a token with Actions read (https://docs.github.com/en/rest/authentication/permissions-required-for-github-apps)
// GITHUB_REPOSITORY owner/repo
// GITHUB_RUN_ID read: this run, which has no map yet
// RUNNER_TEMP read: where the artifact is downloaded
Expand Down
2 changes: 1 addition & 1 deletion .github/scripts/pr-merge/lane-records.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
// check then reads every record, which costs requests, never a decision.
//
// Environment:
// ACTIONS_TOKEN read: the job's GITHUB_TOKEN (actions: read)
// ACTIONS_TOKEN read: a token with Actions read (https://docs.github.com/en/rest/authentication/permissions-required-for-github-apps)
// GITHUB_REPOSITORY owner/repo
// GITHUB_RUN_ID read: this run, which has no file yet
// RUNNER_TEMP read: where the artifact is downloaded
Expand Down
58 changes: 44 additions & 14 deletions .github/scripts/pr-merge/merge-job.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ const stepsOf = (block) =>
.map((b) => ({ name: /^ - name: (.*)$/m.exec(b)[1], block: b }));
const job = jobBlock("merge");
const steps = stepsOf(job);
const LANE_ACTIONS_READ = "ACTIONS_TOKEN: ${{ steps.lane-token.outputs.token }}\n";
const JOB_ACTIONS_READ = "ACTIONS_TOKEN: ${{ github.token }}\n";
const step = (name, list = steps) => {
const found = list.find((s) => s.name === name);
assert.ok(found, `step ${name}`);
Expand Down Expand Up @@ -497,7 +499,13 @@ test("a held listing files no failed lane merge; a run that listed goes by its o
});

test("a held listing writes a sweep summary with no read, and a monitor can tell it held", () => {
const skipped = { gate: { outcome: "skipped" }, candidates: { outputs: {} }, "scan-upload-5": { outputs: { clean: "true" } } };
const skipped = {
gate: { outcome: "skipped" },
candidates: { outputs: {} },
"scan-upload-5": { outputs: { clean: "true" } },
"lane-token": { outputs: { token: "t" } },
};
assert.equal(runsOn("Count the sweep's refusals", { ...skipped, candidates: { outputs: { held: "true" } }, "lane-token": { outputs: { token: "" } } }), false);
for (const name of ["Count the sweep's refusals", "Upload the sweep's verdicts", "Write the sweep cost"]) {
assert.equal(runsOn(name, { ...skipped, candidates: { outputs: { held: "true" } } }), true, name);
assert.equal(runsOn(name, skipped), false, name);
Expand Down Expand Up @@ -670,12 +678,15 @@ test("both token-holding jobs read the carried reads from the last trusted run's
const carried = "${{ runner.temp }}/pr-merge-carried.json";
const runCache = "${{ runner.temp }}/babysit-run-cache.json";
const read = "Read the verdict reads the last run kept";
for (const list of [steps, stepsOf(jobBlock("enable-auto-merge"))]) {
for (const [list, token] of [
[steps, LANE_ACTIONS_READ],
[stepsOf(jobBlock("enable-auto-merge")), JOB_ACTIONS_READ],
]) {
const names = list.map((s) => s.name);
assert.ok(names.indexOf(read) >= 0 && names.indexOf(read) < names.indexOf("Start the run cache from them"));
const block = step(read, list);
assert.match(block, /run: node \.base\/\.github\/scripts\/pr-merge\/carry-run-cache\.mjs read\n/);
assert.ok(block.includes(`CARRY_TO: ${carried}\n`) && block.includes("ACTIONS_TOKEN: ${{ github.token }}\n"));
assert.ok(block.includes(`CARRY_TO: ${carried}\n`) && block.includes(token), block);
assert.match(block, /\n {8}timeout-minutes: 2\n/);
const start = step("Start the run cache from them", list);
assert.ok(start.includes(`CARRY_FROM: ${carried}\n`) && start.includes(`CARRY_TO: ${runCache}\n`));
Expand Down Expand Up @@ -759,7 +770,7 @@ test("the gate reads the head-ref map the last run uploaded and uploads the next
const mapOut = "${{ runner.temp }}/head-refs/head-refs.json";
const read = step("Read the head refs the last run kept");
assert.match(read, /run: node \.base\/\.github\/scripts\/pr-merge\/head-ref-map\.mjs read\n/);
assert.ok(read.includes(`HEAD_REFS_PATH: ${mapIn}\n`) && read.includes("ACTIONS_TOKEN: ${{ github.token }}\n"));
assert.ok(read.includes(`HEAD_REFS_PATH: ${mapIn}\n`) && read.includes(LANE_ACTIONS_READ));
const gate = step("Run the merge gate on each candidate");
assert.ok(gate.includes(`BABYSIT_VERIFY_HEAD_REFS: ${mapIn}\n`));
const keep = step("Keep the head refs the gate read");
Expand Down Expand Up @@ -796,12 +807,15 @@ test("every post-merge check reads the lane records, and only the merge job uplo
const file = "${{ runner.temp }}/lane-records.json";
const out = "${{ runner.temp }}/lane-records/lane-records.json";
const early = stepsOf(jobBlock("dispatch-post-merge-runs"));
for (const list of [steps, early]) {
for (const [list, token] of [
[steps, LANE_ACTIONS_READ],
[early, JOB_ACTIONS_READ],
]) {
const names = list.map((s) => s.name);
const read = step("Read the lane records the last run kept", list);
assert.ok(names.indexOf("Read the lane records the last run kept") < names.indexOf("Check earlier lane merges"));
assert.match(read, /run: node \.base\/\.github\/scripts\/pr-merge\/lane-records\.mjs read\n/);
assert.ok(read.includes(`LANE_RECORDS_PATH: ${file}\n`) && read.includes("ACTIONS_TOKEN: ${{ github.token }}\n"));
assert.ok(read.includes(`LANE_RECORDS_PATH: ${file}\n`) && read.includes(token), read);
assert.match(read, /\n {8}continue-on-error: true\n/);
assert.ok(step("Check earlier lane merges", list).includes(`BABYSIT_POSTMERGE_LANE_RECORDS: ${file}\n`));
}
Expand Down Expand Up @@ -1282,16 +1296,32 @@ test("a failed lane merge reruns the check with --remediate under the lane token
assert.match(runScript("Check earlier lane merges"), /^echo "code=\$code" >>"\$GITHUB_OUTPUT"$/m);
});

// Only --remediate writes, so it alone takes the lane token. The read-only
// check and the gate's evidence reads spend the job's own token, which this
// job grants no write.
test("the read-only post-merge check and the gate's reads use the job's read-only token", () => {
assert.match(step("Check earlier lane merges"), /\n {10}GH_TOKEN: \$\{\{ github\.token \}\}\n/);
test("the post-merge check and the gate read with the lane token, checks with the job's", () => {
for (const name of ["Check earlier lane merges", "Skip refusals whose inputs have not changed", "Run the merge gate on each candidate"]) {
const block = step(name);
assert.match(block, /\n {10}GH_TOKEN: \$\{\{ steps\.lane-token\.outputs\.token \}\}\n/, name);
assert.match(block, /\n {10}API_BUDGET_TOKEN: lanes-app\n/, name);
assert.match(block, /\n {10}BABYSIT_JOB_GH_TOKEN: \$\{\{ github\.token \}\}\n/, name);
assert.match(block, /\n {10}API_BUDGET_OVERRIDE_TOKEN: github-token\n/, name);
assert.doesNotMatch(block, /BABYSIT_VERIFY_GH_TOKEN: \$\{\{ github\.token \}\}/, name);
}
assert.doesNotMatch(runScript("Check earlier lane merges"), /--remediate/);
assert.match(step("Record a failed lane merge"), /\n {10}GH_TOKEN: \$\{\{ steps\.lane-token\.outputs\.token \}\}\n/);
const gate = step("Run the merge gate on each candidate");
assert.match(gate, /\n {10}GH_TOKEN: \$\{\{ steps\.lane-token\.outputs\.token \}\}\n/);
assert.match(gate, /\n {10}BABYSIT_VERIFY_GH_TOKEN: \$\{\{ github\.token \}\}\n/);
assert.match(gate, /\n {10}BABYSIT_VERIFY_GH_TOKEN: \$\{\{ steps\.lane-token\.outputs\.token \}\}\n/);
const listing = step("List the candidate PRs");
assert.match(listing, /\n {10}GH_TOKEN: \$\{\{ steps\.lane-token\.outputs\.token \}\}\n/);
assert.match(listing, /\n {10}API_BUDGET_TOKEN: lanes-app\n/);
assert.match(runScript("List the candidate PRs"), /^api_budget_wrap_gh lanes-app$/m);
for (const name of [
"Start after the candidate the last run reached",
"Read the head refs the last run kept",
"Read the verdict reads the last run kept",
"Read the lane records the last run kept",
]) {
assert.ok(step(name).includes(LANE_ACTIONS_READ), name);
assert.match(step(name), /\n {10}API_BUDGET_TOKEN: lanes-app\n/, name);
}
const permissions = /\n permissions:\n([\s\S]*?)\n [a-z-]+:/.exec(job)[1];
const grants = [...permissions.matchAll(/^ {6}([a-z-]+): ([a-z]+)/gm)].map((m) => `${m[1]}: ${m[2]}`);
assert.deepEqual(grants.filter((g) => g.endsWith(": write")), ["id-token: write"]);
Expand Down Expand Up @@ -1636,7 +1666,7 @@ test("the skip step runs just before the gate and its record between the carry a
assert.match(filter, /\n {8}continue-on-error: true\n/);
assert.match(filter, /\n {8}if: steps\.lane-token\.outputs\.token != '' && steps\.candidates\.outputs\.listed == 'true'\n/);
assert.match(filter, /GH_TOKEN: \$\{\{ steps\.lane-token\.outputs\.token \}\}/);
assert.match(filter, /BABYSIT_VERIFY_GH_TOKEN: \$\{\{ github\.token \}\}/);
assert.match(filter, /BABYSIT_VERIFY_GH_TOKEN: \$\{\{ steps\.lane-token\.outputs\.token \}\}/);
// The listing it reads is saved where the gate's first candidate looks.
const listing = "BABYSIT_VERIFY_LISTING: ${{ runner.temp }}/verify-listing.json\n";
assert.ok(filter.includes(listing) && step("Run the merge gate on each candidate").includes(listing));
Expand Down
2 changes: 1 addition & 1 deletion .github/scripts/pr-merge/rotation.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
// leaves the listing order (ascending PR number) and warns.
//
// Environment:
// ACTIONS_TOKEN the job's GITHUB_TOKEN (actions: read)
// ACTIONS_TOKEN a token with Actions read (https://docs.github.com/en/rest/authentication/permissions-required-for-github-apps)
// GITHUB_REPOSITORY owner/repo
// GITHUB_RUN_ID this run, which has no cursor yet
// CANDIDATES_PATH candidates.json, rewritten in rotated order
Expand Down
4 changes: 2 additions & 2 deletions .github/scripts/pr-merge/workflow.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1271,7 +1271,7 @@ test("every createGitHub step that calls GitHub with the job token names the buc

// The sweep-count step's one read, the run's start, goes through the wrapped
// gh, so the job-end notice counts it; sweep-summary.mjs calls nothing.
test("the merge job's sweep-count read leaves one github-token reading", () => {
test("the merge job's sweep-count read leaves one lanes-app reading", () => {
const step = /- name: Count the sweep's refusals\n([\s\S]*?)(?=\n {6}- name: )/.exec(job("merge"))[1];
const run = /\n {8}run: \|\n((?: {10}.*\n|\s*\n)+)/.exec(step)[1].replace(/^ {10}/gm, "");
const dir = tempDir("pr-merge-sweep-count-");
Expand All @@ -1296,7 +1296,7 @@ while [ $# -gt 0 ]; do if [ "$1" = --jq ]; then echo '{"run_started_at":"2026-10
});
assert.equal(r.status, 0, r.stdout + r.stderr);
assert.equal(readFileSync(join(dir, "started"), "utf8"), "2026-10-28T00:00:00Z\n");
assert.equal(readFileSync(join(dir, "api-budget", "github-token"), "utf8"), "200 5000 4000 1000 9999999999 core repos/{repo}/actions/runs/{n}\n");
assert.equal(readFileSync(join(dir, "api-budget", "lanes-app"), "utf8"), "200 5000 4000 1000 9999999999 core repos/{repo}/actions/runs/{n}\n");
} finally {
rmSync(dir, { recursive: true, force: true });
}
Expand Down
11 changes: 6 additions & 5 deletions .github/scripts/pr-verify/workflow.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -269,15 +269,16 @@ test("the resolver runs before the trigger gate, and the agree step only after t
}
});

test("pr-merge.yml gives the gate an Actions token for the verdict reads only", () => {
// babysit_verify_evidence.py reads BABYSIT_VERIFY_GH_TOKEN; the lane token
// the gate runs gh with holds no Actions permission.
test("pr-merge.yml's gate reads its verdicts with the lane token and checks with the job's", () => {
const merge = readFileSync(new URL("../../workflows/pr-merge.yml", import.meta.url), "utf8");
const job = /\n merge:\n([\s\S]*?)\n [a-z-]+:\n/.exec(merge)[1];
assert.match(job, /\n {6}actions: read\n/);
assert.match(job, /\n {6}checks: read\n/);
const gate = /- name: Run the merge gate on each candidate\n([\s\S]*?)\n {6}- name: /.exec(job)[1];
assert.match(gate, /\n {10}GH_TOKEN: \$\{\{ steps\.lane-token\.outputs\.token \}\}\n/);
assert.match(gate, /\n {10}BABYSIT_VERIFY_GH_TOKEN: \$\{\{ github\.token \}\}\n/);
assert.match(gate, /\n {10}BABYSIT_VERIFY_GH_TOKEN: \$\{\{ steps\.lane-token\.outputs\.token \}\}\n/);
assert.match(gate, /\n {10}BABYSIT_JOB_GH_TOKEN: \$\{\{ github\.token \}\}\n/);
assert.match(gate, /\n {10}API_BUDGET_TOKEN: lanes-app\n/);
assert.match(gate, /\n {10}API_BUDGET_OVERRIDE_TOKEN: github-token\n/);
});

test("the concurrency group is per PR and head and never cancels a running judgment", () => {
Expand Down
Loading
Loading