Public: anyone can read this; the crew can change it.
The pulls list says green while a pull's tests are still running #17262
Test for this, test/pull-list-check-under-deploy.test.ts. It uses the same harness as #17258's test and approve-here.test.ts (forgeHttp(app).handle):
/**
* The pull list's check word reads a head as `checkSummary` does: a preview deploy recorded after
* the check, finished in seconds with no tests, never makes the list say green for a check still to come.
*/
import { afterAll, beforeAll, expect, test } from "bun:test";
import { mkdtemp, rm } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { openPull } from "../src/actions/pulls.ts";
import { commitToBranch, createRepo } from "../src/actions/repos.ts";
import { createApp, type App } from "../src/app.ts";
import { getPull } from "../src/core/pulls.ts";
import type { Repo } from "../src/core/repos.ts";
import { checkSummary, claimRun, createRun, finishRun } from "../src/core/runs.ts";
import { createUser, type User } from "../src/core/users.ts";
import { forgeHttp } from "../src/http/server.ts";
let dataDir: string;
let app: App;
let alice: User;
let repo: Repo;
beforeAll(async () => {
dataDir = await mkdtemp(join(tmpdir(), "forge-list-check-"));
app = createApp({ dataDir, port: 0, host: "forge.test" });
const a = await createUser(app.db, {
origin: "seed", trusted: true, username: "alice", email: "[email protected]",
password: "a-good-passphrase", adminIfFirst: true,
});
if (!a.ok) throw new Error(a.error);
alice = a.value;
const made = await createRepo(app, alice, { name: "lib", visibility: "public" });
if (!made.ok) throw new Error(String(made.error));
repo = made.value;
await commitToBranch(app, alice, repo, { message: "Start", files: [{ path: "a.ts", content: "export const a = 0;\n" }] });
await commitToBranch(app, alice, repo, { branch: "feature/x", base: "main", message: "X", files: [{ path: "x.ts", content: "export const x = 1;\n" }] });
});
afterAll(async () => {
app.close();
await rm(dataDir, { recursive: true, force: true });
});
test("the list says running, then red, then green, as the pull's own verdict does", async () => {
const opened = await openPull(app, alice, repo, { title: "X", body: "", baseBranch: "main", headBranch: "feature/x" });
if (!opened.ok) throw new Error(String(opened.error));
const pull = getPull(app.db, repo.id, opened.value.number)!;
const record = (kind: "check" | "deploy") =>
createRun(app.db, { repoId: repo.id, kind, env: `pull-${pull.number}`, issueId: pull.id, commitOid: pull.headOid, reason: "pull" });
const http = forgeHttp(app);
const listed = async () => {
const res = await http.handle(new Request("http://forge.test/api/v1/repos/alice/lib/pulls?fields=number,check"));
const body = (await res.json()) as { items: { number: number; check: string }[] };
return body.items.find((p) => p.number === pull.number)?.check;
};
const check = record("check");
const deploy = record("deploy");
claimRun(app.db, deploy.id);
finishRun(app.db, deploy.id, { state: "ok", summary: "running · no tests declared, none run" });
expect(checkSummary(app.db, pull.id, pull.headOid).state).toBe("queued");
expect(await listed()).toBe("running");
claimRun(app.db, check.id);
expect(await listed()).toBe("running");
finishRun(app.db, check.id, { state: "failed", summary: "1 test failed" });
expect(await listed()).toBe("red");
const again = record("check");
claimRun(app.db, again.id);
finishRun(app.db, again.id, { state: "ok", summary: "check passed in 1s" });
expect(await listed()).toBe("green");
});
If createApp or forgeHttp needs a different close in this file, follow approve-here.test.ts. Open the pull against main once #17258 lands, since both change checkSummary.
Sign in to join this conversation.
new above
offline
Evidence: at 22:33 UTC,
GET /api/v1/repos/trevato/forge/pullslisted #17249, #17248, #17252 and #17253 ascheck: "green". #17249's test check 01m8st3mdj7xp44hkxfzcc5zdj had been running since 22:20.Cause: the list route in
src/http/api/pulls.tsbuilds its check word fromlatestRunsForIssues, which is MAX(id) over every check kind for each issue. The preview deploy (kind=deploy, env=pull-N) finishes in seconds and is newer than the test check, so it speaks for the head. The single-pull route readscheckSummary, which #17258 fixes (#17256). The list is a second door, and #17258 doesn't touch it. On main, the list also reads green for a failed check that has a later ok deploy on top of it.Fix (build it on #17258 once that lands). One batched read using the existing
checksForHeads:src/core/runs.ts
src/http/api/pulls.ts, list route:
If
latestRunsForIssueshas no other callers after this, delete it (unused-exports). A studio list that shows a pass/fail mark from it has the same gap. Move only those.Test: in the next comment. It fails on main (the list reads "green" at every step). Change no timeouts or limits.