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

An edge-kept finding is the owner's from the moment it exists: every open one is assigned to the owner on each run, even when the edge goes unread #17190

opened this

Merged 46h 49m ago, live in production

scout/forge:scout/17169-an-edge-kept-finding-is-the-owner-s-from → main 0 commits fork

  • Merged. scout/17169-an-edge-kept-finding-is-the-owner-s-from was merged into main as 46b42c3.

Review

Sign in to review this change.
3 files changed +42 −10
src/maintain/duties/edge_kept.ts +13 −7
@@ -13,7 +13,7 @@
1313 */
1414
1515 import { fileIssueOnce } from "../../checks/flake.ts";
16 import { addComment, getIssue, setAssignee, setIssueState } from "../../core/issues.ts";
16 import { addComment, setAssignee, setIssueState } from "../../core/issues.ts";
1717 import { getRepo } from "../../core/repos.ts";
1818 import { ownRepoPath } from "../../kernel/own_repo.ts";
1919 import { cellProxy } from "../../apps/egress.ts";
@@ -48,14 +48,22 @@ export function edgeKept(read: Get = get, inCell: () => boolean = inACell): Duty
4848 intervalMs: 3_600_000,
4949 budget: { runsPerDay: 30, dollarsPerDay: 1, reason: "hourly is 24 runs a day; the rest is room for a catch-up, and it spends no money" },
5050 async run({ db, bus, now, app }) {
51 const url = app?.config.url;
52 if (url === undefined || url === "") return { findings: [], actions: ["skipped: this forge does not know its public origin (FORGE_URL)"] };
53 const origin = new URL(url);
54 if (inCell()) return { findings: [], actions: [`skipped: this forge runs in a cell and does not call its own host ${origin.host}; the edge goes unread (#15350)`] };
5551 const findings: Finding[] = [];
5652 const actions: string[] = [];
5753 const [owner = "", name = ""] = ownRepoPath().split("/");
5854 const repo = getRepo(db, owner, name);
55 // A finding is the owner's from the moment it exists, whether or not this run reads the edge.
56 // A finding a person assigned to someone else is left alone.
57 if (repo !== undefined)
58 for (const path of PATHS) {
59 const issue = findingFor(db, repo, path);
60 if (issue !== undefined && issue.assigneeId === null && setAssignee(db, issue.id, repo.ownerId) !== undefined)
61 actions.push(`assigned #${String(issue.number)} to the owner, whose fix it is`);
62 }
63 const url = app?.config.url;
64 if (url === undefined || url === "") return { findings: [], actions: [...actions, "skipped: this forge does not know its public origin (FORGE_URL)"] };
65 const origin = new URL(url);
66 if (inCell()) return { findings: [], actions: [...actions, `skipped: this forge runs in a cell and does not call its own host ${origin.host}; the edge goes unread (#15350)`] };
5967 for (const path of PATHS) {
6068 const at = new URL(path, origin).href;
6169 let first: Headers | undefined;
@@ -98,8 +106,6 @@ export function edgeKept(read: Get = get, inCell: () => boolean = inACell): Duty
98106 findings.push({ summary: `${summary}; filed ${owner}/${name}#${String(filed.number)}`, probe });
99107 actions.push(`filed issue #${String(filed.number)}`);
100108 } else if (filed.number === 0) actions.push(`${path}: not kept, and the issue could not be filed`);
101 else if (getIssue(db, repo.id, filed.number)?.assigneeId === null && setAssignee(db, getIssue(db, repo.id, filed.number)!.id, repo.ownerId) !== undefined)
102 actions.push(`already filed as issue #${String(filed.number)}; assigned it to the owner, whose fix it is`);
103109 else actions.push(`already filed as issue #${String(filed.number)}`);
104110 }
105111 return { findings, actions };
src/maintain/edge_kept.ts +1 −1
@@ -70,7 +70,7 @@ export function edgeRule(): string {
7070 export const bothKept = (first: Headers, second: Headers): boolean => edgeKept(first) === "kept" && edgeKept(second) === "kept";
7171
7272 /** The one way to find the open finding for a page in a repository; undefined when none. */
73 export function findingFor(db: Database, repo: { id: string }, path: string): { id: string; number: number } | undefined {
73 export function findingFor(db: Database, repo: { id: string }, path: string): ReturnType<typeof getIssue> {
7474 const row = db.query<{ number: number }, [string, string]>("SELECT number FROM issue WHERE repo_id = ?1 AND title = ?2 AND state = 'open' LIMIT 1").get(repo.id, title(path));
7575 return row === null ? undefined : getIssue(db, repo.id, row.number);
7676 }
test/maintain-edge-kept.test.ts +28 −2
@@ -116,10 +116,36 @@ test("an open filing with no assignee is assigned to the owner, once, with an ac
116116 const repo = getRepo(app.db, owner, name)!;
117117 app.db.query("UPDATE issue SET assignee_id = NULL WHERE title = ?1").run(title("/"));
118118 const r = await once();
119 expect(r.actions.some((a) => a.includes("assigned it to the owner"))).toBe(true);
119 expect(r.actions.some((a) => a.includes("to the owner, whose fix it is"))).toBe(true);
120120 const row = app.db.query("SELECT number FROM issue WHERE title = ?1").get(title("/")) as { number: number };
121121 expect(getIssue(app.db, repo.id, row.number)?.assigneeId).toBe(repo.ownerId);
122 expect((await once()).actions.some((a) => a.includes("assigned it to the owner"))).toBe(false);
122 expect((await once()).actions.some((a) => a.includes("to the owner, whose fix it is"))).toBe(false);
123 });
124
125 test("an unassigned finding is the owner's even when the run skips (no FORGE_URL, in a cell); a person's assignee stays", async () => {
126 const [owner = "", name = ""] = ownRepoPath().split("/");
127 for (const [url, inCell] of [["", false], ["https://forge.example", true]] as const) {
128 const { app, once } = await run(shareable({ "cf-cache-status": "DYNAMIC" }));
129 await once();
130 const repo = getRepo(app.db, owner, name)!;
131 const num = (app.db.query("SELECT number FROM issue WHERE title = ?1").get(title("/")) as { number: number }).number;
132 app.db.query("UPDATE issue SET assignee_id = NULL WHERE repo_id = ?1").run(repo.id);
133 const skipped = edgeDuty(async () => undefined, () => inCell);
134 const r = await skipped.run({ db: app.db, bus: app.bus, now: new Date(), app: { ...app, config: { ...app.config, url } } as App });
135 expect(r.actions).toContain(`assigned #${String(num)} to the owner, whose fix it is`);
136 expect(r.actions.some((a) => a.startsWith("skipped"))).toBe(true);
137 expect(getIssue(app.db, repo.id, num)?.assigneeId).toBe(repo.ownerId);
138 }
139 const { app, once } = await run(shareable({ "cf-cache-status": "DYNAMIC" }));
140 await once();
141 const repo = getRepo(app.db, owner, name)!;
142 const other = await createUser(app.db, { origin: "seed", trusted: true, username: "someone", email: "[email protected]", password: "a-good-passphrase" });
143 if (!other.ok) throw new Error(other.error);
144 app.db.query("UPDATE issue SET assignee_id = ?1").run(other.value.id);
145 const r = await once();
146 expect(r.actions.some((a) => a.includes("to the owner"))).toBe(false);
147 expect(app.db.query("SELECT COUNT(*) AS n FROM issue WHERE assignee_id = ?1").get(other.value.id)).toEqual({ n: 2 });
148 expect(repo.ownerId).not.toBe(other.value.id);
123149 });
124150
125151 test("no edge header, an unshared page, a refused host or no URL say nothing", async () => {

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs