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

Merged opened this

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

Merged

scout/forge:scout/14990-only-crew-written-notes-cancel-or-restor → main 2 commits fork

  • Merged. scout/14990-only-crew-written-notes-cancel-or-restor was merged into main as ac873cc.

Review

Sign in to review this change.
3 files changed +45 −11
src/core/done_on_main.ts +11 −7
@@ -34,19 +34,23 @@ export interface Written {
3434 export const LATER = (a: string, b: string): string =>
3535 `(${a}.created_at, ${a}.id) > (${b}.created_at, ${b}.id)`;
3636
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 (
4141 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");
4346
4447 const CHUNK = 400;
4548
4649 /**
4750 * The commits an open issue was found done by, when the crew's newest word
4851 * 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).
5054 */
5155 export function alreadyDone(
5256 db: Database,
@@ -62,7 +66,7 @@ export function alreadyDone(
6266 WHERE n.issue_id IN (${marks}) AND o.state = 'open'
6367 AND n.body LIKE '${DONE_LIKE}' AND ${BY_CREW}
6468 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")})
6670 ORDER BY n.created_at, n.id`,
6771 )
6872 .all(...batch);
src/crew/livetriage.ts +5 −4
@@ -246,9 +246,10 @@ function fold(app: App, repo: Repo, by: User, did: Triaged): void {
246246 /**
247247 * Open issues that carry an already-done note, oldest first. One that
248248 * 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).
252253 */
253254 function candidates(app: App, repo: Repo): string[] {
254255 return app.db
@@ -256,7 +257,7 @@ function candidates(app: App, repo: Repo): string[] {
256257 `SELECT i.id AS id FROM issue i
257258 WHERE i.repo_id = ?1 AND i.kind = 'issue' AND i.state = 'open'
258259 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})
260261 AND NOT EXISTS (SELECT 1 FROM comment n WHERE n.issue_id = i.id
261262 AND substr(n.body, 1, length(?2)) = ?2 AND ${BY_CREW})
262263 ORDER BY i.number`,
test/livetriage.test.ts +29
@@ -11,6 +11,7 @@ import { addToCrew, createAgent } from "../src/actions/crew.ts";
1111 import { addComment, openIssue, setIssueState } from "../src/actions/issues.ts";
1212 import { commitToBranch, createRepo, updateRepoSettings } from "../src/actions/repos.ts";
1313 import { addDependency, blockerNumbersFor } from "../src/core/dependencies.ts";
14 import { PARK_LEAD } from "../src/core/done_on_main.ts";
1415 import { getIssueById, labelsFor, listComments, type Issue } from "../src/core/issues.ts";
1516 import { getRepoById, type Repo } from "../src/core/repos.ts";
1617 import { createUser, getUserByName, type User } from "../src/core/users.ts";
@@ -141,6 +142,34 @@ describe("live triage", () => {
141142 expect(state(held).state).toBe("closed");
142143 });
143144
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
144173 test("a close that rolls back is neither counted nor announced", async () => {
145174 const stuck = issue("Rolls back");
146175 note(stuck, oid);

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs