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
Merged 46h 49m ago, live in production
scout/forge:scout/17169-an-edge-kept-finding-is-the-owner-s-from → main 0 commits fork
3 files
changed +42
−10
src/maintain/duties/edge_kept.ts +13 −7
| @@ -13,7 +13,7 @@ | ||
| 13 | 13 | */ |
| 14 | 14 | |
| 15 | 15 | 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"; | |
| 17 | 17 | import { getRepo } from "../../core/repos.ts"; |
| 18 | 18 | import { ownRepoPath } from "../../kernel/own_repo.ts"; |
| 19 | 19 | import { cellProxy } from "../../apps/egress.ts"; |
| @@ -48,14 +48,22 @@ export function edgeKept(read: Get = get, inCell: () => boolean = inACell): Duty | ||
| 48 | 48 | intervalMs: 3_600_000, |
| 49 | 49 | 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" }, |
| 50 | 50 | 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)`] }; | |
| 55 | 51 | const findings: Finding[] = []; |
| 56 | 52 | const actions: string[] = []; |
| 57 | 53 | const [owner = "", name = ""] = ownRepoPath().split("/"); |
| 58 | 54 | 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)`] }; | |
| 59 | 67 | for (const path of PATHS) { |
| 60 | 68 | const at = new URL(path, origin).href; |
| 61 | 69 | let first: Headers | undefined; |
| @@ -98,8 +106,6 @@ export function edgeKept(read: Get = get, inCell: () => boolean = inACell): Duty | ||
| 98 | 106 | findings.push({ summary: `${summary}; filed ${owner}/${name}#${String(filed.number)}`, probe }); |
| 99 | 107 | actions.push(`filed issue #${String(filed.number)}`); |
| 100 | 108 | } 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`); | |
| 103 | 109 | else actions.push(`already filed as issue #${String(filed.number)}`); |
| 104 | 110 | } |
| 105 | 111 | return { findings, actions }; |
src/maintain/edge_kept.ts +1 −1
| @@ -70,7 +70,7 @@ export function edgeRule(): string { | ||
| 70 | 70 | export const bothKept = (first: Headers, second: Headers): boolean => edgeKept(first) === "kept" && edgeKept(second) === "kept"; |
| 71 | 71 | |
| 72 | 72 | /** 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> { | |
| 74 | 74 | 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)); |
| 75 | 75 | return row === null ? undefined : getIssue(db, repo.id, row.number); |
| 76 | 76 | } |
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 | ||
| 116 | 116 | const repo = getRepo(app.db, owner, name)!; |
| 117 | 117 | app.db.query("UPDATE issue SET assignee_id = NULL WHERE title = ?1").run(title("/")); |
| 118 | 118 | 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); | |
| 120 | 120 | const row = app.db.query("SELECT number FROM issue WHERE title = ?1").get(title("/")) as { number: number }; |
| 121 | 121 | 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); | |
| 123 | 149 | }); |
| 124 | 150 | |
| 125 | 151 | test("no edge header, an unshared page, a refused host or no URL say nothing", async () => { |
new above
offline