From 83d60eab0e4883031d92a38a089bd4ec9b22a037 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Wed, 18 Nov 2026 23:44:15 -0800 Subject: [PATCH 1/3] chore(quest): claim quest/m0/fork-review-record.md Quest-Claim: 3fd337f7fe52354d From f7b15eef69fcfd8d94f717dcd85651fd463adf6c Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Wed, 18 Nov 2026 23:47:05 -0800 Subject: [PATCH 2/3] fix(review): record on a contributor's fork PR from a maintainer's checkout quest review now takes the open PR from the reviewed branch into the base from any head repository, preferring the push repository's, and skips naming every candidate when several forks match. Co-Authored-By: Claude Opus 5.5 --- README.md | 6 +++-- quest/m0/fork-review-record.md | 33 -------------------------- src/cli/main.ts | 4 ++-- src/cli/review-record.ts | 20 +++++++++++----- test/review.test.ts | 42 ++++++++++++++++++++++++++++++---- 5 files changed, 58 insertions(+), 47 deletions(-) delete mode 100644 quest/m0/fork-review-record.md diff --git a/README.md b/README.md index cef4502f..0e132f4a 100644 --- a/README.md +++ b/README.md @@ -1628,8 +1628,10 @@ branch's rounds, `risk`, the head's tier with its classification, `record`, and `next`. After each round, `quest review` rewrites the `## Review` section of the open PR -from the branch into the base, found among the upstream's PRs from the -repository the base's remote pushes to, and prints `record `. The record +from the branch into the base, found among the upstream's PRs: the one from +the repository the base's remote pushes to, else the only one from any +repository, as in a maintainer's checkout of a contributor's fork PR. It +prints `record `. The record names the reviewed head and the base's short SHA, the head's risk tier and who classified it, then for each reviewer its harness, model, and effort, its Reviewer line ending in `, shadow` for the diff --git a/quest/m0/fork-review-record.md b/quest/m0/fork-review-record.md deleted file mode 100644 index 8a3ad3be..00000000 --- a/quest/m0/fork-review-record.md +++ /dev/null @@ -1,33 +0,0 @@ -# [S] quest review records on a contributor's fork PR - -## Goal - -`quest review` in a maintainer's checkout of a contributor's fork PR finds -that PR, reads its `## Models` size, and writes its `## Review` record, so -nobody writes one by hand. Contributors reviewing in their own fork's clone -keep working as today. - -## Plan - -Decided 2026-11-17 (maintainer, `/quest-plan` after `/quest-run`): ✅ m0 -(rejected: m1), since every fork PR's local review now needs a hand-written -record that `/quest-merge` then trusts; ✅ fix the lookup (rejected: a -`--pr ` flag; dropping it). - -- Cause: `openPull` in `src/cli/review-record.ts` matches only an open PR - whose head repository is the one the base's remote pushes to. In a - maintainer's checkout that is the upstream, not the contributor's fork, so - it prints `record skipped: no open PR from ...`, and `pullModels` returns - null, so the round runs at the default size. Both iterates on - [#761](https://github.com/moq-dev/quest/pull/761) hit this: they reviewed - at size M instead of the body's S and wrote the record by hand. -- Those iterates worked in a detached checkout with `--branch` and pushed to - the fork by URL, so the checkout has no push remote naming the fork, and - the reviewed head is not pushed yet when the round ends. -- Recommended: match the open PR into the base whose head branch is the - reviewed branch, from any head repository; prefer the push repository's - when several match, and skip naming every candidate when the choice is - still ambiguous. -- Test: a stub forge with an open PR from `contributor/quest:` - into the upstream gets its record rewritten and its size read from a - maintainer's checkout whose remote is the upstream. diff --git a/src/cli/main.ts b/src/cli/main.ts index 98ea3b2c..ef0e9164 100644 --- a/src/cli/main.ts +++ b/src/cli/main.ts @@ -1707,12 +1707,12 @@ export function main(argv: string[], out: Output): number | Promise { "with the best long-term approach worked out from first principles before fixing them, `next respond` to fix or refute the findings, or `next done`. A reply without a valid score " + "fails as any malformed reply does. --json prints " + "one object: `rounds`, one per reviewer, `tallies`, every reviewer's findings across the branch's rounds, `risk`, the head's tier with its classification, `skipped`, each reviewer passed over with its reason, `record`, and `next`.\n\n" + - "After each round, it rewrites the `## Review` section of the branch's open PR into the base, as the " + + "After each round, it rewrites the `## Review` section of the branch's open PR into the base, the one from the repository the base's remote pushes to, else the only one from any repository, as the " + "user the GitHub token names, keeping the rest of the body, and prints `record `: the reviewed " + "head, named in full only once no reviewer reports a finding, the base, the head's risk tier and reason, " + "the classifier's tier and who set it, a `- Skipped:` line for each reviewer passed over, and each reviewer, its Reviewer line ending in `, shadow` for the shadow, its " + "session and round, score, the tier it raised the risk to and why, its tally of findings across the branch's rounds, and each finding with its disposition. With no " + - "such PR, or a remote off GitHub, it prints `record skipped: ` and changes nothing.\n\n" + + "such PR, several from other repositories, or a remote off GitHub, it prints `record skipped: ` and changes nothing.\n\n" + "Exits 0 once the round finishes, whatever it found, 2 for invalid arguments " + "or a checkout that cannot be reviewed, 3 when no eligible reviewer could run, each not installed, logged " + "out, its login rejected, or at its usage limit, and 1 for other failures, including a PR GitHub will not show or a record it " + diff --git a/src/cli/review-record.ts b/src/cli/review-record.ts index 30e5bf03..718678ad 100644 --- a/src/cli/review-record.ts +++ b/src/cli/review-record.ts @@ -296,9 +296,9 @@ export function withReview(body: string, record: string): string { export type Recorded = { url: string } | { skipped: string }; /** - * The open PR from `branch` into the base `/` names, found among the upstream's PRs from the - * repository the base's remote pushes to, as claims find a branch's PR; or why there is none. It reads the forge - * itself, never an index that may lag, since its body is rewritten. + * The open PR from `branch` into the base `/` names, or why there is none: the one from the repository + * the base's remote pushes to, else the only one from any repository, as a maintainer's checkout of a contributor's + * fork PR finds it. It reads the forge itself, never an index that may lag, since its body is rewritten. */ async function openPull( root: string, @@ -314,10 +314,18 @@ async function openPull( if (hosting === null) return { skipped: `${remote} is not on GitHub or Kixel Quest` }; const { repository, head } = hosting; const name = `${head.owner}/${head.repo}`.toLowerCase(); - const pull = pullsFrom((await hosting.live().pulls(repository)).value, branch).find( - (each) => each.base === base && each.head?.toLowerCase() === name, + const candidates = pullsFrom((await hosting.live().pulls(repository)).value, branch).filter( + (each) => each.base === base, ); - if (pull === undefined) return { skipped: `no open PR from ${head.owner}:${branch} into ${base}` }; + const own = candidates.find((each) => each.head?.toLowerCase() === name); + const pull = own ?? (candidates.length === 1 ? candidates[0] : undefined); + if (pull === undefined) + return { + skipped: + candidates.length === 0 + ? `no open PR from ${branch} into ${base}` + : `several open PRs from ${branch} into ${base}, none from ${head.owner}: ${candidates.map((each) => each.url).join(", ")}`, + }; return { url: pull.url, body: pull.body, diff --git a/test/review.test.ts b/test/review.test.ts index 34ac31bd..a74db2da 100644 --- a/test/review.test.ts +++ b/test/review.test.ts @@ -1093,7 +1093,8 @@ fakes("a change to the applicable instructions starts a new session that weighs * `upstream/widget`, whose root holds the quest tree, and the PRs are upstream's. Returns the PR bodies * each PATCH wrote. */ -type FakePull = { number: number; body: string | null }; +/** An open PR from `feature` into `main`, from `acme/widget` unless `head` names another repository. */ +type FakePull = { number: number; body: string | null; head?: string }; function onGitHub(repo: string, pulls: FakePull[], fork = false): { body: string }[] { const local = git(repo, "remote", "get-url", "origin"); git(repo, "remote", "set-url", "origin", "https://github.com/acme/widget.git"); @@ -1119,10 +1120,10 @@ function onGitHub(repo: string, pulls: FakePull[], fork = false): { body: string return url.pathname.endsWith("/contents/quest/README.md") ? json({}) : json({}, 404); if (url.pathname === `/repos/${owner}/widget/pulls`) { expect(url.searchParams.get("state")).toBe("open"); - const row = (p: FakePull, ref: string, base: string) => ({ + const row = ({ head, ...p }: FakePull, ref: string, base: string) => ({ ...p, html_url: `https://github.com/${owner}/widget/pull/${p.number}`, - head: { ref, repo: { full_name: "acme/widget" } }, + head: { ref, repo: { full_name: head ?? "acme/widget" } }, base: { ref: base }, draft: false, created_at: "2026-10-01T00:00:00Z", @@ -1548,7 +1549,7 @@ fakes("a branch with no open PR, or a body without a Review section, is reported try { const none = await quest("--root", s.repo, "review"); expect(none.code).toBe(0); - expect(none.stdout).toContain("record skipped: no open PR from acme:feature into main\n"); + expect(none.stdout).toContain("record skipped: no open PR from feature into main\n"); pulls.push({ number: 8, body: null }); vi.stubEnv("FAKE_REPLY", JSON.stringify({ score: 10, rationale: "Lands as is.", findings: [] })); @@ -1565,6 +1566,39 @@ fakes("a branch with no open PR, or a body without a Review section, is reported } }); +fakes("a maintainer's checkout records on a contributor's fork PR and reads its size", async () => { + const s = setup(); + const pull = { number: 12, body: "Body.\n\n## Models\n\n- Size: S\n", head: "contributor/widget" }; + const pulls: FakePull[] = [pull]; + onGitHub(s.repo, pulls); + vi.stubEnv("FAKE_REPLY", JSON.stringify({ score: 10, rationale: "Lands as is.", findings: [] })); + try { + const result = await quest("--root", s.repo, "review"); + expect(result.code, result.stderr).toBe(0); + expect(result.stdout).toContain("record https://github.com/acme/widget/pull/12\n"); + // Size S picks the shadow one effort below medium. + expect(result.stdout).toContain(" low shadow\n"); + expect(pull.body).toMatch(/^Body\.\n\n## Models\n\n- Size: S\n\n## Review\n\nRewritten by `quest review`/); + + // A second contributor's PR from a branch of the same name leaves no way to tell them apart. + pulls.push({ number: 13, body: "Other.", head: "someone/widget" }); + const ambiguous = await quest("--root", s.repo, "review", "--size", "S"); + expect(ambiguous.code, ambiguous.stderr).toBe(0); + expect(ambiguous.stdout).toContain( + "record skipped: several open PRs from feature into main, none from acme: https://github.com/acme/widget/pull/12, https://github.com/acme/widget/pull/13\n", + ); + expect(pulls[1]!.body).toBe("Other."); + + // The push repository's own PR wins over any fork's. + pulls.push({ number: 14, body: "Own." }); + const own = await quest("--root", s.repo, "review", "--size", "S"); + expect(own.stdout).toContain("record https://github.com/acme/widget/pull/14\n"); + expect(pulls[1]!.body).toBe("Other."); + } finally { + vi.unstubAllGlobals(); + } +}); + fakes("a review from a subdirectory of a fork records on the upstream PR", async () => { const s = setup(); const pull = { number: 11, body: "Body." }; From c4139dcae757dba5d48ca58157a9569d3e250baf Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Thu, 19 Nov 2026 12:16:57 -0800 Subject: [PATCH 3/3] fix(review): take another repository's PR only when HEAD contains its head A lone fork PR from a branch of the same name no longer sets the round's size or receives its record unless the checkout holds that PR's pushed head. Co-Authored-By: Claude Opus 5.5 --- README.md | 5 +++-- src/cli/main.ts | 4 ++-- src/cli/review-record.ts | 14 ++++++++++---- src/core/forge.ts | 3 +++ src/github/claims.ts | 1 + test/review.test.ts | 39 +++++++++++++++++++++++++++++---------- 6 files changed, 48 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 0e132f4a..bd033cfc 100644 --- a/README.md +++ b/README.md @@ -1629,8 +1629,9 @@ and `next`. After each round, `quest review` rewrites the `## Review` section of the open PR from the branch into the base, found among the upstream's PRs: the one from -the repository the base's remote pushes to, else the only one from any -repository, as in a maintainer's checkout of a contributor's fork PR. It +the repository the base's remote pushes to, else the only one from another +repository whose pushed head the checked-out `HEAD` contains, as in a +maintainer's checkout of a contributor's fork PR. It prints `record `. The record names the reviewed head and the base's short SHA, the head's risk tier and who classified it, then for each reviewer its diff --git a/src/cli/main.ts b/src/cli/main.ts index ef0e9164..cf6d3cc6 100644 --- a/src/cli/main.ts +++ b/src/cli/main.ts @@ -1707,12 +1707,12 @@ export function main(argv: string[], out: Output): number | Promise { "with the best long-term approach worked out from first principles before fixing them, `next respond` to fix or refute the findings, or `next done`. A reply without a valid score " + "fails as any malformed reply does. --json prints " + "one object: `rounds`, one per reviewer, `tallies`, every reviewer's findings across the branch's rounds, `risk`, the head's tier with its classification, `skipped`, each reviewer passed over with its reason, `record`, and `next`.\n\n" + - "After each round, it rewrites the `## Review` section of the branch's open PR into the base, the one from the repository the base's remote pushes to, else the only one from any repository, as the " + + "After each round, it rewrites the `## Review` section of the branch's open PR into the base, the one from the repository the base's remote pushes to, else the only one from another repository whose pushed head `HEAD` contains, as the " + "user the GitHub token names, keeping the rest of the body, and prints `record `: the reviewed " + "head, named in full only once no reviewer reports a finding, the base, the head's risk tier and reason, " + "the classifier's tier and who set it, a `- Skipped:` line for each reviewer passed over, and each reviewer, its Reviewer line ending in `, shadow` for the shadow, its " + "session and round, score, the tier it raised the risk to and why, its tally of findings across the branch's rounds, and each finding with its disposition. With no " + - "such PR, several from other repositories, or a remote off GitHub, it prints `record skipped: ` and changes nothing.\n\n" + + "such PR, several from other repositories that `HEAD` contains, or a remote off GitHub, it prints `record skipped: ` and changes nothing.\n\n" + "Exits 0 once the round finishes, whatever it found, 2 for invalid arguments " + "or a checkout that cannot be reviewed, 3 when no eligible reviewer could run, each not installed, logged " + "out, its login rejected, or at its usage limit, and 1 for other failures, including a PR GitHub will not show or a record it " + diff --git a/src/cli/review-record.ts b/src/cli/review-record.ts index 718678ad..a4ef2d8b 100644 --- a/src/cli/review-record.ts +++ b/src/cli/review-record.ts @@ -5,6 +5,7 @@ import { recorded } from "./models-record"; import { type ClaimDependencies, upstream } from "./claims"; import { pullsFrom } from "../github/claims"; import { git } from "./git"; +import { contains } from "./land"; import { requireRemote } from "./github"; import { type PullModels, @@ -297,8 +298,8 @@ export type Recorded = { url: string } | { skipped: string }; /** * The open PR from `branch` into the base `/` names, or why there is none: the one from the repository - * the base's remote pushes to, else the only one from any repository, as a maintainer's checkout of a contributor's - * fork PR finds it. It reads the forge itself, never an index that may lag, since its body is rewritten. + * the base's remote pushes to, else the only one from any repository whose head `HEAD` contains, as a maintainer's + * checkout of a contributor's fork PR finds it. It reads the forge itself, never an index that may lag, since its body is rewritten. */ async function openPull( root: string, @@ -318,13 +319,18 @@ async function openPull( (each) => each.base === base, ); const own = candidates.find((each) => each.head?.toLowerCase() === name); - const pull = own ?? (candidates.length === 1 ? candidates[0] : undefined); + // Another repository's PR counts only when this checkout holds its pushed head, so a stranger's PR from a + // branch of the same name neither sets the round's size nor receives its record. + const held = candidates.filter((each) => each.sha !== undefined && contains(top, each.sha, "HEAD")); + const pull = own ?? (held.length === 1 ? held[0] : undefined); if (pull === undefined) return { skipped: candidates.length === 0 ? `no open PR from ${branch} into ${base}` - : `several open PRs from ${branch} into ${base}, none from ${head.owner}: ${candidates.map((each) => each.url).join(", ")}`, + : held.length === 0 + ? `no open PR from ${branch} into ${base} from ${head.owner} or with a head this checkout holds: ${candidates.map((each) => each.url).join(", ")}` + : `several open PRs from ${branch} into ${base} with heads this checkout holds, none from ${head.owner}: ${held.map((each) => each.url).join(", ")}`, }; return { url: pull.url, diff --git a/src/core/forge.ts b/src/core/forge.ts index 3d9c8406..228f7ab6 100644 --- a/src/core/forge.ts +++ b/src/core/forge.ts @@ -210,6 +210,8 @@ export interface OpenPull { base: string; /** The head repository as `owner/repo`, or `null` once a fork is deleted. */ head: string | null; + /** The head commit, where the forge reports it. */ + sha?: string; draft: boolean; /** Epoch milliseconds. The earliest open PR on a branch holds the claim. */ created: number; @@ -604,6 +606,7 @@ const openPull = shape({ branch: name, base: name, head: nullable(name), + sha: maybe(sha), draft: boolean, created: count, updated: count, diff --git a/src/github/claims.ts b/src/github/claims.ts index 055de43c..f50d9db2 100644 --- a/src/github/claims.ts +++ b/src/github/claims.ts @@ -24,6 +24,7 @@ export async function openPullRequests(github: GitHub, repository: Repository): branch: string(head.ref), base: string(object(row.base).ref), head: repo === null ? null : string(repo.full_name), + ...(typeof head.sha === "string" ? { sha: head.sha } : {}), draft: row.draft === true, created: Date.parse(string(row.created_at)), updated: Date.parse(string(row.updated_at)), diff --git a/test/review.test.ts b/test/review.test.ts index a74db2da..29b99ee7 100644 --- a/test/review.test.ts +++ b/test/review.test.ts @@ -1094,7 +1094,7 @@ fakes("a change to the applicable instructions starts a new session that weighs * each PATCH wrote. */ /** An open PR from `feature` into `main`, from `acme/widget` unless `head` names another repository. */ -type FakePull = { number: number; body: string | null; head?: string }; +type FakePull = { number: number; body: string | null; head?: string; sha?: string }; function onGitHub(repo: string, pulls: FakePull[], fork = false): { body: string }[] { const local = git(repo, "remote", "get-url", "origin"); git(repo, "remote", "set-url", "origin", "https://github.com/acme/widget.git"); @@ -1120,10 +1120,10 @@ function onGitHub(repo: string, pulls: FakePull[], fork = false): { body: string return url.pathname.endsWith("/contents/quest/README.md") ? json({}) : json({}, 404); if (url.pathname === `/repos/${owner}/widget/pulls`) { expect(url.searchParams.get("state")).toBe("open"); - const row = ({ head, ...p }: FakePull, ref: string, base: string) => ({ + const row = ({ head, sha, ...p }: FakePull, ref: string, base: string) => ({ ...p, html_url: `https://github.com/${owner}/widget/pull/${p.number}`, - head: { ref, repo: { full_name: head ?? "acme/widget" } }, + head: { ref, repo: { full_name: head ?? "acme/widget" }, ...(sha === undefined ? {} : { sha }) }, base: { ref: base }, draft: false, created_at: "2026-10-01T00:00:00Z", @@ -1568,32 +1568,51 @@ fakes("a branch with no open PR, or a body without a Review section, is reported fakes("a maintainer's checkout records on a contributor's fork PR and reads its size", async () => { const s = setup(); - const pull = { number: 12, body: "Body.\n\n## Models\n\n- Size: S\n", head: "contributor/widget" }; - const pulls: FakePull[] = [pull]; + const pushed = git(s.repo, "rev-parse", "HEAD~1"); + const pull = { number: 12, body: "Body.\n\n## Models\n\n- Size: S\n", head: "contributor/widget", sha: pushed }; + // A stranger's PR from a branch of the same name, whose head this checkout lacks. + const stranger = { + number: 13, + body: "Stranger.\n\n## Models\n\n- Size: XS\n", + head: "stranger/widget", + sha: "f".repeat(40), + }; + const pulls: FakePull[] = [stranger]; onGitHub(s.repo, pulls); vi.stubEnv("FAKE_REPLY", JSON.stringify({ score: 10, rationale: "Lands as is.", findings: [] })); try { + const alone = await quest("--root", s.repo, "review"); + expect(alone.code, alone.stderr).toBe(0); + expect(alone.stdout).toContain( + "record skipped: no open PR from feature into main from acme or with a head this checkout holds: https://github.com/acme/widget/pull/13\n", + ); + // Its size went unread: no size picks the default. + expect(alone.stdout).not.toContain(" low shadow\n"); + expect(stranger.body).toBe("Stranger.\n\n## Models\n\n- Size: XS\n"); + + pulls.push(pull); const result = await quest("--root", s.repo, "review"); expect(result.code, result.stderr).toBe(0); expect(result.stdout).toContain("record https://github.com/acme/widget/pull/12\n"); // Size S picks the shadow one effort below medium. expect(result.stdout).toContain(" low shadow\n"); expect(pull.body).toMatch(/^Body\.\n\n## Models\n\n- Size: S\n\n## Review\n\nRewritten by `quest review`/); + expect(stranger.body).toBe("Stranger.\n\n## Models\n\n- Size: XS\n"); - // A second contributor's PR from a branch of the same name leaves no way to tell them apart. - pulls.push({ number: 13, body: "Other.", head: "someone/widget" }); + // A second contributor's PR whose head this checkout also holds leaves no way to tell them apart. + pulls.push({ number: 15, body: "Other.", head: "someone/widget", sha: pushed }); const ambiguous = await quest("--root", s.repo, "review", "--size", "S"); expect(ambiguous.code, ambiguous.stderr).toBe(0); expect(ambiguous.stdout).toContain( - "record skipped: several open PRs from feature into main, none from acme: https://github.com/acme/widget/pull/12, https://github.com/acme/widget/pull/13\n", + "record skipped: several open PRs from feature into main with heads this checkout holds, none from acme: https://github.com/acme/widget/pull/12, https://github.com/acme/widget/pull/15\n", ); - expect(pulls[1]!.body).toBe("Other."); + expect(pulls[2]!.body).toBe("Other."); // The push repository's own PR wins over any fork's. pulls.push({ number: 14, body: "Own." }); const own = await quest("--root", s.repo, "review", "--size", "S"); expect(own.stdout).toContain("record https://github.com/acme/widget/pull/14\n"); - expect(pulls[1]!.body).toBe("Other."); + expect(pulls[2]!.body).toBe("Other."); } finally { vi.unstubAllGlobals(); }