From 96420fdca4b97ab637cb55cf569e1709948db098 Mon Sep 17 00:00:00 2001 From: Kyle Sexton <153232337+kyle-sexton@users.noreply.github.com> Date: Sat, 21 Nov 2026 14:18:47 -0500 Subject: [PATCH 1/4] perf(pr-unblock): count feedback rounds from one GraphQL query roundsSoFar listed the PR's commits, then made one check-runs call per commit to count earlier "pr-unblock / address-feedback" rounds. On 2026-11-21 that was 334 of Address Feedback Select's 896 core calls across 44 runs, and #17880 (59 commits) cost 60 calls a run for it. listModelRounds reads every commit's GitHub Actions check runs of that name, all attempts (checkType ALL), in one GraphQL query (4 points), filtered to the github-actions app (id 15368) and mapped to the listCheckRuns shape, so countCheckRounds and lastRoundAt are unchanged. A commit whose suites or runs run past a page, or a PR past 100 commits, is read over REST as before, one commit at a time, so a round is never undercounted. Probed live on #17939 and #17880: the query's runs match REST run for run. Revert signal: Select core calls per run not falling, or any round count that differs from REST. Co-authored-by: Claude Opus 5.5 --- .../perf-feedback-rounds-graphql-3a9e5c21.md | 7 ++ .../scripts/pr-unblock/address-feedback.mjs | 58 +++++++++++++--- .../pr-unblock/address-feedback.test.mjs | 67 ++++++++++++++++++- 3 files changed, 122 insertions(+), 10 deletions(-) create mode 100644 .changes/pr-pipeline/perf-feedback-rounds-graphql-3a9e5c21.md diff --git a/.changes/pr-pipeline/perf-feedback-rounds-graphql-3a9e5c21.md b/.changes/pr-pipeline/perf-feedback-rounds-graphql-3a9e5c21.md new file mode 100644 index 00000000000..a2037423d7a --- /dev/null +++ b/.changes/pr-pipeline/perf-feedback-rounds-graphql-3a9e5c21.md @@ -0,0 +1,7 @@ +--- +bump: patch +--- + +### Changed + +- pr-unblock's address-feedback select counts a PR's earlier model rounds from one GraphQL query instead of one check-runs listing per commit, so the read no longer grows with the PR's commit count. A commit whose check suites or runs run past a page, or a PR past 100 commits, is still read over REST, so no round is missed. diff --git a/.github/scripts/pr-unblock/address-feedback.mjs b/.github/scripts/pr-unblock/address-feedback.mjs index 610731e4741..cc5ff50f26e 100644 --- a/.github/scripts/pr-unblock/address-feedback.mjs +++ b/.github/scripts/pr-unblock/address-feedback.mjs @@ -1143,11 +1143,7 @@ const touchesProtected = (files) => files.length >= FILES_CAP || files.some((fil // The rounds the PR has had: round markers or model check runs on its // commits, whichever count more, and those check runs. async function roundsSoFar(api, pr, issueComments, appId) { - const commits = await api.listPullCommits(pr); - const checkRuns = []; - for (const commit of commits) { - checkRuns.push(await api.listCheckRuns(commit.sha, MODEL_CHECK)); - } + const checkRuns = await api.listModelRounds(pr, MODEL_CHECK); return { rounds: Math.max(countRounds(issueComments, appId), countCheckRounds(checkRuns)), checkRuns }; } @@ -1745,6 +1741,26 @@ const RESOLVE_MUTATION = `mutation($id: ID!) { resolveReviewThread(input: { threadId: $id }) { thread { isResolved } } }`; +const GITHUB_ACTIONS_APP_ID = 15368; +const ROUNDS_QUERY = `query($owner: String!, $name: String!, $pr: Int!, $check: String!) { + repository(owner: $owner, name: $name) { + pullRequest(number: $pr) { + commits(first: 100) { + pageInfo { hasNextPage } + nodes { + commit { + oid + checkSuites(first: 3, filterBy: { appId: ${GITHUB_ACTIONS_APP_ID} }) { + pageInfo { hasNextPage } + nodes { checkRuns(first: 10, filterBy: { checkName: $check, checkType: ALL }) { pageInfo { hasNextPage } nodes { name conclusion completedAt } } } + } + } + } + } + } + } +}`; + const THREADS_QUERY = `query($owner: String!, $name: String!, $pr: Int!, $after: String) { repository(owner: $owner, name: $name) { pullRequest(number: $pr) { @@ -1815,6 +1831,15 @@ export function createGitHubApi({ token, repository, apiUrl, graphqlUrl, fetch: return data.data; } const encodePath = (path) => path.split("/").map(encodeURIComponent).join("/"); + const checkRunsNamed = async (sha, check) => + (await requestData(`${repo}/commits/${sha}/check-runs?check_name=${encodeURIComponent(check)}&filter=all&per_page=100`)).check_runs ?? []; + const eachCommit = async (shas, check) => { + const runs = []; + for (const sha of shas) { + runs.push(await checkRunsNamed(sha, check)); + } + return runs; + }; return { getPull: async (pr) => requestData(`${repo}/pulls/${pr}`), // A GraphQL answer whole, errors kept for the caller to judge @@ -1845,6 +1870,24 @@ export function createGitHubApi({ token, repository, apiUrl, graphqlUrl, fetch: // Written or edited since `since` (GitHub's since query value) when given. listReviewComments: (pr, since) => paginate(`pulls/${pr}/comments${since === undefined ? "" : `?since=${encodeURIComponent(since)}`}`), listPullCommits: (pr) => paginate(`pulls/${pr}/commits`), + async listModelRounds(pr, check) { + const commits = (await graphql(ROUNDS_QUERY, { owner, name, pr, check })).repository.pullRequest.commits; + if (commits.pageInfo.hasNextPage) { + return eachCommit((await paginate(`pulls/${pr}/commits`)).map((commit) => commit.sha), check); + } + const runs = []; + for (const { commit } of commits.nodes) { + const suites = commit.checkSuites; + runs.push( + suites.pageInfo.hasNextPage || suites.nodes.some((suite) => suite.checkRuns.pageInfo.hasNextPage) + ? await checkRunsNamed(commit.oid, check) + : suites.nodes.flatMap((suite) => + suite.checkRuns.nodes.map((run) => ({ name: run.name, app: { slug: "github-actions" }, conclusion: String(run.conclusion ?? "").toLowerCase() || null, completed_at: run.completedAt })), + ), + ); + } + return runs; + }, // A commit's statuses, newest first (fix-ci-context.mjs weakenStopped). listCommitStatuses: (sha) => paginate(`commits/${sha}/statuses`), // A branch's repository activity, newest first, read by cursor to its end @@ -1858,10 +1901,7 @@ export function createGitHubApi({ token, repository, apiUrl, graphqlUrl, fetch: }; return branchActivity(read, `${owner}/${name}`, branch); }, - async listCheckRuns(sha, name) { - const url = `${repo}/commits/${sha}/check-runs?check_name=${encodeURIComponent(name)}&filter=all&per_page=100`; - return (await requestData(url)).check_runs ?? []; - }, + listCheckRuns: checkRunsNamed, // Every check run on a commit, re-runs and a contract-only run's skips // included (failingChecks prefers a real result over a skip), up to 300 // (fix-ci-context.mjs). diff --git a/.github/scripts/pr-unblock/address-feedback.test.mjs b/.github/scripts/pr-unblock/address-feedback.test.mjs index 00adaca5db2..a38f2b4b73f 100644 --- a/.github/scripts/pr-unblock/address-feedback.test.mjs +++ b/.github/scripts/pr-unblock/address-feedback.test.mjs @@ -78,6 +78,7 @@ function fakeApi(overrides = {}) { }, listPullCommits: async () => Object.keys(overrides.checks ?? { [HEAD]: [] }).map((sha) => ({ sha })), listCheckRuns: async (sha) => (overrides.checks ?? {})[sha] ?? [], + listModelRounds: async () => Object.values(overrides.checks ?? { [HEAD]: [] }), createIssueComment: async (pr, body) => posted.push({ pr, body }), }; } @@ -1777,7 +1778,7 @@ test("at the round cap a Codex finding is a bot finding: it gets the fresh fixer test("at the round cap a Codex finding goes to a person when the security-review lane held its head, and to a session when a person directed it", async () => { const held = codexAt(lanesMarked(securityMarked(), securityHold(HEAD))); - const heldResult = await codexRun({ ...held, listPullCommits: async () => Object.keys(modelRounds(2)).map((sha) => ({ sha })), listCheckRuns: async (sha) => modelRounds(2)[sha] ?? [] }, { maxRounds: 2 }); + const heldResult = await codexRun({ ...held, listPullCommits: async () => Object.keys(modelRounds(2)).map((sha) => ({ sha })), listCheckRuns: async (sha) => modelRounds(2)[sha] ?? [], listModelRounds: async () => Object.values(modelRounds(2)) }, { maxRounds: 2 }); assert.deepEqual([heldResult.decision, heldResult.escalationReason], ["escalate", "feedback-round-cap-security"]); // A write-access fix request older than the newest round directed it. const directed = await codexRun(fakeApi({ ...botThread({ replies: [[101, HUMAN, REQUEST]] }), checks: modelRounds(2) }), { maxRounds: 2 }); @@ -2887,3 +2888,67 @@ test("an ungated PR's kept thread and a workflow change escalate as before, with const result = await run(fakeApi({ files: [{ filename: ".github/workflows/ci.yml" }, { filename: "src/a.js" }], issueComments: [reviewMarker, asking(500)] })); assert.equal(result.escalationReason, "feedback-protected-path"); }); + +const roundsAnswer = (commits, { more = false } = {}) => ({ + data: { + repository: { + pullRequest: { + commits: { + pageInfo: { hasNextPage: more }, + nodes: commits.map(({ oid, runs = [], suitesMore = false, runsMore = false }) => ({ + commit: { oid, checkSuites: { pageInfo: { hasNextPage: suitesMore }, nodes: [{ checkRuns: { pageInfo: { hasNextPage: runsMore }, nodes: runs } }] } }, + })), + }, + }, + }, + }, +}); +const roundsApi = (answer, rest = {}) => { + const urls = []; + const fetch = async (url) => { + urls.push(url); + const data = url === "https://gql" ? answer : rest[url]; + return { ok: true, status: 200, json: async () => data, headers: { get: () => "" } }; + }; + return { urls, api: createGitHubApi({ token: "t", repository: "o/r", apiUrl: "https://api", graphqlUrl: "https://gql", fetch }) }; +}; +const restRuns = (sha) => `https://api/repos/o/r/commits/${sha}/check-runs?check_name=pr-unblock%20%2F%20address-feedback&filter=all&per_page=100`; + +test("listModelRounds reads every commit's model runs in one GraphQL query, in listCheckRuns' shape", async () => { + const { urls, api } = roundsApi( + roundsAnswer([ + { oid: "a".repeat(40), runs: [{ name: "pr-unblock / address-feedback", conclusion: "SUCCESS", completedAt: "2026-11-21T15:19:12Z" }, { name: "pr-unblock / address-feedback", conclusion: null, completedAt: null }] }, + { oid: "b".repeat(40) }, + ]), + ); + assert.deepEqual(await api.listModelRounds(17939, "pr-unblock / address-feedback"), [ + [ + { name: "pr-unblock / address-feedback", app: { slug: "github-actions" }, conclusion: "success", completed_at: "2026-11-21T15:19:12Z" }, + { name: "pr-unblock / address-feedback", app: { slug: "github-actions" }, conclusion: null, completed_at: null }, + ], + [], + ]); + assert.deepEqual(urls, ["https://gql"]); +}); + +test("listModelRounds reads a commit over REST when its suites or runs run past a page", async () => { + const [a, b, c] = ["a", "b", "c"].map((x) => x.repeat(40)); + const kept = { name: "pr-unblock / address-feedback", app: { slug: "github-actions" }, conclusion: "failure" }; + const { urls, api } = roundsApi(roundsAnswer([{ oid: a, suitesMore: true }, { oid: b, runsMore: true }, { oid: c }]), { + [restRuns(a)]: { check_runs: [kept] }, + [restRuns(b)]: { check_runs: [] }, + }); + assert.deepEqual(await api.listModelRounds(1, "pr-unblock / address-feedback"), [[kept], [], []]); + assert.deepEqual(urls, ["https://gql", restRuns(a), restRuns(b)]); +}); + +test("listModelRounds reads every commit over REST for a PR past 100 commits", async () => { + const shas = ["d", "e"].map((x) => x.repeat(40)); + const { urls, api } = roundsApi(roundsAnswer([], { more: true }), { + "https://api/repos/o/r/pulls/7/commits?per_page=100": shas.map((sha) => ({ sha })), + [restRuns(shas[0])]: { check_runs: [{ name: "x" }] }, + [restRuns(shas[1])]: { check_runs: [] }, + }); + assert.deepEqual(await api.listModelRounds(7, "pr-unblock / address-feedback"), [[{ name: "x" }], []]); + assert.deepEqual(urls, ["https://gql", "https://api/repos/o/r/pulls/7/commits?per_page=100", restRuns(shas[0]), restRuns(shas[1])]); +}); From 947780919a1bdce136e791a1a56fbbe49e1433be Mon Sep 17 00:00:00 2001 From: Kyle Sexton <153232337+kyle-sexton@users.noreply.github.com> Date: Sat, 21 Nov 2026 14:30:10 -0500 Subject: [PATCH 2/4] fix(pr-unblock): filter rounds' check suites by the check name claude-review was right: GitHub Actions makes one check suite per workflow run, so `first: 3` suites filtered only by app paged over on most commits and sent them back to REST, saving almost nothing. Live on 2026-11-21 the app-only filter truncated 10 of #17880's 59 commits, both of #17939's and all 5 of #17926's. The suites now also filter by checkName, so only suites holding the model run come back (at most 3 per commit on those PRs), at first: 5. GraphQL returns one suite once per attempt, so runs are deduped by databaseId. Verified on #17880, #17939 and #17926 (66 commits): 0 truncated, the run ids match REST check-runs per commit exactly, 6 GraphQL points a query. Co-authored-by: Claude Opus 5.5 --- .github/scripts/pr-unblock/address-feedback.mjs | 14 +++++++++----- .../scripts/pr-unblock/address-feedback.test.mjs | 12 ++++++------ 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/.github/scripts/pr-unblock/address-feedback.mjs b/.github/scripts/pr-unblock/address-feedback.mjs index cc5ff50f26e..048a0b5403c 100644 --- a/.github/scripts/pr-unblock/address-feedback.mjs +++ b/.github/scripts/pr-unblock/address-feedback.mjs @@ -1750,9 +1750,9 @@ const ROUNDS_QUERY = `query($owner: String!, $name: String!, $pr: Int!, $check: nodes { commit { oid - checkSuites(first: 3, filterBy: { appId: ${GITHUB_ACTIONS_APP_ID} }) { + checkSuites(first: 5, filterBy: { appId: ${GITHUB_ACTIONS_APP_ID}, checkName: $check }) { pageInfo { hasNextPage } - nodes { checkRuns(first: 10, filterBy: { checkName: $check, checkType: ALL }) { pageInfo { hasNextPage } nodes { name conclusion completedAt } } } + nodes { checkRuns(first: 10, filterBy: { checkName: $check, checkType: ALL }) { pageInfo { hasNextPage } nodes { databaseId name conclusion completedAt } } } } } } @@ -1881,9 +1881,13 @@ export function createGitHubApi({ token, repository, apiUrl, graphqlUrl, fetch: runs.push( suites.pageInfo.hasNextPage || suites.nodes.some((suite) => suite.checkRuns.pageInfo.hasNextPage) ? await checkRunsNamed(commit.oid, check) - : suites.nodes.flatMap((suite) => - suite.checkRuns.nodes.map((run) => ({ name: run.name, app: { slug: "github-actions" }, conclusion: String(run.conclusion ?? "").toLowerCase() || null, completed_at: run.completedAt })), - ), + : [...new Map(suites.nodes.flatMap((suite) => suite.checkRuns.nodes).map((run) => [run.databaseId, run])).values()].map((run) => ({ + id: run.databaseId, + name: run.name, + app: { slug: "github-actions" }, + conclusion: String(run.conclusion ?? "").toLowerCase() || null, + completed_at: run.completedAt, + })), ); } return runs; diff --git a/.github/scripts/pr-unblock/address-feedback.test.mjs b/.github/scripts/pr-unblock/address-feedback.test.mjs index a38f2b4b73f..3d432065357 100644 --- a/.github/scripts/pr-unblock/address-feedback.test.mjs +++ b/.github/scripts/pr-unblock/address-feedback.test.mjs @@ -2895,8 +2895,8 @@ const roundsAnswer = (commits, { more = false } = {}) => ({ pullRequest: { commits: { pageInfo: { hasNextPage: more }, - nodes: commits.map(({ oid, runs = [], suitesMore = false, runsMore = false }) => ({ - commit: { oid, checkSuites: { pageInfo: { hasNextPage: suitesMore }, nodes: [{ checkRuns: { pageInfo: { hasNextPage: runsMore }, nodes: runs } }] } }, + nodes: commits.map(({ oid, runs = [], suitesMore = false, runsMore = false, repeats = 1 }) => ({ + commit: { oid, checkSuites: { pageInfo: { hasNextPage: suitesMore }, nodes: Array.from({ length: repeats }, () => ({ checkRuns: { pageInfo: { hasNextPage: runsMore }, nodes: runs } })) } }, })), }, }, @@ -2914,17 +2914,17 @@ const roundsApi = (answer, rest = {}) => { }; const restRuns = (sha) => `https://api/repos/o/r/commits/${sha}/check-runs?check_name=pr-unblock%20%2F%20address-feedback&filter=all&per_page=100`; -test("listModelRounds reads every commit's model runs in one GraphQL query, in listCheckRuns' shape", async () => { +test("listModelRounds reads every commit's model runs in one GraphQL query, in listCheckRuns' shape, once each when a suite repeats", async () => { const { urls, api } = roundsApi( roundsAnswer([ - { oid: "a".repeat(40), runs: [{ name: "pr-unblock / address-feedback", conclusion: "SUCCESS", completedAt: "2026-11-21T15:19:12Z" }, { name: "pr-unblock / address-feedback", conclusion: null, completedAt: null }] }, + { oid: "a".repeat(40), runs: [{ databaseId: 1, name: "pr-unblock / address-feedback", conclusion: "SUCCESS", completedAt: "2026-11-21T15:19:12Z" }, { databaseId: 2, name: "pr-unblock / address-feedback", conclusion: null, completedAt: null }], repeats: 2 }, { oid: "b".repeat(40) }, ]), ); assert.deepEqual(await api.listModelRounds(17939, "pr-unblock / address-feedback"), [ [ - { name: "pr-unblock / address-feedback", app: { slug: "github-actions" }, conclusion: "success", completed_at: "2026-11-21T15:19:12Z" }, - { name: "pr-unblock / address-feedback", app: { slug: "github-actions" }, conclusion: null, completed_at: null }, + { id: 1, name: "pr-unblock / address-feedback", app: { slug: "github-actions" }, conclusion: "success", completed_at: "2026-11-21T15:19:12Z" }, + { id: 2, name: "pr-unblock / address-feedback", app: { slug: "github-actions" }, conclusion: null, completed_at: null }, ], [], ]); From ee817cdb52e31cf1fa8a58a094113aeac0f1db24 Mon Sep 17 00:00:00 2001 From: Kyle Sexton <153232337+kyle-sexton@users.noreply.github.com> Date: Sat, 21 Nov 2026 15:37:57 -0500 Subject: [PATCH 3/4] test(pr-unblock): read only the files address-feedback loads The Test Selection trace failed this suite on 658 undeclared reads of the whole tree. The planLanes test and the main select calls ran the real scripts/plan-test-lanes.sh over the live tree, and the staged-layout test copied every file of pr-unblock and lib. main takes the planner as a dependency and the tests pass a stub; planLanes runs against a fake planner in a temporary root; the staged layout copies only the import closure of address-feedback.mjs; the one read left, resolve-config's package.json, is declared. Local trace: 6,514 tree reads to 43, 0 gaps; the suite runs in under a second instead of 83 s. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01RAoAtVQsKbWdcHeEJeiY2U --- .../scripts/pr-unblock/address-feedback.mjs | 4 +- .../pr-unblock/address-feedback.test.mjs | 80 +++++++++++-------- 2 files changed, 48 insertions(+), 36 deletions(-) diff --git a/.github/scripts/pr-unblock/address-feedback.mjs b/.github/scripts/pr-unblock/address-feedback.mjs index 048a0b5403c..993777bd222 100644 --- a/.github/scripts/pr-unblock/address-feedback.mjs +++ b/.github/scripts/pr-unblock/address-feedback.mjs @@ -2210,7 +2210,7 @@ export function pullFromFile(path, pr, headSha) { } } -export async function main(argv, env, { api, actions, log = (line) => console.log(line) } = {}) { +export async function main(argv, env, { api, actions, plan, log = (line) => console.log(line) } = {}) { const command = argv[0]; need(env, ["GITHUB_TOKEN", "GITHUB_REPOSITORY", "GITHUB_OUTPUT", "PR_NUMBER", "HEAD_SHA", "APP_SENDER_ID"]); const pr = positive(env.PR_NUMBER, "PR_NUMBER"); @@ -2246,7 +2246,7 @@ export async function main(argv, env, { api, actions, log = (line) => console.lo humanGatedLabel: humanGatedLabelFrom(env.TRACKER_CONFIG || ".base/docs/conventions/work-items.yaml"), maxRounds: maxRoundsFrom(env.REVIEW_ROUNDS), adoption: await ownerAdoption(env, log), - ci: ({ headSha, files }) => ciSnapshot({ api: client, headSha, files }), + ci: ({ headSha, files }) => ciSnapshot({ api: client, headSha, files, plan }), earlierFailHeads, // Loaded only for such a round: it reads pr-verify's scripts. readFailNotes: async ({ heads, files }) => { diff --git a/.github/scripts/pr-unblock/address-feedback.test.mjs b/.github/scripts/pr-unblock/address-feedback.test.mjs index 3d432065357..17a3485a757 100644 --- a/.github/scripts/pr-unblock/address-feedback.test.mjs +++ b/.github/scripts/pr-unblock/address-feedback.test.mjs @@ -1,7 +1,8 @@ +// test-scope: .github/actions/resolve-config/package.json import assert from "node:assert/strict"; import { cpSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs"; import { tmpdir } from "node:os"; -import { dirname, join } from "node:path"; +import { dirname, join, relative, resolve } from "node:path"; import { test } from "node:test"; import { fileURLToPath, pathToFileURL } from "node:url"; @@ -20,6 +21,7 @@ const HUMAN = 153232337; const STRANGER = 4242; const HEAD = "a".repeat(40); const OLD_HEAD = "b".repeat(40); +const noPlan = () => ({}); const ROUND = ""; const marker = (lane, sha) => `\n${lane} has reviewed this pull request.`; const INJECTION = @@ -612,9 +614,9 @@ test("a thread read that fails throws, so main writes no outputs and resolves no writeFileSync(actors, JSON.stringify({ actors: [{ id: REVIEWER, login: "claude[bot]", kind: "bot" }] })); const env = { GITHUB_TOKEN: "t", GITHUB_REPOSITORY: "o/r", GITHUB_OUTPUT: join(dir, "out"), PR_NUMBER: "42", HEAD_SHA: HEAD, APP_SENDER_ID: String(APP), THREAD_FILE: join(dir, "t.json"), RUN_FILE: join(dir, "r.json"), TRUSTED_ACTORS: actors }; const broken = { ...fakeApi(), listThreads: async () => Promise.reject(new Error("GraphQL: timeout")) }; - await assert.rejects(main(["select"], env, { api: broken, log: () => {} }), /timeout/); + await assert.rejects(main(["select"], env, { plan: noPlan, api: broken, log: () => {} }), /timeout/); assert.throws(() => readFileSync(env.GITHUB_OUTPUT, "utf8")); - await main(["select"], { ...env, GITHUB_OUTPUT: join(dir, "resolved") }, { api: fakeApi({ threads: [] }), log: () => {} }); + await main(["select"], { ...env, GITHUB_OUTPUT: join(dir, "resolved") }, { plan: noPlan, api: fakeApi({ threads: [] }), log: () => {} }); assert.match(readFileSync(join(dir, "resolved"), "utf8"), /^skip-reason=stop-resolved\n(?:.*\n)*stop-resolved=true$/m); }); @@ -1164,7 +1166,7 @@ test("main select writes outputs and the thread file; escalation writes no threa RUN_FILE: join(dir, `${name}.run.json`), TRUSTED_ACTORS: actors, }); - await main(["select"], env("ok"), { api: fakeApi(), log: () => {} }); + await main(["select"], env("ok"), { plan: noPlan, api: fakeApi(), log: () => {} }); assert.equal(readFileSync(join(dir, "ok.out"), "utf8"), "proceed=true\nhuman-gate=\nmodel-rung=\nskip-reason=\nescalation-reason=\nnot-run-detail=\nstop-resolved=false\nperson-opened=false\n"); const okFile = JSON.parse(readFileSync(join(dir, "ok.json"), "utf8")); assert.equal(okFile.threads[0].id, "PRRT_1"); @@ -1180,7 +1182,7 @@ test("main select writes outputs and the thread file; escalation writes no threa ); // The people on the list come from TRUSTED_ACTORS. - await main(["select"], env("decided"), { api: fakeApi(escalated()), log: () => {} }); + await main(["select"], env("decided"), { plan: noPlan, api: fakeApi(escalated()), log: () => {} }); assert.equal(readFileSync(join(dir, "decided.out"), "utf8"), "proceed=true\nhuman-gate=\nmodel-rung=\nskip-reason=\nescalation-reason=\nnot-run-detail=\nstop-resolved=false\nperson-opened=false\n"); assert.equal(JSON.parse(readFileSync(join(dir, "decided.json"), "utf8")).threads[0].comments[2].direction, true); @@ -1188,13 +1190,13 @@ test("main select writes outputs and the thread file; escalation writes no threa const tracker = join(dir, "tracker.json"); writeFileSync(tracker, JSON.stringify({ config: { role_labels: { "human-gated": "status: blocked-human" } } })); const gatedEnv = { ...env("gated"), TRACKER_CONFIG: tracker }; - await main(["select"], gatedEnv, { api: fakeApi({ ...escalated({ replies: [[102, HUMAN, REQUEST]] }), labels: ["status: blocked-human"] }), log: () => {} }); + await main(["select"], gatedEnv, { plan: noPlan, api: fakeApi({ ...escalated({ replies: [[102, HUMAN, REQUEST]] }), labels: ["status: blocked-human"] }), log: () => {} }); assert.equal(readFileSync(join(dir, "gated.out"), "utf8"), "proceed=true\nhuman-gate=fix-request\nmodel-rung=\nskip-reason=\nescalation-reason=\nnot-run-detail=\nstop-resolved=false\nperson-opened=false\n"); const heldEnv = { ...env("held"), TRACKER_CONFIG: tracker }; - await main(["select"], heldEnv, { api: fakeApi({ ...escalated(), labels: ["status: blocked-human"] }), log: () => {} }); + await main(["select"], heldEnv, { plan: noPlan, api: fakeApi({ ...escalated(), labels: ["status: blocked-human"] }), log: () => {} }); assert.equal(readFileSync(join(dir, "held.out"), "utf8"), "proceed=false\nhuman-gate=\nmodel-rung=\nskip-reason=awaiting-human\nescalation-reason=\nnot-run-detail=\nstop-resolved=false\nperson-opened=false\n"); - await main(["select"], env("esc"), { api: fakeApi({ files: [{ filename: ".github/workflows/x.yml" }] }), log: () => {} }); + await main(["select"], env("esc"), { plan: noPlan, api: fakeApi({ files: [{ filename: ".github/workflows/x.yml" }] }), log: () => {} }); assert.equal( readFileSync(join(dir, "esc.out"), "utf8"), "proceed=false\nhuman-gate=\nmodel-rung=\nskip-reason=lane-stopped\nescalation-reason=feedback-protected-path\nnot-run-detail=\nstop-resolved=false\nperson-opened=false\n", @@ -1212,7 +1214,7 @@ test("main select writes outputs and the thread file; escalation writes no threa ...[1, 2].map((n) => ({ id: 10 + n, user: { id: APP }, body: `${ROUND}\nround ${n}`, created_at: at(10) })), ], }); - await main(["select"], { ...env("bound"), REVIEW_ROUNDS: "1" }, { api: bound, log: () => {} }); + await main(["select"], { ...env("bound"), REVIEW_ROUNDS: "1" }, { plan: noPlan, api: bound, log: () => {} }); assert.equal( readFileSync(join(dir, "bound.out"), "utf8"), "proceed=false\nhuman-gate=\nmodel-rung=\nskip-reason=lane-stopped\nescalation-reason=feedback-not-converging\nnot-run-detail=round 2 of max 2\nstop-resolved=false\nperson-opened=false\n", @@ -1245,7 +1247,7 @@ test("main select takes the head step's PR read for this PR and head, and reads const go = async (name, path) => { const api = counted(); const env = { GITHUB_TOKEN: "t", GITHUB_REPOSITORY: "o/r", GITHUB_OUTPUT: join(dir, `${name}.out`), PR_NUMBER: "42", HEAD_SHA: HEAD, APP_SENDER_ID: String(APP), THREAD_FILE: join(dir, `${name}.json`), RUN_FILE: join(dir, `${name}.run.json`), TRUSTED_ACTORS: actors, ...(path === undefined ? {} : { PULL_FILE: path }) }; - await main(["select"], env, { api, log: () => {} }); + await main(["select"], env, { plan: noPlan, api, log: () => {} }); return { reads: api.pullReads, out: readFileSync(join(dir, `${name}.out`), "utf8") }; }; const same = { number: 42, head: { sha: HEAD }, user: { id: APP, type: "Bot" }, labels: [], body: "" }; @@ -1278,7 +1280,7 @@ test("main select takes the head step's PR read for this PR and head, and reads writeFileSync(tracker, JSON.stringify({ config: { role_labels: { "human-gated": "status: blocked-human" } } })); const api = counted(); const held = join(dir, "held.out"); - await main(["select"], { GITHUB_TOKEN: "t", GITHUB_REPOSITORY: "o/r", GITHUB_OUTPUT: held, PR_NUMBER: "42", HEAD_SHA: HEAD, APP_SENDER_ID: String(APP), THREAD_FILE: join(dir, "held.json"), RUN_FILE: join(dir, "held.run.json"), TRUSTED_ACTORS: actors, TRACKER_CONFIG: tracker, PULL_FILE: pullFile("held", { ...same, labels: [{ name: "status: blocked-human" }] }) }, { api, log: () => {} }); + await main(["select"], { GITHUB_TOKEN: "t", GITHUB_REPOSITORY: "o/r", GITHUB_OUTPUT: held, PR_NUMBER: "42", HEAD_SHA: HEAD, APP_SENDER_ID: String(APP), THREAD_FILE: join(dir, "held.json"), RUN_FILE: join(dir, "held.run.json"), TRUSTED_ACTORS: actors, TRACKER_CONFIG: tracker, PULL_FILE: pullFile("held", { ...same, labels: [{ name: "status: blocked-human" }] }) }, { plan: noPlan, api, log: () => {} }); assert.equal(api.pullReads, 0); assert.match(readFileSync(held, "utf8"), /^skip-reason=awaiting-human$/m); }); @@ -1294,7 +1296,7 @@ test("main select needs RUN_FILE beside THREAD_FILE, and no LANE_BRANCH", async THREAD_FILE: join(tmpdir(), "unused.json"), TRUSTED_ACTORS: join(tmpdir(), "unused-actors.json"), }; - await assert.rejects(main(["select"], env, { api: fakeApi() }), /RUN_FILE is not set/); + await assert.rejects(main(["select"], env, { plan: noPlan, api: fakeApi() }), /RUN_FILE is not set/); }); test("run.json carries each kept thread's named_paths and no comment body", () => { @@ -1321,8 +1323,8 @@ test("main refuses bad inputs and any subcommand but select", async () => { APP_SENDER_ID: String(APP), }; const api = fakeApi(); - await assert.rejects(main(["select"], { ...env, HEAD_SHA: "x" }, { api }), /HEAD_SHA/); - await assert.rejects(main(["select"], { ...env, PR_NUMBER: "0" }, { api }), /PR_NUMBER/); + await assert.rejects(main(["select"], { ...env, HEAD_SHA: "x" }, { plan: noPlan, api }), /HEAD_SHA/); + await assert.rejects(main(["select"], { ...env, PR_NUMBER: "0" }, { plan: noPlan, api }), /PR_NUMBER/); await assert.rejects(main(["record-round"], env, { api }), /usage/); assert.equal(api.posted.length, 0); }); @@ -1390,10 +1392,18 @@ test("listActivity rejects when a later page answers an error, never returning t test("listActivity loads its cursor reader from the staged layout a script activity runs in", async () => { const root = tempDir("base-activity-"); try { - cpSync(dirname(fileURLToPath(import.meta.url)), join(root, "base-script"), { recursive: true }); - cpSync(fileURLToPath(new URL("../lib", import.meta.url)), join(root, "lib"), { recursive: true }); - mkdirSync(join(root, "pr-merge")); - cpSync(fileURLToPath(new URL("../pr-merge/merge-holds.mjs", import.meta.url)), join(root, "pr-merge", "merge-holds.mjs")); + const scripts = fileURLToPath(new URL("../", import.meta.url)); + const dest = (file) => join(root, relative(scripts, file).replace(/^pr-unblock\//, "base-script/")); + const seen = new Set(); + const stage = (file) => { + if (seen.has(file) || !file.startsWith(scripts) || !existsSync(file)) return; + seen.add(file); + mkdirSync(dirname(dest(file)), { recursive: true }); + cpSync(file, dest(file)); + if (!file.endsWith(".mjs")) return; + for (const [, spec] of readFileSync(file, "utf8").matchAll(/(?:from |import\(|new URL\()"(\.\.?\/[^"]+)"/g)) stage(resolve(dirname(file), spec)); + }; + stage(fileURLToPath(new URL("./address-feedback.mjs", import.meta.url))); const { createGitHubApi: staged } = await import(pathToFileURL(join(root, "base-script", "address-feedback.mjs")).href); const api = staged({ token: "tok", repository: "o/r", apiUrl: "https://api", graphqlUrl: "https://gql", fetch: activityFetch([rows(100), rows(1)]) }); assert.equal((await api.listActivity("b")).length, 101); @@ -2287,7 +2297,7 @@ test("main select takes the FAILed heads only from a dispatcher's model round, a ["self", { VERIFY_EARLIER_FAIL_HEADS: HEAD }], ["twice", { VERIFY_EARLIER_FAIL_HEADS: `${OLD_HEAD} ${OLD_HEAD}` }], ]) { - await assert.rejects(main(["select"], env(name, extra), { api: fakeApi(), log: () => {} }), /VERIFY_EARLIER_FAIL_HEADS|earlier FAILed heads/, name); + await assert.rejects(main(["select"], env(name, extra), { plan: noPlan, api: fakeApi(), log: () => {} }), /VERIFY_EARLIER_FAIL_HEADS|earlier FAILed heads/, name); } assert.deepEqual(earlierFailHeadsFrom({ VERIFY_EARLIER_FAIL_HEADS: "" }), []); assert.deepEqual(earlierFailHeadsFrom({ HEAD_SHA: HEAD, DISPATCHER_RUN_ID: "1", VERIFY_EARLIER_FAIL_HEADS: `${OLD_HEAD} ${"c".repeat(40)}` }), [OLD_HEAD, "c".repeat(40)]); @@ -2322,31 +2332,31 @@ test("main select with a pass head lists the stale fail-note threads for the rep const api = (threads) => ({ listThreads: async () => threads }); const out = (name) => (existsSync(join(dir, `${name}.out`)) ? readFileSync(join(dir, `${name}.out`), "utf8") : ""); - await main(["select"], env("pass"), { api: api([note("PRRT_old"), note("PRRT_now", HEAD), note("PRRT_done", OLD, true)]), log: () => {} }); + await main(["select"], env("pass"), { plan: noPlan, api: api([note("PRRT_old"), note("PRRT_now", HEAD), note("PRRT_done", OLD, true)]), log: () => {} }); assert.equal(out("pass"), "resolve-only=true\n"); assert.equal(readFileSync(join(dir, "pass.run.json"), "utf8"), `{"version":1,"head_sha":"${HEAD}","pr_paths":[],"threads":[],"stale_notes":["PRRT_old"]}\n`); assert.deepEqual(JSON.parse(readFileSync(join(dir, "pass.json"), "utf8")).threads, []); // The PR moved past the passing head: nothing to do, and no output, so // neither a model job nor a neutral check runs. - await main(["select"], env("moved", { VERIFY_PASS_HEAD: "c".repeat(40) }), { api: api([note("PRRT_old")]), log: () => {} }); + await main(["select"], env("moved", { VERIFY_PASS_HEAD: "c".repeat(40) }), { plan: noPlan, api: api([note("PRRT_old")]), log: () => {} }); assert.equal(out("moved"), ""); // Only a dispatcher sends a pass head. - await assert.rejects(main(["select"], env("human", { DISPATCHER_RUN_ID: "" }), { api: api([note("PRRT_old")]), log: () => {} }), /dispatcher/); - await assert.rejects(main(["select"], env("bad", { VERIFY_PASS_HEAD: "main" }), { api: api([note("PRRT_old")]), log: () => {} }), /VERIFY_PASS_HEAD/); + await assert.rejects(main(["select"], env("human", { DISPATCHER_RUN_ID: "" }), { plan: noPlan, api: api([note("PRRT_old")]), log: () => {} }), /dispatcher/); + await assert.rejects(main(["select"], env("bad", { VERIFY_PASS_HEAD: "main" }), { plan: noPlan, api: api([note("PRRT_old")]), log: () => {} }), /VERIFY_PASS_HEAD/); // A same-head FAIL the gate's reader found superseded (the dispatcher's // verify-superseded-head) adds its notes, and run.json names that head for // the reply job's re-check; a FAIL not superseded there, or one superseded // at another head, adds none. const threads = [note("PRRT_old"), note("PRRT_now", HEAD), note("PRRT_done", OLD, true)]; - await main(["select"], env("superseded", { VERIFY_SUPERSEDED_HEAD: HEAD }), { api: api(threads), log: () => {} }); + await main(["select"], env("superseded", { VERIFY_SUPERSEDED_HEAD: HEAD }), { plan: noPlan, api: api(threads), log: () => {} }); assert.equal(out("superseded"), "resolve-only=true\n"); assert.equal(readFileSync(join(dir, "superseded.run.json"), "utf8"), `{"version":1,"head_sha":"${HEAD}","pr_paths":[],"threads":[],"stale_notes":["PRRT_old","PRRT_now"],"superseded_head":"${HEAD}"}\n`); - await main(["select"], env("elsewhere", { VERIFY_SUPERSEDED_HEAD: OLD }), { api: api(threads), log: () => {} }); + await main(["select"], env("elsewhere", { VERIFY_SUPERSEDED_HEAD: OLD }), { plan: noPlan, api: api(threads), log: () => {} }); assert.equal(readFileSync(join(dir, "elsewhere.run.json"), "utf8"), `{"version":1,"head_sha":"${HEAD}","pr_paths":[],"threads":[],"stale_notes":["PRRT_old"]}\n`); - await assert.rejects(main(["select"], env("bad-superseded", { VERIFY_SUPERSEDED_HEAD: "main" }), { api: api(threads), log: () => {} }), /VERIFY_SUPERSEDED_HEAD/); + await assert.rejects(main(["select"], env("bad-superseded", { VERIFY_SUPERSEDED_HEAD: "main" }), { plan: noPlan, api: api(threads), log: () => {} }), /VERIFY_SUPERSEDED_HEAD/); }); // A rerun of a pass-only round after its stale notes were resolved by hand @@ -2371,7 +2381,7 @@ async function passOnlyWithoutStale(t, api) { VERIFY_PASS_HEAD: HEAD, DISPATCHER_RUN_ID: "5000", }; - await main(["select"], env, { api, log: () => {} }); + await main(["select"], env, { plan: noPlan, api, log: () => {} }); assert.equal(existsSync(env.RUN_FILE), false); return existsSync(env.GITHUB_OUTPUT) ? readFileSync(env.GITHUB_OUTPUT, "utf8") : ""; } @@ -2591,11 +2601,13 @@ test("ciSnapshot plans from every changed path, rename sources included", async assert.deepEqual(seen, [".github/workflows/x.yml", "docs/new.md", "docs/old.md"]); }); -const PLAN_SCRIPT = new URL("../../../scripts/plan-test-lanes.sh", import.meta.url); -test("planLanes runs the repository's scripts/plan-test-lanes.sh over the paths", { skip: !existsSync(PLAN_SCRIPT) && "no scripts/plan-test-lanes.sh in this repository" }, () => { - const plan = planLanes(["scripts/plan-test-lanes.sh"]); - assert.equal(plan.bash, "true"); - assert.ok(coveringLanes(plan).includes("test-bash (0)")); +test("planLanes runs the root's scripts/plan-test-lanes.sh over the paths and reads its key=value lines", () => { + const root = tempDir("address-feedback-plan-"); + mkdirSync(join(root, "scripts")); + writeFileSync(join(root, "scripts", "plan-test-lanes.sh"), '[ "$1 $2" = "-- a.sh" ] || exit 1\necho "plan for $2"\necho bash=true\necho \'bash_legs=[0]\'\n'); + const plan = planLanes(["a.sh"], root); + assert.deepEqual(plan, { bash: "true", bash_legs: "[0]" }); + assert.deepEqual(coveringLanes(plan), ["test-bash (0)"]); }); test("select records the ci snapshot for run.json; with no snapshot function it records none", async () => { @@ -2766,7 +2778,7 @@ test("main select writes the offered sections to the thread file unless pr_body_ writeFileSync(pull, JSON.stringify({ number: 42, head: { sha: HEAD }, user: { id: APP, type: "Bot" }, labels: [], body: REFRESH_BODY })); const go = async (name, extra) => { const env = { GITHUB_TOKEN: "t", GITHUB_REPOSITORY: "o/r", GITHUB_OUTPUT: join(dir, `${name}.out`), PR_NUMBER: "42", HEAD_SHA: HEAD, APP_SENDER_ID: String(APP), THREAD_FILE: join(dir, `${name}.json`), RUN_FILE: join(dir, `${name}.run.json`), TRUSTED_ACTORS: actors, PULL_FILE: pull, ...extra }; - await main(["select"], env, { api: fakeApi(), log: () => {} }); + await main(["select"], env, { plan: noPlan, api: fakeApi(), log: () => {} }); return [JSON.parse(readFileSync(env.THREAD_FILE, "utf8")), JSON.parse(readFileSync(env.RUN_FILE, "utf8"))]; }; const [threads, run] = await go("on", { BODY_SECTIONS: "Verification" }); @@ -2791,7 +2803,7 @@ test("main select shows every ## section in body_view, a Summary over the refres writeFileSync(pull, JSON.stringify({ number: 42, head: { sha: HEAD }, user: { id: APP, type: "Bot" }, labels: [], body })); const go = async (name, extra) => { const env = { GITHUB_TOKEN: "t", GITHUB_REPOSITORY: "o/r", GITHUB_OUTPUT: join(dir, `${name}.out`), PR_NUMBER: "42", HEAD_SHA: HEAD, APP_SENDER_ID: String(APP), THREAD_FILE: join(dir, `${name}.json`), RUN_FILE: join(dir, `${name}.run.json`), TRUSTED_ACTORS: actors, PULL_FILE: pull, ...extra }; - await main(["select"], env, { api: fakeApi(), log: () => {} }); + await main(["select"], env, { plan: noPlan, api: fakeApi(), log: () => {} }); return [JSON.parse(readFileSync(env.THREAD_FILE, "utf8")), JSON.parse(readFileSync(env.RUN_FILE, "utf8"))]; }; const [threads, run] = await go("on", {}); From 91797a1062e711726b3f1f5c423d73146d99c4c9 Mon Sep 17 00:00:00 2001 From: Kyle Sexton <153232337+kyle-sexton@users.noreply.github.com> Date: Sat, 21 Nov 2026 15:42:36 -0500 Subject: [PATCH 4/4] test(pr-unblock): tie planLanes to the planner's output lines The planLanes test now runs a fake planner, so nothing checked that scripts/plan-test-lanes.sh still prints the lines planLanes parses. The new test reads the planner and matches its =true/false, _legs and windows_jobs lines, without running it over the tree; a change to the planner selects this suite. Changing `%s_legs=[%s]` to `%s_legs=%s` fails it. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01RAoAtVQsKbWdcHeEJeiY2U --- .github/scripts/pr-unblock/address-feedback.test.mjs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/scripts/pr-unblock/address-feedback.test.mjs b/.github/scripts/pr-unblock/address-feedback.test.mjs index 17a3485a757..091339cf72d 100644 --- a/.github/scripts/pr-unblock/address-feedback.test.mjs +++ b/.github/scripts/pr-unblock/address-feedback.test.mjs @@ -2610,6 +2610,13 @@ test("planLanes runs the root's scripts/plan-test-lanes.sh over the paths and re assert.deepEqual(coveringLanes(plan), ["test-bash (0)"]); }); +test("scripts/plan-test-lanes.sh still prints the , _legs and windows_jobs lines planLanes reads", () => { + const planner = readFileSync(new URL("../../../scripts/plan-test-lanes.sh", import.meta.url), "utf8"); + assert.match(planner, /printf "%s=true\\n%s_legs=\[%s\]\\n/); + assert.match(planner, /printf "%s=false\\n%s_legs=\[0\]\\n/); + assert.match(planner, /echo "windows_jobs=\$\(json_on /); +}); + test("select records the ci snapshot for run.json; with no snapshot function it records none", async () => { let asked; const ci = { state: "green", runs: [{ name: "Test Node", url: "https://github.com/o/r/actions/runs/1/job/3" }] };