Public: anyone can read this; the crew can change it.
Only crew-written notes cancel or restore the already-done auto-close, never a commenter's #15003
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/14990-only-crew-written-notes-cancel-or-restor → main 2 commits fork
3 files
changed +45
−11
src/core/done_on_main.ts +11 −7
| @@ -34,19 +34,23 @@ export interface Written { | ||
| 34 | 34 | export const LATER = (a: string, b: string): string => |
| 35 | 35 | `(${a}.created_at, ${a}.id) > (${b}.created_at, ${b}.id)`; |
| 36 | 36 | |
| 37 | /** `n` is a note written by the crew: the one who set it going, or its own agent. */ | |
| 38 | export const BY_CREW = `n.origin_author IS NULL AND (n.author_id IN ( | |
| 39 | SELECT r.autonomy_by FROM issue i JOIN repo r ON r.id = i.repo_id WHERE i.id = n.issue_id) | |
| 40 | OR n.author_id IN ( | |
| 37 | /** Comment `a` is a note written by the crew: the one who set it going, or its own agent. */ | |
| 38 | export const byCrew = (a: string): string => `${a}.origin_author IS NULL AND (${a}.author_id IN ( | |
| 39 | SELECT r.autonomy_by FROM issue i JOIN repo r ON r.id = i.repo_id WHERE i.id = ${a}.issue_id) | |
| 40 | OR ${a}.author_id IN ( | |
| 41 | 41 | SELECT rc.user_id FROM repo_crew rc JOIN issue i ON i.repo_id = rc.repo_id |
| 42 | WHERE i.id = n.issue_id))`; | |
| 42 | WHERE i.id = ${a}.issue_id))`; | |
| 43 | ||
| 44 | /** `n` is a note written by the crew. */ | |
| 45 | export const BY_CREW = byCrew("n"); | |
| 43 | 46 | |
| 44 | 47 | const CHUNK = 400; |
| 45 | 48 | |
| 46 | 49 | /** |
| 47 | 50 | * The commits an open issue was found done by, when the crew's newest word |
| 48 | 51 | * on it is an already-done note and nobody has closed it yet: one read for |
| 49 | * these issues, empty for the rest. A later park is a newer word. | |
| 52 | * these issues, empty for the rest. A later park by the crew is a newer word; | |
| 53 | * a commenter's text that merely reads like one is not (#14990). | |
| 50 | 54 | */ |
| 51 | 55 | export function alreadyDone( |
| 52 | 56 | db: Database, |
| @@ -62,7 +66,7 @@ export function alreadyDone( | ||
| 62 | 66 | WHERE n.issue_id IN (${marks}) AND o.state = 'open' |
| 63 | 67 | AND n.body LIKE '${DONE_LIKE}' AND ${BY_CREW} |
| 64 | 68 | AND NOT EXISTS (SELECT 1 FROM comment q WHERE q.issue_id = n.issue_id |
| 65 | AND q.body LIKE '${PARK_LIKE}' AND ${LATER("q", "n")}) | |
| 69 | AND q.body LIKE '${PARK_LIKE}' AND ${byCrew("q")} AND ${LATER("q", "n")}) | |
| 66 | 70 | ORDER BY n.created_at, n.id`, |
| 67 | 71 | ) |
| 68 | 72 | .all(...batch); |
src/crew/livetriage.ts +5 −4
| @@ -246,9 +246,10 @@ function fold(app: App, repo: Repo, by: User, did: Triaged): void { | ||
| 246 | 246 | /** |
| 247 | 247 | * Open issues that carry an already-done note, oldest first. One that |
| 248 | 248 | * already has a close note was closed once and reopened by a person: that |
| 249 | * reopen stands, so it is not closed again. Only the crew's own close note | |
| 250 | * counts (`BY_CREW`, exact prefix): a stranger's comment that starts the | |
| 251 | * same way cannot keep a done issue open. | |
| 249 | * reopen stands, so it is not closed again. Only the crew's own notes count | |
| 250 | * either way (`BY_CREW`, the close note by exact prefix): a commenter's text | |
| 251 | * that reads like one neither makes an issue a candidate nor keeps a done | |
| 252 | * issue open (#14990). | |
| 252 | 253 | */ |
| 253 | 254 | function candidates(app: App, repo: Repo): string[] { |
| 254 | 255 | return app.db |
| @@ -256,7 +257,7 @@ function candidates(app: App, repo: Repo): string[] { | ||
| 256 | 257 | `SELECT i.id AS id FROM issue i |
| 257 | 258 | WHERE i.repo_id = ?1 AND i.kind = 'issue' AND i.state = 'open' |
| 258 | 259 | AND EXISTS (SELECT 1 FROM comment n WHERE n.issue_id = i.id |
| 259 | AND n.body LIKE '${DONE_LIKE}') | |
| 260 | AND n.body LIKE '${DONE_LIKE}' AND ${BY_CREW}) | |
| 260 | 261 | AND NOT EXISTS (SELECT 1 FROM comment n WHERE n.issue_id = i.id |
| 261 | 262 | AND substr(n.body, 1, length(?2)) = ?2 AND ${BY_CREW}) |
| 262 | 263 | ORDER BY i.number`, |
test/livetriage.test.ts +29
| @@ -11,6 +11,7 @@ import { addToCrew, createAgent } from "../src/actions/crew.ts"; | ||
| 11 | 11 | import { addComment, openIssue, setIssueState } from "../src/actions/issues.ts"; |
| 12 | 12 | import { commitToBranch, createRepo, updateRepoSettings } from "../src/actions/repos.ts"; |
| 13 | 13 | import { addDependency, blockerNumbersFor } from "../src/core/dependencies.ts"; |
| 14 | import { PARK_LEAD } from "../src/core/done_on_main.ts"; | |
| 14 | 15 | import { getIssueById, labelsFor, listComments, type Issue } from "../src/core/issues.ts"; |
| 15 | 16 | import { getRepoById, type Repo } from "../src/core/repos.ts"; |
| 16 | 17 | import { createUser, getUserByName, type User } from "../src/core/users.ts"; |
| @@ -141,6 +142,34 @@ describe("live triage", () => { | ||
| 141 | 142 | expect(state(held).state).toBe("closed"); |
| 142 | 143 | }); |
| 143 | 144 | |
| 145 | test("a commenter's park wording does not cancel the crew's close (#14990)", async () => { | |
| 146 | const dave = await createUser(app.db, { | |
| 147 | origin: "seed", | |
| 148 | trusted: true, | |
| 149 | username: "dave", | |
| 150 | email: "[email protected]", | |
| 151 | password: "a-good-passphrase", | |
| 152 | }); | |
| 153 | if (!dave.ok) throw new Error(dave.error); | |
| 154 | const parkWord = issue("Commenter says parked"); | |
| 155 | note(parkWord, oid); | |
| 156 | app.db | |
| 157 | .query(`INSERT INTO comment (id, issue_id, author_id, body, created_at) VALUES (?1, ?2, ?3, ?4, ?5)`) | |
| 158 | .run("c-dave-park", parkWord.id, dave.value.id, `${PARK_LEAD}: no, leave it`, new Date(Date.now() + 60_000).toISOString()); | |
| 159 | expect((await liveTriage(app, fresh())).closed).toBe(1); | |
| 160 | expect(state(parkWord).state).toBe("closed"); | |
| 161 | }); | |
| 162 | ||
| 163 | test("the crew's own park still cancels the close", async () => { | |
| 164 | const parked = issue("Crew parked after"); | |
| 165 | note(parked, oid); | |
| 166 | app.db | |
| 167 | .query(`INSERT INTO comment (id, issue_id, author_id, body, created_at) VALUES (?1, ?2, ?3, ?4, ?5)`) | |
| 168 | .run("c-alice-park", parked.id, alice.id, `${PARK_LEAD}: blocked`, new Date(Date.now() + 60_000).toISOString()); | |
| 169 | expect((await liveTriage(app, fresh())).closed).toBe(0); | |
| 170 | expect(state(parked).state).toBe("open"); | |
| 171 | }); | |
| 172 | ||
| 144 | 173 | test("a close that rolls back is neither counted nor announced", async () => { |
| 145 | 174 | const stuck = issue("Rolls back"); |
| 146 | 175 | note(stuck, oid); |
new above
offline