Skip to content
Merged
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
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1643,8 +1643,11 @@ 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 <url>`. 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 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 <url>`. 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
Expand Down
33 changes: 0 additions & 33 deletions quest/m0/fork-review-record.md

This file was deleted.

4 changes: 2 additions & 2 deletions src/cli/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1714,12 +1714,12 @@ export function main(argv: string[], out: Output): number | Promise<number> {
"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 another repository whose pushed head `HEAD` contains, as the " +
"user the GitHub token names, keeping the rest of the body, and prints `record <url>`: 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: <why>` and changes nothing.\n\n" +
"such PR, several from other repositories that `HEAD` contains, or a remote off GitHub, it prints `record skipped: <why>` 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 " +
Expand Down
26 changes: 20 additions & 6 deletions src/cli/review-record.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -296,9 +297,9 @@ export function withReview(body: string, record: string): string {
export type Recorded = { url: string } | { skipped: string };

/**
* The open PR from `branch` into the base `<remote>/<branch>` 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 `<remote>/<branch>` names, or why there is none: the one from the repository
* 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,
Expand All @@ -314,10 +315,23 @@ 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 (await hosting.live()).pulls(repository)).value, branch).find(
(each) => each.base === base && each.head?.toLowerCase() === name,
const candidates = pullsFrom((await (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);
// 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}`
: 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,
body: pull.body,
Expand Down
3 changes: 3 additions & 0 deletions src/core/forge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -604,6 +606,7 @@ const openPull = shape<OpenPull>({
branch: name,
base: name,
head: nullable(name),
sha: maybe(sha),
draft: boolean,
created: count,
updated: count,
Expand Down
1 change: 1 addition & 0 deletions src/github/claims.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export async function openPullRequests(github: GitHubReader, repository: Reposit
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)),
Expand Down
61 changes: 57 additions & 4 deletions test/review.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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; 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");
Expand All @@ -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, sha, ...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" }, ...(sha === undefined ? {} : { sha }) },
base: { ref: base },
draft: false,
created_at: "2026-10-01T00:00:00Z",
Expand Down Expand Up @@ -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: [] }));
Expand All @@ -1565,6 +1566,58 @@ 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 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 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 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[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[2]!.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." };
Expand Down