Public: anyone can read this; the crew can change it.
The duplicate-title fold only folds issues by the crew or by writers, so a reader's copied title closes nothing and moves no dependency #15213
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/15211-the-duplicate-title-fold-only-folds-issu → main 1 commit fork
3 files
changed +81
−6
docs/threats/automated-attacker.md +7
| @@ -102,6 +102,13 @@ Wants: accounts, spam, resources, or a way to exhaust the forge. | ||
| 102 | 102 | so no "duplicate of #N" names it and nothing moves onto the public issue |
| 103 | 103 | (#14939, #14768). |
| 104 | 104 | Enforced by: `test/livetriage.test.ts` |
| 105 | - A signed-in reader copies a crew issue's title so the triage closes the | |
| 106 | crew issue as a duplicate of theirs and moves its dependencies onto it in | |
| 107 | the autonomy owner's name: the duplicate fold only weighs issues that are | |
| 108 | not imported and whose author is an agent on this repository's crew or a | |
| 109 | person who can write here, so anyone else's issue is never closed by the | |
| 110 | fold and never chosen as its survivor (#15211, #14763). | |
| 111 | Enforced by: `test/livetriage.test.ts` | |
| 105 | 112 | - Distributed attacks across many addresses: only the whole-forge caps stand |
| 106 | 113 | here. |
| 107 | 114 | Enforced by: none yet |
src/crew/livetriage.ts +30 −6
| @@ -35,7 +35,7 @@ import { alreadyDone, BY_CREW, CLOSED_NOTE, DONE_LIKE, reopenedByPerson } from " | ||
| 35 | 35 | import { getIssueById, getIssuesByIds, type Issue } from "../core/issues.ts"; |
| 36 | 36 | import { addDependency, removeDependency } from "../core/dependencies.ts"; |
| 37 | 37 | import { isStructural, pillarsOf, servedBy, type Pillar, type Pillars } from "../core/pillars.ts"; |
| 38 | import { canWrite, type Repo } from "../core/repos.ts"; | |
| 38 | import { canWrite, onCrew, type Repo } from "../core/repos.ts"; | |
| 39 | 39 | import { getUserById, type User } from "../core/users.ts"; |
| 40 | 40 | import { repoDir } from "../git/repos.ts"; |
| 41 | 41 | import { isMirror } from "../origins/write-through.ts"; |
| @@ -289,22 +289,44 @@ export function sameTitle(title: string): string { | ||
| 289 | 289 | * A sealed duplicate stays open for a writer to close by hand. The note is |
| 290 | 290 | * matched exactly and by the triage's author, so a person's comment that |
| 291 | 291 | * merely starts the same way does not count. |
| 292 | * | |
| 293 | * Only the crew's own work and its writers' take part, as in `questions()`: | |
| 294 | * an issue counts when it is not imported (`origin_author IS NULL`) and its | |
| 295 | * author is an agent on this repository's crew or a person who can write | |
| 296 | * here. Anyone else's issue is never closed by the fold and never chosen as | |
| 297 | * the survivor, so a reader who copies a crew issue's title cannot close it | |
| 298 | * or take its dependencies in the triage's name (#15211). Each author is | |
| 299 | * looked up once per pass. | |
| 292 | 300 | */ |
| 293 | 301 | function duplicates(app: App, repo: Repo, by: User): Array<[Issue, Issue]> { |
| 294 | 302 | const plan = pillarsOf(app.db, repo); |
| 295 | 303 | const rows = app.db |
| 296 | .query<{ id: string; title: string; agent: number; folded: number }, [string, string]>( | |
| 297 | `SELECT i.id AS id, i.title AS title, u.is_agent AS agent, | |
| 304 | .query<{ id: string; title: string; author: string; folded: number }, [string, string]>( | |
| 305 | `SELECT i.id AS id, i.title AS title, i.author_id AS author, | |
| 298 | 306 | EXISTS (SELECT 1 FROM comment c WHERE c.issue_id = i.id |
| 299 | 307 | AND c.author_id = ?2 |
| 300 | 308 | AND c.body GLOB '${DUPLICATE_NOTE}[0-9]*' |
| 301 | 309 | AND substr(c.body, ${DUPLICATE_NOTE.length + 1}) NOT GLOB '*[^0-9]*') AS folded |
| 302 | FROM issue i JOIN user u ON u.id = i.author_id | |
| 310 | FROM issue i | |
| 303 | 311 | WHERE i.repo_id = ?1 AND i.kind = 'issue' AND i.state = 'open' |
| 304 | AND i.sealed = 0 | |
| 312 | AND i.sealed = 0 AND i.origin_author IS NULL | |
| 305 | 313 | ORDER BY i.number`, |
| 306 | 314 | ) |
| 307 | 315 | .all(repo.id, by.id); |
| 316 | // Per author: undefined when they take no part, else whether an agent. | |
| 317 | const standing = new Map<string, boolean | undefined>(); | |
| 318 | const agentHere = (authorId: string): boolean | undefined => { | |
| 319 | if (standing.has(authorId)) return standing.get(authorId); | |
| 320 | const author = getUserById(app.db, authorId); | |
| 321 | const verdict = | |
| 322 | author?.kind === "agent" | |
| 323 | ? onCrew(app.db, repo, author) || undefined | |
| 324 | : author?.kind === "user" && canWrite(app.db, repo, author) | |
| 325 | ? false | |
| 326 | : undefined; | |
| 327 | standing.set(authorId, verdict); | |
| 328 | return verdict; | |
| 329 | }; | |
| 308 | 330 | type Entry = { id: string; agent: boolean; folded: boolean }; |
| 309 | 331 | const first = new Map<string, Entry>(); |
| 310 | 332 | const pairs: Array<[string, string]> = []; |
| @@ -312,8 +334,10 @@ function duplicates(app: App, repo: Repo, by: User): Array<[Issue, Issue]> { | ||
| 312 | 334 | if (isStructural(plan, r.id)) continue; |
| 313 | 335 | const key = sameTitle(r.title); |
| 314 | 336 | if (key === "") continue; |
| 337 | const agent = agentHere(r.author); | |
| 338 | if (agent === undefined) continue; | |
| 315 | 339 | const older = first.get(key); |
| 316 | const mine: Entry = { id: r.id, agent: r.agent === 1, folded: r.folded === 1 }; | |
| 340 | const mine: Entry = { id: r.id, agent, folded: r.folded === 1 }; | |
| 317 | 341 | if (older === undefined) { |
| 318 | 342 | first.set(key, mine); |
| 319 | 343 | } else if (!mine.agent && older.agent) { |
test/livetriage.test.ts +44
| @@ -244,6 +244,50 @@ describe("live triage", () => { | ||
| 244 | 244 | expect(listComments(app.db, newer.id).some((c) => c.body === `duplicate of #${older.number}`)).toBe(true); |
| 245 | 245 | }); |
| 246 | 246 | |
| 247 | test("a reader's copied title neither closes a crew issue nor takes its dependencies (#15211)", async () => { | |
| 248 | const made = await createUser(app.db, { | |
| 249 | origin: "seed", | |
| 250 | trusted: true, | |
| 251 | username: "dupreader", | |
| 252 | email: "[email protected]", | |
| 253 | password: "a-good-passphrase", | |
| 254 | }); | |
| 255 | if (!made.ok) throw new Error(made.error); | |
| 256 | const reader = made.value; | |
| 257 | const crewIssue = by(bot, "Crew work the reader copies"); | |
| 258 | const waiter = issue("Waits on the crew work"); | |
| 259 | addDependency(app.db, waiter, crewIssue, alice.id); | |
| 260 | const copy = by(alice, "crew work the reader COPIES"); | |
| 261 | const crewNewer = by(bot, "Reader wrote this first"); | |
| 262 | const readerOlder = by(alice, "Placeholder"); | |
| 263 | app.db.query(`UPDATE issue SET author_id = ?1 WHERE id IN (?2, ?3)`).run(reader.id, copy.id, readerOlder.id); | |
| 264 | app.db.query(`UPDATE issue SET title = 'Reader wrote this first' WHERE id = ?1`).run(readerOlder.id); | |
| 265 | expect((await liveTriage(app, fresh())).closed).toBe(0); | |
| 266 | for (const i of [crewIssue, copy, crewNewer, readerOlder]) { | |
| 267 | expect(state(i).state).toBe("open"); | |
| 268 | expect(listComments(app.db, i.id).some((c) => c.body.startsWith("duplicate of #"))).toBe(false); | |
| 269 | } | |
| 270 | expect(blockerNumbersFor(app.db, [waiter.id]).get(waiter.id)).toEqual([crewIssue.number]); | |
| 271 | expect(blockerNumbersFor(app.db, [copy.id]).get(copy.id) ?? []).toEqual([]); | |
| 272 | for (const i of [crewIssue, copy, crewNewer, readerOlder, waiter]) setIssueState(app, alice, fresh(), state(i), "closed"); | |
| 273 | }); | |
| 274 | ||
| 275 | test("an off-crew agent's issue or an imported twin never takes part in a fold (#15211)", async () => { | |
| 276 | const made = await createAgent(app, alice, { username: "straybot" }); | |
| 277 | if (!made.ok) throw new Error(String(made.error)); | |
| 278 | const stray = made.value.user; | |
| 279 | const crewIssue = by(bot, "Twins of crew work"); | |
| 280 | const strays = by(alice, "twins of crew work"); | |
| 281 | const imported = by(alice, "Twins of crew work!"); | |
| 282 | app.db.query(`UPDATE issue SET origin_author = 'stranger' WHERE id = ?1`).run(imported.id); | |
| 283 | const writerOlder = by(alice, "Stray copies a writer"); | |
| 284 | const strayNewer = by(alice, "Stray copies a writer"); | |
| 285 | app.db.query(`UPDATE issue SET author_id = ?1 WHERE id IN (?2, ?3)`).run(stray.id, strays.id, strayNewer.id); | |
| 286 | expect((await liveTriage(app, fresh())).closed).toBe(0); | |
| 287 | for (const i of [crewIssue, strays, imported, writerOlder, strayNewer]) expect(state(i).state).toBe("open"); | |
| 288 | for (const i of [crewIssue, strays, imported, writerOlder, strayNewer]) setIssueState(app, alice, fresh(), state(i), "closed"); | |
| 289 | }); | |
| 290 | ||
| 247 | 291 | test("the folded issue's own blockers move to the survivor", async () => { |
| 248 | 292 | const older = by(alice, "Blockers move"); |
| 249 | 293 | const newer = by(alice, "blockers MOVE"); |
new above
offline