Public: anyone can read this; the crew can change it.
An issue held behind the Later gate can be snoozed until a date #13138
Check · Review · Land · Live done — Landed and live in production.
mason/forge:mason/13113-an-issue-held-behind-the-later-gate-can → main 9 commits fork 5 threads · 5 unresolved
docs/MCP.md +1 −1
| @@ -145,7 +145,7 @@ bytes in `tools/list`. After changing a tool run `bun scripts/mcp-table.ts`; | ||
| 145 | 145 | | `knobs` | — | The crew's five knobs and what each does now | 307 | |
| 146 | 146 | | `labels` | `set`, `add`, `remove` | Set an issue's or pull's labels to exactly these (none clears) | 365 | |
| 147 | 147 | | `land_past_gate` | — | Land one pull past a broken gate, with a recorded reason; an owner's only | 321 | |
| 148 | | `lift` | — | Lift an issue out from behind the Later gate | 214 | | |
| 148 | | `lift` | — | Lift an issue out from behind the Later gate | 240 | | |
| 149 | 149 | | `limb` | `defer`, `resume`, `close`, `raise`, `lower`, `replan`, `takeback`, `undo` | Act on a limb by `action` | 532 | |
| 150 | 150 | | `limits` | — | Every limit the owner can hit | 1101 | |
| 151 | 151 | | `maintenance` | `status`, `prepare`, `resume`, `pause-duty`, `resume-duty` | Prepare the forge for a power-off, check the drain, or end maintenance (admin) | 308 | |
docs/features/later-gate.md +1 −1
| @@ -9,7 +9,7 @@ The Later gate (`Later gate: …`, read by `core/pillars.ts`) holds work back fr | ||
| 9 | 9 | - **Closed ones stay findable.** The apply writes the `issue.gate_reviewed` event after each close, and a comment note beside it. The event, not the note, is the marker (`closedByReview`): it is the review's only while it is newer than the issue's last close and reopen, and a comment cannot forge it. Each is listed under "Closed by the review" on the held page and shows **Revive** at its top. Revive (the same `lift` action) lets it out from behind the gate and reopens it as one outcome: the hold is checked first, and a reopen that fails puts the hold back. |
| 10 | 10 | - **The terminal** has the same page: `h` on a repository's issues, or "Held by the Later gate" in the palette (`tui/screens/held.ts`). `space` ticks (a keep row shows `[-]` and has no tick), `A` applies the ticked (close or merge), `l` lifts or revives. It reads and acts through the same functions, so a reader is refused in the same words and a private repository is not found; the web hears each write as the close, reopen and unblock events it already follows. |
| 11 | 11 | |
| 12 | Not done: snoozing an issue until a date or until new activity. | |
| 12 | - **Lift until a date** (#13113): the held page (a date field beside Lift), the terminal (`u`) and the MCP `lift` (`until`, `YYYY-MM-DD`) lift the issue and have the gate take it back at the start of that day, UTC (`actions/gate_snooze.ts`, run each minute by `engine/duties.ts`). The day must be after today; anything else is refused with one sentence and nothing moves. `issue.snoozed` and `issue.snooze_ended` are recorded. A plain lift clears the snooze. Not done: snoozing until new activity. | |
| 13 | 13 | |
| 14 | 14 | ## The pass proposes keep and merge too (#8813) |
| 15 | 15 |
src/actions/gate.ts +23 −3
| @@ -15,6 +15,7 @@ import { servePillar } from "../core/pillar_pick.ts"; | ||
| 15 | 15 | import type { Repo } from "../core/repos.ts"; |
| 16 | 16 | import type { User } from "../core/users.ts"; |
| 17 | 17 | import { err, ok, type Result } from "../kernel/result.ts"; |
| 18 | import { clearSnooze, parseUntil, setSnooze } from "../core/gate_snooze.ts"; | |
| 18 | 19 | import { isMirror } from "../origins/write-through.ts"; |
| 19 | 20 | import type { DependencyError } from "../core/dependencies.ts"; |
| 20 | 21 | import type { AccessError } from "./access.ts"; |
| @@ -50,20 +51,39 @@ export function stopWaiting( | ||
| 50 | 51 | * part of it: an idea that matters comes back with one tap. The hold is |
| 51 | 52 | * checked first, and a reopen that fails puts the hold back, so the answer |
| 52 | 53 | * is the whole outcome. One action, the same for a person and an agent; |
| 53 | * whoever may link may lift. | |
| 54 | * whoever may link may lift. With `until` (a day, `YYYY-MM-DD`) the lift is | |
| 55 | * a snooze: the gate takes the issue back on that day (`actions/gate_snooze.ts`), | |
| 56 | * and the day is checked before anything moves; a revive has no day, and one given is refused. | |
| 54 | 57 | */ |
| 55 | 58 | export function liftHold( |
| 56 | 59 | app: App, |
| 57 | 60 | actor: User | undefined, |
| 58 | 61 | repo: Repo, |
| 59 | 62 | issue: Issue, |
| 60 | ): Result<Issue, AccessError | "not_held"> { | |
| 63 | until?: string, | |
| 64 | now: Date = new Date(), | |
| 65 | ): Result<Issue, AccessError | "not_held" | "bad_date" | "revive_until"> { | |
| 66 | const day = until === undefined || until === "" ? undefined : parseUntil(until, now); | |
| 67 | if (day !== undefined && !day.ok) return day; | |
| 61 | 68 | const revive = closedByReview(app.db, issue); |
| 62 | 69 | const gate = revive ? gateOf(app.db, repo, issue) : gateHolding(app.db, repo, issue); |
| 63 | 70 | if (gate === undefined) return err("not_held"); |
| 71 | if (revive && day !== undefined) return err("revive_until"); | |
| 64 | 72 | const lifted = stopWaiting(app, actor, repo, issue, gate); |
| 65 | 73 | if (!lifted.ok) return lifted; |
| 66 | if (!revive) return ok(issue); | |
| 74 | if (!revive) { | |
| 75 | if (day !== undefined && actor !== undefined) { | |
| 76 | setSnooze(app.db, issue.id, day.value, actor.id, now); | |
| 77 | app.bus.append({ | |
| 78 | kind: "issue.snoozed", | |
| 79 | repoId: repo.id, | |
| 80 | actorId: actor.id, | |
| 81 | payload: { number: issue.number, until: day.value }, | |
| 82 | }); | |
| 83 | } else clearSnooze(app.db, issue.id); | |
| 84 | return ok(issue); | |
| 85 | } | |
| 86 | clearSnooze(app.db, issue.id); | |
| 67 | 87 | const reopened = setIssueState(app, actor, repo, issue, "open"); |
| 68 | 88 | if (!reopened.ok) { |
| 69 | 89 | linkIssue(app, actor, repo, issue, gate); |
src/actions/gate_snooze.ts added +42
| @@ -0,0 +1,42 @@ | ||
| 1 | /** | |
| 2 | * The day a snoozed issue comes back (#13113): the gate takes it again, as | |
| 3 | * the person who snoozed it, and the forge records it. Run from the engine's | |
| 4 | * duties on a timer (`engine/duties.ts`); a missed tick only delays it. | |
| 5 | */ | |
| 6 | import type { App } from "../app.ts"; | |
| 7 | import { dueSnoozes, clearSnooze } from "../core/gate_snooze.ts"; | |
| 8 | import { gateHolding } from "../core/gate_hold.ts"; | |
| 9 | import { getIssueById } from "../core/issues.ts"; | |
| 10 | import { pillarsOf } from "../core/pillars.ts"; | |
| 11 | import { getRepoById } from "../core/repos.ts"; | |
| 12 | import { getUserById } from "../core/users.ts"; | |
| 13 | import { linkIssue } from "./dependencies.ts"; | |
| 14 | ||
| 15 | /** Put every issue whose day has come behind the gate again; the number returned. */ | |
| 16 | export function returnSnoozed(app: App, now: Date = new Date()): number { | |
| 17 | let returned = 0; | |
| 18 | for (const due of dueSnoozes(app.db, now)) { | |
| 19 | const issue = getIssueById(app.db, due.issueId); | |
| 20 | const repo = issue === undefined ? undefined : getRepoById(app.db, issue.repoId); | |
| 21 | const actor = getUserById(app.db, due.setBy); | |
| 22 | const gate = repo === undefined ? undefined : pillarsOf(app.db, repo).gate; | |
| 23 | if (issue === undefined || repo === undefined || gate === undefined || issue.state !== "open" || gateHolding(app.db, repo, issue) !== undefined) { | |
outdated
The snooze row is cleared before the relink is known to work; a failed |
||
| 24 | clearSnooze(app.db, due.issueId); | |
| 25 | continue; | |
| 26 | } | |
| 27 | const back = linkIssue(app, actor, repo, issue, gate); | |
| 28 | if (!back.ok) { | |
| 29 | app.log.warn("snooze return failed", { issue: issue.number, error: String(back.error) }); | |
| 30 | continue; // the snooze stays, so the next tick tries again | |
| 31 | } | |
| 32 | clearSnooze(app.db, due.issueId); | |
| 33 | app.bus.append({ | |
| 34 | kind: "issue.snooze_ended", | |
| 35 | repoId: repo.id, | |
| 36 | actorId: actor?.id, | |
| 37 | payload: { number: issue.number }, | |
| 38 | }); | |
| 39 | returned++; | |
| 40 | } | |
| 41 | return returned; | |
| 42 | } |
src/core/event_audience.ts +22 −9
| @@ -45,7 +45,10 @@ function answersForDeleted(db: Database, viewer: User | undefined, event: ForgeE | ||
| 45 | 45 | return typeof owner === "string" && (owner === viewer.id || personOwners(db, owner).includes(viewer.id)); |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | /** A `repo.deleted` names its repository; unless it was public (said so outright), the name is not for readers. */ | |
| 48 | /** | |
| 49 | * A `repo.deleted` names its repository; unless it was public (said so outright), the name is not | |
| 50 | * for readers. | |
| 51 | */ | |
| 49 | 52 | const namesHiddenRepo = (event: ForgeEvent): boolean => |
| 50 | 53 | event.kind === "repo.deleted" && |
| 51 | 54 | event.payload.repo !== undefined && |
| @@ -62,6 +65,8 @@ const READER_KINDS: ReadonlySet<string> = new Set([ | ||
| 62 | 65 | "week.retro", |
| 63 | 66 | "issue.closed", |
| 64 | 67 | "issue.gate_reviewed", |
| 68 | "issue.snoozed", | |
| 69 | "issue.snooze_ended", | |
| 65 | 70 | "issue.commented", |
| 66 | 71 | "usage.delta", |
| 67 | 72 | "issue.raised", |
| @@ -237,9 +242,11 @@ export function classifiedAudience(kind: string): EventAudience | undefined { | ||
| 237 | 242 | kind.startsWith("maintenance.") || |
| 238 | 243 | // The weekly model review's changes and results are the owner's (`actions/model_review.ts`). |
| 239 | 244 | kind.startsWith("crew.model_") || |
| 240 | // A child forge answering no one at its public address is the owner's to hear (`spawn/reach.ts`). | |
| 245 | // A child forge answering no one at its public address is the owner's to hear | |
| 246 | // (`spawn/reach.ts`). | |
| 241 | 247 | kind.startsWith("forge.child_") || |
| 242 | // What a hosted forge asked to reach, was refused and was allowed is the owner's to answer (`spawn/child_reach.ts`). | |
| 248 | // What a hosted forge asked to reach, was refused and was allowed is the owner's to answer | |
| 249 | // (`spawn/child_reach.ts`). | |
| 243 | 250 | kind.startsWith("forge.reach_") || |
| 244 | 251 | // A failed production probe names the forge's own defect: the admins' (`maintain/proven.ts`). |
| 245 | 252 | kind === "probe_defect" || |
| @@ -247,11 +254,13 @@ export function classifiedAudience(kind: string): EventAudience | undefined { | ||
| 247 | 254 | kind.startsWith("clog.") || |
| 248 | 255 | // What the throughput keeper did to lift a brake is the owner's too (`flow/keeper.ts`). |
| 249 | 256 | kind.startsWith("keeper.") || |
| 250 | // The flow keeper's acts on pulls, lulls and forge-down are the owner's too (`maintain/keeper/`, #7556). | |
| 257 | // The flow keeper's acts on pulls, lulls and forge-down are the owner's too | |
| 258 | // (`maintain/keeper/`, #7556). | |
| 251 | 259 | kind.startsWith("keeper_") || |
| 252 | 260 | kind === "forge_down" || |
| 253 | 261 | kind === "forge_up" || |
| 254 | // Who is trusted to fold in, and the switch that stops it, are the owner's (`actions/trusted_sources.ts`). | |
| 262 | // Who is trusted to fold in, and the switch that stops it, are the owner's | |
| 263 | // (`actions/trusted_sources.ts`). | |
| 255 | 264 | kind.startsWith("trust.") || |
| 256 | 265 | kind.startsWith("foldin.") || |
| 257 | 266 | // A way-back link minted for an account the platform edge signed in (#11802). |
| @@ -291,18 +300,21 @@ export function classifiedAudience(kind: string): EventAudience | undefined { | ||
| 291 | 300 | kind === "repo.crew_outsiders" || |
| 292 | 301 | // An outside agent's token and the owner's yes to them are the admins' (#12012). |
| 293 | 302 | kind.startsWith("contribute.") || |
| 294 | // A valve turn names a repository and the owner's budget: for those who administer it (`actions/valves.ts`). | |
| 303 | // A valve turn names a repository and the owner's budget: for those who administer it | |
| 304 | // (`actions/valves.ts`). | |
| 295 | 305 | kind === "valve.turned" || |
| 296 | 306 | // A clog starting names the forge's own pile-up: the owner's to hear (#6524). |
| 297 | 307 | kind.startsWith("clog.") || |
| 298 | // The release keeper's steps name images and probe numbers: the forge owner's (`keeper/keeper.ts`, #7557). | |
| 308 | // The release keeper's steps name images and probe numbers: the forge owner's | |
| 309 | // (`keeper/keeper.ts`, #7557). | |
| 299 | 310 | kind.startsWith("release.") || |
| 300 | 311 | // A file held against new work is its admins' book-keeping (#6522). |
| 301 | 312 | kind === "repo.file_held" || |
| 302 | 313 | kind === "repo.file_released" || |
| 303 | 314 | // Which repositories New app offers is the admins' choice (`actions/app_templates.ts`). |
| 304 | 315 | kind.startsWith("app_template.") || |
| 305 | // What a parent lends a child's crew, by name and dollar, is the admins' business (`actions/child_credit.ts`, #10484). | |
| 316 | // What a parent lends a child's crew, by name and dollar, is the admins' business | |
| 317 | // (`actions/child_credit.ts`, #10484). | |
| 306 | 318 | kind === "forge.credit_set" || |
| 307 | 319 | // Which child forge was moved out of this forge's process, left there or put back, and why: |
| 308 | 320 | // what its |
| @@ -331,7 +343,8 @@ export function classifiedAudience(kind: string): EventAudience | undefined { | ||
| 331 | 343 | // A person's pinned panels changed (`actions/board-pins.ts`): theirs alone. |
| 332 | 344 | kind === "board.pins" || |
| 333 | 345 | kind.startsWith("fleet.") || |
| 334 | // A person's own ask to the forge that hosts this one, and how it was answered (`actions/ask_host.ts`). | |
| 346 | // A person's own ask to the forge that hosts this one, and how it was answered | |
| 347 | // (`actions/ask_host.ts`). | |
| 335 | 348 | kind.startsWith("reach.") || |
| 336 | 349 | kind.startsWith("thought.") |
| 337 | 350 | ) |
src/core/gate_snooze.ts added +58
| @@ -0,0 +1,58 @@ | ||
| 1 | /** | |
| 2 | * Snoozing an issue behind the Later gate until a date (#13113): the day is | |
| 3 | * a calendar day (UTC) as `YYYY-MM-DD`, and the issue is due at that day's | |
| 4 | * first instant. Rows only; `actions/gate.ts` lifts and `actions/gate_snooze.ts` | |
| 5 | * returns what is due. | |
| 6 | */ | |
| 7 | import type { Database } from "bun:sqlite"; | |
| 8 | import { err, ok, type Result } from "../kernel/result.ts"; | |
| 9 | ||
| 10 | /** The one sentence a refused date gets, the same on every surface. */ | |
| 11 | export const BAD_DATE = "Pick a day after today, written YYYY-MM-DD."; | |
| 12 | ||
| 13 | /** | |
| 14 | * The sentence for a date given with a revive: a closed idea comes back open, not held until a day. | |
| 15 | */ | |
| 16 | export const REVIVE_UNTIL = "A closed idea is revived now; a day can only be set when lifting what is held."; | |
| 17 | ||
| 18 | const DAY = /^(\d{4})-(\d{2})-(\d{2})$/; | |
| 19 | ||
| 20 | /** | |
| 21 | * The instant a day begins, or undefined when the text is no real calendar day, | |
| 22 | * or is not after `now`. | |
| 23 | */ | |
| 24 | export function parseUntil(text: string, now: Date): Result<string, "bad_date"> { | |
| 25 | const m = DAY.exec(text.trim()); | |
| 26 | if (m === null) return err("bad_date"); | |
| 27 | const at = new Date(Date.UTC(Number(m[1]), Number(m[2]) - 1, Number(m[3]))); | |
| 28 | if (at.toISOString().slice(0, 10) !== text.trim()) return err("bad_date"); | |
| 29 | if (at.getTime() <= now.getTime()) return err("bad_date"); | |
| 30 | return ok(at.toISOString()); | |
| 31 | } | |
| 32 | ||
| 33 | export interface Snooze { | |
| 34 | readonly issueId: string; | |
| 35 | readonly until: string; | |
| 36 | readonly setBy: string; | |
| 37 | } | |
| 38 | ||
| 39 | export function setSnooze(db: Database, issueId: string, until: string, setBy: string, now: Date): void { | |
| 40 | db.query( | |
| 41 | `INSERT INTO gate_snooze (issue_id, until, set_by, created_at) VALUES (?1, ?2, ?3, ?4) | |
| 42 | ON CONFLICT(issue_id) DO UPDATE SET until = ?2, set_by = ?3, created_at = ?4`, | |
| 43 | ).run(issueId, until, setBy, now.toISOString()); | |
| 44 | } | |
| 45 | ||
| 46 | export function clearSnooze(db: Database, issueId: string): void { | |
| 47 | db.query(`DELETE FROM gate_snooze WHERE issue_id = ?1`).run(issueId); | |
| 48 | } | |
| 49 | ||
| 50 | /** The snoozes whose day has come, oldest first. */ | |
| 51 | export function dueSnoozes(db: Database, now: Date, limit = 200): Snooze[] { | |
| 52 | return db | |
| 53 | .query<{ issue_id: string; until: string; set_by: string }, [string, number]>( | |
| 54 | `SELECT issue_id, until, set_by FROM gate_snooze WHERE until <= ?1 ORDER BY until LIMIT ?2`, | |
| 55 | ) | |
| 56 | .all(now.toISOString(), limit) | |
| 57 | .map((r) => ({ issueId: r.issue_id, until: r.until, setBy: r.set_by })); | |
| 58 | } |
src/core/migration-pins/20261115120000-gate-snooze.pin added +1
| @@ -0,0 +1,1 @@ | ||
| 1 | 356ee20afc29c4e59b49cd967136d9b6c2885533de23937d196be1008784c9c5 |
src/core/migrations/20261115120000-gate-snooze.ts added +12
| @@ -0,0 +1,12 @@ | ||
| 1 | // An issue lifted from the Later gate until a date (#13113): one row per issue, the day the gate | |
| 2 | // takes it back and who asked. The row goes when the day comes or the issue is held again. | |
| 3 | // Additive. | |
| 4 | export default ` | |
| 5 | CREATE TABLE IF NOT EXISTS gate_snooze ( | |
| 6 | issue_id TEXT PRIMARY KEY REFERENCES issue(id) ON DELETE CASCADE, | |
| 7 | until TEXT NOT NULL, | |
| 8 | set_by TEXT NOT NULL, | |
| 9 | created_at TEXT NOT NULL | |
| 10 | ); | |
| 11 | CREATE INDEX IF NOT EXISTS gate_snooze_due ON gate_snooze(until); | |
| 12 | `; |
src/engine/duties.ts +11 −4
| @@ -17,6 +17,7 @@ import type { App } from "../app.ts"; | ||
| 17 | 17 | import { runModelReview } from "../actions/model_review.ts"; |
| 18 | 18 | import { expireCrewHolds } from "../actions/holds.ts"; |
| 19 | 19 | import { settleDue } from "../actions/estimates_settle.ts"; |
| 20 | import { returnSnoozed } from "../actions/gate_snooze.ts"; | |
| 20 | 21 | import { sweepStarts } from "../actions/start_sweep.ts"; |
| 21 | 22 | import { runDelivery } from "../core/webhooks.ts"; |
| 22 | 23 | import { pruneSessions } from "../core/sessions.ts"; |
| @@ -57,6 +58,9 @@ export function startDuties(app: App, options: { onWorker: boolean }): () => voi | ||
| 57 | 58 | during("delivery", delivery, undefined, app); |
| 58 | 59 | // Estimates of "done" come due as time passes (#11955). |
| 59 | 60 | timers.push(setInterval(() => during("estimates-due", () => void settleDue(app.db), undefined, app), 300_000)); |
| 61 | // An issue snoozed behind the Later gate comes back on its day (#13113). | |
| 62 | timers.push(setInterval(() => during("gate-snooze", () => void returnSnoozed(app), undefined, app), 60_000)); | |
| 63 | during("gate-snooze", () => void returnSnoozed(app), undefined, app); | |
| 60 | 64 | // Accounts an agent started and nobody claimed sleep after a week and are |
| 61 | 65 | // archived after a month (`actions/start_sweep.ts`, #10912): hourly, and on boot. |
| 62 | 66 | timers.push(setInterval(() => during("starts", () => void sweepStarts(app), undefined, app), HOUR_MS)); |
| @@ -79,7 +83,8 @@ export function startDuties(app: App, options: { onWorker: boolean }): () => voi | ||
| 79 | 83 | 60_000, |
| 80 | 84 | ), |
| 81 | 85 | ); |
| 82 | // The weekly model review (#7815): settles last week's changes, then proposes this week's; it runs once a week whatever the tick. | |
| 86 | // The weekly model review (#7815): settles last week's changes, then proposes this week's; it | |
| 87 | // runs once a week whatever the tick. | |
| 83 | 88 | timers.push( |
| 84 | 89 | setInterval( |
| 85 | 90 | () => |
| @@ -93,7 +98,8 @@ export function startDuties(app: App, options: { onWorker: boolean }): () => voi | ||
| 93 | 98 | HOUR_MS, |
| 94 | 99 | ), |
| 95 | 100 | ); |
| 96 | // The week is the sprint (#8704): at each weekly reset the forge writes its retrospective, unasked. | |
| 101 | // The week is the sprint (#8704): at each weekly reset the forge writes its retrospective, | |
| 102 | // unasked. | |
| 97 | 103 | timers.push( |
| 98 | 104 | setInterval( |
| 99 | 105 | () => |
| @@ -114,8 +120,9 @@ export function startDuties(app: App, options: { onWorker: boolean }): () => voi | ||
| 114 | 120 | if (options.onWorker) { |
| 115 | 121 | // What reads what the serving thread observes (`engine/observed.ts`) adopts its rows first. |
| 116 | 122 | stops.push(startReaders(app, () => void adoptObserved(app.db))); |
| 117 | // The one checkpointer: the serving thread's commits never pay for it (`main.ts`). A passive one | |
| 118 | // takes what no reader still needs and waits for none; a log nobody reads is reset by the next write. | |
| 123 | // The one checkpointer: the serving thread's commits never pay for it (`main.ts`). A passive | |
| 124 | // one takes what no reader still needs and waits for none; a log nobody reads is reset by the | |
| 125 | // next write. | |
| 119 | 126 | timers.push(setInterval(() => during("checkpoint", () => app.db.exec("PRAGMA wal_checkpoint(PASSIVE)"), undefined, app), 2_000)); |
| 120 | 127 | } |
| 121 | 128 | return () => { |
src/http/mcp/tools/lift.ts +14 −5
| @@ -1,14 +1,15 @@ | ||
| 1 | 1 | import { liftHold } from "../../../actions/gate.ts"; |
| 2 | import { BAD_DATE, REVIVE_UNTIL } from "../../../core/gate_snooze.ts"; | |
| 2 | 3 | import { THREAD_SAYS } from "../../../actions/thread_words.ts"; |
| 3 | 4 | import { good, bad, type Tool, APP_ARG, planRepo, issueArg, isAnswer } from "../shared.ts"; |
| 4 | 5 | |
| 5 | 6 | export const tool: Tool = { |
| 6 | 7 | name: "lift", |
| 7 | doc: "`{ app, issue }`: let an issue out from behind the Later gate, as the page's Lift does; its `Later` label goes with it, and the answer carries the issue's URL", | |
| 8 | doc: "`{ app, issue, until? }`: let an issue out from behind the Later gate, as the page's Lift does; `until` (YYYY-MM-DD) takes it back that day; its answer carries the URL", | |
| 8 | 9 | description: "Lift an issue out from behind the Later gate.", |
| 9 | 10 | inputSchema: { |
| 10 | 11 | type: "object", |
| 11 | properties: { app: APP_ARG, issue: { type: "integer", minimum: 1 } }, | |
| 12 | properties: { app: APP_ARG, issue: { type: "integer", minimum: 1 }, until: { type: "string", maxLength: 10 } }, | |
| 12 | 13 | required: ["app", "issue"], |
| 13 | 14 | }, |
| 14 | 15 | writes: true, |
| @@ -17,14 +18,22 @@ export const tool: Tool = { | ||
| 17 | 18 | if (isAnswer(repo)) return repo; |
| 18 | 19 | const issue = issueArg(ctx, repo, args, "issue"); |
| 19 | 20 | if ("ok" in issue) return issue; |
A non-string |
||
| 20 | const lifted = liftHold(ctx.app, user, repo, issue); | |
| 21 | if (args["until"] !== undefined && typeof args["until"] !== "string") return bad("bad_date", BAD_DATE); | |
| 22 | const until = args["until"]; | |
| 23 | const lifted = liftHold(ctx.app, user, repo, issue, until); | |
| 21 | 24 | if (!lifted.ok) |
| 22 | 25 | return bad( |
| 23 | 26 | lifted.error, |
| 24 | lifted.error === "not_held" ? `#${issue.number} is not behind the Later gate.` : THREAD_SAYS.planForbidden, | |
| 27 | lifted.error === "not_held" | |
| 28 | ? `#${issue.number} is not behind the Later gate.` | |
| 29 | : lifted.error === "bad_date" | |
| 30 | ? BAD_DATE | |
| 31 | : lifted.error === "revive_until" | |
| 32 | ? REVIVE_UNTIL | |
| 33 | : THREAD_SAYS.planForbidden, | |
| 25 | 34 | ); |
| 26 | 35 | return good({ |
| 27 | says: `#${issue.number} is lifted from behind the Later gate.`, | |
| 36 | says: until ? `#${issue.number} is lifted until ${until}, when the Later gate takes it back.` : `#${issue.number} is lifted from behind the Later gate.`, | |
| 28 | 37 | url: `${ctx.url.origin}/${repo.ownerName}/${repo.name}/issues/${issue.number}`, |
| 29 | 38 | }); |
| 30 | 39 | }, |
src/tui/screens/held.ts +30 −6
| @@ -11,6 +11,7 @@ | ||
| 11 | 11 | * l lift (or revive, on a closed) enter open the issue |
| 12 | 12 | */ |
| 13 | 13 | |
| 14 | import { BAD_DATE, REVIVE_UNTIL } from "../../core/gate_snooze.ts"; | |
| 14 | 15 | import { liftHold } from "../../actions/gate.ts"; |
| 15 | 16 | import { applyGateReview, reviewGate, type GateReview } from "../../actions/gate_review.ts"; |
| 16 | 17 | import { THREAD_SAYS } from "../../actions/thread_words.ts"; |
| @@ -22,7 +23,7 @@ import type { Repo } from "../../core/repos.ts"; | ||
| 22 | 23 | import type { Ctx, Screen } from "../app/app.ts"; |
| 23 | 24 | import { binding } from "../app/keys.ts"; |
| 24 | 25 | import type { Session } from "../session.ts"; |
| 25 | import { ListState, drawList, hitList, live, metaOf, runAsync, type ListRow } from "./common.ts"; | |
| 26 | import { ListState, drawList, hitList, live, metaOf, promptScreen, runAsync, type ListRow } from "./common.ts"; | |
| 26 | 27 | import { issueScreen } from "./issue.ts"; |
| 27 | 28 | import { local } from "./where.ts"; |
| 28 | 29 | import { emptyState } from "../ui/widgets.ts"; |
| @@ -88,15 +89,35 @@ export function heldScreen(f: Session, ctx: Ctx, repo: Repo): Screen { | ||
| 88 | 89 | state.clamp(lines().length); |
| 89 | 90 | ctx.invalidate(); |
| 90 | 91 | }; |
| 91 | const lift = (index: number): void => { | |
| 92 | const lift = (index: number, until?: string): string | undefined => { | |
| 92 | 93 | const line = lines()[index]; |
| 93 | 94 | if (line === undefined) return; |
| 94 | 95 | const issue = getIssue(f.db, repo.id, line.number); |
| 95 | 96 | if (issue === undefined) return; |
| 96 | const done = liftHold(f.app, f.user, repo, issue); | |
| 97 | if (done.ok) ctx.toast(`#${line.number} is lifted from behind the Later gate.`, "success"); | |
| 97 | const done = liftHold(f.app, f.user, repo, issue, until); | |
| 98 | if (done.ok) { | |
| 99 | ctx.toast( | |
| 100 | until === undefined | |
| 101 | ? `#${line.number} is lifted from behind the Later gate.` | |
| 102 | : `#${line.number} is lifted until ${until}, when the Later gate takes it back.`, | |
| 103 | "success", | |
| 104 | ); | |
| 105 | } else if (done.error === "bad_date") return BAD_DATE; | |
| 106 | else if (done.error === "revive_until") return REVIVE_UNTIL; | |
| 98 | 107 | else ctx.toast(done.error === "not_held" ? `#${line.number} is not behind the Later gate.` : THREAD_SAYS.planForbidden, "danger"); |
| 99 | 108 | reload(); |
| 109 | return undefined; | |
| 110 | }; | |
| 111 | const snooze = (index: number): void => { | |
| 112 | if (lines()[index] === undefined) return; | |
| 113 | if (lines()[index]!.closed) return void ctx.toast(REVIVE_UNTIL, "danger"); | |
| 114 | ctx.push( | |
| 115 | promptScreen(ctx, screen, { | |
| 116 | title: "Lift until a date", | |
| 117 | label: "Day (YYYY-MM-DD)", | |
| 118 | onSubmit: (raw) => lift(index, raw.trim()), | |
| 119 | }), | |
| 120 | ); | |
| 100 | 121 | }; |
| 101 | 122 | const apply = (): void => { |
| 102 | 123 | if (read === undefined) return; |
| @@ -129,13 +150,14 @@ export function heldScreen(f: Session, ctx: Ctx, repo: Repo): Screen { | ||
| 129 | 150 | if (!ticked.delete(line.number)) ticked.add(line.number); |
| 130 | 151 | ctx.invalidate(); |
| 131 | 152 | }; |
| 132 | return { | |
| 153 | const screen: Screen = { | |
| 133 | 154 | title: `Held · ${repo.ownerName}/${repo.name}`, |
| 134 | 155 | keys: [ |
| 135 | 156 | binding(["j", "k"], "move"), |
| 136 | 157 | binding(["space"], "tick"), |
| 137 | 158 | binding(["A"], "apply the ticked"), |
| 138 | 159 | binding(["l"], "lift / revive"), |
| 160 | binding(["u"], "lift until a date"), | |
| 139 | 161 | binding(["enter"], "open"), |
| 140 | 162 | binding(["esc", "q"], "close"), |
| 141 | 163 | ], |
| @@ -156,10 +178,12 @@ export function heldScreen(f: Session, ctx: Ctx, repo: Repo): Screen { | ||
| 156 | 178 | if (e.key === "esc" || e.key === "q") ctx.pop(); |
| 157 | 179 | else if (e.key === " " || e.key === "space") toggle(state.index); |
| 158 | 180 | else if (e.key === "A") apply(); |
| 159 | else if (e.key === "l") lift(state.index); | |
| 181 | else if (e.key === "l") void lift(state.index); | |
| 182 | else if (e.key === "u") snooze(state.index); | |
| 160 | 183 | else if (e.key === "enter") openAt(state.index); |
| 161 | 184 | else state.key(e, lines().length); |
| 162 | 185 | return true; |
| 163 | 186 | }, |
| 164 | 187 | }; |
| 188 | return screen; | |
| 165 | 189 | } |
src/web/pages/gate.ts +29 −6
| @@ -6,6 +6,7 @@ | ||
| 6 | 6 | |
| 7 | 7 | import { applyGateReview, reviewGate } from "../../actions/gate_review.ts"; |
| 8 | 8 | import { liftHold } from "../../actions/gate.ts"; |
| 9 | import { BAD_DATE, REVIVE_UNTIL } from "../../core/gate_snooze.ts"; | |
| 9 | 10 | import { startsTicked, tallyLine, type Theme, type Triaged } from "../../core/gate_triage.ts"; |
| 10 | 11 | import { pillarsOf } from "../../core/pillars.ts"; |
| 11 | 12 | import { THREAD_SAYS } from "../../actions/thread_words.ts"; |
| @@ -22,6 +23,17 @@ import { flashTo, page } from "../layout.ts"; | ||
| 22 | 23 | import { btn, disclosure, time } from "../ui.ts"; |
| 23 | 24 | import { threadContext } from "./thread.ts"; |
| 24 | 25 | |
| 26 | /** Tomorrow's UTC day, the earliest a snooze may end: the browser's help, the server checks. */ | |
| 27 | const tomorrow = (now: Date = new Date()): string => new Date(now.getTime() + 86_400_000).toISOString().slice(0, 10); | |
| 28 | ||
| 29 | /** Lift until a day: the date field and its button, beside Lift. */ | |
| 30 | function snoozeForm(base: string, number: number): Html { | |
| 31 | return html`<form method="post" action="${base}/issues/${number}/lift" class="inline"> | |
| 32 | <input type="date" name="until" min="${tomorrow()}" required aria-label="Lift #${number} until" /> | |
| 33 | ${btn("Lift until", { type: "submit", size: "sm", variant: "ghost" })} | |
| 34 | </form>`; | |
| 35 | } | |
| 36 | ||
| 25 | 37 | /** What the banner says about the hold, and the one button that ends it. */ |
| 26 | 38 | export function heldBanner(ctx: Ctx, repo: Repo, issue: Issue): Html | null { |
| 27 | 39 | const user = ctx.auth.user; |
| @@ -50,7 +62,7 @@ export function heldBanner(ctx: Ctx, repo: Repo, issue: Issue): Html | null { | ||
| 50 | 62 | ${mayLift |
| 51 | 63 | ? html`<form method="post" action="${base}/issues/${issue.number}/lift" class="inline"> |
| 52 | 64 | ${btn("Lift", { type: "submit", variant: "primary", size: "sm" })} |
| 53 | </form>` | |
| 65 | </form>${snoozeForm(base, issue.number)}` | |
| 54 | 66 | : null} |
| 55 | 67 | </div>`; |
| 56 | 68 | } |
| @@ -64,23 +76,34 @@ export async function liftHoldSubmit(ctx: Ctx): Promise<Response> { | ||
| 64 | 76 | if (form instanceof Response) return form; |
outdated
The flash says 'lifted until' even when the issue was a revive and nothing was snoozed. Also no test drives this handler. |
||
| 65 | 77 | const repo = loadRepo(ctx) ?? found.repo; |
| 66 | 78 | const dest = `${repoBase(repo)}/issues/${found.issue.number}`; |
| 67 | const lifted = liftHold(ctx.app, ctx.auth.user, repo, found.issue); | |
| 79 | const until = form.get("until")?.toString().trim().slice(0, 32) ?? ""; | |
| 80 | const lifted = liftHold(ctx.app, ctx.auth.user, repo, found.issue, until); | |
| 68 | 81 | if (!lifted.ok) |
| 69 | 82 | return flashTo(ctx, dest, { |
| 70 | 83 | tone: "danger", |
| 71 | 84 | message: |
| 72 | 85 | lifted.error === "not_held" |
| 73 | 86 | ? `#${found.issue.number} is not behind the Later gate.` |
| 74 | : THREAD_SAYS.planForbidden, | |
| 87 | : lifted.error === "bad_date" | |
| 88 | ? BAD_DATE | |
| 89 | : lifted.error === "revive_until" | |
| 90 | ? REVIVE_UNTIL | |
| 91 | : THREAD_SAYS.planForbidden, | |
| 75 | 92 | }); |
| 76 | 93 | return flashTo(ctx, dest, { |
| 77 | message: `#${found.issue.number} is lifted from behind the Later gate.`, | |
| 94 | message: | |
| 95 | until === "" | |
| 96 | ? `#${found.issue.number} is lifted from behind the Later gate.` | |
| 97 | : `#${found.issue.number} is lifted until ${until}, when the Later gate takes it back.`, | |
| 78 | 98 | }); |
| 79 | 99 | } |
| 80 | 100 | |
| 81 | 101 | // ---- the list, and the one pass over it ---- |
| 82 | 102 | |
| 83 | /** One row of the review: ticked to close or merge, a keep with nothing to tick, and Lift to let it go instead. */ | |
| 103 | /** | |
| 104 | * One row of the review: ticked to close or merge, a keep with nothing to tick, and Lift to let it | |
| 105 | * go instead. | |
| 106 | */ | |
| 84 | 107 | function reviewRow(base: string, mayLift: boolean, item: Triaged): Html { |
| 85 | 108 | return html`<li class="bar"> |
| 86 | 109 | ${item.verdict.kind === "keep" |
| @@ -94,7 +117,7 @@ function reviewRow(base: string, mayLift: boolean, item: Triaged): Html { | ||
| 94 | 117 | ${mayLift |
| 95 | 118 | ? html`<form method="post" action="${base}/issues/${item.number}/lift" class="inline"> |
| 96 | 119 | ${btn("Lift", { type: "submit", size: "sm", variant: "ghost" })} |
| 97 | </form>` | |
| 120 | </form>${snoozeForm(base, item.number)}` | |
| 98 | 121 | : null} |
| 99 | 122 | </li>`; |
| 100 | 123 | } |
test/gate-snooze.test.ts added +132
| @@ -0,0 +1,132 @@ | ||
| 1 | /** | |
Only the action is tested. The web form, MCP |
||
| 2 | * Lifting until a date (#13113): refused when past or invalid, | |
| 3 | * back behind the gate on the day and not before. | |
| 4 | */ | |
| 5 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | |
| 6 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 7 | import { tmpdir } from "node:os"; | |
| 8 | import { join } from "node:path"; | |
| 9 | import { createApp, type App } from "../src/app.ts"; | |
| 10 | import { linkIssue } from "../src/actions/dependencies.ts"; | |
| 11 | import { applyGateReview, reviewGate } from "../src/actions/gate_review.ts"; | |
| 12 | import { liftHold } from "../src/actions/gate.ts"; | |
| 13 | import { returnSnoozed } from "../src/actions/gate_snooze.ts"; | |
| 14 | import { openIssue } from "../src/actions/issues.ts"; | |
| 15 | import { createRepo } from "../src/actions/repos.ts"; | |
| 16 | import { gateHolding } from "../src/core/gate_hold.ts"; | |
| 17 | import { parseUntil } from "../src/core/gate_snooze.ts"; | |
| 18 | import { getIssueById, type Issue } from "../src/core/issues.ts"; | |
| 19 | import { getRepoById, type Repo } from "../src/core/repos.ts"; | |
| 20 | import { createUser, type User } from "../src/core/users.ts"; | |
| 21 | ||
| 22 | let dataDir: string; | |
| 23 | let app: App; | |
| 24 | let alice: User; | |
| 25 | let repo: Repo; | |
| 26 | let gate: Issue; | |
| 27 | const fresh = () => getRepoById(app.db, repo.id)!; | |
| 28 | const current = (i: Issue) => getIssueById(app.db, i.id)!; | |
| 29 | const open = (title: string): Issue => { | |
| 30 | const made = openIssue(app, alice, fresh(), { title }); | |
| 31 | if (!made.ok) throw new Error(String(made.error)); | |
| 32 | return made.value; | |
| 33 | }; | |
| 34 | const held = (i: Issue) => gateHolding(app.db, fresh(), current(i)) !== undefined; | |
| 35 | const events = (kind: string) => | |
| 36 | app.db.query<{ n: number }, [string]>(`SELECT COUNT(*) AS n FROM event WHERE kind = ?1`).get(kind)!.n; | |
| 37 | ||
| 38 | beforeAll(async () => { | |
| 39 | dataDir = await mkdtemp(join(tmpdir(), "forge-gate-snooze-")); | |
| 40 | app = createApp({ dataDir, port: 0 }); | |
| 41 | const a = await createUser(app.db, { | |
| 42 | origin: "seed", trusted: true, username: "alice", email: "[email protected]", | |
| 43 | password: "a-good-passphrase", adminIfFirst: true, | |
| 44 | }); | |
| 45 | if (!a.ok) throw new Error(a.error); | |
| 46 | alice = a.value; | |
| 47 | const made = await createRepo(app, alice, { name: "notes", visibility: "public" }); | |
| 48 | if (!made.ok) throw new Error(String(made.error)); | |
| 49 | repo = made.value; | |
| 50 | open("P0 Notes: keep notes"); | |
| 51 | gate = open("Later gate: nothing behind this starts until the owner opens it"); | |
| 52 | }); | |
| 53 | afterAll(async () => { | |
| 54 | app.close(); | |
| 55 | await rm(dataDir, { recursive: true, force: true }); | |
| 56 | }); | |
| 57 | ||
| 58 | describe("parseUntil", () => { | |
| 59 | const now = new Date("2026-11-15T12:00:00Z"); | |
| 60 | test("a later day is its first instant", () => { | |
| 61 | expect(parseUntil("2026-11-16", now)).toEqual({ ok: true, value: "2026-11-16T00:00:00.000Z" }); | |
| 62 | }); | |
| 63 | test("today, the past, and non-days are refused", () => { | |
| 64 | for (const bad of ["2026-11-15", "2026-11-14", "2026-02-30", "soon", "", "2026-1-20"]) | |
| 65 | expect(parseUntil(bad, now)).toEqual({ ok: false, error: "bad_date" }); | |
| 66 | }); | |
| 67 | }); | |
| 68 | ||
| 69 | describe("lift until a date", () => { | |
| 70 | test("a bad date is refused and nothing moves", () => { | |
| 71 | const issue = open("Rename a note"); | |
| 72 | expect(linkIssue(app, alice, fresh(), issue, gate).ok).toBe(true); | |
| 73 | expect(liftHold(app, alice, fresh(), current(issue), "2020-01-01")).toEqual({ ok: false, error: "bad_date" }); | |
| 74 | expect(liftHold(app, alice, fresh(), current(issue), "tomorrow")).toEqual({ ok: false, error: "bad_date" }); | |
| 75 | expect(held(issue)).toBe(true); | |
| 76 | }); | |
| 77 | ||
| 78 | test("it comes back on the day and not before, and both ends are recorded", () => { | |
| 79 | const issue = open("Export as text"); | |
| 80 | expect(linkIssue(app, alice, fresh(), issue, gate).ok).toBe(true); | |
| 81 | const now = new Date("2026-11-15T12:00:00Z"); | |
| 82 | expect(liftHold(app, alice, fresh(), current(issue), "2026-11-20", now).ok).toBe(true); | |
| 83 | expect(held(issue)).toBe(false); | |
| 84 | expect(events("issue.snoozed")).toBe(1); | |
| 85 | ||
| 86 | expect(returnSnoozed(app, new Date("2026-11-19T23:59:59Z"))).toBe(0); | |
| 87 | expect(held(issue)).toBe(false); | |
| 88 | expect(returnSnoozed(app, new Date("2026-11-20T00:00:00Z"))).toBe(1); | |
| 89 | expect(held(issue)).toBe(true); | |
| 90 | expect(events("issue.snooze_ended")).toBe(1); | |
| 91 | expect(returnSnoozed(app, new Date("2026-11-21T00:00:00Z"))).toBe(0); | |
| 92 | }); | |
| 93 | ||
| 94 | test("a plain lift clears a snooze, so the day brings nothing back", () => { | |
| 95 | const issue = open("Pin the title"); | |
| 96 | expect(linkIssue(app, alice, fresh(), issue, gate).ok).toBe(true); | |
| 97 | const now = new Date("2026-11-15T12:00:00Z"); | |
| 98 | expect(liftHold(app, alice, fresh(), current(issue), "2026-11-20", now).ok).toBe(true); | |
| 99 | expect(linkIssue(app, alice, fresh(), current(issue), gate).ok).toBe(true); | |
| 100 | expect(liftHold(app, alice, fresh(), current(issue)).ok).toBe(true); | |
| 101 | expect(returnSnoozed(app, new Date("2026-11-21T00:00:00Z"))).toBe(0); | |
| 102 | expect(held(issue)).toBe(false); | |
| 103 | }); | |
| 104 | ||
| 105 | test("a revive refuses a day, and the idea stays closed and unsnoozed", () => { | |
| 106 | const issue = open("Idea nobody chose"); | |
| 107 | expect(linkIssue(app, alice, fresh(), issue, gate).ok).toBe(true); | |
| 108 | const closed = applyGateReview(app, alice, fresh(), [issue.number], reviewGate(app, fresh())!.digest); | |
| 109 | expect(closed.ok).toBe(true); | |
| 110 | expect(liftHold(app, alice, fresh(), current(issue), "2099-01-01")).toEqual({ ok: false, error: "revive_until" }); | |
| 111 | expect(current(issue).state).toBe("closed"); | |
| 112 | expect(app.db.query(`SELECT 1 FROM gate_snooze WHERE issue_id = ?1`).get(issue.id)).toBeNull(); | |
| 113 | expect(liftHold(app, alice, fresh(), current(issue)).ok).toBe(true); | |
| 114 | expect(current(issue).state).toBe("open"); | |
| 115 | }); | |
| 116 | ||
| 117 | test("a snooze whose return fails stays, and returns when it can", () => { | |
| 118 | const issue = open("Return fails once"); | |
| 119 | expect(linkIssue(app, alice, fresh(), issue, gate).ok).toBe(true); | |
| 120 | const now = new Date("2026-11-15T12:00:00Z"); | |
| 121 | expect(liftHold(app, alice, fresh(), current(issue), "2026-11-20", now).ok).toBe(true); | |
| 122 | const db = app.db; | |
| 123 | // The setter has lost the account the relink runs as. | |
| 124 | db.query(`UPDATE gate_snooze SET set_by = 'nobody' WHERE issue_id = ?1`).run(issue.id); | |
| 125 | expect(returnSnoozed(app, new Date("2026-11-21T00:00:00Z"))).toBe(0); | |
| 126 | expect(db.query(`SELECT 1 FROM gate_snooze WHERE issue_id = ?1`).get(issue.id)).not.toBeNull(); | |
| 127 | db.query(`UPDATE gate_snooze SET set_by = ?2 WHERE issue_id = ?1`).run(issue.id, alice.id); | |
| 128 | expect(returnSnoozed(app, new Date("2026-11-21T00:00:00Z"))).toBe(1); | |
| 129 | expect(held(issue)).toBe(true); | |
| 130 | expect(db.query(`SELECT 1 FROM gate_snooze WHERE issue_id = ?1`).get(issue.id)).toBeNull(); | |
| 131 | }); | |
| 132 | }); |
test/job-slices.test.ts +30 −11
| @@ -68,11 +68,16 @@ import { fireDue } from "../src/apps/feature_schedule.ts"; | ||
| 68 | 68 | import { pullDue } from "../src/apps/pull_schedule.ts"; |
| 69 | 69 | import { startMaintain } from "../src/maintain/runner.ts"; |
| 70 | 70 | import { retentionJobs } from "../src/system/retention.ts"; |
| 71 | import { returnSnoozed } from "../src/actions/gate_snooze.ts"; | |
| 71 | 72 | |
| 72 | /** Thousands of issues and pulls, as the issue asks; runs, comments and events thinned so the file runs in seconds (#1242). */ | |
| 73 | /** | |
| 74 | * Thousands of issues and pulls, as the issue asks; runs, comments and events thinned so the file | |
| 75 | * runs in seconds (#1242). | |
| 76 | */ | |
| 73 | 77 | const BUSY = { issues: 2000, pulls: 2000, requested: 100, runs: 5000, comments: 5000, events: 10000, reviewComments: 500 }; |
| 74 | 78 | |
| 75 | // A job's warnings (a sandbox without git warns once per pull) are not its slice: the terminal's write is. | |
| 79 | // A job's warnings (a sandbox without git warns once per pull) are not its slice: the terminal's | |
| 80 | // write is. | |
| 76 | 81 | quietLogs(); |
| 77 | 82 | |
| 78 | 83 | let app: App; |
| @@ -94,7 +99,10 @@ afterAll(() => { | ||
| 94 | 99 | rmSync(dir, { recursive: true, force: true }); |
| 95 | 100 | }); |
| 96 | 101 | |
| 97 | /** The longest the loop stood still while `fn` ran, in ms: its synchronous call, or any continuation after. */ | |
| 102 | /** | |
| 103 | * The longest the loop stood still while `fn` ran, in ms: its synchronous call, or any continuation | |
| 104 | * after. | |
| 105 | */ | |
| 98 | 106 | async function slice(fn: () => unknown): Promise<number> { |
| 99 | 107 | let last = performance.now(); |
| 100 | 108 | let worst = 0; |
| @@ -145,6 +153,7 @@ function jobs(): Record<string, () => unknown> { | ||
| 145 | 153 | sampler: () => sampler.tick(), |
| 146 | 154 | "memory-sampler": () => memory.tick(), |
| 147 | 155 | keeper: () => tickKeeper(app, new Date(), () => {}), |
| 156 | "gate-snooze": () => returnSnoozed(app), | |
| 148 | 157 | // The pictures' keeper (`flow/keep.ts`): one look at what is kept; a due reading is started on |
| 149 | 158 | // a worker, never read here. |
| 150 | 159 | pictures: () => keepTick(app.db), |
| @@ -157,22 +166,26 @@ function jobs(): Record<string, () => unknown> { | ||
| 157 | 166 | sweepAssigned(app); |
| 158 | 167 | pump(app, NO_SLOT, new Map()); |
| 159 | 168 | }, |
| 160 | // The orphan sweep reads the crew root (empty here); the claims it checks against are the fixture's. | |
| 169 | // The orphan sweep reads the crew root (empty here); the claims it checks against are the | |
| 170 | // fixture's. | |
| 161 | 171 | "clone-sweep": async () => { |
| 162 | 172 | await sweepOrphanClones(crewRoot(app.config.dataDir), claimedClones(app.db)); |
| 163 | 173 | pruneRunFiles(app.config.dataDir); |
| 164 | 174 | }, |
| 165 | // The radar's night: every repository's pins (git fails fast: no repositories on disk), npm faked. | |
| 175 | // The radar's night: every repository's pins (git fails fast: no repositories on disk), npm | |
| 176 | // faked. | |
| 166 | 177 | nightly: () => radarNight(app, async () => "not looked up"), |
| 167 | 178 | // The census of /proc main.ts logs each minute (`processTick`), without the crew's reaping. |
| 168 | 179 | processes: () => censusWords(census(processRows())), |
| 169 | // The fixture has no origins, mirrors, children or parent link: each is its empty pass, one read. | |
| 180 | // The fixture has no origins, mirrors, children or parent link: each is its empty pass, one | |
| 181 | // read. | |
| 170 | 182 | ahead: () => runAheadReads(app), |
| 171 | 183 | "guard-sweep": () => runGuardSweep(app), |
| 172 | 184 | "mirror-pulls": () => sweepMirrorPulls(app), |
| 173 | 185 | reach: () => sweepReach(app), |
| 174 | 186 | upstream: () => checkParent(app), |
| 175 | // Its first pass on start tells and pages everyone (`tell(id, true)`, then `page`), a superset of the clock's tick. | |
| 187 | // Its first pass on start tells and pages everyone (`tell(id, true)`, then `page`), a superset | |
| 188 | // of the clock's tick. | |
| 176 | 189 | notify: async () => { |
| 177 | 190 | const told = startNotifier(app, { |
| 178 | 191 | forgeUrl: "https://forge.test/", send: async () => true, clockMs: 1e9, |
| @@ -186,7 +199,8 @@ function jobs(): Record<string, () => unknown> { | ||
| 186 | 199 | "spawn-idle": () => sleepIdleChildren(app), |
| 187 | 200 | // One renewal of every lease this process holds: the runs a dead forge left running. |
| 188 | 201 | "lease-renew": () => heartbeatRuns(app.db, RUNNING), |
| 189 | // A minute's reads and page views, buffered then written in one flush: the noting is in the slice too. | |
| 202 | // A minute's reads and page views, buffered then written in one flush: the noting is in the | |
| 203 | // slice too. | |
| 190 | 204 | reads: () => { |
| 191 | 205 | for (let n = 0; n < 1000; n++) readLedger.note(Date.now(), { repo: "r", ref: "main", path: `f${n % 400}` }, n % 2 === 0); |
| 192 | 206 | reads.flush(); |
| @@ -232,7 +246,8 @@ function jobs(): Record<string, () => unknown> { | ||
| 232 | 246 | "feature-schedule": () => fireDue(app), |
| 233 | 247 | "pull-schedule": () => pullDue(app), |
| 234 | 248 | maintain: () => maintainer.tick(new Date(Date.now() + 1e9)), |
| 235 | // The retention slices, each as its timer calls it: bounded rows, paced by their own cost (`system/retention.ts`). | |
| 249 | // The retention slices, each as its timer calls it: bounded rows, paced by their own cost | |
| 250 | // (`system/retention.ts`). | |
| 236 | 251 | "retention-events": () => retention.events.slice(Date.now() + 40 * 86_400_000), |
| 237 | 252 | "retention-live": () => retention.live.slice(Date.now()), |
| 238 | 253 | "retention-samples": () => retention.samples.slice(Date.now()), |
| @@ -242,7 +257,8 @@ function jobs(): Record<string, () => unknown> { | ||
| 242 | 257 | } |
| 243 | 258 | |
| 244 | 259 | /** |
| 245 | * The jobs not timed here, each with why. The release keeper's are off unless a cluster turns them on. | |
| 260 | * The jobs not timed here, each with why. The release keeper's are off unless a cluster turns them | |
| 261 | * on. | |
| 246 | 262 | */ |
| 247 | 263 | const UNTIMED: Record<string, string> = { |
| 248 | 264 | "drill-watch": "a /proc read of the drill child's memory and a state write every WATCH_MS, only while a restore drill runs in its own process; drill-job tests drive runDrillInChild directly", |
| @@ -310,7 +326,10 @@ const UNTIMED: Record<string, string> = { | ||
| 310 | 326 | "spawn-due-wake": "a timer in the spawn host that wakes a due run: needs a spawned run; the fixture has none", |
| 311 | 327 | }; |
| 312 | 328 | |
| 313 | /** A job held past this in one slice fails the test: five times the issue's 50 ms, so no runner flakes it. */ | |
| 329 | /** | |
| 330 | * A job held past this in one slice fails the test: five times the issue's 50 ms, so no runner | |
| 331 | * flakes it. | |
| 332 | */ | |
| 314 | 333 | const CEILING_MS = 250; |
| 315 | 334 | |
| 316 | 335 | /** Every name src/ passes to `during`: the list a new job joins, timed or not. */ |
test/later-gate.test.ts +42 −1
| @@ -402,7 +402,8 @@ describe("the Later gate in plain sight", () => { | ||
| 402 | 402 | expect(liftHold(app, alice, fresh(), current(a))).toEqual({ ok: false, error: "not_held" }); |
| 403 | 403 | expect(current(a).state).toBe("closed"); |
| 404 | 404 | expect(holds(a)).toBe(false); |
| 405 | // Reviewed-closed, then let out of the gate by another road: nothing to lift, and it stays closed. | |
| 405 | // Reviewed-closed, then let out of the gate by another road: nothing to lift, and it stays | |
| 406 | // closed. | |
| 406 | 407 | const b = held("Reviewed then unlinked"); |
| 407 | 408 | expect(applyGateReview(app, alice, fresh(), [b.number], proposal().digest).ok).toBe(true); |
| 408 | 409 | expect(unlinkIssue(app, alice, fresh(), current(b), gate).ok).toBe(true); |
| @@ -482,6 +483,46 @@ describe("the Later gate in plain sight", () => { | ||
| 482 | 483 | expect(page).not.toContain(`/issues/${a.number}/lift`); |
| 483 | 484 | }); |
| 484 | 485 | |
| 486 | test("the page's Lift until: a bad day flashes and holds, a good day snoozes, a revive refuses a day", async () => { | |
| 487 | const path = (i: Issue) => `/alice/engine/issues/${i.number}/lift`; | |
| 488 | const a = held("Snoozed from the page"); | |
| 489 | const refused = await as(cookie, path(a), { until: "2001-01-01" }); | |
| 490 | expect(refused.status).toBe(303); | |
| 491 | const flash = (refused.headers.get("set-cookie") ?? "").split(";")[0]!; | |
| 492 | expect(decodeURIComponent(flash)).toContain("Pick a day after today"); | |
| 493 | expect(holds(a)).toBe(true); | |
| 494 | const ok = await as(cookie, path(a), { until: "2099-01-01" }); | |
| 495 | expect(ok.status).toBe(303); | |
| 496 | expect(holds(a)).toBe(false); | |
| 497 | expect( | |
| 498 | app.db.query<{ until: string }, [string]>(`SELECT until FROM gate_snooze WHERE issue_id = ?1`).get(a.id)?.until, | |
| 499 | ).toBe("2099-01-01T00:00:00.000Z"); | |
| 500 | // The date field is bounded to tomorrow or later, and a closed idea has none. | |
| 501 | const b = held("Offered a day"); | |
| 502 | expect(await get(`/alice/engine/issues/${b.number}`)).toMatch(/name="until" min="\d{4}-\d{2}-\d{2}"/); | |
| 503 | const c = held("Closed, then revived with a day"); | |
| 504 | expect(applyGateReview(app, alice, fresh(), [c.number], proposal().digest).ok).toBe(true); | |
| 505 | const revive = await as(cookie, path(c), { until: "2099-01-01" }); | |
| 506 | expect(decodeURIComponent((revive.headers.get("set-cookie") ?? "").split(";")[0]!)).toContain("closed idea is revived now"); | |
| 507 | expect(current(c).state).toBe("closed"); | |
| 508 | }); | |
| 509 | ||
| 510 | test("the MCP lift with until: a bad, a non-string, and a revive's day are refused; a good day snoozes", async () => { | |
| 511 | const a = held("Snoozed over MCP"); | |
| 512 | const args = { app: "alice/engine", issue: a.number }; | |
| 513 | expect((await mcp(aliceToken, "lift", { ...args, until: "2001-01-01" })).error).toContain("bad_date"); | |
| 514 | expect((await mcp(aliceToken, "lift", { ...args, until: 20991231 })).error).toBeDefined(); | |
| 515 | expect(holds(a)).toBe(true); | |
| 516 | const ok = await mcp(aliceToken, "lift", { ...args, until: "2099-01-01" }); | |
| 517 | expect(ok.value.says).toContain("until 2099-01-01"); | |
| 518 | expect(holds(a)).toBe(false); | |
| 519 | expect(app.db.query(`SELECT 1 FROM gate_snooze WHERE issue_id = ?1`).get(a.id)).not.toBeNull(); | |
| 520 | const b = held("Closed then revived over MCP with a day"); | |
| 521 | expect(applyGateReview(app, alice, fresh(), [b.number], proposal().digest).ok).toBe(true); | |
| 522 | expect((await mcp(aliceToken, "lift", { app: "alice/engine", issue: b.number, until: "2099-01-01" })).error).toContain("revive_until"); | |
| 523 | expect(current(b).state).toBe("closed"); | |
| 524 | }); | |
| 525 | ||
| 485 | 526 | test("the MCP lift and held tools hold the same line", async () => { |
| 486 | 527 | const a = held("Lifted over MCP"); |
| 487 | 528 | const read = await mcp(aliceToken, "held", { app: "alice/engine" }); |
test/tui-held.test.ts +24
| @@ -167,4 +167,28 @@ describe("the Later gate, in the terminal", () => { | ||
| 167 | 167 | off(); |
| 168 | 168 | h.stop(); |
| 169 | 169 | }); |
| 170 | ||
| 171 | test("u asks for a day: a bad one keeps the prompt open and changes nothing, a good one snoozes", async () => { | |
| 172 | const alice = getUserByName(forge.db, "alice")!; | |
| 173 | const made = openIssue(forge, alice, fresh(), { title: "Zzz snooze me" }); | |
| 174 | if (!made.ok) throw new Error("issue"); | |
| 175 | const snoozed = made.value; | |
| 176 | linkIssue(forge, alice, fresh(), snoozed, gate); | |
| 177 | const h = boot(alice); | |
| 178 | await h.toHeld("alice/plan"); | |
| 179 | await h.press("u"); | |
| 180 | expect(h.text()).toContain("Lift until a date"); | |
| 181 | await h.typeText("2001-01-01"); | |
| 182 | await h.press("enter"); | |
| 183 | expect(h.text()).toContain("Pick a day after today"); | |
| 184 | expect(held(snoozed)).toBe(true); | |
| 185 | await h.press("esc", "u"); | |
| 186 | await h.typeText("2099-01-01"); | |
| 187 | await h.press("enter"); | |
| 188 | expect(held(snoozed)).toBe(false); | |
| 189 | expect(forge.db.query(`SELECT until FROM gate_snooze WHERE issue_id = ?1`).get(snoozed.id)).toEqual({ | |
| 190 | until: "2099-01-01T00:00:00.000Z", | |
| 191 | }); | |
| 192 | h.stop(); | |
| 193 | }); | |
| 170 | 194 | }); |
untilis validated, but on the revive path (line 68 onward) it is dropped without a word. Refuse it there or support it; callers claim a snooze happened.