From 5ec5d42b91ca001749d6b583348dd12bf8ac334c Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Thu, 12 Nov 2026 16:31:58 -0800 Subject: [PATCH 01/10] chore(quest): claim quest/m0/superseded-runs.md Quest-Claim: 6c30c86a27d12c10 From 250c36575ef3c4250b24808b992773f434a7b2ae Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Thu, 12 Nov 2026 16:47:01 -0800 Subject: [PATCH 02/10] fix(checks): ignore checks from superseded workflow runs A check that reported cancelled stops counting once a newer GitHub Actions run of its workflow exists on the head, by its latest attempt's start, so `quest status`, `quest merge`, `quest wait`, and `quest land` with its daemons agree. `quest status` also judges the base's required checks and workflows as `quest wait` does, reporting each one nothing reports as pending. Co-Authored-By: Claude Opus 5.5 --- README.md | 30 ++++--- quest/m0/superseded-runs.md | 59 -------------- src/cli/github.ts | 36 +++++++++ src/cli/hold.ts | 6 +- src/cli/land-bump.ts | 36 +++------ src/cli/land-serve.ts | 2 + src/cli/land.ts | 17 ++-- src/cli/status.ts | 72 +++++++++++++++-- src/cli/wait.ts | 55 ++++++------- src/github/checks.ts | 49 ++++++++++- test/checks.test.ts | 87 ++++++++++++++++++-- test/github.ts | 16 +++- test/hold.test.ts | 24 ++++++ test/land-bump.test.ts | 25 ++++-- test/land.test.ts | 45 +++++++++++ test/status.test.ts | 157 +++++++++++++++++++++++++++++------- test/wait.test.ts | 4 +- 17 files changed, 528 insertions(+), 192 deletions(-) delete mode 100644 quest/m0/superseded-runs.md diff --git a/README.md b/README.md index c6d3f8560..d4bdd24b6 100644 --- a/README.md +++ b/README.md @@ -421,8 +421,9 @@ present (except `quest land`'s, which no head carries), and every required check passed; it names the last required check that passed and is dated when the head went idle. Each prints once per head, with the check's name (spaces as `_`) in the actor field and its details URL. Results count as -`quest status` counts them, so neutral and skipped results pass and a rerun -supersedes an earlier run of the same check. Each job of a +`quest status` counts them, so neutral and skipped results pass, a rerun +supersedes an earlier run of the same check, and a cancelled check a newer run +of its workflow replaced is dropped. Each job of a workflow a ruleset requires is required. Requiredness comes from the base branch's protection and rulesets, readable with read access. A failed optional check prints separately as `check:failed`, @@ -501,8 +502,8 @@ comes last, and a missing value prints as `-`: | `auto-merge` | Method, who enabled it, when, and the head it was enabled on. | | `merge-queue` | Queue state, position, and when it was enqueued. | | `landing-stopped` | The reason the latest merge-queue entry, auto-merge, or [`quest land`](#land-a-batch-with-quest-land) queue entry ended (such as `merge_conflict`, `failed_checks`, `manual`, `manually_disabled`, or `merged`), who ended it, and when; `-` once the PR has entered the merge queue or auto-merge again since. | -| `checks` | `failure` if any check fails, else `pending` if any is pending, else `success`, and `passed=`, `failing=`, `pending=` counts, all from each check's latest run; `-` when the head has no checks. | -| `check` | `failing` or `pending`, `required` or `optional`, the result, details URL, and name. | +| `checks` | `failure` if any check fails, else `pending` if any is pending or a requirement is unreported, else `success`, and `passed=`, `failing=`, `pending=` counts, all from the checks that count; `-` when the head has no checks and the base requires none. | +| `check` | `failing` or `pending`, `required` or `optional`, the result, details URL, and name. A required check or required workflow nothing reports yet prints as `pending required expected -` with its name, or the workflow's path. | | `review` | `current` or `stale` against the head, state, reviewer, time, and URL of each reviewer's latest review. | | `checkpoint` | Each bot reviewer that approves or requests changes, such as one whose approval the base requires, its round, and its review's URL, when that review is of the head and its latest verdict there, ignoring plain comments, is neither an approval nor a dismissal, at the end of its third, sixth, ... round: [`/quest-review`'s design checkpoint](#review-locally) for an online reviewer. A round is one commit it reviewed; a dismissed review counts as one that approves or requests changes. Only printed when due. | | `reacted:` | Actor, time, and the PR or review reacted to, as `quest wait` names reactions. | @@ -514,9 +515,17 @@ The node ID is what GraphQL's `addPullRequestReviewThreadReply` and `resolveReviewThread` take. Neutral and skipped checks pass. Only each check's latest run counts, as for GitHub's mergeability: a rerun, or the same workflow run again on the head, supersedes an earlier run of that name from the same -app, and a newer commit status supersedes an older one of its context. GitHub's -own rollup state counts the superseded runs too. A required check -is one branch protection or a ruleset requires for this PR. `--json` prints the +app, and a newer commit status supersedes an older one of its context. A check +that reported `cancelled` also stops counting once a newer GitHub Actions run of +its workflow exists on the head, from any event, as when `cancel-in-progress` +cancels a run whose jobs, such as a matrix job under its unexpanded name, the +newer run never reports; a rerun counts as newer than every run that started +before it. Any other result keeps counting, as does a cancelled run nothing +replaced. Only then does it read the head's workflow runs, which needs Actions +read access. GitHub's own rollup state counts the superseded runs too. A required +check is one branch protection or a ruleset requires for this PR, or a job of a +workflow a ruleset requires; like `quest wait`, it matches a requirement by name +and leaves out `quest land`'s check, which no head carries. `--json` prints the same facts as one object with the fields `url`, `state`, `draft`, `head`, `mergeable`, `mergeState`, `reviewDecision`, `autoMerge`, `mergeQueue`, `landingStopped`, `checks` (`state`, `passed`, `failing`, `pending`), `reviews`, `checkpoints` (`reviewer`, `round`, `url`), `reactions`, @@ -561,8 +570,8 @@ are not told apart. `quest merge` takes no label: the head-pinned auto-merge or merge-queue entry it creates is the queue signal, so a queued PR shows no hold. It refuses while any session holds the PR, so release your own hold first. `--land` needs the full 40-character -head SHA and refuses once the head moves, or while the latest run of any -check on it failed, required or not, naming each; pending checks do not block. +head SHA and refuses once the head moves, or while any check on it that +counts in `quest status` failed, required or not, naming each; pending checks do not block. It enables auto-merge bound to that SHA, or merges at once when nothing is left to wait for. `--squash` or `--rebase` picks the method, and it refuses one the repository disallows; otherwise it uses the only method the repository @@ -754,8 +763,7 @@ down to one PR, and each batch that lands grows it back by one; the order and size persist in the state directory. Conflicting additions stay queued. A PR whose required checks are still running, or that still needs an approving review the base requires, stays queued and sits out -batches until they pass and it is approved; only each check's latest run counts, -as in `quest status`. If it still waits two hours after +batches until they pass and it is approved; checks count as in `quest status`. If it still waits two hours after its pick (twice the default `--timeout`), the daemon comments once on that pick, naming what it waits for, since a check that never reports or an approval nobody gives would hold it silently. The sandbox checks the tip once, without diff --git a/quest/m0/superseded-runs.md b/quest/m0/superseded-runs.md deleted file mode 100644 index 39a1dad38..000000000 --- a/quest/m0/superseded-runs.md +++ /dev/null @@ -1,59 +0,0 @@ -# [M] Ignore checks from superseded workflow runs - -## Goal - -`quest status`, `quest merge`, `quest wait` and `quest land`, including its -daemons, stop failing a head on a check that reported `cancelled` once a -newer GitHub Actions run of the same workflow exists on that head. This -includes a matrix job the cancelled run left under an unexpanded name, such -as `Tests (${{ matrix.os }})`. A completed check keeps today's rule, where -each check's latest report counts. A cancelled run that nothing replaced -still fails. All of these readers agree on the head's state. - -## Plan - -Decided 2026-11-12 (user, /quest-plan of the follow-ups from a -/quest-complete run on kixelated/token-max): ✅ drop the cancelled checks of -replaced workflow runs (rejected: treating every cancelled check as passing, -since a genuinely cancelled required run would then pass; fixing each -repository's workflow, since every repository would need it and token-max's -`edited` trigger is deliberate). - -Decided 2026-11-12 (user, /quest-review design checkpoint): ✅ `quest status` -judges the base's required checks as `quest wait` does, with the same -exceptions, such as the gate's own `quest land` check. It reports each -missing required check or required workflow as a pending line, the -workflow named by its path. A cancelled -pull_request run can be replaced by a push run that lacks a PR-only required -job, and status would otherwise read success while land and wait read -pending (rejected: leaving it to the implementer; letting a cancelled run -yield only to a run of its own event, which fails the push/pull_request -race again). - -What happened: in kixelated/token-max, editing a PR body right after a push -starts an `edited` run, which cancels the push's `synchronize` run through -`cancel-in-progress`. The cancelled run's matrix job reports under its -unexpanded name, which no newer run reuses. `latestContexts` -(`src/github/checks.ts`) keys check runs by app and name, so it keeps that -job as the latest, and `quest merge` refused -[kixelated/token-max#75](https://github.com/kixelated/token-max/pull/75), -[#76](https://github.com/kixelated/token-max/pull/76) and -[#78](https://github.com/kixelated/token-max/pull/78) until the cancelled run -was rerun. - -Recommendations: - -- Drop only checks that reported `cancelled`, not whole runs: a check the - cancelled run completed before it stopped keeps counting. Dropping a run because a newer - run of its event exists would also drop passed checks that the newer run - gated off, such as jobs an `edited` run skips by `github.event.action`. -- land-bump (`latestRuns` in `src/cli/land-bump.ts`) already treats a run - that a newer run cancelled as replaced, and reads the head's runs over - REST, which also sees a newer run that has no check runs yet. Share one - rule with it where that stays simple. -- Workflow-run data needs Actions read. `quest land serve` mints its API - token with only `checks` and `statuses` read (`src/cli/land-serve.ts`). - Add `actions: "read"`, which the GitHub App already grants, since - land-bump and land-watch request it. -- Count a rerun of the cancelled run as current, since rerunning it is the - workaround today. diff --git a/src/cli/github.ts b/src/cli/github.ts index cc117c0a8..a42fe7fa3 100644 --- a/src/cli/github.ts +++ b/src/cli/github.ts @@ -1,6 +1,7 @@ // The GitHub client shared by the commands that talk to GitHub, outside the repository-independent core. import { execFileSync } from "node:child_process"; import { setTimeout as sleep } from "node:timers/promises"; +import { cancelled, currentContexts, latestContexts, type RollupContext, type WorkflowRun } from "../github/checks"; import { git } from "./git"; const API = "https://api.github.com"; @@ -570,6 +571,41 @@ export async function requirements(github: GitHub, repository: Repository, branc }; } +/** Every GitHub Actions workflow run on `head`. Reading them needs Actions read access. */ +export async function workflowRuns(github: GitHub, repository: Repository, head: string): Promise { + const runs: WorkflowRun[] = []; + let path: string | undefined = + `/repos/${encodeURIComponent(repository.owner)}/${encodeURIComponent(repository.repo)}/actions/runs?head_sha=${head}&per_page=100`; + while (path) { + const response: Response = await github.request(path); + for (const row of array(object(await response.json()).workflow_runs)) + runs.push({ + ...row, + id: Number(row.id), + workflow_id: Number(row.workflow_id), + check_suite_id: Number(row.check_suite_id), + run_started_at: string(row.run_started_at), + }); + path = link(response, "next"); + } + return runs; +} + +/** + * Each check's latest report on `head` that still counts, as {@link currentContexts} judges it. The head's + * workflow runs are read only when a latest report is a cancelled check run, the only report they can drop. + */ +export async function currentChecks( + github: GitHub, + repository: Repository, + head: string, + contexts: T[], +): Promise { + const latest = latestContexts(contexts); + if (!latest.some(cancelled)) return latest; + return currentContexts(contexts, await workflowRuns(github, repository, head)); +} + /** * Whether a merged PR in `repository` had `commit` as its head or below it, as when `quest land` merged * the base into the head before squashing; false for a commit GitHub does not have. diff --git a/src/cli/hold.ts b/src/cli/hold.ts index 8961bd6b6..6eebee74c 100644 --- a/src/cli/hold.ts +++ b/src/cli/hold.ts @@ -7,6 +7,7 @@ import { cleanAutoMergeRefusal, immediateMerge, queueHead } from "../github/merg import { repositoryPath } from "./claims"; import { array, + currentChecks, GitHub, type GitHubDependencies, GitHubGraphQLError, @@ -16,7 +17,6 @@ import { requirements, string, } from "./github"; -import { latestContexts } from "../github/checks"; import { ALLOWS, LAND_CHECK, METHOD_NAMES, contexts, enqueue } from "./land"; import { QUEUE_CHECK } from "./land-queue"; import { classifyCheck } from "./status"; @@ -321,12 +321,12 @@ export async function land( } /** - * Refuse a head on which any check's latest run failed, required or not, naming each: landing it + * Refuse a head on which any current check failed, required or not, naming each: landing it * would spend a queue build on a known failure. Pending and absent checks do not block, nor does the * own queue's informational check, which reports how a past pick ended rather than the head. */ async function passing(github: GitHub, pr: PullRequest, url: string, sha: string): Promise { - const failing = latestContexts(await contexts(github, pr, sha)) + const failing = (await currentChecks(github, pr, sha, await contexts(github, pr, sha))) .filter((context) => context.name !== QUEUE_CHECK) .map(classifyCheck) .filter(({ outcome }) => outcome === "failing") diff --git a/src/cli/land-bump.ts b/src/cli/land-bump.ts index 9bcce2c9f..084975bcf 100644 --- a/src/cli/land-bump.ts +++ b/src/cli/land-bump.ts @@ -3,7 +3,7 @@ import { spawnSync } from "node:child_process"; import { existsSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, writeFileSync } from "node:fs"; import { isAbsolute, join, relative, sep } from "node:path"; -import { checksState } from "../github/checks"; +import { checksState, currentContexts, newerRun, replacedRun, type WorkflowRun } from "../github/checks"; import { array, GitHub, @@ -13,6 +13,7 @@ import { type Repository, requirements, string, + workflowRuns, } from "./github"; import { land } from "./hold"; import { commandEnvironment, contexts, git, type RemoteRead } from "./land"; @@ -420,23 +421,13 @@ async function settle(target: Repository, record: Bump, connection: BumpConnecti // A workflow's later jobs report only once they start, and a queued workflow may have no check run yet, // so Actions is judged by its workflow runs. Another app's suite that never ran a check stays queued // forever, and counts for nothing. - const runs = object(await (await github.request(`${path}/actions/runs?head_sha=${head}&per_page=100`)).json()); - const all = array(runs.workflow_runs); + const all = await workflowRuns(github, target, head); const suites = object(await (await github.request(`${path}/commits/${head}/check-suites?per_page=100`)).json()); const listed = array(suites.check_suites); - if (Number(runs.total_count) > all.length || Number(suites.total_count) > listed.length) - throw new Error(`${head} has more workflow runs or check suites than one page, more than a bump reads`); + if (Number(suites.total_count) > listed.length) + throw new Error(`${head} has more check suites than one page, more than a bump reads`); const workflows = latestRuns(all); - // The check runs of a replaced workflow run, such as one a newer run cancelled, are replaced with it. - const replaced = new Set( - all - .filter((run) => !workflows.includes(run) && run.check_suite_id != null) - .map((run) => Number(run.check_suite_id)), - ); - const found = (await contexts(github, target, head)).filter((context) => { - const suite = object(context.checkSuite ?? {}).databaseId; - return suite == null || !replaced.has(Number(suite)); - }); + const found = currentContexts(await contexts(github, target, head), all); const state = found.length === 0 ? "PENDING" : checksState(found); if (state === "FAILURE") return fail(`a check failed on its head ${head}`); if (workflows.some((run) => run.status === "completed" && !PASSING.includes(String(run.conclusion)))) @@ -463,17 +454,16 @@ async function settle(target: Repository, record: Bump, connection: BumpConnecti } /** - * The workflow runs on a head that still count: each workflow's latest run per event. A cancelled run - * also yields to a newer run of its workflow from another event, as when push and pull_request share a - * `cancel-in-progress` concurrency group, so a run a newer one replaced counts as replaced, not failed. + * The workflow runs on a head that still count: each workflow's latest run per event, by when its latest + * attempt started. A cancelled run also yields to a newer run of its workflow from another event, as when + * push and pull_request share a `cancel-in-progress` concurrency group, so a run a newer one replaced + * counts as replaced, not failed, as {@link currentContexts} treats its cancelled checks. */ -export function latestRuns(runs: ObjectValue[]): ObjectValue[] { +export function latestRuns(runs: WorkflowRun[]): WorkflowRun[] { return runs.filter((run) => { - const newer = runs.filter( - (other) => other.workflow_id === run.workflow_id && Number(other.id) > Number(run.id), - ); + const newer = runs.filter((other) => other.workflow_id === run.workflow_id && newerRun(other, run)); if (newer.some((other) => other.event === run.event)) return false; - return !(run.conclusion === "cancelled" && newer.length > 0); + return !(run.conclusion === "cancelled" && replacedRun(run, runs)); }); } diff --git a/src/cli/land-serve.ts b/src/cli/land-serve.ts index 6ea670062..7d584d658 100644 --- a/src/cli/land-serve.ts +++ b/src/cli/land-serve.ts @@ -838,6 +838,8 @@ export async function serve( administration: "read", checks: "read", statuses: "read", + // The head's workflow runs, which say whether a newer run replaced a cancelled check. + actions: "read", }, { fetch, now: Date.now }, ), diff --git a/src/cli/land.ts b/src/cli/land.ts index 708f17502..7b5b4eb7c 100644 --- a/src/cli/land.ts +++ b/src/cli/land.ts @@ -13,10 +13,11 @@ import { type Repository, type RequiredCheck, array, + currentChecks, requirements, string, } from "./github"; -import { appOf, latestContexts } from "../github/checks"; +import { appOf } from "../github/checks"; import { classifyCheck } from "./status"; import type { Method } from "./hold"; import { committedSources, snapshot } from "./tree"; @@ -432,7 +433,8 @@ export async function resolveQueue( // The queue's first page holds the head's checks, unless the head moved from the pin since. const commit = object(object(array(object(node.commits).nodes)[0]).commit); const rollup = commit.oid === approved ? commit.statusCheckRollup : undefined; - const unmet = checks(await contexts(github, repository, approved, rollup), required); + const found = await contexts(github, repository, approved, rollup); + const unmet = checks(await currentChecks(github, repository, approved, found), required); // An approval can still arrive on the pinned head, such as an automated reviewer's, so it waits like a check. const approval = node.reviewDecision === "REVIEW_REQUIRED"; if (unmet.failing.length > 0) { @@ -496,18 +498,17 @@ export async function requiredChecks( sha: string, required: RequiredCheck[], ): Promise<{ failing: string[]; pending: string[] }> { - return checks(await contexts(github, repository, sha), required); + return checks(await currentChecks(github, repository, sha, await contexts(github, repository, sha)), required); } /** - * The required checks a head failed, and those pending or not yet reported, each from its app. Only - * each check's latest run counts, as for GitHub's mergeability, so a rerun supersedes a cancelled or - * failed run. + * The required checks a head failed, and those pending or not yet reported, each from its app. Only the + * head's current checks count, from {@link currentChecks}: each check's latest run, as for GitHub's + * mergeability, so a rerun supersedes a cancelled or failed run, without a cancelled run a newer one replaced. */ -function checks(contexts: ObjectValue[], required: RequiredCheck[]): { failing: string[]; pending: string[] } { +function checks(latest: ObjectValue[], required: RequiredCheck[]): { failing: string[]; pending: string[] } { const failing: string[] = []; const pending: string[] = []; - const latest = latestContexts(contexts); for (const need of required) { let result: "passed" | "failing" | "pending" = "pending"; let reported = false; diff --git a/src/cli/status.ts b/src/cli/status.ts index 571f9b766..102e1f06e 100644 --- a/src/cli/status.ts +++ b/src/cli/status.ts @@ -2,6 +2,7 @@ import { actor, array, + currentChecks, GitHub, GitHubDeadline, type GitHubDependencies, @@ -9,10 +10,12 @@ import { object, type ObjectValue, type PullRequest, + type Repository, + requirements, string, } from "./github"; -import { checksState, contextOutcome, latestContexts } from "../github/checks"; -import { EJECTED, pinned } from "./land"; +import { checksState, contextOutcome } from "../github/checks"; +import { EJECTED, LAND_CHECK, pinned } from "./land"; import { reviewSection } from "../core"; import { readHoldStatus, type HoldFact, type HoldReport } from "./hold"; @@ -43,7 +46,7 @@ const STATUS = `query($owner: String!, $repo: String!, $number: Int!, __typename ... on CheckRun { databaseId name status conclusion detailsUrl isRequired(pullRequestNumber: $number) - checkSuite { app { databaseId } } + checkSuite { databaseId app { databaseId } workflowRun { file { path } } } } ... on StatusContext { context state createdAt targetUrl isRequired(pullRequestNumber: $number) } } @@ -199,7 +202,10 @@ export async function pullRequestStatus(pr: PullRequest, deps: GitHubDependencie const ownership = await readHoldStatus(pr, deps); if (ownership.head !== first!.headRefOid) throw new Error("the PR head changed while reading its holds; rerun quest status"); - const status = summarize(first!, rollup, contexts, reviewNodes, threadNodes); + const head = string(first!.headRefOid); + const current = await currentChecks(github, pr, head, contexts); + const needs = await requiredOf(github, pr, string(first!.baseRefName)); + const status = summarize(first!, rollup, current, needs, reviewNodes, threadNodes); status.reviewRecord = await reviewRecord(github, pr, first!, deps.warn); if (status.autoMerge !== null) status.autoMerge.head = await enabledHead(github, first!, deps.warn); return { ...status, holds: ownership.holds, starterHold: ownership.starter }; @@ -313,27 +319,79 @@ export async function headBefore( return pushes.find((push) => push.time < time)?.sha ?? null; } +/** The checks and workflow files a base requires of a PR head. */ +export interface Needs { + /** Required check names; GitHub's own merge checks which app reports each. */ + checks: string[]; + /** Workflow files that must pass as a whole, by path. */ + workflows: string[]; +} + +/** What `branch` requires of a PR head. The gate's own check is never on one, so it is left out. */ +export async function requiredOf(github: GitHub, repository: Repository, branch: string): Promise { + const found = await requirements(github, repository, branch); + const names = found.checks.map((check) => check.name).filter((name) => name !== LAND_CHECK); + return { checks: [...new Set(names)], workflows: found.workflows }; +} + +/** A check as a requirement matches it: its name, and the workflow file a GitHub Actions job runs in. */ +export interface Reported { + name: string; + workflow?: string; +} + +/** A rollup context as a requirement matches it; queries ask for `checkSuite { workflowRun { file { path } } }`. */ +export function reported(context: ObjectValue): Reported { + const run = context.__typename === "CheckRun" && context.checkSuite ? object(context.checkSuite).workflowRun : null; + const file = run ? object(run).file : null; + return { + name: string(context.__typename === "CheckRun" ? context.name : context.context), + ...(file ? { workflow: string(object(file).path) } : {}), + }; +} + +/** The required checks, by name, and required workflows, by path, that nothing on the head reports yet. */ +export function unreported(found: Reported[], needs: Needs): string[] { + return [ + ...needs.checks.filter((name) => !found.some((entry) => entry.name === name)), + ...needs.workflows.filter((path) => !found.some((entry) => entry.workflow === path)), + ]; +} + +/** + * The PR's state from its pages. `current` holds the head's checks that count, from {@link currentChecks}; a + * check is required when the base requires it or its workflow, and a requirement nothing reports is pending. + */ function summarize( pull: ObjectValue, rollup: ObjectValue | null, - contexts: ObjectValue[], + current: ObjectValue[], + needs: Needs, reviewNodes: ObjectValue[], threadNodes: ObjectValue[], ): Status { const head = string(pull.headRefOid); const url = string(pull.url); + const missing = unreported(current.map(reported), needs); // The rollup's own state counts runs a newer run of the same check replaced. + const state = checksState(current); const checks = { - state: rollup === null ? null : lower(checksState(contexts)), + state: + rollup === null && missing.length === 0 + ? null + : lower(state === "SUCCESS" && missing.length > 0 ? "PENDING" : state), passed: 0, failing: [], pending: [], } as Status["checks"]; - for (const context of latestContexts(contexts)) { + for (const context of current) { const { check, outcome } = classifyCheck(context); + const workflow = reported(context).workflow; + if (workflow !== undefined && needs.workflows.includes(workflow)) check.required = true; if (outcome === "passed") checks.passed++; else checks[outcome].push(check); } + for (const name of missing) checks.pending.push({ name, required: true, result: "expected", url: null }); const reactions: Reaction[] = []; const reacted = (owner: ObjectValue, target: string) => { diff --git a/src/cli/wait.ts b/src/cli/wait.ts index 75438b5e8..d6d3a15ed 100644 --- a/src/cli/wait.ts +++ b/src/cli/wait.ts @@ -4,6 +4,7 @@ import { createHash } from "node:crypto"; import { actor, array, + currentChecks, GitHub, type GitHubDependencies, GitHubInputError, @@ -11,12 +12,18 @@ import { object, type ObjectValue, type PullRequest, - requirements, string, } from "./github"; -import { LAND_CHECK } from "./land"; -import { latestContexts } from "../github/checks"; -import { BRANCH_UPDATES, classifyCheck, enabledHead } from "./status"; +import { + BRANCH_UPDATES, + classifyCheck, + enabledHead, + type Needs, + type Reported, + reported, + requiredOf, + unreported, +} from "./status"; const POLL = 5 * 60_000; /** @@ -65,7 +72,7 @@ const CHECKS = `query($owner: String!, $repo: String!, $number: Int!, $after: St __typename ... on CheckRun { databaseId name status conclusion completedAt detailsUrl isRequired(pullRequestNumber: $number) - checkSuite { status app { databaseId } workflowRun { file { path } } } + checkSuite { databaseId status app { databaseId } workflowRun { file { path } } } } ... on StatusContext { context state createdAt targetUrl isRequired(pullRequestNumber: $number) } } @@ -117,19 +124,10 @@ interface Cursor { checks: { since: number; reported: string[] }; } -/** The check names and workflow files a base branch requires. */ -interface Needs { - names: Set; - workflows: string[]; -} - /** One check run or commit status on the head, with its result once it has one. */ -interface Check { - name: string; +interface Check extends Reported { required: boolean; url: string | null; - /** The workflow file a GitHub Actions job runs in. */ - workflow?: string; /** A GitHub Actions job whose workflow run has not finished, so it may still create jobs. */ running: boolean; result?: { outcome: "passed" | "failed"; point: string; time: number }; @@ -375,22 +373,18 @@ async function watch( const page = object(contexts.pageInfo); after = page.hasNextPage === true ? string(page.endCursor) : null; } while (after !== null); - return { head: head!, base: string(pull.baseRefName), checks: latestContexts(rows).map(check), pull }; + const current = await currentChecks(github, pr, head!, rows); + return { head: head!, base: string(pull.baseRefName), checks: current.map(check), pull }; }; /** - * What the base branch requires, read once per wait. Only a requirement says whether a missing - * check has yet to start, or whether the repository requires none. The gate's own check is never - * on a PR head, so a gated base waits only for the rest. + * What the base branch requires, read once per wait, as `quest status` reads it. Only a requirement + * says whether a missing check has yet to start, or whether the repository requires none. */ const known = new Map(); const required = async (branch: string): Promise => { const cached = known.get(branch); if (cached) return cached; - const found = await requirements(github, pr, branch); - const needs = { - names: new Set(found.checks.map((check) => check.name).filter((name) => name !== LAND_CHECK)), - workflows: found.workflows, - }; + const needs = await requiredOf(github, pr, branch); known.set(branch, needs); return needs; }; @@ -575,12 +569,10 @@ function check(row: ObjectValue): Check { const run = row.__typename === "CheckRun"; const { check: classified, outcome } = classifyCheck(row); const suite = run && row.checkSuite ? object(row.checkSuite) : undefined; - const file = suite?.workflowRun ? object(suite.workflowRun).file : null; const found: Check = { - name: classified.name, + ...reported(row), required: classified.required, url: classified.url, - ...(file ? { workflow: string(object(file).path) } : {}), running: suite?.workflowRun ? suite.status !== "COMPLETED" : false, }; if (outcome === "pending") return found; @@ -597,7 +589,9 @@ function check(row: ObjectValue): Check { function checkActivities(head: string, all: Check[], needs: Needs, state: Cursor["checks"], prUrl: string): Activity[] { const inWorkflow = (entry: Check) => entry.workflow !== undefined && needs.workflows.includes(entry.workflow); const required = - needs.names.size || needs.workflows.length ? all.filter((entry) => entry.required || inWorkflow(entry)) : all; + needs.checks.length || needs.workflows.length + ? all.filter((entry) => entry.required || inWorkflow(entry)) + : all; const reached = ( outcome: "passed" | "failed", entry: Check | undefined, @@ -623,10 +617,7 @@ function checkActivities(head: string, all: Check[], needs: Needs, state: Cursor // A pass waits for the head to go idle, including jobs a running workflow // may still create. Its date is the last completion, but its name and link // always identify a required check that passed. - const idle = - all.every((entry) => entry.result && !entry.running) && - [...needs.names].every((name) => all.some((entry) => entry.name === name)) && - needs.workflows.every((path) => all.some((entry) => entry.workflow === path)); + const idle = all.every((entry) => entry.result && !entry.running) && unreported(all, needs).length === 0; const passed = idle && settled.length === required.length && settled.every((entry) => entry.result.outcome === "passed") ? settled.at(-1) diff --git a/src/github/checks.ts b/src/github/checks.ts index 735136c65..21406308c 100644 --- a/src/github/checks.ts +++ b/src/github/checks.ts @@ -40,6 +40,49 @@ export function latestContexts(contexts: T[]): T[] { return contexts.filter((context) => latest.get(key(context)) === context); } +/** A GitHub Actions workflow run on a head, as `GET /actions/runs` lists it. */ +export interface WorkflowRun { + id: number; + workflow_id: number; + check_suite_id: number; + /** When its latest attempt started, so a rerun is newer than runs that started before it. */ + run_started_at: string; + [field: string]: unknown; +} + +/** Whether `run` started after `other`: by its latest attempt's start, then by ID on a tie. */ +export function newerRun(run: WorkflowRun, other: WorkflowRun): boolean { + const started = Date.parse(run.run_started_at) - Date.parse(other.run_started_at); + if (Number.isNaN(started)) throw new Error(`workflow run ${run.id} or ${other.id} has no valid start time`); + return started === 0 ? run.id > other.id : started > 0; +} + +/** Whether a newer run of `run`'s workflow exists among `runs`, from any event. */ +export function replacedRun(run: WorkflowRun, runs: WorkflowRun[]): boolean { + return runs.some((other) => other.workflow_id === run.workflow_id && newerRun(other, run)); +} + +/** Whether a context is a check run that reported cancelled, the only result a replaced run's check drops. */ +export function cancelled(context: RollupContext): boolean { + return context.__typename === "CheckRun" && String(context.conclusion).toUpperCase() === "CANCELLED"; +} + +/** + * Each check's latest report that still counts: a check that reported cancelled drops once a newer run of + * its workflow exists on the head, as when `cancel-in-progress` cancels a run for a newer one, which may + * never report the cancelled run's names, such as a matrix job's unexpanded name. Any other result keeps + * counting, as does a cancelled run nothing replaced. A rerun reports anew in its run's check suite, so + * the rollup holds only its latest attempt. Queries must also ask for a check run's `conclusion` and + * `checkSuite { databaseId }`; `runs` are the head's workflow runs, needed only when a latest context is + * {@link cancelled}. + */ +export function currentContexts(contexts: T[], runs: WorkflowRun[]): T[] { + const replaced = new Set(runs.filter((run) => replacedRun(run, runs)).map((run) => run.check_suite_id)); + const suite = (context: T) => + Number((context.checkSuite as { databaseId?: unknown } | null | undefined)?.databaseId); + return latestContexts(contexts.filter((context) => !(cancelled(context) && replaced.has(suite(context))))); +} + /** Whether a context passed, failed, or is still pending. Neutral and skipped check runs pass. */ export function contextOutcome(context: RollupContext): "passed" | "failing" | "pending" { if (context.__typename === "CheckRun") { @@ -51,9 +94,9 @@ export function contextOutcome(context: RollupContext): "passed" | "failing" | " return state === "SUCCESS" ? "passed" : "failing"; } -/** The head's check state from its latest contexts: any failing fails, else any pending is pending. */ -export function checksState(contexts: RollupContext[]): "SUCCESS" | "FAILURE" | "PENDING" { - const outcomes = latestContexts(contexts).map(contextOutcome); +/** The state of a head's current contexts, from {@link currentContexts}: any failing fails, else any pending is pending. */ +export function checksState(current: RollupContext[]): "SUCCESS" | "FAILURE" | "PENDING" { + const outcomes = current.map(contextOutcome); if (outcomes.includes("failing")) return "FAILURE"; return outcomes.includes("pending") ? "PENDING" : "SUCCESS"; } diff --git a/test/checks.test.ts b/test/checks.test.ts index cbf00fd27..e0737f53c 100644 --- a/test/checks.test.ts +++ b/test/checks.test.ts @@ -1,6 +1,6 @@ import { expect, test } from "vitest"; -import { checksState, contextOutcome, latestContexts } from "../src/github/checks"; +import { checksState, contextOutcome, currentContexts, latestContexts, type WorkflowRun } from "../src/github/checks"; const ACTIONS = 15368; const run = (name: string, databaseId: number, conclusion: string | null, app = ACTIONS) => ({ @@ -30,22 +30,22 @@ const moq7325 = [ test("only the latest run of each check counts, as on moq-dev/moq#7325", () => { expect(latestContexts(moq7325)).toEqual([moq7325[2], moq7325[3]]); - expect(checksState(moq7325)).toBe("SUCCESS"); + expect(checksState(latestContexts(moq7325))).toBe("SUCCESS"); }); test("a newer run decides the check whatever order the rollup lists it in", () => { - expect(checksState([run("test", 9, null), run("test", 3, "SUCCESS")])).toBe("PENDING"); - expect(checksState([run("test", 3, "SUCCESS"), run("test", 9, "FAILURE")])).toBe("FAILURE"); - expect(checksState([run("test", 9, "SUCCESS"), run("test", 3, "FAILURE")])).toBe("SUCCESS"); + expect(checksState(latestContexts([run("test", 9, null), run("test", 3, "SUCCESS")]))).toBe("PENDING"); + expect(checksState(latestContexts([run("test", 3, "SUCCESS"), run("test", 9, "FAILURE")]))).toBe("FAILURE"); + expect(checksState(latestContexts([run("test", 9, "SUCCESS"), run("test", 3, "FAILURE")]))).toBe("SUCCESS"); }); test("the same name from two apps, or as a run and a status, counts as separate checks", () => { const twoApps = [run("test", 1, "FAILURE", 99), run("test", 2, "SUCCESS")]; expect(latestContexts(twoApps)).toEqual(twoApps); - expect(checksState(twoApps)).toBe("FAILURE"); + expect(checksState(latestContexts(twoApps))).toBe("FAILURE"); const runAndStatus = [run("deploy", 1, "SUCCESS"), status("deploy", "FAILURE", "2026-10-07T12:00:00Z")]; expect(latestContexts(runAndStatus)).toEqual(runAndStatus); - expect(checksState(runAndStatus)).toBe("FAILURE"); + expect(checksState(latestContexts(runAndStatus))).toBe("FAILURE"); }); test("a commit status counts by its newest report, and on a tie the one listed later", () => { @@ -75,3 +75,76 @@ test("outcomes follow GitHub's passing results", () => { ]); expect(checksState([])).toBe("SUCCESS"); }); + +const job = (name: string, databaseId: number, conclusion: string, suite: number) => ({ + ...run(name, databaseId, conclusion), + checkSuite: { databaseId: suite, app: { databaseId: ACTIONS } }, +}); +const workflowRun = (id: number, started: string, workflow = 1): WorkflowRun => ({ + id, + workflow_id: workflow, + check_suite_id: id * 10, + run_started_at: started, +}); + +// kixelated/token-max's head daaaadc: an `edited` run cancelled each `synchronize` run through +// `cancel-in-progress`, and the cancelled run's matrix job kept its unexpanded name, which the newest +// run never reports. GitHub's rollup state was FAILURE. +const tokenMax = { + runs: [ + workflowRun(1, "2026-11-12T23:39:32Z"), + workflowRun(2, "2026-11-12T23:39:42Z"), + workflowRun(3, "2026-11-12T23:42:53Z"), + workflowRun(4, "2026-11-12T23:42:56Z"), + ], + contexts: [ + job("Tests (${{ matrix.os }})", 11, "SKIPPED", 10), + job("Check", 12, "FAILURE", 10), + job("Tests (${{ matrix.os }})", 21, "SKIPPED", 20), + job("Check", 22, "FAILURE", 20), + job("Tests (${{ matrix.os }})", 31, "CANCELLED", 30), + job("Check", 32, "FAILURE", 30), + job("Tests (macos-15)", 41, "SUCCESS", 40), + job("Check", 42, "SUCCESS", 40), + ], +}; + +test("a cancelled check drops once a newer run of its workflow exists, as on kixelated/token-max's daaaadc", () => { + expect(checksState(latestContexts(tokenMax.contexts))).toBe("FAILURE"); + const current = currentContexts(tokenMax.contexts, tokenMax.runs); + expect(current.map((context) => context.databaseId)).toEqual([21, 41, 42]); + expect(checksState(current)).toBe("SUCCESS"); +}); + +test("a cancelled check counts while nothing replaced its run, and other results always count", () => { + const contexts = [job("test", 1, "CANCELLED", 10), job("lint", 2, "FAILURE", 10), job("build", 3, "CANCELLED", 20)]; + // Run 2 is another workflow, so it replaces nothing of run 1's. + expect( + checksState( + currentContexts(contexts, [ + workflowRun(1, "2026-11-12T10:00:00Z"), + workflowRun(2, "2026-11-12T11:00:00Z", 2), + ]), + ), + ).toBe("FAILURE"); + const replaced = currentContexts(contexts, [ + workflowRun(1, "2026-11-12T10:00:00Z"), + workflowRun(9, "2026-11-12T11:00:00Z"), + ]); + expect(replaced.map((context) => context.name)).toEqual(["lint", "build"]); + // Another app's cancelled check has no workflow run to be replaced by. + expect(currentContexts([run("deploy", 1, "CANCELLED", 99)], [workflowRun(1, "2026-11-12T10:00:00Z")])).toHaveLength( + 1, + ); +}); + +test("a rerun is newer than every run that started before its latest attempt", () => { + // Run 1 was rerun after run 2 started, and its rerun cancelled run 2. + const runs = [workflowRun(1, "2026-11-12T12:00:00Z"), workflowRun(2, "2026-11-12T11:00:00Z")]; + const contexts = [job("test", 1, "SUCCESS", 10), job("test", 2, "CANCELLED", 20)]; + expect(currentContexts(contexts, runs)).toEqual([contexts[0]]); + // Runs that started in the same second order by ID. + const tied = [workflowRun(1, "2026-11-12T12:00:00Z"), workflowRun(2, "2026-11-12T12:00:00Z")]; + expect(currentContexts([job("test", 1, "CANCELLED", 10)], tied)).toEqual([]); + expect(currentContexts([job("test", 1, "CANCELLED", 20)], tied)).toHaveLength(1); +}); diff --git a/test/github.ts b/test/github.ts index b6b1a51e3..861cec8b7 100644 --- a/test/github.ts +++ b/test/github.ts @@ -26,7 +26,16 @@ export type Pull = Issue & { checks: "SUCCESS" | "FAILURE" | "PENDING" | null; /** The check runs behind `checks`, oldest first. */ /** `commit` is the one a run reports on; the head by default. */ - runs?: { name: string; conclusion: string; url: string; app?: number; context?: boolean; commit?: string }[]; + runs?: { + name: string; + conclusion: string; + url: string; + app?: number; + context?: boolean; + commit?: string; + /** The check suite of the workflow run that reported it. */ + suite?: number; + }[]; review: "APPROVED" | "CHANGES_REQUESTED" | "REVIEW_REQUIRED" | null; /** Oldest first; `commit` is the one a review was submitted on, the head by default. */ reviews?: { state: string; author: string; body?: string; commit?: string }[]; @@ -143,6 +152,9 @@ export type Repo = { /** GitHub Actions workflow runs, as `GET /actions/runs` lists them, with their jobs and each job's log. */ actionRuns?: { id: number; + workflow_id?: number; + check_suite_id?: number; + run_started_at?: string; name: string; head_branch: string; head_sha: string; @@ -259,7 +271,7 @@ function contextPage(pull: Pick, after: unknown) { status: "COMPLETED", conclusion: run.conclusion, detailsUrl: run.url, - checkSuite: { app: { databaseId: run.app ?? ACTIONS_APP } }, + checkSuite: { databaseId: run.suite ?? null, app: { databaseId: run.app ?? ACTIONS_APP } }, }, ); const end = start + 100; diff --git a/test/hold.test.ts b/test/hold.test.ts index 59454cab8..b2271f830 100644 --- a/test/hold.test.ts +++ b/test/hold.test.ts @@ -43,6 +43,8 @@ class FakePull { rules: ObjectValue[] = []; /** The head's check runs, as its `statusCheckRollup` lists them. */ checks: ObjectValue[] = []; + /** The head's workflow runs, as `GET /actions/runs` lists them. */ + runs: ObjectValue[] = []; autoMerge: ObjectValue | null = null; queueEntry: ObjectValue | null = null; labels: string[] = []; @@ -106,6 +108,8 @@ class FakePull { return json(200, []); } if (url.pathname === "/repos/example/project/branches/main") return json(200, { protection: {} }); + if (url.pathname === "/repos/example/project/actions/runs" && url.searchParams.get("head_sha") === this.head) + return json(200, { total_count: this.runs.length, workflow_runs: this.runs }); if (url.pathname === `/repos/example/project/compare/main...${this.head}`) { this.comparisons.push(`${url.pathname}${url.search}`); return json(200, { status: this.comparison, base_commit: { sha: this.base } }); @@ -332,6 +336,26 @@ describe("merge --land", () => { expect(pull.writes).not.toEqual([]); }); + test("lands past a cancelled check once a newer run of its workflow exists, as on kixelated/token-max#78", async () => { + const pull = new FakePull(); + const run = (databaseId: number, name: string, conclusion: string, suite: number) => ({ + __typename: "CheckRun", + databaseId, + name, + status: "COMPLETED", + conclusion, + detailsUrl: `https://ci.example/${databaseId}`, + checkSuite: { databaseId: suite, app: { databaseId: 15368 } }, + }); + pull.checks = [run(1, "Tests (${{ matrix.os }})", "CANCELLED", 10), run(2, "Tests (macos-15)", "SUCCESS", 20)]; + pull.runs = [{ id: 1, workflow_id: 7, check_suite_id: 10, run_started_at: "2026-11-12T23:42:53Z" }]; + expect(await refused(land(PR, HEAD, "merge", pull.deps()))).toContain("Tests (${{ matrix.os }})"); + expect(pull.writes).toEqual([]); + pull.runs.push({ id: 2, workflow_id: 7, check_suite_id: 20, run_started_at: "2026-11-12T23:42:56Z" }); + await land(PR, HEAD, "merge", pull.deps()); + expect(pull.writes).not.toEqual([]); + }); + test("refuses when the token cannot see the auto-merge setting", async () => { const pull = new FakePull(); pull.allowAutoMerge = null; diff --git a/test/land-bump.test.ts b/test/land-bump.test.ts index 5c46f7e36..4bb3e233c 100644 --- a/test/land-bump.test.ts +++ b/test/land-bump.test.ts @@ -244,6 +244,9 @@ const bare = (world: World) => world.remote.slice("file://".length); beforeEach(() => landed.mockClear()); +/** A workflow run as `GET /actions/runs` lists it, before its status. */ +const STARTED = { id: 1, workflow_id: 10, event: "push", check_suite_id: 100, run_started_at: "2026-11-12T12:00:00Z" }; + describe("questInput", () => { test("finds the one root input locking the source, skipping follows and other inputs", () => { expect(questInput(JSON.parse(lockFile(OLD, true)), SOURCE)).toEqual({ @@ -385,11 +388,11 @@ describe("bumpPass", () => { target.suites[head][0].status = "completed"; // A queued workflow with no check run yet still holds it. target.suites[head].push({ status: "queued", latest_check_runs_count: 0, app: { slug: "github-actions" } }); - target.runs[head] = [{ status: "queued", conclusion: null }]; + target.runs[head] = [{ ...STARTED, status: "queued", conclusion: null }]; expect(await bumpPass(ctx, NEW)).toEqual([]); expect(landed).not.toHaveBeenCalled(); - target.runs[head] = [{ status: "completed", conclusion: "success" }]; + target.runs[head] = [{ ...STARTED, status: "completed", conclusion: "success" }]; expect(await bumpPass(ctx, NEW)).toEqual(["bump landing moq-dev/widget 7"]); expect(landed).toHaveBeenCalledExactlyOnceWith( { ...target.target, number: 7 }, @@ -407,8 +410,20 @@ describe("bumpPass", () => { const head = git(bare(target), "rev-parse", BUMP_BRANCH); // Push and pull_request share a cancel-in-progress group: the pull_request run cancelled the push run, // whose later job reported cancelled before the newer run started it. - const cancelled = { id: 1, workflow_id: 10, event: "push", check_suite_id: 100 }; - const newer = { id: 2, workflow_id: 10, event: "pull_request", check_suite_id: 200 }; + const cancelled = { + id: 1, + workflow_id: 10, + event: "push", + check_suite_id: 100, + run_started_at: "2026-11-12T12:00:00Z", + }; + const newer = { + id: 2, + workflow_id: 10, + event: "pull_request", + check_suite_id: 200, + run_started_at: "2026-11-12T12:00:01Z", + }; const run = (suite: number, id: number, name: string, status: string, conclusion?: string) => ({ __typename: "CheckRun", databaseId: id, @@ -448,7 +463,7 @@ describe("bumpPass", () => { { id: 5, workflow_id: 30, event: "push", conclusion: "failure" }, { id: 6, workflow_id: 30, event: "pull_request", conclusion: "success" }, { id: 7, workflow_id: 40, event: "push", conclusion: "cancelled" }, - ]; + ].map((run) => ({ ...run, check_suite_id: run.id * 10, run_started_at: "2026-11-12T12:00:00Z" })); // Another event's failure still counts, as does a cancellation nothing replaced. expect(latestRuns(runs).map((run) => run.id)).toEqual([2, 4, 5, 6, 7]); }); diff --git a/test/land.test.ts b/test/land.test.ts index a497eebee..ddca6aada 100644 --- a/test/land.test.ts +++ b/test/land.test.ts @@ -393,6 +393,7 @@ class Forge { pull_requests: "write", issues: "write", metadata: "read", + actions: "read", ...permissions, }, }), @@ -1151,6 +1152,50 @@ describe.skipIf(process.platform === "win32")("quest land", () => { expect(plan.waiting?.map(({ number }) => number)).toEqual([3]); }); + test("drops a cancelled check once a newer run of its workflow exists, even one with no checks yet", async () => { + const forge = new Forge(); + const test = (conclusion: string, suite: number) => ({ name: "test", conclusion, url: "u", suite }); + const workflow = (pull: Pull, runs: [number, string, string][]) => { + for (const [id, conclusion, started] of runs) + (forge.repo.actionRuns ??= []).push({ + id, + workflow_id: 7, + check_suite_id: id * 10, + run_started_at: started, + name: "CI", + head_branch: pull.branch ?? "", + head_sha: pull.head!, + status: conclusion === "queued" ? "queued" : "completed", + conclusion: conclusion === "queued" ? null : conclusion, + html_url: "u", + jobs: [], + }); + }; + // As on kixelated/token-max#78: an edit's run cancelled the push's run, and has yet to report a check. + const replaced = forge.pull("Replaced", { "1.txt": "1\n" }, { pull: { runs: [test("CANCELLED", 10)] } }); + workflow(replaced, [ + [1, "cancelled", "2026-11-12T23:42:53Z"], + [2, "queued", "2026-11-12T23:42:56Z"], + ]); + // A cancelled run that nothing replaced still fails. + const alone = forge.pull("Alone", { "2.txt": "2\n" }, { pull: { runs: [test("CANCELLED", 30)] } }); + workflow(alone, [[3, "cancelled", "2026-11-12T23:42:53Z"]]); + // Rerunning the cancelled run makes it the newest, so the run it cancelled in turn is the replaced one. + const rerun = forge.pull( + "Rerun", + { "3.txt": "3\n" }, + { pull: { runs: [test("SUCCESS", 40), test("CANCELLED", 50)] } }, + ); + workflow(rerun, [ + [4, "success", "2026-11-12T23:50:00Z"], + [5, "cancelled", "2026-11-12T23:43:00Z"], + ]); + const plan = await resolveQueue(REPOSITORY, { base: "main", method: "squash" }, await forge.deps()); + expect(plan.queue.map((entry) => entry.number)).toEqual([3]); + expect(plan.waiting?.map(({ number }) => number)).toEqual([1]); + expect(plan.eject.map((ejected) => [ejected.number, ejected.reason])).toEqual([[2, "failed_checks"]]); + }); + test("counts a required check only from the app its rule names", async () => { const forge = new Forge(); forge.repo.rules = [ diff --git a/test/status.test.ts b/test/status.test.ts index 51da6e172..e08ef1de4 100644 --- a/test/status.test.ts +++ b/test/status.test.ts @@ -16,6 +16,8 @@ const page = (nodes: Node[], next?: string) => ({ }); /** A recorded GraphQL response; omitted connections stand for ones the query skipped. */ +const CI = ".github/workflows/ci.yml"; + function pull( fields: { head?: string; @@ -114,6 +116,10 @@ function setup( warnings?: string[]; /** The base-to-head diff per compared head, or the status GitHub refuses it with. */ diffs?: Record; + /** The base's active ruleset rules. */ + rules?: Node[]; + /** The head's workflow runs, as `GET /actions/runs` lists them. */ + runs?: Node[]; } = {}, ) { const queries: Record[] = []; @@ -139,6 +145,14 @@ function setup( return Response.json({ message: "Resource not accessible by integration" }, { status: 403 }); return Response.json(page.rows, { headers: page.next ? { Link: `<${page.next}>; rel="next"` } : {} }); } + if (path.pathname === "/repos/example/project/branches/main") + return Response.json({ protection: { enabled: false } }); + if (path.pathname === "/repos/example/project/rules/branches/main") + return Response.json(options.rules ?? []); + if (path.pathname === "/repos/example/project/actions/runs") { + if (!options.runs) throw new Error("unexpected workflow run request"); + return Response.json({ total_count: options.runs.length, workflow_runs: options.runs }); + } const compare = /^\/repos\/example\/project\/compare\/main\.\.\.([0-9a-f]{40})$/.exec(path.pathname); if (compare) { expect(new Headers(init?.headers).get("Accept")).toBe("application/vnd.github.diff"); @@ -185,36 +199,45 @@ function setup( } test("reports checks by requiredness, each reviewer's latest review against the head, and open threads", async () => { - const fixture = setup([ - pull({ - checks: page([ - run("lint", "COMPLETED", "FAILURE", true), - run("docs", "COMPLETED", "CANCELLED", false), - run("test", "IN_PROGRESS", null, true), - run("build", "COMPLETED", "SUCCESS", true), - run("publish", "COMPLETED", "SKIPPED", false), - { - __typename: "StatusContext", - context: "ci/legacy", - state: "ERROR", - targetUrl: null, - isRequired: false, - }, - { __typename: "StatusContext", context: "deploy", state: "EXPECTED", targetUrl: "", isRequired: true }, - ]), - reviews: page([ - review("alice", "APPROVED", B, 1), - review("bob", "CHANGES_REQUESTED", B, 2), - review("alice", "COMMENTED", A, 3, [ - { content: "THUMBS_UP", createdAt: "2026-10-07T12:04:00Z", user: { login: "codex[bot]" } }, + const fixture = setup( + [ + pull({ + checks: page([ + run("lint", "COMPLETED", "FAILURE", true), + run("docs", "COMPLETED", "CANCELLED", false), + run("test", "IN_PROGRESS", null, true), + run("build", "COMPLETED", "SUCCESS", true), + run("publish", "COMPLETED", "SKIPPED", false), + { + __typename: "StatusContext", + context: "ci/legacy", + state: "ERROR", + targetUrl: null, + isRequired: false, + }, + { + __typename: "StatusContext", + context: "deploy", + state: "EXPECTED", + targetUrl: "", + isRequired: true, + }, ]), - review("viewer", "PENDING", A, 4), - review("gone", "COMMENTED", null, 5), - ]), - threads: page([thread("T1", true), thread("T2", false), thread("T3", false, null, "author")]), - reactions: [{ content: "EYES", createdAt: "2026-10-07T12:00:00Z", user: null }], - }), - ]); + reviews: page([ + review("alice", "APPROVED", B, 1), + review("bob", "CHANGES_REQUESTED", B, 2), + review("alice", "COMMENTED", A, 3, [ + { content: "THUMBS_UP", createdAt: "2026-10-07T12:04:00Z", user: { login: "codex[bot]" } }, + ]), + review("viewer", "PENDING", A, 4), + review("gone", "COMMENTED", null, 5), + ]), + threads: page([thread("T1", true), thread("T2", false), thread("T3", false, null, "author")]), + reactions: [{ content: "EYES", createdAt: "2026-10-07T12:00:00Z", user: null }], + }), + ], + { runs: [] }, + ); const status = await pullRequestStatus(pr, fixture.deps); expect(fixture.queries).toHaveLength(1); expect(fixture.holdQueries).toHaveLength(1); @@ -460,6 +483,80 @@ test("drops the landing exit once the PR enters the merge queue or auto-merge ag expect(await stopped(ejected, { mergeQueueEntry: queue("2026-10-07T12:00:59Z") })).toBe("merge_conflict"); }); +test("drops a cancelled check a newer run of its workflow replaced, as on kixelated/token-max#78", async () => { + const job = (name: string, conclusion: string, databaseId: number, suite: number) => ({ + ...run(name, "COMPLETED", conclusion, false), + databaseId, + checkSuite: { databaseId: suite, app: { databaseId: 15368 }, workflowRun: { file: { path: CI } } }, + }); + const runs = (started: string) => [ + { id: 1, workflow_id: 7, check_suite_id: 10, run_started_at: "2026-11-12T23:42:53Z" }, + { id: 2, workflow_id: 7, check_suite_id: 20, run_started_at: started }, + ]; + const checks = () => + page([job("Tests (${{ matrix.os }})", "CANCELLED", 1, 10), job("Tests (macos-15)", "SUCCESS", 2, 20)]); + const fixture = setup([pull({ checks: checks(), reviews: page([]), threads: page([]) })], { + runs: runs("2026-11-12T23:42:56Z"), + }); + const status = await pullRequestStatus(pr, fixture.deps); + expect(status.checks).toEqual({ state: "success", passed: 1, failing: [], pending: [] }); + // A rerun of the cancelled run started later, so its run is the newest and its cancellation counts. + const rerun = setup([pull({ checks: checks(), reviews: page([]), threads: page([]) })], { + runs: runs("2026-11-12T23:40:00Z"), + }); + expect((await pullRequestStatus(pr, rerun.deps)).checks.state).toBe("failure"); +}); + +test("a required check or workflow nothing reports is pending, except the gate's own check", async () => { + const job = (name: string, workflow: string) => ({ + ...run(name, "COMPLETED", "SUCCESS", false), + databaseId: 1, + checkSuite: { databaseId: 10, app: { databaseId: 15368 }, workflowRun: { file: { path: workflow } } }, + }); + const rules = [ + { + type: "required_status_checks", + parameters: { + required_status_checks: [{ context: "test" }, { context: "lint" }, { context: "quest land" }], + }, + }, + { type: "workflows", parameters: { workflows: [{ path: CI }, { path: ".github/workflows/pr.yml" }] } }, + ]; + const fixture = setup([pull({ checks: page([job("test", CI)]), reviews: page([]), threads: page([]) })], { + rules, + }); + const status = await pullRequestStatus(pr, fixture.deps); + expect(statusLines(status).filter((line) => line.startsWith("check"))).toEqual([ + "checks pending passed=1 failing=0 pending=2", + "check pending required expected - lint", + "check pending required expected - .github/workflows/pr.yml", + ]); + // With no checks on the head at all, the requirements still leave it pending. + const empty = setup([pull({ checks: null, reviews: page([]), threads: page([]) })], { rules }); + expect((await pullRequestStatus(pr, empty.deps)).checks.state).toBe("pending"); +}); + +test("a job in a required workflow counts as required", async () => { + const fixture = setup( + [ + pull({ + checks: page([ + { + ...run("build", "COMPLETED", "FAILURE", false), + databaseId: 1, + checkSuite: { databaseId: 10, app: { databaseId: 15368 }, workflowRun: { file: { path: CI } } }, + }, + ]), + reviews: page([]), + threads: page([]), + }), + ], + { rules: [{ type: "workflows", parameters: { workflows: [{ path: CI }] } }] }, + ); + const status = await pullRequestStatus(pr, fixture.deps); + expect(status.checks.failing.map((check) => [check.name, check.required])).toEqual([["build", true]]); +}); + test("counts only each check's newest run from its app", async () => { const rerun = (name: string, conclusion: string, databaseId: number, app = 15368) => ({ ...run(name, "COMPLETED", conclusion, true), @@ -483,7 +580,7 @@ test("counts only each check's newest run from its app", async () => { const status = await pullRequestStatus(pr, fixture.deps); // The fixture answers whatever is asked, so the query must ask for what tells runs apart. expect(fixture.texts[0].replace(/\s+/g, " ")).toContain( - "... on CheckRun { databaseId name status conclusion detailsUrl isRequired(pullRequestNumber: $number) checkSuite { app { databaseId } } }", + "... on CheckRun { databaseId name status conclusion detailsUrl isRequired(pullRequestNumber: $number) checkSuite { databaseId app { databaseId } workflowRun { file { path } } } }", ); expect(status.checks.passed).toBe(2); expect(status.checks.failing.map((check) => check.name)).toEqual(["test", "lint"]); diff --git a/test/wait.test.ts b/test/wait.test.ts index f3233bb62..896d45b44 100644 --- a/test/wait.test.ts +++ b/test/wait.test.ts @@ -1077,7 +1077,7 @@ test("a rerun supersedes a cancelled run of a required check, which never wakes expect(lines[0]).toMatch(/^2026-10-07T12:08:00Z checks:passed check /); const query = (fixture.checkCalls[0].body as { query: string }).query.replace(/\s+/g, " "); expect(query).toContain("... on CheckRun { databaseId name"); - expect(query).toContain("checkSuite { status app { databaseId }"); + expect(query).toContain("checkSuite { databaseId status app { databaseId }"); }); test("a superseded workflow run's failed gate never wakes the wait, as on moq-dev/moq#7325", async () => { @@ -1219,7 +1219,7 @@ test("checks:passed is dated when the head goes idle, after required checks fini expect(lines[0]).toMatch(/^2026-10-07T12:08:00Z checks:passed check /); const query = (fixture.checkCalls[0].body as { query: string }).query.replace(/\s+/g, " "); expect(query).toContain("... on CheckRun { databaseId name"); - expect(query).toContain("checkSuite { status app { databaseId }"); + expect(query).toContain("checkSuite { databaseId status app { databaseId }"); }); test("with no required checks, an unfinished workflow run holds back checks:passed", async () => { From 45ad1db4242d5903c9255a8f30156e66ff7fe2e6 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Thu, 12 Nov 2026 17:13:52 -0800 Subject: [PATCH 03/10] fix(checks): address review round 1 Match required checks by app, read requirements only for open PRs, keep wait busy while a replacing run is unfinished, let a run not yet started stand in by its creation time, dedupe required workflows, and update quest status --help. Co-Authored-By: Claude Opus 5.5 --- README.md | 11 +++++--- src/cli/github.ts | 27 +++++++++++------- src/cli/hold.ts | 2 +- src/cli/land.ts | 7 +++-- src/cli/main.ts | 7 +++-- src/cli/status.ts | 34 ++++++++++++++++------- src/cli/wait.ts | 18 ++++++++---- test/status.test.ts | 51 +++++++++++++++++++++++++++++++++- test/wait.test.ts | 68 ++++++++++++++++++++++++++++++++++++++++++++- 9 files changed, 189 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index d4bdd24b6..16d3607b3 100644 --- a/README.md +++ b/README.md @@ -417,7 +417,8 @@ CI results are read for the current head. The first required check to fail prints `checks:failed` right away. `checks:passed` prints once nothing on the head is still going (no pending check and no unfinished GitHub Actions run, which may still create jobs), every check and workflow the base branch names is -present (except `quest land`'s, which no head carries), and every required +present (except `quest land`'s, which no head carries), each required check +from the app its requirement names, if any, and every required check passed; it names the last required check that passed and is dated when the head went idle. Each prints once per head, with the check's name (spaces as `_`) in the actor field and its details URL. Results count as @@ -503,7 +504,7 @@ comes last, and a missing value prints as `-`: | `merge-queue` | Queue state, position, and when it was enqueued. | | `landing-stopped` | The reason the latest merge-queue entry, auto-merge, or [`quest land`](#land-a-batch-with-quest-land) queue entry ended (such as `merge_conflict`, `failed_checks`, `manual`, `manually_disabled`, or `merged`), who ended it, and when; `-` once the PR has entered the merge queue or auto-merge again since. | | `checks` | `failure` if any check fails, else `pending` if any is pending or a requirement is unreported, else `success`, and `passed=`, `failing=`, `pending=` counts, all from the checks that count; `-` when the head has no checks and the base requires none. | -| `check` | `failing` or `pending`, `required` or `optional`, the result, details URL, and name. A required check or required workflow nothing reports yet prints as `pending required expected -` with its name, or the workflow's path. | +| `check` | `failing` or `pending`, `required` or `optional`, the result, details URL, and name. A required check or required workflow nothing reports yet prints as `pending required expected -` with its name, followed by `(from app )` when the requirement names an app, or the workflow's path. | | `review` | `current` or `stale` against the head, state, reviewer, time, and URL of each reviewer's latest review. | | `checkpoint` | Each bot reviewer that approves or requests changes, such as one whose approval the base requires, its round, and its review's URL, when that review is of the head and its latest verdict there, ignoring plain comments, is neither an approval nor a dismissal, at the end of its third, sixth, ... round: [`/quest-review`'s design checkpoint](#review-locally) for an online reviewer. A round is one commit it reviewed; a dismissed review counts as one that approves or requests changes. Only printed when due. | | `reacted:` | Actor, time, and the PR or review reacted to, as `quest wait` names reactions. | @@ -524,8 +525,10 @@ before it. Any other result keeps counting, as does a cancelled run nothing replaced. Only then does it read the head's workflow runs, which needs Actions read access. GitHub's own rollup state counts the superseded runs too. A required check is one branch protection or a ruleset requires for this PR, or a job of a -workflow a ruleset requires; like `quest wait`, it matches a requirement by name -and leaves out `quest land`'s check, which no head carries. `--json` prints the +workflow a ruleset requires. Like `quest wait`, it reads an open PR's +requirements from the base, matches a required check by name and, when the +requirement names one, its app, as GitHub and `quest land` do, and leaves out +`quest land`'s check, which no head carries. `--json` prints the same facts as one object with the fields `url`, `state`, `draft`, `head`, `mergeable`, `mergeState`, `reviewDecision`, `autoMerge`, `mergeQueue`, `landingStopped`, `checks` (`state`, `passed`, `failing`, `pending`), `reviews`, `checkpoints` (`reviewer`, `round`, `url`), `reactions`, diff --git a/src/cli/github.ts b/src/cli/github.ts index a42fe7fa3..8ac5e9fca 100644 --- a/src/cli/github.ts +++ b/src/cli/github.ts @@ -561,10 +561,14 @@ export async function requirements(github: GitHub, repository: Repository, branc (check, index) => checks.findIndex((other) => other.name === check.name && other.app === check.app) === index, ), - workflows: rules - .filter((rule) => rule.type === "workflows") - .flatMap((rule) => array(object(rule.parameters).workflows)) - .map((row) => string(row.path)), + workflows: [ + ...new Set( + rules + .filter((rule) => rule.type === "workflows") + .flatMap((rule) => array(object(rule.parameters).workflows)) + .map((row) => string(row.path)), + ), + ], rules, // Unknown counts as on, so a reader that needs the settings reads them rather than assume none. classic: protection.enabled !== false, @@ -584,7 +588,8 @@ export async function workflowRuns(github: GitHub, repository: Repository, head: id: Number(row.id), workflow_id: Number(row.workflow_id), check_suite_id: Number(row.check_suite_id), - run_started_at: string(row.run_started_at), + // A run not yet started, such as one awaiting approval, has no start time, so its creation stands in. + run_started_at: string(row.run_started_at ?? row.created_at), }); path = link(response, "next"); } @@ -592,18 +597,20 @@ export async function workflowRuns(github: GitHub, repository: Repository, head: } /** - * Each check's latest report on `head` that still counts, as {@link currentContexts} judges it. The head's - * workflow runs are read only when a latest report is a cancelled check run, the only report they can drop. + * Each check's latest report on `head` that still counts, as {@link currentContexts} judges it, and the + * head's workflow runs when they were read: only when a latest report is a cancelled check run, the only + * report they can drop. */ export async function currentChecks( github: GitHub, repository: Repository, head: string, contexts: T[], -): Promise { +): Promise<{ checks: T[]; runs?: WorkflowRun[] }> { const latest = latestContexts(contexts); - if (!latest.some(cancelled)) return latest; - return currentContexts(contexts, await workflowRuns(github, repository, head)); + if (!latest.some(cancelled)) return { checks: latest }; + const runs = await workflowRuns(github, repository, head); + return { checks: currentContexts(contexts, runs), runs }; } /** diff --git a/src/cli/hold.ts b/src/cli/hold.ts index 6eebee74c..3153ef454 100644 --- a/src/cli/hold.ts +++ b/src/cli/hold.ts @@ -326,7 +326,7 @@ export async function land( * own queue's informational check, which reports how a past pick ended rather than the head. */ async function passing(github: GitHub, pr: PullRequest, url: string, sha: string): Promise { - const failing = (await currentChecks(github, pr, sha, await contexts(github, pr, sha))) + const failing = (await currentChecks(github, pr, sha, await contexts(github, pr, sha))).checks .filter((context) => context.name !== QUEUE_CHECK) .map(classifyCheck) .filter(({ outcome }) => outcome === "failing") diff --git a/src/cli/land.ts b/src/cli/land.ts index 7b5b4eb7c..babc5e9a4 100644 --- a/src/cli/land.ts +++ b/src/cli/land.ts @@ -434,7 +434,7 @@ export async function resolveQueue( const commit = object(object(array(object(node.commits).nodes)[0]).commit); const rollup = commit.oid === approved ? commit.statusCheckRollup : undefined; const found = await contexts(github, repository, approved, rollup); - const unmet = checks(await currentChecks(github, repository, approved, found), required); + const unmet = checks((await currentChecks(github, repository, approved, found)).checks, required); // An approval can still arrive on the pinned head, such as an automated reviewer's, so it waits like a check. const approval = node.reviewDecision === "REVIEW_REQUIRED"; if (unmet.failing.length > 0) { @@ -498,7 +498,10 @@ export async function requiredChecks( sha: string, required: RequiredCheck[], ): Promise<{ failing: string[]; pending: string[] }> { - return checks(await currentChecks(github, repository, sha, await contexts(github, repository, sha)), required); + return checks( + (await currentChecks(github, repository, sha, await contexts(github, repository, sha))).checks, + required, + ); } /** diff --git a/src/cli/main.ts b/src/cli/main.ts index 0c5a9c2bf..89dab5a18 100644 --- a/src/cli/main.ts +++ b/src/cli/main.ts @@ -540,7 +540,7 @@ export function main(argv: string[], out: Output): number | Promise { "in one call. It reports facts; it does not decide whether the PR is ready or whose review counts.\n\n" + "Plain output prints one record per line, its type first and any free text (a check name or path) last: " + "url, state, draft, head, mergeable, merge-state, review-decision, review-record, auto-merge, merge-queue, " + - "landing-stopped, and checks, whose state and counts follow each check's latest run; review-record gives whether the PR body's ## Review record " + + "landing-stopped, and checks, whose state and counts follow the checks that count, pending while an open PR's base requires a check or workflow nothing reports; review-record gives whether the PR body's ## Review record " + "covers the head, as current, diff-identical (git diff ... prints the same as for the head it names), " + "stale, or unknown when GitHub cannot compare them, then the head it names last; auto-merge gives its method, who enabled it and when, and the head it was " + "enabled on, which differs from head once a push follows, as GitHub keeps auto-merge across a writer's " + @@ -548,7 +548,10 @@ export function main(argv: string[], out: Output): number | Promise { "activity, which GitHub lists up to minutes late); landing-stopped is the latest exit from the merge queue, auto-merge, or " + "quest land's queue, with the reason (such as merge_conflict, failed_checks, manual, or manually_disabled), " + "actor, and time, until the PR enters the merge queue or auto-merge again. Then " + - "a check line per failing or pending check, marked required or optional, counting only each check's latest run; a review line per " + + "a check line per failing or pending check, marked required or optional, counting only each check's latest run " + + "and dropping a cancelled check once a newer GitHub Actions run of its workflow exists on the head (reading the head's " + + "workflow runs, which needs Actions read access); a required check or workflow nothing reports prints as pending required " + + "expected, with its name or the workflow's path; a review line per " + "reviewer's latest review, marked current or stale against the head; a checkpoint line per bot " + "reviewer that approves or requests changes, its round, and its review, when that review is of the " + "head, while its latest verdict on the head is neither an approval nor a dismissal, and ends its third, sixth, ... round (one commit it reviewed), as " + diff --git a/src/cli/status.ts b/src/cli/status.ts index 102e1f06e..bafe9abf7 100644 --- a/src/cli/status.ts +++ b/src/cli/status.ts @@ -14,7 +14,7 @@ import { requirements, string, } from "./github"; -import { checksState, contextOutcome } from "../github/checks"; +import { appOf, checksState, contextOutcome } from "../github/checks"; import { EJECTED, LAND_CHECK, pinned } from "./land"; import { reviewSection } from "../core"; import { readHoldStatus, type HoldFact, type HoldReport } from "./hold"; @@ -203,8 +203,12 @@ export async function pullRequestStatus(pr: PullRequest, deps: GitHubDependencie if (ownership.head !== first!.headRefOid) throw new Error("the PR head changed while reading its holds; rerun quest status"); const head = string(first!.headRefOid); - const current = await currentChecks(github, pr, head, contexts); - const needs = await requiredOf(github, pr, string(first!.baseRefName)); + const { checks: current } = await currentChecks(github, pr, head, contexts); + // Only an open PR can still merge, and a closed one's base may be gone. + const needs: Needs = + first!.state === "OPEN" + ? await requiredOf(github, pr, string(first!.baseRefName)) + : { checks: [], workflows: [] }; const status = summarize(first!, rollup, current, needs, reviewNodes, threadNodes); status.reviewRecord = await reviewRecord(github, pr, first!, deps.warn); if (status.autoMerge !== null) status.autoMerge.head = await enabledHead(github, first!, deps.warn); @@ -321,8 +325,8 @@ export async function headBefore( /** The checks and workflow files a base requires of a PR head. */ export interface Needs { - /** Required check names; GitHub's own merge checks which app reports each. */ - checks: string[]; + /** Required checks, each from its app, or from any when `app` is null. */ + checks: { name: string; app: number | null }[]; /** Workflow files that must pass as a whole, by path. */ workflows: string[]; } @@ -330,13 +334,14 @@ export interface Needs { /** What `branch` requires of a PR head. The gate's own check is never on one, so it is left out. */ export async function requiredOf(github: GitHub, repository: Repository, branch: string): Promise { const found = await requirements(github, repository, branch); - const names = found.checks.map((check) => check.name).filter((name) => name !== LAND_CHECK); - return { checks: [...new Set(names)], workflows: found.workflows }; + return { checks: found.checks.filter((check) => check.name !== LAND_CHECK), workflows: found.workflows }; } -/** A check as a requirement matches it: its name, and the workflow file a GitHub Actions job runs in. */ +/** A check as a requirement matches it: its name, its app, and the workflow file a GitHub Actions job runs in. */ export interface Reported { name: string; + /** The app behind a check run; null for a commit status. */ + app: number | null; workflow?: string; } @@ -346,14 +351,23 @@ export function reported(context: ObjectValue): Reported { const file = run ? object(run).file : null; return { name: string(context.__typename === "CheckRun" ? context.name : context.context), + app: appOf(context), ...(file ? { workflow: string(object(file).path) } : {}), }; } -/** The required checks, by name, and required workflows, by path, that nothing on the head reports yet. */ +/** + * The required checks and workflows nothing on the head reports yet: a check by its name, from its app when + * the requirement names one, as GitHub and `quest land` match it, and a workflow by its path. + */ export function unreported(found: Reported[], needs: Needs): string[] { return [ - ...needs.checks.filter((name) => !found.some((entry) => entry.name === name)), + ...needs.checks + .filter( + (need) => + !found.some((entry) => entry.name === need.name && (need.app === null || entry.app === need.app)), + ) + .map((need) => (need.app === null ? need.name : `${need.name} (from app ${need.app})`)), ...needs.workflows.filter((path) => !found.some((entry) => entry.workflow === path)), ]; } diff --git a/src/cli/wait.ts b/src/cli/wait.ts index d6d3a15ed..3a142e925 100644 --- a/src/cli/wait.ts +++ b/src/cli/wait.ts @@ -354,7 +354,7 @@ async function watch( }; /** GraphQL says which checks the base branch requires, through branch protection or rulesets. */ const checks = async (): Promise< - { head: string; base: string; checks: Check[]; pull: ObjectValue } | undefined + { head: string; base: string; checks: Check[]; unfinished: boolean; pull: ObjectValue } | undefined > => { const rows: ObjectValue[] = []; let head: string | undefined; @@ -374,7 +374,9 @@ async function watch( after = page.hasNextPage === true ? string(page.endCursor) : null; } while (after !== null); const current = await currentChecks(github, pr, head!, rows); - return { head: head!, base: string(pull.baseRefName), checks: current.map(check), pull }; + // A replacing run may have no check run yet, so an unfinished run it read keeps the head busy. + const unfinished = current.runs?.some((run) => run.status !== "completed") ?? false; + return { head: head!, base: string(pull.baseRefName), checks: current.checks.map(check), unfinished, pull }; }; /** * What the base branch requires, read once per wait, as `quest status` reads it. Only a requirement @@ -491,7 +493,7 @@ async function watch( const head = await checks(); const reached = head ? [ - ...checkActivities(head.head, head.checks, await required(head.base), cursor.checks, prUrl), + ...checkActivities(head, await required(head.base), cursor.checks, prUrl), ...(await movedAutoMerge(head.head, head.pull)), ] : []; @@ -586,7 +588,12 @@ function check(row: ObjectValue): Check { * reported once per head when reached at or after the starting point. A base branch that requires * no checks requires them all. */ -function checkActivities(head: string, all: Check[], needs: Needs, state: Cursor["checks"], prUrl: string): Activity[] { +function checkActivities( + { head, checks: all, unfinished }: { head: string; checks: Check[]; unfinished: boolean }, + needs: Needs, + state: Cursor["checks"], + prUrl: string, +): Activity[] { const inWorkflow = (entry: Check) => entry.workflow !== undefined && needs.workflows.includes(entry.workflow); const required = needs.checks.length || needs.workflows.length @@ -617,7 +624,8 @@ function checkActivities(head: string, all: Check[], needs: Needs, state: Cursor // A pass waits for the head to go idle, including jobs a running workflow // may still create. Its date is the last completion, but its name and link // always identify a required check that passed. - const idle = all.every((entry) => entry.result && !entry.running) && unreported(all, needs).length === 0; + const idle = + !unfinished && all.every((entry) => entry.result && !entry.running) && unreported(all, needs).length === 0; const passed = idle && settled.length === required.length && settled.every((entry) => entry.result.outcome === "passed") ? settled.at(-1) diff --git a/test/status.test.ts b/test/status.test.ts index e08ef1de4..70c32d2d8 100644 --- a/test/status.test.ts +++ b/test/status.test.ts @@ -118,6 +118,8 @@ function setup( diffs?: Record; /** The base's active ruleset rules. */ rules?: Node[]; + /** The base branch is gone, so reading it fails. */ + noBase?: boolean; /** The head's workflow runs, as `GET /actions/runs` lists them. */ runs?: Node[]; } = {}, @@ -146,7 +148,9 @@ function setup( return Response.json(page.rows, { headers: page.next ? { Link: `<${page.next}>; rel="next"` } : {} }); } if (path.pathname === "/repos/example/project/branches/main") - return Response.json({ protection: { enabled: false } }); + return options.noBase + ? Response.json({ message: "Branch not found" }, { status: 404 }) + : Response.json({ protection: { enabled: false } }); if (path.pathname === "/repos/example/project/rules/branches/main") return Response.json(options.rules ?? []); if (path.pathname === "/repos/example/project/actions/runs") { @@ -536,6 +540,51 @@ test("a required check or workflow nothing reports is pending, except the gate's expect((await pullRequestStatus(pr, empty.deps)).checks.state).toBe("pending"); }); +test("a required check from another app than its requirement names stays pending, and a closed PR reads no requirements", async () => { + const rules = [ + { + type: "required_status_checks", + parameters: { required_status_checks: [{ context: "test", integration_id: 99 }] }, + }, + ]; + const test = { + ...run("test", "COMPLETED", "SUCCESS", false), + databaseId: 1, + checkSuite: { databaseId: 10, app: { databaseId: 15368 }, workflowRun: { file: { path: CI } } }, + }; + const open = setup([pull({ checks: page([test]), reviews: page([]), threads: page([]) })], { rules }); + expect(statusLines(await pullRequestStatus(pr, open.deps)).filter((line) => line.startsWith("check"))).toEqual([ + "checks pending passed=1 failing=0 pending=1", + "check pending required expected - test (from app 99)", + ]); + // A merged PR's base may be gone, and nothing it requires can change the PR anymore. + const merged = setup([pull({ state: "MERGED", checks: page([test]), reviews: page([]), threads: page([]) })], { + rules: undefined, + noBase: true, + }); + expect((await pullRequestStatus(pr, merged.deps)).checks.state).toBe("success"); +}); + +test("a replacing run that has not started yet stands in by its creation time", async () => { + const job = { + ...run("Tests (${{ matrix.os }})", "COMPLETED", "CANCELLED", false), + databaseId: 1, + checkSuite: { databaseId: 10, app: { databaseId: 15368 }, workflowRun: { file: { path: CI } } }, + }; + const fixture = setup([pull({ checks: page([job]), reviews: page([]), threads: page([]) })], { + runs: [ + { id: 1, workflow_id: 7, check_suite_id: 10, run_started_at: "2026-11-12T23:42:53Z" }, + { id: 2, workflow_id: 7, check_suite_id: 20, run_started_at: null, created_at: "2026-11-12T23:42:56Z" }, + ], + }); + expect((await pullRequestStatus(pr, fixture.deps)).checks).toEqual({ + state: "success", + passed: 0, + failing: [], + pending: [], + }); +}); + test("a job in a required workflow counts as required", async () => { const fixture = setup( [ diff --git a/test/wait.test.ts b/test/wait.test.ts index 896d45b44..4aabd57ee 100644 --- a/test/wait.test.ts +++ b/test/wait.test.ts @@ -88,6 +88,10 @@ interface CheckFixture { running?: boolean; /** A check run's ID, which grows with each run; its place in the page by default. */ id?: number; + /** The app behind a check run; GitHub Actions by default. */ + app?: number; + /** The check suite of the workflow run behind a check run. */ + suite?: number; } /** The head's checks; `null` means the head has no checks at all. */ @@ -119,6 +123,8 @@ function checks( isRequired: entry.required ?? false, checkSuite: { status: entry.result && !entry.running ? "COMPLETED" : "IN_PROGRESS", + databaseId: entry.suite ?? null, + app: { databaseId: entry.app ?? ACTIONS }, workflowRun: { file: { path: entry.workflow ?? ".github/workflows/check.yml" } }, }, }; @@ -165,6 +171,8 @@ function setup( contextsOnly?: boolean; ruled?: string[]; rules?: unknown[]; + /** The head's workflow runs, as `GET /actions/runs` lists them, one listing per read; the last repeats. */ + runs?: unknown[][]; } = {}, ) { let now = Date.parse("2026-10-07T12:10:00Z"); @@ -217,6 +225,11 @@ function setup( }, }); } + if (parsed.pathname === `${base}/actions/runs` && side.runs) { + ruleCalls.push(call); + const listed = side.runs.length > 1 ? side.runs.shift()! : side.runs[0]!; + return response({ total_count: listed.length, workflow_runs: listed }); + } if (parsed.pathname === `${base}/rules/branches/main`) { ruleCalls.push(call); if (parsed.searchParams.get("page") === "2") return response(side.rules); @@ -1135,7 +1148,7 @@ test("a required check named on a later page of rules holds back checks:passed", checks([{ name: "check", required: true, result: "SUCCESS", time: LATER }]), checks([ { name: "check", required: true, result: "SUCCESS", time: LATER }, - { name: "deploy", required: true, result: "SUCCESS", time: LATEST }, + { name: "deploy", required: true, result: "SUCCESS", time: LATEST, app: 42 }, ]), ], ruled: ["check"], @@ -1157,6 +1170,59 @@ test("a required check named on a later page of rules holds back checks:passed", ]); }); +test("a required check from another app than its requirement names holds back checks:passed", async () => { + const fixture = setup([pull(), response([pushed()]), response([committed(A)]), response([committed(A)])], [A], { + checks: [ + checks([{ name: "check", required: true, result: "SUCCESS", time: LATER, app: 99 }]), + checks([ + { name: "check", required: true, result: "SUCCESS", time: LATER, app: 99 }, + { name: "check", required: true, result: "SUCCESS", time: LATEST, id: 5 }, + ]), + ], + ruled: ["check"], + }); + const lines = await waitForActivity(pr, {}, fixture.deps); + expect(fixture.sleeps).toEqual([300_000]); + expect(lines).toEqual([expect.stringMatching(/^2026-10-07T12:08:00Z checks:passed check /)]); +}); + +test("a cancelled check a newer run replaced never fails the wait, which stays busy until that run finishes", async () => { + const run = (id: number, status: string) => ({ + id, + workflow_id: 7, + check_suite_id: id * 10, + status, + // A run not started yet has no start time. + run_started_at: status === "queued" ? null : "2026-10-07T12:01:00Z", + created_at: `2026-10-07T12:0${id}:00Z`, + }); + const cancelled: CheckFixture = { + name: "Tests (${{ matrix.os }})", + result: "CANCELLED", + time: LATER, + id: 1, + suite: 10, + }; + const fixture = setup([pull(), response([pushed()]), response([committed(A)]), response([committed(A)])], [A], { + checks: [ + checks([cancelled, { name: "check", required: true, result: "SUCCESS", time: LATER, id: 2 }]), + checks([ + cancelled, + { name: "check", required: true, result: "SUCCESS", time: LATER, id: 2 }, + { name: "later", result: "SUCCESS", time: LATEST, id: 3 }, + ]), + ], + ruled: ["check"], + runs: [ + [run(1, "completed"), run(2, "queued")], + [run(1, "completed"), { ...run(2, "completed"), run_started_at: "2026-10-07T12:02:00Z" }], + ], + }); + const lines = await waitForActivity(pr, {}, fixture.deps); + expect(fixture.sleeps).toEqual([300_000]); + expect(lines).toEqual([expect.stringMatching(/^2026-10-07T12:08:00Z checks:passed check /)]); +}); + const CI = ".github/workflows/ci.yml"; const workflowRule = { type: "workflows", parameters: { workflows: [{ path: CI, repository_id: 1 }] } }; From 0fe14e820af0bb334baef5a8c9ba5cd75f7418cb Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Thu, 12 Nov 2026 17:22:38 -0800 Subject: [PATCH 04/10] docs(status): name the app suffix in quest status --help Co-Authored-By: Claude Opus 5.5 --- src/cli/main.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cli/main.ts b/src/cli/main.ts index 89dab5a18..b6d048152 100644 --- a/src/cli/main.ts +++ b/src/cli/main.ts @@ -551,7 +551,7 @@ export function main(argv: string[], out: Output): number | Promise { "a check line per failing or pending check, marked required or optional, counting only each check's latest run " + "and dropping a cancelled check once a newer GitHub Actions run of its workflow exists on the head (reading the head's " + "workflow runs, which needs Actions read access); a required check or workflow nothing reports prints as pending required " + - "expected, with its name or the workflow's path; a review line per " + + "expected, with its name, followed by (from app ) when the requirement names an app, or the workflow's path; a review line per " + "reviewer's latest review, marked current or stale against the head; a checkpoint line per bot " + "reviewer that approves or requests changes, its round, and its review, when that review is of the " + "head, while its latest verdict on the head is neither an approval nor a dismissal, and ends its third, sixth, ... round (one commit it reviewed), as " + From a209f6935195171ae23b719027cc2ab027838c08 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Thu, 12 Nov 2026 17:25:10 -0800 Subject: [PATCH 05/10] quest: plan the gate counting required workflows Co-Authored-By: Claude Opus 5.5 --- quest/m0/gate-required-workflows.md | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 quest/m0/gate-required-workflows.md diff --git a/quest/m0/gate-required-workflows.md b/quest/m0/gate-required-workflows.md new file mode 100644 index 000000000..8fc4f5d32 --- /dev/null +++ b/quest/m0/gate-required-workflows.md @@ -0,0 +1,11 @@ +# [S] Gate counts required workflows + +## Goal + +The gate's check matching (`checks()` in `src/cli/land.ts`) counts the base's required workflows (ruleset `workflows` rules) the same way `quest status` and `quest wait` do, so the gate never lands a head whose required workflow never ran or has not passed. + +## Plan + +- Settled on [moq-dev/quest#674](https://github.com/moq-dev/quest/pull/674): keep this as its own quest in m0, since it is the same disagreement between readers that #674 fixes for status and wait. +- Reuse the shared `requiredOf` and `unreported` from `src/cli/status.ts`: a job in a required workflow counts as required, and a required workflow path nothing reports keeps the PR waiting rather than landing. +- Test the gate with a base whose ruleset requires a workflow that has not run on the head. From b6f7daf259f29872cd9be7925bf218d5db981fbc Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Thu, 12 Nov 2026 17:38:02 -0800 Subject: [PATCH 06/10] quest: settle #674's review threads on check and workflow matching - A replaced cancellation leaves its check unreported instead of reviving an older report. - A required workflow matches its source repository as well as its path. - Workflow presence reads every current report, not one per name and app, in status and wait. Co-Authored-By: Claude Opus 5.5 --- src/cli/github.ts | 37 +++++++++++++----- src/cli/status.ts | 23 ++++++----- src/cli/wait.ts | 28 +++++++++----- src/github/checks.ts | 4 +- test/checks.test.ts | 7 ++-- test/land.test.ts | 3 +- test/status.test.ts | 91 +++++++++++++++++++++++++++++++++++++++----- test/wait.test.ts | 23 ++++++++++- 8 files changed, 173 insertions(+), 43 deletions(-) diff --git a/src/cli/github.ts b/src/cli/github.ts index 8ac5e9fca..993a486ae 100644 --- a/src/cli/github.ts +++ b/src/cli/github.ts @@ -506,7 +506,7 @@ export interface RequiredCheck { /** What a base branch requires, read from branch protection and rulesets. */ export interface Requirements { checks: RequiredCheck[]; - /** Workflow files that must pass as a whole, so each of their jobs is required. */ + /** Workflow files that must pass as a whole, so each of their jobs is required, from {@link workflowKey}. */ workflows: string[]; /** Every rule the branch's active rulesets apply: `type`, `parameters`, and the ruleset's source. */ rules: ObjectValue[]; @@ -531,6 +531,32 @@ async function branchRules(github: GitHub, path: string): Promise ); } +/** + * A workflow file as requirements name it: its repository's `owner/name` and its path, since a ruleset may + * require a workflow from another repository at the same path as a local one. + */ +export function workflowKey(repository: string, path: string): string { + return `${repository.toLowerCase()}:${path}`; +} + +/** The workflow files `rules` require, each keyed by {@link workflowKey} from its rule's `repository_id`. */ +async function requiredWorkflows(github: GitHub, rules: ObjectValue[]): Promise { + const names = new Map(); + const keys: string[] = []; + for (const row of rules + .filter((rule) => rule.type === "workflows") + .flatMap((rule) => array(object(rule.parameters).workflows))) { + const id = Number(row.repository_id); + if (!names.has(id)) { + const response = await github.request(`/repositories/${id}`, { allow: [404] }); + // A repository the token cannot see is still required; nothing on the head can match its name. + names.set(id, response.ok ? string(object(await response.json()).full_name) : `repository ${id}`); + } + keys.push(workflowKey(names.get(id)!, string(row.path))); + } + return [...new Set(keys)]; +} + /** What `branch` of `repository` requires, read with read access from branch protection and rulesets. */ export async function requirements(github: GitHub, repository: Repository, branch: string): Promise { const base = `/repos/${encodeURIComponent(repository.owner)}/${encodeURIComponent(repository.repo)}`; @@ -561,14 +587,7 @@ export async function requirements(github: GitHub, repository: Repository, branc (check, index) => checks.findIndex((other) => other.name === check.name && other.app === check.app) === index, ), - workflows: [ - ...new Set( - rules - .filter((rule) => rule.type === "workflows") - .flatMap((rule) => array(object(rule.parameters).workflows)) - .map((row) => string(row.path)), - ), - ], + workflows: await requiredWorkflows(github, rules), rules, // Unknown counts as on, so a reader that needs the settings reads them rather than assume none. classic: protection.enabled !== false, diff --git a/src/cli/status.ts b/src/cli/status.ts index bafe9abf7..a74d81813 100644 --- a/src/cli/status.ts +++ b/src/cli/status.ts @@ -13,6 +13,7 @@ import { type Repository, requirements, string, + workflowKey, } from "./github"; import { appOf, checksState, contextOutcome } from "../github/checks"; import { EJECTED, LAND_CHECK, pinned } from "./land"; @@ -46,7 +47,7 @@ const STATUS = `query($owner: String!, $repo: String!, $number: Int!, __typename ... on CheckRun { databaseId name status conclusion detailsUrl isRequired(pullRequestNumber: $number) - checkSuite { databaseId app { databaseId } workflowRun { file { path } } } + checkSuite { databaseId app { databaseId } workflowRun { file { path repositoryName } } } } ... on StatusContext { context state createdAt targetUrl isRequired(pullRequestNumber: $number) } } @@ -209,7 +210,7 @@ export async function pullRequestStatus(pr: PullRequest, deps: GitHubDependencie first!.state === "OPEN" ? await requiredOf(github, pr, string(first!.baseRefName)) : { checks: [], workflows: [] }; - const status = summarize(first!, rollup, current, needs, reviewNodes, threadNodes); + const status = summarize(first!, rollup, current, contexts, needs, reviewNodes, threadNodes); status.reviewRecord = await reviewRecord(github, pr, first!, deps.warn); if (status.autoMerge !== null) status.autoMerge.head = await enabledHead(github, first!, deps.warn); return { ...status, holds: ownership.holds, starterHold: ownership.starter }; @@ -327,7 +328,7 @@ export async function headBefore( export interface Needs { /** Required checks, each from its app, or from any when `app` is null. */ checks: { name: string; app: number | null }[]; - /** Workflow files that must pass as a whole, by path. */ + /** Workflow files that must pass as a whole, from {@link workflowKey}. */ workflows: string[]; } @@ -342,25 +343,28 @@ export interface Reported { name: string; /** The app behind a check run; null for a commit status. */ app: number | null; + /** The workflow file a GitHub Actions job runs in, from {@link workflowKey}. */ workflow?: string; } -/** A rollup context as a requirement matches it; queries ask for `checkSuite { workflowRun { file { path } } }`. */ +/** A rollup context as a requirement matches it; queries ask for `checkSuite { workflowRun { file { path repositoryName } } }`. */ export function reported(context: ObjectValue): Reported { const run = context.__typename === "CheckRun" && context.checkSuite ? object(context.checkSuite).workflowRun : null; const file = run ? object(run).file : null; return { name: string(context.__typename === "CheckRun" ? context.name : context.context), app: appOf(context), - ...(file ? { workflow: string(object(file).path) } : {}), + ...(file ? { workflow: workflowKey(string(object(file).repositoryName), string(object(file).path)) } : {}), }; } /** * The required checks and workflows nothing on the head reports yet: a check by its name, from its app when - * the requirement names one, as GitHub and `quest land` match it, and a workflow by its path. + * the requirement names one, as GitHub and `quest land` match it, and a workflow by its repository and path. + * `ran` holds every current report, before keeping one per name and app, so a required workflow's job still + * counts when a same-named job from another workflow replaced it in `found`. */ -export function unreported(found: Reported[], needs: Needs): string[] { +export function unreported(found: Reported[], needs: Needs, ran: Reported[] = found): string[] { return [ ...needs.checks .filter( @@ -368,7 +372,7 @@ export function unreported(found: Reported[], needs: Needs): string[] { !found.some((entry) => entry.name === need.name && (need.app === null || entry.app === need.app)), ) .map((need) => (need.app === null ? need.name : `${need.name} (from app ${need.app})`)), - ...needs.workflows.filter((path) => !found.some((entry) => entry.workflow === path)), + ...needs.workflows.filter((key) => !ran.some((entry) => entry.workflow === key)), ]; } @@ -380,13 +384,14 @@ function summarize( pull: ObjectValue, rollup: ObjectValue | null, current: ObjectValue[], + ran: ObjectValue[], needs: Needs, reviewNodes: ObjectValue[], threadNodes: ObjectValue[], ): Status { const head = string(pull.headRefOid); const url = string(pull.url); - const missing = unreported(current.map(reported), needs); + const missing = unreported(current.map(reported), needs, ran.map(reported)); // The rollup's own state counts runs a newer run of the same check replaced. const state = checksState(current); const checks = { diff --git a/src/cli/wait.ts b/src/cli/wait.ts index 3a142e925..68109f427 100644 --- a/src/cli/wait.ts +++ b/src/cli/wait.ts @@ -72,7 +72,7 @@ const CHECKS = `query($owner: String!, $repo: String!, $number: Int!, $after: St __typename ... on CheckRun { databaseId name status conclusion completedAt detailsUrl isRequired(pullRequestNumber: $number) - checkSuite { databaseId status app { databaseId } workflowRun { file { path } } } + checkSuite { databaseId status app { databaseId } workflowRun { file { path repositoryName } } } } ... on StatusContext { context state createdAt targetUrl isRequired(pullRequestNumber: $number) } } @@ -354,7 +354,8 @@ async function watch( }; /** GraphQL says which checks the base branch requires, through branch protection or rulesets. */ const checks = async (): Promise< - { head: string; base: string; checks: Check[]; unfinished: boolean; pull: ObjectValue } | undefined + | { head: string; base: string; checks: Check[]; ran: Reported[]; unfinished: boolean; pull: ObjectValue } + | undefined > => { const rows: ObjectValue[] = []; let head: string | undefined; @@ -376,7 +377,14 @@ async function watch( const current = await currentChecks(github, pr, head!, rows); // A replacing run may have no check run yet, so an unfinished run it read keeps the head busy. const unfinished = current.runs?.some((run) => run.status !== "completed") ?? false; - return { head: head!, base: string(pull.baseRefName), checks: current.checks.map(check), unfinished, pull }; + return { + head: head!, + base: string(pull.baseRefName), + checks: current.checks.map(check), + ran: rows.map(reported), + unfinished, + pull, + }; }; /** * What the base branch requires, read once per wait, as `quest status` reads it. Only a requirement @@ -589,7 +597,7 @@ function check(row: ObjectValue): Check { * no checks requires them all. */ function checkActivities( - { head, checks: all, unfinished }: { head: string; checks: Check[]; unfinished: boolean }, + { head, checks: all, ran, unfinished }: { head: string; checks: Check[]; ran: Reported[]; unfinished: boolean }, needs: Needs, state: Cursor["checks"], prUrl: string, @@ -625,17 +633,19 @@ function checkActivities( // may still create. Its date is the last completion, but its name and link // always identify a required check that passed. const idle = - !unfinished && all.every((entry) => entry.result && !entry.running) && unreported(all, needs).length === 0; - const passed = - idle && settled.length === required.length && settled.every((entry) => entry.result.outcome === "passed") - ? settled.at(-1) - : undefined; + !unfinished && all.every((entry) => entry.result && !entry.running) && unreported(all, needs, ran).length === 0; const last = idle ? all.reduce( (latest, entry) => (!latest || entry.result!.time >= latest.result!.time ? entry : latest), undefined, ) : undefined; + // A required workflow whose only job lost to a same-named job of another workflow leaves no required + // check to name, so the head's last check names the pass. + const passed = + idle && settled.length === required.length && settled.every((entry) => entry.result.outcome === "passed") + ? (settled.at(-1) ?? (needs.workflows.length ? last : undefined)) + : undefined; const optional = all.filter((entry) => !required.includes(entry) && entry.result?.outcome === "failed"); return [ ...reached("failed", failed), diff --git a/src/github/checks.ts b/src/github/checks.ts index 21406308c..79be40030 100644 --- a/src/github/checks.ts +++ b/src/github/checks.ts @@ -69,7 +69,7 @@ export function cancelled(context: RollupContext): boolean { /** * Each check's latest report that still counts: a check that reported cancelled drops once a newer run of - * its workflow exists on the head, as when `cancel-in-progress` cancels a run for a newer one, which may + * its workflow exists on the head, leaving the check unreported rather than reviving an older report, as when `cancel-in-progress` cancels a run for a newer one, which may * never report the cancelled run's names, such as a matrix job's unexpanded name. Any other result keeps * counting, as does a cancelled run nothing replaced. A rerun reports anew in its run's check suite, so * the rollup holds only its latest attempt. Queries must also ask for a check run's `conclusion` and @@ -80,7 +80,7 @@ export function currentContexts(contexts: T[], runs: Wo const replaced = new Set(runs.filter((run) => replacedRun(run, runs)).map((run) => run.check_suite_id)); const suite = (context: T) => Number((context.checkSuite as { databaseId?: unknown } | null | undefined)?.databaseId); - return latestContexts(contexts.filter((context) => !(cancelled(context) && replaced.has(suite(context))))); + return latestContexts(contexts).filter((context) => !(cancelled(context) && replaced.has(suite(context)))); } /** Whether a context passed, failed, or is still pending. Neutral and skipped check runs pass. */ diff --git a/test/checks.test.ts b/test/checks.test.ts index e0737f53c..7adb6e768 100644 --- a/test/checks.test.ts +++ b/test/checks.test.ts @@ -112,7 +112,7 @@ const tokenMax = { test("a cancelled check drops once a newer run of its workflow exists, as on kixelated/token-max's daaaadc", () => { expect(checksState(latestContexts(tokenMax.contexts))).toBe("FAILURE"); const current = currentContexts(tokenMax.contexts, tokenMax.runs); - expect(current.map((context) => context.databaseId)).toEqual([21, 41, 42]); + expect(current.map((context) => context.databaseId)).toEqual([41, 42]); expect(checksState(current)).toBe("SUCCESS"); }); @@ -141,8 +141,9 @@ test("a cancelled check counts while nothing replaced its run, and other results test("a rerun is newer than every run that started before its latest attempt", () => { // Run 1 was rerun after run 2 started, and its rerun cancelled run 2. const runs = [workflowRun(1, "2026-11-12T12:00:00Z"), workflowRun(2, "2026-11-12T11:00:00Z")]; - const contexts = [job("test", 1, "SUCCESS", 10), job("test", 2, "CANCELLED", 20)]; - expect(currentContexts(contexts, runs)).toEqual([contexts[0]]); + // The rerun reports anew, after the run it cancelled. + const contexts = [job("test", 2, "CANCELLED", 20), job("test", 3, "SUCCESS", 10)]; + expect(currentContexts(contexts, runs)).toEqual([contexts[1]]); // Runs that started in the same second order by ID. const tied = [workflowRun(1, "2026-11-12T12:00:00Z"), workflowRun(2, "2026-11-12T12:00:00Z")]; expect(currentContexts([job("test", 1, "CANCELLED", 10)], tied)).toEqual([]); diff --git a/test/land.test.ts b/test/land.test.ts index ddca6aada..700074b11 100644 --- a/test/land.test.ts +++ b/test/land.test.ts @@ -1181,10 +1181,11 @@ describe.skipIf(process.platform === "win32")("quest land", () => { const alone = forge.pull("Alone", { "2.txt": "2\n" }, { pull: { runs: [test("CANCELLED", 30)] } }); workflow(alone, [[3, "cancelled", "2026-11-12T23:42:53Z"]]); // Rerunning the cancelled run makes it the newest, so the run it cancelled in turn is the replaced one. + // The rerun reports anew, after the run it cancelled. const rerun = forge.pull( "Rerun", { "3.txt": "3\n" }, - { pull: { runs: [test("SUCCESS", 40), test("CANCELLED", 50)] } }, + { pull: { runs: [test("CANCELLED", 50), test("SUCCESS", 40)] } }, ); workflow(rerun, [ [4, "success", "2026-11-12T23:50:00Z"], diff --git a/test/status.test.ts b/test/status.test.ts index 70c32d2d8..669d63334 100644 --- a/test/status.test.ts +++ b/test/status.test.ts @@ -147,6 +147,9 @@ function setup( return Response.json({ message: "Resource not accessible by integration" }, { status: 403 }); return Response.json(page.rows, { headers: page.next ? { Link: `<${page.next}>; rel="next"` } : {} }); } + // Ruleset workflows name their repository by ID: 1 is this one, 2 another. + if (path.pathname === "/repositories/1") return Response.json({ full_name: "example/project" }); + if (path.pathname === "/repositories/2") return Response.json({ full_name: "example/policies" }); if (path.pathname === "/repos/example/project/branches/main") return options.noBase ? Response.json({ message: "Branch not found" }, { status: 404 }) @@ -491,7 +494,11 @@ test("drops a cancelled check a newer run of its workflow replaced, as on kixela const job = (name: string, conclusion: string, databaseId: number, suite: number) => ({ ...run(name, "COMPLETED", conclusion, false), databaseId, - checkSuite: { databaseId: suite, app: { databaseId: 15368 }, workflowRun: { file: { path: CI } } }, + checkSuite: { + databaseId: suite, + app: { databaseId: 15368 }, + workflowRun: { file: { path: CI, repositoryName: "example/project" } }, + }, }); const runs = (started: string) => [ { id: 1, workflow_id: 7, check_suite_id: 10, run_started_at: "2026-11-12T23:42:53Z" }, @@ -515,7 +522,11 @@ test("a required check or workflow nothing reports is pending, except the gate's const job = (name: string, workflow: string) => ({ ...run(name, "COMPLETED", "SUCCESS", false), databaseId: 1, - checkSuite: { databaseId: 10, app: { databaseId: 15368 }, workflowRun: { file: { path: workflow } } }, + checkSuite: { + databaseId: 10, + app: { databaseId: 15368 }, + workflowRun: { file: { path: workflow, repositoryName: "example/project" } }, + }, }); const rules = [ { @@ -524,7 +535,15 @@ test("a required check or workflow nothing reports is pending, except the gate's required_status_checks: [{ context: "test" }, { context: "lint" }, { context: "quest land" }], }, }, - { type: "workflows", parameters: { workflows: [{ path: CI }, { path: ".github/workflows/pr.yml" }] } }, + { + type: "workflows", + parameters: { + workflows: [ + { path: CI, repository_id: 1 }, + { path: ".github/workflows/pr.yml", repository_id: 1 }, + ], + }, + }, ]; const fixture = setup([pull({ checks: page([job("test", CI)]), reviews: page([]), threads: page([]) })], { rules, @@ -533,7 +552,7 @@ test("a required check or workflow nothing reports is pending, except the gate's expect(statusLines(status).filter((line) => line.startsWith("check"))).toEqual([ "checks pending passed=1 failing=0 pending=2", "check pending required expected - lint", - "check pending required expected - .github/workflows/pr.yml", + "check pending required expected - example/project:.github/workflows/pr.yml", ]); // With no checks on the head at all, the requirements still leave it pending. const empty = setup([pull({ checks: null, reviews: page([]), threads: page([]) })], { rules }); @@ -550,7 +569,11 @@ test("a required check from another app than its requirement names stays pending const test = { ...run("test", "COMPLETED", "SUCCESS", false), databaseId: 1, - checkSuite: { databaseId: 10, app: { databaseId: 15368 }, workflowRun: { file: { path: CI } } }, + checkSuite: { + databaseId: 10, + app: { databaseId: 15368 }, + workflowRun: { file: { path: CI, repositoryName: "example/project" } }, + }, }; const open = setup([pull({ checks: page([test]), reviews: page([]), threads: page([]) })], { rules }); expect(statusLines(await pullRequestStatus(pr, open.deps)).filter((line) => line.startsWith("check"))).toEqual([ @@ -569,7 +592,11 @@ test("a replacing run that has not started yet stands in by its creation time", const job = { ...run("Tests (${{ matrix.os }})", "COMPLETED", "CANCELLED", false), databaseId: 1, - checkSuite: { databaseId: 10, app: { databaseId: 15368 }, workflowRun: { file: { path: CI } } }, + checkSuite: { + databaseId: 10, + app: { databaseId: 15368 }, + workflowRun: { file: { path: CI, repositoryName: "example/project" } }, + }, }; const fixture = setup([pull({ checks: page([job]), reviews: page([]), threads: page([]) })], { runs: [ @@ -585,6 +612,48 @@ test("a replacing run that has not started yet stands in by its creation time", }); }); +test("a required workflow matches its repository as well as its path", async () => { + const build = { + ...run("build", "COMPLETED", "SUCCESS", false), + databaseId: 1, + checkSuite: { + databaseId: 10, + app: { databaseId: 15368 }, + workflowRun: { file: { path: CI, repositoryName: "example/project" } }, + }, + }; + // The rule requires example/policies's ci.yml, which the local ci.yml at the same path does not satisfy. + const fixture = setup([pull({ checks: page([build]), reviews: page([]), threads: page([]) })], { + rules: [{ type: "workflows", parameters: { workflows: [{ path: CI, repository_id: 2 }] } }], + }); + const status = await pullRequestStatus(pr, fixture.deps); + expect(status.checks.state).toBe("pending"); + expect(status.checks.pending.map((check) => check.name)).toEqual([`example/policies:${CI}`]); +}); + +test("a required workflow counts as reported when another workflow's same-named job is the newer one", async () => { + const build = (databaseId: number, path: string) => ({ + ...run("build", "COMPLETED", "SUCCESS", false), + databaseId, + checkSuite: { + databaseId: databaseId * 10, + app: { databaseId: 15368 }, + workflowRun: { file: { path, repositoryName: "example/project" } }, + }, + }); + const fixture = setup( + [ + pull({ + checks: page([build(1, CI), build(2, ".github/workflows/docs.yml")]), + reviews: page([]), + threads: page([]), + }), + ], + { rules: [{ type: "workflows", parameters: { workflows: [{ path: CI, repository_id: 1 }] } }] }, + ); + expect((await pullRequestStatus(pr, fixture.deps)).checks.state).toBe("success"); +}); + test("a job in a required workflow counts as required", async () => { const fixture = setup( [ @@ -593,14 +662,18 @@ test("a job in a required workflow counts as required", async () => { { ...run("build", "COMPLETED", "FAILURE", false), databaseId: 1, - checkSuite: { databaseId: 10, app: { databaseId: 15368 }, workflowRun: { file: { path: CI } } }, + checkSuite: { + databaseId: 10, + app: { databaseId: 15368 }, + workflowRun: { file: { path: CI, repositoryName: "example/project" } }, + }, }, ]), reviews: page([]), threads: page([]), }), ], - { rules: [{ type: "workflows", parameters: { workflows: [{ path: CI }] } }] }, + { rules: [{ type: "workflows", parameters: { workflows: [{ path: CI, repository_id: 1 }] } }] }, ); const status = await pullRequestStatus(pr, fixture.deps); expect(status.checks.failing.map((check) => [check.name, check.required])).toEqual([["build", true]]); @@ -629,7 +702,7 @@ test("counts only each check's newest run from its app", async () => { const status = await pullRequestStatus(pr, fixture.deps); // The fixture answers whatever is asked, so the query must ask for what tells runs apart. expect(fixture.texts[0].replace(/\s+/g, " ")).toContain( - "... on CheckRun { databaseId name status conclusion detailsUrl isRequired(pullRequestNumber: $number) checkSuite { databaseId app { databaseId } workflowRun { file { path } } } }", + "... on CheckRun { databaseId name status conclusion detailsUrl isRequired(pullRequestNumber: $number) checkSuite { databaseId app { databaseId } workflowRun { file { path repositoryName } } } }", ); expect(status.checks.passed).toBe(2); expect(status.checks.failing.map((check) => check.name)).toEqual(["test", "lint"]); diff --git a/test/wait.test.ts b/test/wait.test.ts index 4aabd57ee..79fcac487 100644 --- a/test/wait.test.ts +++ b/test/wait.test.ts @@ -125,7 +125,12 @@ function checks( status: entry.result && !entry.running ? "COMPLETED" : "IN_PROGRESS", databaseId: entry.suite ?? null, app: { databaseId: entry.app ?? ACTIONS }, - workflowRun: { file: { path: entry.workflow ?? ".github/workflows/check.yml" } }, + workflowRun: { + file: { + path: entry.workflow ?? ".github/workflows/check.yml", + repositoryName: "example/project", + }, + }, }, }; return response({ @@ -211,6 +216,7 @@ function setup( sideCalls.push({ ...call, body }); return side.graphql?.shift() ?? reactions(); } + if (parsed.pathname === "/repositories/1") return Response.json({ full_name: "example/project" }); if (parsed.pathname === `${base}/branches/main`) { ruleCalls.push(call); const contexts = side.protected ?? []; @@ -1253,6 +1259,21 @@ test("a required workflow requires its jobs, keeps optional checks optional, and expect(lines[0]).toMatch(/^2026-10-07T12:08:00Z checks:passed gate /); }); +test("a required workflow's job counts toward checks:passed when another workflow's same-named job is newer", async () => { + const fixture = setup([pull(), response([pushed()]), response([committed(A)]), response([committed(A)])], [A], { + checks: [ + checks([ + { name: "build", result: "SUCCESS", time: LATER, workflow: CI, id: 1 }, + { name: "build", result: "SUCCESS", time: LATEST, workflow: ".github/workflows/docs.yml", id: 2 }, + ]), + ], + rules: [workflowRule], + }); + const lines = await waitForActivity(pr, {}, fixture.deps); + expect(lines).toHaveLength(1); + expect(lines[0]).toMatch(/ checks:passed /); +}); + test("a failing job in a required workflow wakes the wait", async () => { const fixture = setup([pull(), response([pushed()]), response([committed(A)])], [A], { checks: [ From 8ea8df5541489542dedf8b1304ce0c1f2be022f4 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Thu, 12 Nov 2026 17:38:34 -0800 Subject: [PATCH 07/10] docs: name a required workflow by repository and path in status and wait help Co-Authored-By: Claude Opus 5.5 --- README.md | 7 ++++--- src/cli/main.ts | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 16d3607b3..1d3d85a72 100644 --- a/README.md +++ b/README.md @@ -419,8 +419,9 @@ head is still going (no pending check and no unfinished GitHub Actions run, whic may still create jobs), every check and workflow the base branch names is present (except `quest land`'s, which no head carries), each required check from the app its requirement names, if any, and every required -check passed; it names the last required check that passed and is dated when -the head went idle. Each prints once per head, with the check's name +check passed; it names the last required check that passed, or the last check +when a required workflow's only job lost to another workflow's same-named job, +and is dated when the head went idle. Each prints once per head, with the check's name (spaces as `_`) in the actor field and its details URL. Results count as `quest status` counts them, so neutral and skipped results pass, a rerun supersedes an earlier run of the same check, and a cancelled check a newer run @@ -504,7 +505,7 @@ comes last, and a missing value prints as `-`: | `merge-queue` | Queue state, position, and when it was enqueued. | | `landing-stopped` | The reason the latest merge-queue entry, auto-merge, or [`quest land`](#land-a-batch-with-quest-land) queue entry ended (such as `merge_conflict`, `failed_checks`, `manual`, `manually_disabled`, or `merged`), who ended it, and when; `-` once the PR has entered the merge queue or auto-merge again since. | | `checks` | `failure` if any check fails, else `pending` if any is pending or a requirement is unreported, else `success`, and `passed=`, `failing=`, `pending=` counts, all from the checks that count; `-` when the head has no checks and the base requires none. | -| `check` | `failing` or `pending`, `required` or `optional`, the result, details URL, and name. A required check or required workflow nothing reports yet prints as `pending required expected -` with its name, followed by `(from app )` when the requirement names an app, or the workflow's path. | +| `check` | `failing` or `pending`, `required` or `optional`, the result, details URL, and name. A required check or required workflow nothing reports yet prints as `pending required expected -` with its name, followed by `(from app )` when the requirement names an app, or the workflow's repository and path, as `owner/name:path`. | | `review` | `current` or `stale` against the head, state, reviewer, time, and URL of each reviewer's latest review. | | `checkpoint` | Each bot reviewer that approves or requests changes, such as one whose approval the base requires, its round, and its review's URL, when that review is of the head and its latest verdict there, ignoring plain comments, is neither an approval nor a dismissal, at the end of its third, sixth, ... round: [`/quest-review`'s design checkpoint](#review-locally) for an online reviewer. A round is one commit it reviewed; a dismissed review counts as one that approves or requests changes. Only printed when due. | | `reacted:` | Actor, time, and the PR or review reacted to, as `quest wait` names reactions. | diff --git a/src/cli/main.ts b/src/cli/main.ts index b6d048152..81bb9f719 100644 --- a/src/cli/main.ts +++ b/src/cli/main.ts @@ -503,7 +503,7 @@ export function main(argv: string[], out: Output): number | Promise { "The head's first failing required check prints as checks:failed, and every required check passing as checks:passed, " + "each once per head, with the required check's name as the actor and its details URL. " + "Results count as quest status counts them, so neutral and skipped results pass. " + - "checks:passed waits until no check is pending, no GitHub Actions run is unfinished, and every check and workflow the base branch names is present, then names the last required check that passed. " + + "checks:passed waits until no check is pending, no GitHub Actions run is unfinished, and every check and workflow the base branch names is present, then names the last required check that passed, or the last check when a required workflow's only job lost to another workflow's same-named job. " + "Optional failures print separately as check:failed; a base branch requiring no checks requires them all. " + "When auto-merge stays enabled on a head other than the current one, which GitHub allows across a writer's push, " + "auto-merge:moved prints once per head, with the account that enabled it as the actor and a URL naming the head it " + @@ -551,7 +551,7 @@ export function main(argv: string[], out: Output): number | Promise { "a check line per failing or pending check, marked required or optional, counting only each check's latest run " + "and dropping a cancelled check once a newer GitHub Actions run of its workflow exists on the head (reading the head's " + "workflow runs, which needs Actions read access); a required check or workflow nothing reports prints as pending required " + - "expected, with its name, followed by (from app ) when the requirement names an app, or the workflow's path; a review line per " + + "expected, with its name, followed by (from app ) when the requirement names an app, or the workflow's repository and path, as owner/name:path; a review line per " + "reviewer's latest review, marked current or stale against the head; a checkpoint line per bot " + "reviewer that approves or requests changes, its round, and its review, when that review is of the " + "head, while its latest verdict on the head is neither an approval nor a dismissal, and ends its third, sixth, ... round (one commit it reviewed), as " + From f3ab8f7d288178e9c367aceeea7c3a54e7af1b8c Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Thu, 12 Nov 2026 18:15:26 -0800 Subject: [PATCH 08/10] quest: key each check's latest report by its workflow file Replaces the separate workflow-presence list, which hid a required workflow's failed job and counted a replaced cancellation as presence. Co-Authored-By: Claude Opus 5.5 --- README.md | 9 ++++----- src/cli/main.ts | 4 ++-- src/cli/status.ts | 11 ++++------- src/cli/wait.ts | 26 ++++++++---------------- src/github/checks.ts | 13 ++++++++++-- test/status.test.ts | 47 ++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 76 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index 1d3d85a72..b918fb1e2 100644 --- a/README.md +++ b/README.md @@ -419,12 +419,11 @@ head is still going (no pending check and no unfinished GitHub Actions run, whic may still create jobs), every check and workflow the base branch names is present (except `quest land`'s, which no head carries), each required check from the app its requirement names, if any, and every required -check passed; it names the last required check that passed, or the last check -when a required workflow's only job lost to another workflow's same-named job, -and is dated when the head went idle. Each prints once per head, with the check's name +check passed; it names the last required check that passed and is dated when +the head went idle. Each prints once per head, with the check's name (spaces as `_`) in the actor field and its details URL. Results count as `quest status` counts them, so neutral and skipped results pass, a rerun -supersedes an earlier run of the same check, and a cancelled check a newer run +supersedes an earlier run of the same check from the same workflow, and a cancelled check a newer run of its workflow replaced is dropped. Each job of a workflow a ruleset requires is required. Requiredness comes from the base branch's protection and rulesets, readable @@ -517,7 +516,7 @@ The node ID is what GraphQL's `addPullRequestReviewThreadReply` and `resolveReviewThread` take. Neutral and skipped checks pass. Only each check's latest run counts, as for GitHub's mergeability: a rerun, or the same workflow run again on the head, supersedes an earlier run of that name from the same -app, and a newer commit status supersedes an older one of its context. A check +app and workflow file, and a newer commit status supersedes an older one of its context. A check that reported `cancelled` also stops counting once a newer GitHub Actions run of its workflow exists on the head, from any event, as when `cancel-in-progress` cancels a run whose jobs, such as a matrix job under its unexpanded name, the diff --git a/src/cli/main.ts b/src/cli/main.ts index 81bb9f719..9ee4e09df 100644 --- a/src/cli/main.ts +++ b/src/cli/main.ts @@ -503,7 +503,7 @@ export function main(argv: string[], out: Output): number | Promise { "The head's first failing required check prints as checks:failed, and every required check passing as checks:passed, " + "each once per head, with the required check's name as the actor and its details URL. " + "Results count as quest status counts them, so neutral and skipped results pass. " + - "checks:passed waits until no check is pending, no GitHub Actions run is unfinished, and every check and workflow the base branch names is present, then names the last required check that passed, or the last check when a required workflow's only job lost to another workflow's same-named job. " + + "checks:passed waits until no check is pending, no GitHub Actions run is unfinished, and every check and workflow the base branch names is present, then names the last required check that passed. " + "Optional failures print separately as check:failed; a base branch requiring no checks requires them all. " + "When auto-merge stays enabled on a head other than the current one, which GitHub allows across a writer's push, " + "auto-merge:moved prints once per head, with the account that enabled it as the actor and a URL naming the head it " + @@ -548,7 +548,7 @@ export function main(argv: string[], out: Output): number | Promise { "activity, which GitHub lists up to minutes late); landing-stopped is the latest exit from the merge queue, auto-merge, or " + "quest land's queue, with the reason (such as merge_conflict, failed_checks, manual, or manually_disabled), " + "actor, and time, until the PR enters the merge queue or auto-merge again. Then " + - "a check line per failing or pending check, marked required or optional, counting only each check's latest run " + + "a check line per failing or pending check, marked required or optional, counting only each check's latest run (by name, app, and workflow file) " + "and dropping a cancelled check once a newer GitHub Actions run of its workflow exists on the head (reading the head's " + "workflow runs, which needs Actions read access); a required check or workflow nothing reports prints as pending required " + "expected, with its name, followed by (from app ) when the requirement names an app, or the workflow's repository and path, as owner/name:path; a review line per " + diff --git a/src/cli/status.ts b/src/cli/status.ts index a74d81813..9668769e0 100644 --- a/src/cli/status.ts +++ b/src/cli/status.ts @@ -210,7 +210,7 @@ export async function pullRequestStatus(pr: PullRequest, deps: GitHubDependencie first!.state === "OPEN" ? await requiredOf(github, pr, string(first!.baseRefName)) : { checks: [], workflows: [] }; - const status = summarize(first!, rollup, current, contexts, needs, reviewNodes, threadNodes); + const status = summarize(first!, rollup, current, needs, reviewNodes, threadNodes); status.reviewRecord = await reviewRecord(github, pr, first!, deps.warn); if (status.autoMerge !== null) status.autoMerge.head = await enabledHead(github, first!, deps.warn); return { ...status, holds: ownership.holds, starterHold: ownership.starter }; @@ -361,10 +361,8 @@ export function reported(context: ObjectValue): Reported { /** * The required checks and workflows nothing on the head reports yet: a check by its name, from its app when * the requirement names one, as GitHub and `quest land` match it, and a workflow by its repository and path. - * `ran` holds every current report, before keeping one per name and app, so a required workflow's job still - * counts when a same-named job from another workflow replaced it in `found`. */ -export function unreported(found: Reported[], needs: Needs, ran: Reported[] = found): string[] { +export function unreported(found: Reported[], needs: Needs): string[] { return [ ...needs.checks .filter( @@ -372,7 +370,7 @@ export function unreported(found: Reported[], needs: Needs, ran: Reported[] = fo !found.some((entry) => entry.name === need.name && (need.app === null || entry.app === need.app)), ) .map((need) => (need.app === null ? need.name : `${need.name} (from app ${need.app})`)), - ...needs.workflows.filter((key) => !ran.some((entry) => entry.workflow === key)), + ...needs.workflows.filter((key) => !found.some((entry) => entry.workflow === key)), ]; } @@ -384,14 +382,13 @@ function summarize( pull: ObjectValue, rollup: ObjectValue | null, current: ObjectValue[], - ran: ObjectValue[], needs: Needs, reviewNodes: ObjectValue[], threadNodes: ObjectValue[], ): Status { const head = string(pull.headRefOid); const url = string(pull.url); - const missing = unreported(current.map(reported), needs, ran.map(reported)); + const missing = unreported(current.map(reported), needs); // The rollup's own state counts runs a newer run of the same check replaced. const state = checksState(current); const checks = { diff --git a/src/cli/wait.ts b/src/cli/wait.ts index 68109f427..39bb8efa2 100644 --- a/src/cli/wait.ts +++ b/src/cli/wait.ts @@ -354,8 +354,7 @@ async function watch( }; /** GraphQL says which checks the base branch requires, through branch protection or rulesets. */ const checks = async (): Promise< - | { head: string; base: string; checks: Check[]; ran: Reported[]; unfinished: boolean; pull: ObjectValue } - | undefined + { head: string; base: string; checks: Check[]; unfinished: boolean; pull: ObjectValue } | undefined > => { const rows: ObjectValue[] = []; let head: string | undefined; @@ -377,14 +376,7 @@ async function watch( const current = await currentChecks(github, pr, head!, rows); // A replacing run may have no check run yet, so an unfinished run it read keeps the head busy. const unfinished = current.runs?.some((run) => run.status !== "completed") ?? false; - return { - head: head!, - base: string(pull.baseRefName), - checks: current.checks.map(check), - ran: rows.map(reported), - unfinished, - pull, - }; + return { head: head!, base: string(pull.baseRefName), checks: current.checks.map(check), unfinished, pull }; }; /** * What the base branch requires, read once per wait, as `quest status` reads it. Only a requirement @@ -597,7 +589,7 @@ function check(row: ObjectValue): Check { * no checks requires them all. */ function checkActivities( - { head, checks: all, ran, unfinished }: { head: string; checks: Check[]; ran: Reported[]; unfinished: boolean }, + { head, checks: all, unfinished }: { head: string; checks: Check[]; unfinished: boolean }, needs: Needs, state: Cursor["checks"], prUrl: string, @@ -633,19 +625,17 @@ function checkActivities( // may still create. Its date is the last completion, but its name and link // always identify a required check that passed. const idle = - !unfinished && all.every((entry) => entry.result && !entry.running) && unreported(all, needs, ran).length === 0; + !unfinished && all.every((entry) => entry.result && !entry.running) && unreported(all, needs).length === 0; + const passed = + idle && settled.length === required.length && settled.every((entry) => entry.result.outcome === "passed") + ? settled.at(-1) + : undefined; const last = idle ? all.reduce( (latest, entry) => (!latest || entry.result!.time >= latest.result!.time ? entry : latest), undefined, ) : undefined; - // A required workflow whose only job lost to a same-named job of another workflow leaves no required - // check to name, so the head's last check names the pass. - const passed = - idle && settled.length === required.length && settled.every((entry) => entry.result.outcome === "passed") - ? (settled.at(-1) ?? (needs.workflows.length ? last : undefined)) - : undefined; const optional = all.filter((entry) => !required.includes(entry) && entry.result?.outcome === "failed"); return [ ...reached("failed", failed), diff --git a/src/github/checks.ts b/src/github/checks.ts index 79be40030..b54f37f93 100644 --- a/src/github/checks.ts +++ b/src/github/checks.ts @@ -15,9 +15,18 @@ export function appOf(context: RollupContext): number | null { return app?.databaseId == null ? null : Number(app.databaseId); } +/** The repository and path of the workflow file a check run's job runs in, when the query asked for them. */ +function workflowOf(context: RollupContext): [unknown, unknown] | null { + const suite = context.checkSuite as + { workflowRun?: { file?: { repositoryName?: unknown; path?: unknown } | null } | null } | null | undefined; + const file = suite?.workflowRun?.file; + return file ? [file.repositoryName ?? null, file.path ?? null] : null; +} + /** * Each check's latest report on the head, in rollup order. A check run is keyed by its app and name, - * as a required check is, and the latest is the one created last: the highest `databaseId`. A commit + * as a required check is, and by the workflow file a GitHub Actions job runs in, so a required workflow's + * job never loses to another workflow's same-named job; and the latest is the one created last: the highest `databaseId`. A commit * status is keyed by its context, and the latest is the newest `createdAt`, or on a tie the one listed * later. A check run and a status with the same name stay apart, since GitHub requires both. * Queries must ask for a check run's `databaseId name checkSuite { app { databaseId } }` and a @@ -26,7 +35,7 @@ export function appOf(context: RollupContext): number | null { export function latestContexts(contexts: T[]): T[] { const key = (context: T) => context.__typename === "CheckRun" - ? JSON.stringify(["run", appOf(context), context.name]) + ? JSON.stringify(["run", appOf(context), context.name, workflowOf(context)]) : JSON.stringify(["status", context.context]); const newer = (context: T, seen: T) => context.__typename === "CheckRun" diff --git a/test/status.test.ts b/test/status.test.ts index 669d63334..22501b72d 100644 --- a/test/status.test.ts +++ b/test/status.test.ts @@ -654,6 +654,53 @@ test("a required workflow counts as reported when another workflow's same-named expect((await pullRequestStatus(pr, fixture.deps)).checks.state).toBe("success"); }); +test("a required workflow's failed job still fails when another workflow's same-named job passed later", async () => { + const build = (databaseId: number, path: string, conclusion: string) => ({ + ...run("build", "COMPLETED", conclusion, false), + databaseId, + checkSuite: { + databaseId: databaseId * 10, + app: { databaseId: 15368 }, + workflowRun: { file: { path, repositoryName: "example/project" } }, + }, + }); + const fixture = setup( + [ + pull({ + checks: page([build(1, CI, "FAILURE"), build(2, ".github/workflows/docs.yml", "SUCCESS")]), + reviews: page([]), + threads: page([]), + }), + ], + { rules: [{ type: "workflows", parameters: { workflows: [{ path: CI, repository_id: 1 }] } }] }, + ); + const status = await pullRequestStatus(pr, fixture.deps); + expect(status.checks.state).toBe("failure"); + expect(status.checks.failing.map((check) => [check.name, check.required])).toEqual([["build", true]]); +}); + +test("a required workflow whose only job a queued run replaced is pending", async () => { + const build = { + ...run("build", "COMPLETED", "CANCELLED", false), + databaseId: 1, + checkSuite: { + databaseId: 10, + app: { databaseId: 15368 }, + workflowRun: { file: { path: CI, repositoryName: "example/project" } }, + }, + }; + const fixture = setup([pull({ checks: page([build]), reviews: page([]), threads: page([]) })], { + rules: [{ type: "workflows", parameters: { workflows: [{ path: CI, repository_id: 1 }] } }], + runs: [ + { id: 1, workflow_id: 7, check_suite_id: 10, run_started_at: "2026-11-12T23:42:53Z" }, + { id: 2, workflow_id: 7, check_suite_id: 20, run_started_at: null, created_at: "2026-11-12T23:42:56Z" }, + ], + }); + const status = await pullRequestStatus(pr, fixture.deps); + expect(status.checks.state).toBe("pending"); + expect(status.checks.pending.map((check) => check.name)).toEqual([`example/project:${CI}`]); +}); + test("a job in a required workflow counts as required", async () => { const fixture = setup( [ From bf9c5c4d0704d6065afa62041d28e1988f031f54 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Thu, 12 Nov 2026 18:19:45 -0800 Subject: [PATCH 09/10] test: pass merge --land's options in the cancelled-check case Co-Authored-By: Claude Opus 5.5 --- test/hold.test.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/hold.test.ts b/test/hold.test.ts index 15d33fc17..e80b30166 100644 --- a/test/hold.test.ts +++ b/test/hold.test.ts @@ -361,10 +361,12 @@ describe("merge --land", () => { }); pull.checks = [run(1, "Tests (${{ matrix.os }})", "CANCELLED", 10), run(2, "Tests (macos-15)", "SUCCESS", 20)]; pull.runs = [{ id: 1, workflow_id: 7, check_suite_id: 10, run_started_at: "2026-11-12T23:42:53Z" }]; - expect(await refused(land(PR, HEAD, "merge", pull.deps()))).toContain("Tests (${{ matrix.os }})"); + expect(await refused(land(PR, { sha: HEAD, method: "merge", check: clean }, pull.deps()))).toContain( + "Tests (${{ matrix.os }})", + ); expect(pull.writes).toEqual([]); pull.runs.push({ id: 2, workflow_id: 7, check_suite_id: 20, run_started_at: "2026-11-12T23:42:56Z" }); - await land(PR, HEAD, "merge", pull.deps()); + await land(PR, { sha: HEAD, method: "merge", check: clean }, pull.deps()); expect(pull.writes).not.toEqual([]); }); From 756614085e383c00a6179c219c047a11b5dd2ad6 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Thu, 12 Nov 2026 18:23:42 -0800 Subject: [PATCH 10/10] quest: ask every check reader for workflow identity The gate, merge --land, and land-bump share land.ts's contexts query, which now asks for each job's workflow file, so they keep a required workflow's job apart from another workflow's same-named job as status and wait do. Co-Authored-By: Claude Opus 5.5 --- src/cli/land.ts | 2 +- src/github/checks.ts | 2 +- test/checks.test.ts | 15 +++++++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/cli/land.ts b/src/cli/land.ts index babc5e9a4..23e3bb42b 100644 --- a/src/cli/land.ts +++ b/src/cli/land.ts @@ -175,7 +175,7 @@ export interface Waiting { const CONTEXTS = `pageInfo { hasNextPage endCursor } nodes { __typename - ... on CheckRun { databaseId name status conclusion detailsUrl checkSuite { databaseId app { databaseId } } } + ... on CheckRun { databaseId name status conclusion detailsUrl checkSuite { databaseId app { databaseId } workflowRun { file { path repositoryName } } } } ... on StatusContext { context state createdAt targetUrl } }`; diff --git a/src/github/checks.ts b/src/github/checks.ts index b54f37f93..a3b2e70e7 100644 --- a/src/github/checks.ts +++ b/src/github/checks.ts @@ -29,7 +29,7 @@ function workflowOf(context: RollupContext): [unknown, unknown] | null { * job never loses to another workflow's same-named job; and the latest is the one created last: the highest `databaseId`. A commit * status is keyed by its context, and the latest is the newest `createdAt`, or on a tie the one listed * later. A check run and a status with the same name stay apart, since GitHub requires both. - * Queries must ask for a check run's `databaseId name checkSuite { app { databaseId } }` and a + * Queries must ask for a check run's `databaseId name checkSuite { app { databaseId } workflowRun { file { path repositoryName } } }` and a * status's `context createdAt`. */ export function latestContexts(contexts: T[]): T[] { diff --git a/test/checks.test.ts b/test/checks.test.ts index 7adb6e768..da4ab38dc 100644 --- a/test/checks.test.ts +++ b/test/checks.test.ts @@ -149,3 +149,18 @@ test("a rerun is newer than every run that started before its latest attempt", ( expect(currentContexts([job("test", 1, "CANCELLED", 10)], tied)).toEqual([]); expect(currentContexts([job("test", 1, "CANCELLED", 20)], tied)).toHaveLength(1); }); + +test("a job keeps its latest report per workflow file, so another workflow's same-named job never hides it", () => { + const inWorkflow = (databaseId: number, conclusion: string, repositoryName: string, path: string) => ({ + ...run("build", databaseId, conclusion), + checkSuite: { databaseId, app: { databaseId: ACTIONS }, workflowRun: { file: { path, repositoryName } } }, + }); + const ci = inWorkflow(1, "FAILURE", "example/project", ".github/workflows/ci.yml"); + const docs = inWorkflow(2, "SUCCESS", "example/project", ".github/workflows/docs.yml"); + const policy = inWorkflow(3, "SUCCESS", "example/policies", ".github/workflows/ci.yml"); + expect(latestContexts([ci, docs, policy])).toEqual([ci, docs, policy]); + expect(checksState(latestContexts([ci, docs, policy]))).toBe("FAILURE"); + // A rerun in the same workflow still supersedes. + const rerun = inWorkflow(4, "SUCCESS", "example/project", ".github/workflows/ci.yml"); + expect(latestContexts([ci, rerun])).toEqual([rerun]); +});