diff --git a/docs/pipeline.md b/docs/pipeline.md index a2ee8d05..b6384cf1 100644 --- a/docs/pipeline.md +++ b/docs/pipeline.md @@ -110,7 +110,7 @@ Model: Sonnet (summaries). Daily limit 100. - Nothing is written to GitHub (no label, comment, close or merge), and a duplicate group needs no `textsHash` for it because it stores no comment texts. - The item (every member of a batch or group) is held out of Decide, Review, Verify, Fix, Fix-up, Act and the merge queue, the same way an open Duplicate? decision holds it, and no new decision is asked for it. The Work queue shows a held PR as "Held". The Flow page counts scope items under their own bucket, "Backlog". - The decision leaves the Waiting list. The Decisions page has a Backlog view that lists them. An operator can Reopen one there (two clicks, audited as `reopen`, nothing written to GitHub): the answer is cleared and the decision is open again. Other users see the view without controls. -- An operator can move many open decisions at once: `craft-auto decisions backlog --outside-pilot` (open decisions none of whose items is in the pilot; with no pilot set, none) or `--repo R`. It lists what it would change and writes only with `--apply`; each answer is recorded for the CLI user and audited. The admin API offers the same as `POST /api/decisions/backlog` with `{outsidePilot, repo, apply}` (operators only; a dry run unless `apply` is true). +- An operator can move many open decisions at once: `craft-auto decisions backlog --outside-pilot` (open decisions none of whose items is in scope: a repo with its pipeline on and, when a pilot is set, a pilot item) or `--repo R`. It lists what it would change and writes only with `--apply`; each answer is recorded for the CLI user and audited. The admin API offers the same as `POST /api/decisions/backlog` with `{outsidePilot, repo, apply}` (operators only; a dry run unless `apply` is true). **Withdraw.** `craft-auto decisions withdraw --outside-pilot` (or `--repo R`, dry run unless `--apply`) deletes open scope decisions with their opinions, comments and the stage row Decide wrote when asking, so the items count as never asked and Decide asks them again when they are in scope. Other kinds are not withdrawn. Each is audited as `withdraw`; nothing is written to GitHub. diff --git a/src/decisions.ts b/src/decisions.ts index dd9d092e..56cea8a2 100644 --- a/src/decisions.ts +++ b/src/decisions.ts @@ -137,12 +137,12 @@ export type BacklogResult = { applied: boolean; decisions: { id: string; kind: K export function backlogCandidates(db: DatabaseSync, scope: BacklogScope): DecisionRow[] { if (!scope.outsidePilot && !scope.repo) throw new Error("name a scope: outsidePilot or a repo"); const rows = db.prepare("SELECT * FROM decisions WHERE answer IS NULL ORDER BY asked_at, id").all() as DecisionRow[]; - const pilot = !!db.prepare("SELECT 1 FROM settings WHERE key = 'pilot_items' AND json_valid(value) AND json_array_length(value) > 0").get(); const members = db.prepare("SELECT repo, number FROM dupe_group_items WHERE decision_id = ?"); return rows.filter((d) => { const refs = [...itemsOf(d), ...(members.all(d.id) as Ref[])]; if (scope.repo && !reposOf(d).includes(scope.repo) && !refs.some((x) => x.repo === scope.repo)) return false; - return !scope.outsidePilot || (pilot && !refs.some((x) => inPilot(db, x.repo, x.number))); + // Outside the scope: no item in a repo whose pipeline is on and, with an item pilot, in that pilot. + return !scope.outsidePilot || !refs.some((x) => inPilot(db, x.repo, x.number)); }); } diff --git a/test/backlog.test.ts b/test/backlog.test.ts index d8975163..90a540ee 100644 --- a/test/backlog.test.ts +++ b/test/backlog.test.ts @@ -151,7 +151,7 @@ describe("Backlog", () => { const db = fresh(); ask(db, [question("a1", "scope", "app", 1), question("a2", "scope", "app", 2), question("o1", "scope", "other", 1), question("o2", "merge", "other", 2), question("done", "scope", "other", 1)]); db.prepare("UPDATE decisions SET answer = 'yes', answered_by = 'op', answered_at = ? WHERE id = 'done'").run(T1); - // No pilot set: nothing is outside it. + // Every repo is on and no pilot is set: nothing is outside the scope. assert.deepEqual(backlogOpen(db, { outsidePilot: true }, "cli", true).decisions, []); setPilot(db, "op", ["app#1", "app#2"]); const dry = backlogOpen(db, { outsidePilot: true }, "cli", false);