Public: anyone can read this; the crew can change it.

The full-suite report for a file that is only slow names the budget and files nothing a second time #15807

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

torque/forge:torque/15806-the-full-suite-report-for-a-file-that-is → main 0 commits fork 1 thread · 1 unresolved

  • Merged. torque/15806-the-full-suite-report-for-a-file-that-is was merged into main as b29acf8.

Review

Sign in to review this change.
2 files changed +99 −4
test/fork-offers-sent.test.ts +19 −4
@@ -6,7 +6,8 @@ import { join } from "node:path";
66 import { commitToBranch, createRepo, forkRepo, updateRepoSettings } from "../src/actions/repos.ts";
77 import { mergePull, openPull } from "../src/actions/pulls.ts";
88 import { setIssueState } from "../src/actions/issues.ts";
9 import { getIssue } from "../src/core/issues.ts";
9 import { createIssue, getIssue } from "../src/core/issues.ts";
10 import { transact } from "../src/kernel/db.ts";
1011 import { getPull } from "../src/core/pulls.ts";
1112 import { createApp, type App } from "../src/app.ts";
1213 import { sentOffers } from "../src/core/fork_offers.ts";
@@ -95,8 +96,22 @@ describe("sent offers", () => {
9596 expect(sentOffers(app.db, up, undefined)).toEqual([]);
9697 });
9798
98 test("at most 20 offers come back, newest first", async () => {
99 for (let i = 0; i < 18; i++) await offer(`n${i}`, `Extra ${i}`);
99 // The 18 extra offers are written as rows in one transaction, not pushed and opened one by one:
100 // the cap is the query's, and 18 pushes took 4.85 s under the full suite's load (#15806).
101 test("at most 20 offers come back, newest first", () => {
102 const first = getPull(app.db, up.id, 1)!; // "Waits", the first offer opened
103 transact(app.db, () => {
104 for (let i = 0; i < 18; i++) {
105 const made = createIssue(app.db, { repoId: up.id, authorId: bob.id, title: `Extra ${i}`, kind: "pull" });
106 if (!made.ok) throw new Error(made.error);
107 app.db
108 .query(
109 `INSERT INTO pull (issue_id, base_branch, head_branch, base_oid, head_oid, head_repo_id)
110 VALUES (?1, 'main', ?2, ?3, ?4, ?5)`,
111 )
112 .run(made.value.id, `n${i}`, first.baseOid, first.headOid, fork.id);

Raw INSERT couples this test to the pull table columns; move it into a shared test seeding helper when a second test needs it.

113 }
114 });
100115 const total = app.db
101116 .query<{ n: number }, [string]>("SELECT COUNT(*) AS n FROM pull WHERE head_repo_id = ?")
102117 .get(fork.id)!.n;
@@ -108,7 +123,7 @@ describe("sent offers", () => {
108123 // The oldest of the 21 (the first one opened) is the one left out.
109124 expect(list.some((o) => o.title === "Waits")).toBe(false);
110125 expect(list[0]!.title).toBe("Extra 17");
111 }, 120_000);
126 });
112127
113128 test("a viewer who cannot read the upstream sees nothing sent", async () => {
114129 const hid = await updateRepoSettings(app, alice, up, { visibility: "private" });
test/full-suite-report-dedupe.test.ts added +80
@@ -0,0 +1,80 @@
1 /**
2 * A file red in two full-suite runs gets one report issue, and the second run is a comment on it
3 * naming that run (#15806). The case is #15800's: a file red only for being slow, passed alone, so
4 * filed held; the second red names the new run on the same issue and lifts the hold.
5 */
6
7 import { afterEach, beforeEach, expect, test } from "bun:test";
8 import { mkdtemp, rm } from "node:fs/promises";
9 import { tmpdir } from "node:os";
10 import { join } from "node:path";
11 import { createApp, type App } from "../src/app.ts";
12 import { createRepo } from "../src/actions/repos.ts";
13 import { ALONE_GREEN_LABEL, REPORT_LABEL, reportRed, reportTitle } from "../src/checks/report.ts";
14 import { VERIFY_ENV } from "../src/checks/verify.ts";
15 import { labelsFor, listComments, listIssues } from "../src/core/issues.ts";
16 import type { Repo } from "../src/core/repos.ts";
17 import { createRun, getRun, type Run } from "../src/core/runs.ts";
18 import { createUser } from "../src/core/users.ts";
19
20 const FILE = "test/fork-offers-sent.test.ts";
21 const SLOW = "sent offers > at most 20 offers come back, newest first took 4.85 s, over the 2 s test budget";
22
23 let dataDir: string;
24 let app: App;
25 let repo: Repo;
26
27 beforeEach(async () => {
28 dataDir = await mkdtemp(join(tmpdir(), "forge-report-dedupe-"));
29 app = createApp({ dataDir, port: 0 });
30 const user = await createUser(app.db, {
31 origin: "seed", trusted: true, username: "alice", email: "[email protected]",
32 password: "a-good-passphrase", adminIfFirst: true,
33 });
34 if (!user.ok) throw new Error(user.error);
35 const made = await createRepo(app, user.value, { name: "app", visibility: "public" });
36 if (!made.ok) throw new Error(String(made.error));
37 repo = made.value;
38 });
39
40 afterEach(async () => {
41 app.close();
42 await rm(dataDir, { recursive: true, force: true });
43 });
44
45 /** A finished full-suite run red in {@link FILE} only, for its one slow test. */
46 function red(commit: string): Run {
47 const run = createRun(app.db, { repoId: repo.id, kind: "check", env: VERIFY_ENV, commitOid: commit, reason: "schedule" });
48 const failures = [{ file: FILE, name: SLOW }];
49 const detail = { passed: 4, failed: 1, names: [SLOW], files: [FILE], failures };
50 app.db
51 .query("UPDATE run SET state = 'failed', check_detail = ?2, finished_at = ?3 WHERE id = ?1")
52 .run(run.id, JSON.stringify(detail), new Date().toISOString());
53 return getRun(app.db, run.id)!;
54 }
55
56 test("two reds of one file: one issue, and one comment naming the second run", () => {
57 const passedAlone = new Map([[FILE, { passed: true, ms: 900, others: 3 }]]);
58 const first = red("a".repeat(40));
59 const filed = reportRed(app, repo, first, passedAlone);
60 expect(filed).toHaveLength(1);
61 expect(filed[0]).toMatch(/^report: filed #\d+ for test\/fork-offers-sent\.test\.ts, held as /);
62
63 const second = red("b".repeat(40));
64 const added = reportRed(app, repo, second, passedAlone);
65
66 const issues = listIssues(app.db, repo.id, { label: REPORT_LABEL, state: "all" });
67 expect(issues.map((i) => i.title)).toEqual([reportTitle(FILE)]);
68 const [issue] = issues;
69 expect(added).toEqual([`report: added to #${issue!.number} for ${FILE}`]);
70 expect(issue!.body).toContain(`check run ${first.id}`);
71 expect(issue!.body).toContain("over the 2 s test budget");
72
73 const comments = listComments(app.db, issue!.id);
74 expect(comments).toHaveLength(1);
75 expect(comments[0]!.body).toContain(`Still red in the full suite (check run ${second.id}, bbbbbbb).`);
76 expect(comments[0]!.body).not.toContain(first.id);
77 // The second red lifts the hold the first one filed it under.
78 expect(labelsFor(app.db, issue!.id).map((l) => l.name)).toEqual([REPORT_LABEL]);
79 expect(comments[0]!.body).toContain(`no longer held as \`${ALONE_GREEN_LABEL}\``);
80 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs