Public: anyone can read this; the crew can change it.
Asks: routes so a client can clear the whole queue (resume paused, snooze, group contents, dismiss all kinds) #17966
Merged 12h 28m ago, live in production
mason/forge:mason/17960-asks-routes-so-a-client-can-clear-the-wh → main 0 commits fork 3 threads · 3 unresolved
15 files
changed +611
−6
- docs/features/asks-clear-queue.md
- src/actions/asks_raise.ts
- src/actions/asks_snooze.ts
- src/contract/openapi/routes/index.ts
- src/contract/openapi/routes/postApiV1AsksKeySnooze.ts
- src/contract/openapi/routes/postApiV1AsksRaise.ts
- src/core/ask_snooze.ts
- src/core/migration-pins/20261203090000-ask-snooze.pin
- src/core/migrations/20261203090000-ask-snooze.ts
- src/http/feed.ts
- src/http/lazy_lists.ts
- src/tui/screens/dashboard.ts
- src/web/studio/asks.ts
- test/asks-clear-queue.test.ts
- test/tui-onyou.test.ts
docs/features/asks-clear-queue.md added +12
| @@ -0,0 +1,12 @@ | ||
| 1 | --- | |
| 2 | topic: Tell the crew | |
| 3 | row: A client can clear the whole queue: snooze, raise a pause, open a group, dismiss a decline | |
| 4 | --- | |
| 5 | # A client can clear the whole queue | |
| 6 | ||
| 7 | What the iOS app needs to end the day clear, as JSON routes (#17960); the terminal's On you pane and the web home read the same queue. | |
| 8 | ||
| 9 | - **Snooze one ask**: `POST /api/v1/asks/{key}/snooze` with `{ "until": "2026-12-05T09:00:00Z" }` (an ISO instant, or a UTC day `2026-12-05`; after now, within a year). `key` is an ask's id or the row's id, as `GET /api/v1/asks` hands them out (URL-encode the colon). The ask is gone from the web home, the terminal and the API until then, then asks again; `{ "until": null }` wakes it now. A row's snooze holds the asks that were waiting when it was set; one that starts waiting later shows in the row, as after a dismissal. In the terminal, `z` in the On you pane snoozes the marked rows (or the one under the cursor) for a day. Both call `snoozeAsk` in `src/actions/asks_snooze.ts`; the rows are `ask_snooze` (`src/core/ask_snooze.ts`), read by the queue itself. | |
| 10 | - **A paused ask** (`paused:<repo id>`, the crew stopped at its week's share): `POST /api/v1/asks/raise` with `{ "item": "paused:<id>" }` adds ten points to the share of the week the crew may use (`week.use`, the Weekly budget knob), up to the whole week, and answers `{ item, from, to }`. A forge admin only (`src/actions/asks_raise.ts`). At the whole week it says the crew waits for the provider's reset. Raise is API-only for now: no terminal key or web button calls it; an admin lifts the pause on the Weekly budget knob (`week.use`) in the settings. | |
| 11 | - **A group row** (`look:<repo>`, `GET /api/v1/asks`) carries `changes`: each change's `item`, `number`, `numberOf` and `title`, so the group opens without a preview per change. | |
| 12 | - **Dismiss** in `POST /api/v1/asks/bulk` now takes a `declined:<run>` ask (it is held until the planner declines again, and undo asks again). A `proposal:<id>` is still refused, with the reason: a wave is approved, redirected or put aside (`POST /api/v1/asks/proposal/<id>/later`), not dismissed. |
src/actions/asks_raise.ts added +44
| @@ -0,0 +1,44 @@ | ||
| 1 | /** | |
| 2 | * Raise the ceiling a `paused:<repo>` ask waits on (#17960), for a client that clears the queue. | |
| 3 | * The pause is the week's share spent (`crew/week.ts`: the crew stops at `week.use`, the weekly | |
| 4 | * budget knob), so the one lever is that knob: each Raise is `RAISE_POINTS` more of the provider's | |
| 5 | * week, up to all of it. Only a forge admin turns it (the share is the whole forge's), only while | |
| 6 | * the ask asks them now, and the crew's next pump reads it. The change is recorded as any capacity | |
| 7 | * change. | |
| 8 | */ | |
| 9 | import type { App } from "../app.ts"; | |
| 10 | import { weekUse } from "../core/capacity.ts"; | |
| 11 | import type { User } from "../core/users.ts"; | |
| 12 | import { err, ok, type Result } from "../kernel/result.ts"; | |
| 13 | import { askKeysFor } from "../web/studio/asks.ts"; | |
| 14 | import { NO_LONGER_ASKS, SIGN_IN_TO_ACT } from "./asks_words.ts"; | |
| 15 | import { changeCapacity } from "./capacity.ts"; | |
| 16 | import type { FleetError } from "./fleet.ts"; | |
| 17 | ||
| 18 | /** Refused to a person who is not a forge admin: the share is the whole forge's. */ | |
| 19 | const ONLY_ADMIN_RAISES = "only a forge admin raises the crew's share of the week"; | |
| 20 | ||
| 21 | /** | |
| 22 | * Said when the crew may already use all of the week: only the provider's reset lifts the pause. | |
| 23 | */ | |
| 24 | export const AT_WHOLE_WEEK = "the crew may already use the whole week; it waits for the provider's reset"; | |
| 25 | ||
| 26 | /** How many points of the week one Raise adds. */ | |
| 27 | const RAISE_POINTS = 10; | |
| 28 | ||
| 29 | /** One Raise: the share of the week the crew may use, before and after, in percent. */ | |
| 30 | export function raisePausedAsk( | |
| 31 | app: App, | |
| 32 | actor: User | undefined, | |
| 33 | item: unknown, | |
| 34 | ): Result<{ item: string; from: number; to: number }, FleetError> { | |
| 35 | if (!actor) return err({ code: "unauthorized", message: SIGN_IN_TO_ACT }); | |
| 36 | if (typeof item !== "string" || !item.startsWith("paused:") || !askKeysFor(app.db, actor).has(item)) | |
| 37 | return err({ code: "not_found", message: NO_LONGER_ASKS }); | |
| 38 | if (!actor.isAdmin || actor.kind === "agent") return err({ code: "forbidden", message: ONLY_ADMIN_RAISES }); | |
| 39 | const from = weekUse(app.db); | |
| 40 | if (from >= 100) return err({ code: "bad_action", message: AT_WHOLE_WEEK }); | |
| 41 | const to = Math.min(100, from + RAISE_POINTS); | |
| 42 | const changed = changeCapacity(app, actor, "week.use", String(to), `raised from the asks queue (${item})`); | |
| 43 | return changed.ok ? ok({ item, from, to }) : err({ code: "bad_action", message: `the share could not be raised: ${changed.error}` }); | |
| 44 | } |
src/actions/asks_snooze.ts added +42
| @@ -0,0 +1,42 @@ | ||
| 1 | /** | |
| 2 | * Snooze one ask until a time, for every door (#17960): `POST /api/v1/asks/{key}/snooze` and the | |
| 3 | * terminal's On you pane call this one function. The queue reads the snooze (`web/studio/asks.ts` | |
| 4 | * `notDismissed`), so the web home, the terminal, the API and the phone all stop showing the ask | |
| 5 | * until it wakes. `until: null` wakes it now. | |
| 6 | */ | |
| 7 | import type { App } from "../app.ts"; | |
| 8 | import { clearAskSnooze, parseSnoozeUntil, setAskSnooze } from "../core/ask_snooze.ts"; | |
| 9 | import type { User } from "../core/users.ts"; | |
| 10 | import { err, ok, type Result } from "../kernel/result.ts"; | |
| 11 | import { askKeysFor } from "../web/studio/asks.ts"; | |
| 12 | import { NO_LONGER_ASKS, SIGN_IN_TO_ACT } from "./asks_words.ts"; | |
| 13 | import type { FleetError } from "./fleet.ts"; | |
| 14 | ||
| 15 | export interface SnoozeAnswer { | |
| 16 | readonly key: string; | |
| 17 | /** When the ask comes back (ISO), or null when it was woken. */ | |
| 18 | readonly until: string | null; | |
| 19 | } | |
| 20 | ||
| 21 | /** | |
| 22 | * Snooze `key` (an ask's id, or the id of the row it collapsed into) until `until`; null wakes it. | |
| 23 | */ | |
| 24 | export function snoozeAsk( | |
| 25 | app: App, | |
| 26 | actor: User | undefined, | |
| 27 | key: unknown, | |
| 28 | until: unknown, | |
| 29 | now: Date = new Date(), | |
| 30 | ): Result<SnoozeAnswer, FleetError> { | |
| 31 | if (!actor) return err({ code: "unauthorized", message: SIGN_IN_TO_ACT }); | |
| 32 | if (typeof key !== "string" || !askKeysFor(app.db, actor).has(key)) | |
| 33 | return err({ code: "not_found", message: NO_LONGER_ASKS }); | |
| 34 | if (until === null) { | |
| 35 | clearAskSnooze(app.db, actor.id, key); | |
| 36 | return ok({ key, until: null }); | |
| 37 | } | |
| 38 | const at = parseSnoozeUntil(until, now); | |
| 39 | if (!at.ok) return err({ code: "bad_action", message: at.error }); | |
| 40 | setAskSnooze(app.db, actor.id, key, at.value, now); | |
| 41 | return ok({ key, until: at.value }); | |
| 42 | } |
src/contract/openapi/routes/index.ts +2
| @@ -361,7 +361,9 @@ export { route as postApiV1AsksBulkIdUndo } from "./postApiV1AsksBulkIdUndo.ts"; | ||
| 361 | 361 | export { route as postApiV1AsksDecide } from "./postApiV1AsksDecide.ts"; |
| 362 | 362 | export { route as postApiV1AsksDecideIdUndo } from "./postApiV1AsksDecideIdUndo.ts"; |
| 363 | 363 | export { route as postApiV1AsksGiveBack } from "./postApiV1AsksGiveBack.ts"; |
| 364 | export { route as postApiV1AsksKeySnooze } from "./postApiV1AsksKeySnooze.ts"; | |
| 364 | 365 | export { route as postApiV1AsksProposalIdVerb } from "./postApiV1AsksProposalIdVerb.ts"; |
| 366 | export { route as postApiV1AsksRaise } from "./postApiV1AsksRaise.ts"; | |
| 365 | 367 | export { route as postApiV1BoardsPins } from "./postApiV1BoardsPins.ts"; |
| 366 | 368 | export { route as postApiV1BoardsQuery } from "./postApiV1BoardsQuery.ts"; |
| 367 | 369 | export { route as postApiV1BrokerOrigins } from "./postApiV1BrokerOrigins.ts"; |
src/contract/openapi/routes/postApiV1AsksKeySnooze.ts added +18
| @@ -0,0 +1,18 @@ | ||
| 1 | import type { Route } from "../shared.ts"; | |
| 2 | ||
| 3 | export const route: Route = { | |
| 4 | method: "post", | |
| 5 | path: "/api/v1/asks/{key}/snooze", | |
| 6 | summary: "Snooze one ask until a time on every door; `until: null` wakes it", | |
| 7 | detail: "Snooze one ask (rw scope): `key` is an ask's id or the id of the row it collapsed into, as GET /api/v1/asks hands them out; `until` is a time after now and within a year, as an ISO instant or a UTC day, or null to wake the ask now. The web home, the terminal and the API stop listing it until then. Answers 201 with the key and when it wakes", | |
| 8 | auth: true, | |
| 9 | role: "member", | |
| 10 | status: 201, | |
| 11 | body: { until: "string" }, | |
| 12 | refusals: { | |
| 13 | bad_action: "until is not a time after now within a year", | |
| 14 | not_found: "the ask no longer asks the caller", | |
| 15 | }, | |
| 16 | errorStatus: { 422: "`bad_action`: until is not a time after now within a year" }, | |
| 17 | refuses: [401, 403, 404], | |
| 18 | }; |
src/contract/openapi/routes/postApiV1AsksRaise.ts added +18
| @@ -0,0 +1,18 @@ | ||
| 1 | import type { Route } from "../shared.ts"; | |
| 2 | ||
| 3 | export const route: Route = { | |
| 4 | method: "post", | |
| 5 | path: "/api/v1/asks/raise", | |
| 6 | summary: "Raise the ceiling a paused ask waits on: `item` is `paused:<repo id>`", | |
| 7 | detail: "Raise the crew's share of the week (rw scope; the `week.use` knob the pause is read from) by 10 points, up to the whole week: `item` is a `paused:<repo id>` ask that asks the caller. Only a forge admin may; answers 201 with the share before and after, in percent", | |
| 8 | auth: true, | |
| 9 | role: "admin", | |
| 10 | status: 201, | |
| 11 | body: { item: "string" }, | |
| 12 | refusals: { | |
| 13 | bad_action: "the crew may already use the whole week", | |
| 14 | forbidden: "only a forge admin raises the crew's share of the week", | |
| 15 | not_found: "the ask is not a pause, or no longer asks the caller", | |
| 16 | }, | |
| 17 | refuses: [401, 403, 404], | |
| 18 | }; |
src/core/ask_snooze.ts added +81
| @@ -0,0 +1,81 @@ | ||
| 1 | /** | |
| 2 | * A person's snooze of one ask until an instant (#17960): rows only. The queue reads the ones still | |
| 3 | * running (`web/studio/asks.ts`), so every door that shows asks honours them; | |
| 4 | * `actions/asks_snooze.ts` owns who may set one. | |
| 5 | */ | |
| 6 | import type { Database } from "bun:sqlite"; | |
| 7 | import { err, ok, type Result } from "../kernel/result.ts"; | |
| 8 | ||
| 9 | /** The longest a snooze may run: a snooze is "not now", a year out is a dismissal. */ | |
| 10 | const SNOOZE_MAX_MS = 366 * 24 * 60 * 60 * 1000; | |
| 11 | ||
| 12 | /** The one sentence a refused `until` gets, the same on every door. */ | |
| 13 | export const BAD_UNTIL = "until is a time after now and within a year, as 2026-12-05T09:00:00Z or 2026-12-05"; | |
| 14 | ||
| 15 | const DAY = /^\d{4}-\d{2}-\d{2}$/; | |
| 16 | const INSTANT = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(:\d{2}(\.\d{1,3})?)?(Z|[+-]\d{2}:\d{2})$/; | |
| 17 | ||
| 18 | /** | |
| 19 | * `until` as an ISO instant: a UTC day starts at its first instant. Refused when past or over a | |
| 20 | * year. | |
| 21 | */ | |
| 22 | export function parseSnoozeUntil(raw: unknown, now: Date): Result<string, typeof BAD_UNTIL> { | |
| 23 | if (typeof raw !== "string") return err(BAD_UNTIL); | |
| 24 | const text = raw.trim(); | |
| 25 | if (!DAY.test(text) && !INSTANT.test(text)) return err(BAD_UNTIL); | |
| 26 | const at = new Date(DAY.test(text) ? `${text}T00:00:00Z` : text); | |
| 27 | const ms = at.getTime(); | |
| 28 | if (Number.isNaN(ms) || ms <= now.getTime() || ms - now.getTime() > SNOOZE_MAX_MS) return err(BAD_UNTIL); | |
| 29 | if (DAY.test(text) && at.toISOString().slice(0, 10) !== text) return err(BAD_UNTIL); | |
| 30 | return ok(at.toISOString()); | |
| 31 | } | |
| 32 | ||
| 33 | /** Snooze `itemId` for `viewerId` until `until`; a second snooze replaces the first. */ | |
| 34 | export function setAskSnooze(db: Database, viewerId: string, itemId: string, until: string, now = new Date()): void { | |
| 35 | db.query( | |
| 36 | `INSERT INTO ask_snooze (viewer_id, item_id, until, created_at) VALUES (?1, ?2, ?3, ?4) | |
| 37 | ON CONFLICT(viewer_id, item_id) DO UPDATE SET until = ?3, created_at = ?4`, | |
| 38 | ).run(viewerId, itemId, until, now.toISOString()); | |
| 39 | } | |
| 40 | ||
| 41 | /** Wake `itemId`: the snooze is gone and the ask is back in the queue. Whether one was there. */ | |
| 42 | export function clearAskSnooze(db: Database, viewerId: string, itemId: string): boolean { | |
| 43 | return db.query("DELETE FROM ask_snooze WHERE viewer_id = ?1 AND item_id = ?2").run(viewerId, itemId).changes > 0; | |
| 44 | } | |
| 45 | ||
| 46 | /** The asks this person has snoozed that are still asleep at `now`, each with when it wakes. */ | |
| 47 | export function askSnoozes(db: Database, viewerId: string, now = new Date()): Map<string, string> { | |
| 48 | return new Map( | |
| 49 | db | |
| 50 | .query<{ item_id: string; until: string }, [string, string]>( | |
| 51 | "SELECT item_id, until FROM ask_snooze WHERE viewer_id = ?1 AND until > ?2", | |
| 52 | ) | |
| 53 | .all(viewerId, now.toISOString()) | |
| 54 | .map((r) => [r.item_id, r.until]), | |
| 55 | ); | |
| 56 | } | |
| 57 | ||
| 58 | /** | |
| 59 | * A person's dismissals and running snoozes in one statement, so the queue's read costs the page no | |
| 60 | * more than it did before snoozes (`test/pages-budget.test.ts` counts it): `dismissed` is | |
| 61 | * `askDismissals`; `snoozed` is the running snoozes, each with when it was set, so a group's snooze | |
| 62 | * holds only the asks that were waiting then, as a dismissal does. | |
| 63 | */ | |
| 64 | export function askHolds( | |
| 65 | db: Database, | |
| 66 | viewerId: string, | |
| 67 | now = new Date(), | |
| 68 | ): { dismissed: Map<string, string>; snoozed: Map<string, string> } { | |
| 69 | const dismissed = new Map<string, string>(); | |
| 70 | const snoozed = new Map<string, string>(); | |
| 71 | const rows = db | |
| 72 | .query<{ snoozed: number; item_id: string; at: string }, [string, string]>( | |
| 73 | `SELECT 0 AS snoozed, item_id, MAX(created_at) AS at FROM interaction | |
| 74 | WHERE viewer_id = ?1 AND kind = 'dismissed' AND item_id LIKE 'ask:%' GROUP BY item_id | |
| 75 | UNION ALL | |
| 76 | SELECT 1, item_id, created_at FROM ask_snooze WHERE viewer_id = ?1 AND until > ?2`, | |
| 77 | ) | |
| 78 | .all(viewerId, now.toISOString()); | |
| 79 | for (const r of rows) (r.snoozed === 1 ? snoozed : dismissed).set(r.item_id, r.at); | |
| 80 | return { dismissed, snoozed }; | |
| 81 | } |
src/core/migration-pins/20261203090000-ask-snooze.pin added +1
| @@ -0,0 +1,1 @@ | ||
| 1 | 0d1c9de380329ec30d1f1f7ca98a8425d53193e8259191b3564d9e6c86fbd1c0 |
src/core/migrations/20261203090000-ask-snooze.ts added +12
| @@ -0,0 +1,12 @@ | ||
| 1 | // A person's snooze of one ask until an instant (#17960): the ask (or the row it collapsed into) | |
| 2 | // is out of their queue on every door until `until`, then asks again. One row per person and ask, | |
| 3 | // replaced by a new snooze, so it cannot grow by repeats. | |
| 4 | export default ` | |
| 5 | CREATE TABLE ask_snooze ( | |
| 6 | viewer_id TEXT NOT NULL REFERENCES user(id) ON DELETE CASCADE, | |
| 7 | item_id TEXT NOT NULL, | |
| 8 | until TEXT NOT NULL, | |
| 9 | created_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ','now')), | |
| 10 | PRIMARY KEY (viewer_id, item_id) | |
| 11 | ) WITHOUT ROWID; | |
| 12 | `; |
src/http/feed.ts +23
| @@ -3,6 +3,8 @@ | ||
| 3 | 3 | * are the signed-in viewer's own — there is no way to ask for another's. |
| 4 | 4 | */ |
| 5 | 5 | |
| 6 | import { snoozeAsk } from "../actions/asks_snooze.ts"; | |
| 7 | import { raisePausedAsk } from "../actions/asks_raise.ts"; | |
| 6 | 8 | import { cursorRefusal, limitRefusal } from "../contract/page_query.ts"; |
| 7 | 9 | import { parseLimit } from "../contract/page_query.ts"; |
| 8 | 10 | import { |
| @@ -245,6 +247,27 @@ export function feedRoutes(router: Router<Handler>): void { | ||
| 245 | 247 | return json(undone.value, 201); |
| 246 | 248 | }); |
| 247 | 249 | |
| 250 | // Snooze one ask until a time, honoured on every door (`actions/asks_snooze.ts`); `until: null` | |
| 251 | // wakes it. | |
| 252 | router.add("POST", "/api/v1/asks/:key/snooze", async (ctx) => { | |
| 253 | const denied = requireScope(ctx, "rw"); | |
| 254 | if (denied) return denied; | |
| 255 | const input = await body(ctx.request); | |
| 256 | const done = snoozeAsk(ctx.app, ctx.auth.user, ctx.params.key, input.until); | |
| 257 | if (!done.ok) return bulkError(done.error); | |
| 258 | return json(done.value, 201); | |
| 259 | }); | |
| 260 | ||
| 261 | // Raise the ceiling a `paused:<repo>` ask waits on: the week's share (`actions/asks_raise.ts`). | |
| 262 | router.add("POST", "/api/v1/asks/raise", async (ctx) => { | |
| 263 | const denied = requireScope(ctx, "rw"); | |
| 264 | if (denied) return denied; | |
| 265 | const input = await body(ctx.request); | |
| 266 | const done = raisePausedAsk(ctx.app, ctx.auth.user, input.item); | |
| 267 | if (!done.ok) return bulkError(done.error); | |
| 268 | return json(done.value, 201); | |
| 269 | }); | |
| 270 | ||
| 248 | 271 | // A wave proposal's four verbs (`actions/proposals.ts`): approve, redirect (with `words`), later, again. |
| 249 | 272 | router.add("POST", "/api/v1/asks/proposal/:id/:verb", async (ctx) => { |
| 250 | 273 | const denied = requireScope(ctx, "rw"); |
src/http/lazy_lists.ts +2
| @@ -1712,6 +1712,8 @@ export const FEED_ROUTES = [ | ||
| 1712 | 1712 | ["POST", "/api/v1/asks/decide"], |
| 1713 | 1713 | ["POST", "/api/v1/asks/give-back"], |
| 1714 | 1714 | ["POST", "/api/v1/asks/decide/:id/undo"], |
| 1715 | ["POST", "/api/v1/asks/:key/snooze"], | |
| 1716 | ["POST", "/api/v1/asks/raise"], | |
| 1715 | 1717 | ["POST", "/api/v1/asks/proposal/:id/:verb"], |
| 1716 | 1718 | ["POST", "/api/v1/feed/interactions"], |
| 1717 | 1719 | ["GET", "/api/v1/feed/likes"], |
src/tui/screens/dashboard.ts +30
| @@ -73,6 +73,8 @@ import { returnsScreen, returnsStrip } from "./returns.ts"; | ||
| 73 | 73 | import { pinRepo, unpinRepo } from "../../actions/origins.ts"; |
| 74 | 74 | import { getProposal } from "../../core/proposals.ts"; |
| 75 | 75 | import { getIssueById, listAssignedTo, type Issue } from "../../core/issues.ts"; |
| 76 | import { askSnoozes } from "../../core/ask_snooze.ts"; | |
| 77 | import { snoozeAsk } from "../../actions/asks_snooze.ts"; | |
| 76 | 78 | import { askLinesFor } from "../../web/studio/asks.ts"; |
| 77 | 79 | import { applyAskFilter } from "../../actions/ask_filter.ts"; |
| 78 | 80 | import { askFiltersOf, hasAskFilters, hiddenLine, HIDE_APP_DAY_WORDS, SHOW_ALL_WORDS } from "../../core/ask_filters.ts"; |
| @@ -173,6 +175,8 @@ const FIRST_TELL_LINE = "What do you want built? t says it to the crew."; | ||
| 173 | 175 | |
| 174 | 176 | /** Rows the list keeps under the figures strip; below it the strip shows fewer figures. */ |
| 175 | 177 | const FIGURES_ROOM = 6; |
| 178 | /** How long a snooze from the On you pane lasts. */ | |
| 179 | const SNOOZE_DAY_MS = 24 * 60 * 60 * 1000; | |
| 176 | 180 | |
| 177 | 181 | /** |
| 178 | 182 | * The next steps as keys: `t ask for a change · w see what shipped`, plus `i invite someone` for an |
| @@ -639,7 +643,10 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen { | ||
| 639 | 643 | // A filtered ask is not in `rows`; one that is there (a trust alarm) always shows. |
| 640 | 644 | const asked = (id: string): boolean => |
| 641 | 645 | rows.some((row) => row.items.some((item) => item.slice(item.indexOf(":") + 1) === id)); |
| 646 | // A snoozed ask is not on the pane until it wakes, as on the web home (#17960). | |
| 647 | const asleep = new Set([...askSnoozes(f.db, f.user.id).keys()].map((k) => k.slice(k.indexOf(":") + 1))); | |
| 642 | 648 | const assigned = issues.flatMap((issue) => { |
| 649 | if (asleep.has(issue.id)) return []; | |
| 643 | 650 | if ((filters.apps.has(issue.repoId) || filters.kinds.has("assigned")) && !asked(issue.id)) return []; |
| 644 | 651 | if (off.has(issue.authorId)) return []; |
| 645 | 652 | const repo = byId.get(issue.repoId); |
| @@ -796,6 +803,27 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen { | ||
| 796 | 803 | }); |
| 797 | 804 | }; |
| 798 | 805 | |
| 806 | /** Snooze the set for a day (#17960): the ask's own id, as the API's snooze takes it. */ | |
| 807 | const snoozeSet = (): void => { | |
| 808 | const until = new Date(Date.now() + SNOOZE_DAY_MS).toISOString(); | |
| 809 | let n = 0; | |
| 810 | let first = ""; | |
| 811 | // The key is the ask's own id as the queue hands it out, never rebuilt from the row's flags. | |
| 812 | const asks = f.user === undefined ? [] : askLinesFor(f.db, f.user).flatMap((row) => row.items); | |
| 813 | for (const t of targets()) { | |
| 814 | const key = asks.find((item) => item.slice(item.indexOf(":") + 1) === t.issue.id); | |
| 815 | const done = snoozeAsk(f.app, f.user, key, until); | |
| 816 | if (done.ok) n++; | |
| 817 | else if (first === "") first = done.error.message; | |
| 818 | } | |
| 819 | marked.clear(); | |
| 820 | reload(); | |
| 821 | ctx.toast( | |
| 822 | `snoozed ${n} until tomorrow` + (first === "" ? "" : ` (${first})`), | |
| 823 | n > 0 ? "success" : "attn", | |
| 824 | ); | |
| 825 | }; | |
| 826 | ||
| 799 | 827 | const closeSet = (): void => { |
| 800 | 828 | if (targets().length === 0) return; |
| 801 | 829 | ctx.push( |
| @@ -1259,6 +1287,7 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen { | ||
| 1259 | 1287 | binding(["v"], "mark"), |
| 1260 | 1288 | binding(["x"], "close"), |
| 1261 | 1289 | binding(["m"], "mute"), |
| 1290 | binding(["z"], "snooze a day"), | |
| 1262 | 1291 | binding(["H"], HIDE_APP_DAY_WORDS.toLowerCase()), |
| 1263 | 1292 | binding(["S"], "ship"), |
| 1264 | 1293 | ] |
| @@ -1521,6 +1550,7 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen { | ||
| 1521 | 1550 | return true; |
| 1522 | 1551 | } |
| 1523 | 1552 | if (e.key === "x") return closeSet(), true; |
| 1553 | if (e.key === "z") return snoozeSet(), true; | |
| 1524 | 1554 | if (e.key === "Z") return archiveStale(), true; |
| 1525 | 1555 | if (e.key === "m") return clear("mute"), true; |
| 1526 | 1556 | if (e.key === "S") return shipSet(), true; |
src/web/studio/asks.ts +55 −6
| @@ -21,6 +21,7 @@ import { getHold, holdsFor } from "../../core/holds.ts"; | ||
| 21 | 21 | import { issueTitles, proposalsFor, type Proposal } from "../../core/proposals.ts"; |
| 22 | 22 | import { chipsOf, type Chips } from "../../core/feed_chips.ts"; |
| 23 | 23 | import { chipHides } from "../../feed/chips.ts"; |
| 24 | import { askHolds } from "../../core/ask_snooze.ts"; | |
| 24 | 25 | import { askDismissals, mutedRepos } from "../../core/interactions.ts"; |
| 25 | 26 | import { askFiltersOf, filterHides, hasAskFilters, hiddenLine, TRUST_ALARM_SCORE, type AskKind } from "../../core/ask_filters.ts"; |
| 26 | 27 | import { ASKS_WINDOW_DAYS, askMeasureWeek, syncAskLedger, type AskEnd } from "../../core/ask_ledger.ts"; |
| @@ -772,6 +773,14 @@ function consequencesOf( | ||
| 772 | 773 | return out; |
| 773 | 774 | } |
| 774 | 775 | |
| 776 | /** | |
| 777 | * What a dismissal of the planner's decline on a direction issue is kept under | |
| 778 | * (`ask:declined-on:<issue>`): | |
| 779 | * the issue, not the declining run, so a bulk dismiss of the issue's asks and its undo reach it; a | |
| 780 | * newer decline is newer than the dismissal and asks again (#17960). | |
| 781 | */ | |
| 782 | const DECLINED_OF = "declined-on:"; | |
| 783 | ||
| 775 | 784 | /** The row an ask collapses into: one kind in one repository. */ |
| 776 | 785 | const groupId = (a: { kind: DecisionKind; repo: Repo; id: string }): string => |
| 777 | 786 | // Work assigned to you is each its own row: they share no decision. |
| @@ -790,7 +799,7 @@ function notDismissed<T extends AskCandidate>( | ||
| 790 | 799 | given?: Chips, |
| 791 | 800 | ): T[] { |
| 792 | 801 | const muted = mutedRepos(db, user.id); |
| 793 | const dismissed = askDismissals(db, user.id); | |
| 802 | const { dismissed, snoozed } = askHolds(db, user.id); | |
| 794 | 803 | const chips = given ?? chipsOf(db, user.id); |
| 795 | 804 | // A change waiting on review is a `pull`; anything else is a decision. |
| 796 | 805 | // The author is the actor the person chip names. |
| @@ -814,6 +823,10 @@ function notDismissed<T extends AskCandidate>( | ||
| 814 | 823 | !chipped(a) && |
| 815 | 824 | !holds(a.id, a.since) && |
| 816 | 825 | !holds(groupId(a), a.since) && |
| 826 | !(a.kind === "declined" && a.issue !== undefined && holds(`${DECLINED_OF}${a.issue.id}`, a.since)) && | |
| 827 | !snoozed.has(a.id) && | |
| 828 | // A row's snooze is set on the asks in it then: one that starts waiting later asks (#17960). | |
A snooze on the group key hides every ask in that row, including asks that began waiting after the snooze was set. The dismissal checks just above compare |
||
| 829 | !((snoozed.get(groupId(a)) ?? "") > a.since) && | |
| 817 | 830 | !setAside(a), |
| 818 | 831 | ); |
| 819 | 832 | } |
| @@ -1129,6 +1142,11 @@ export function askLinesFor( | ||
| 1129 | 1142 | /** For a wave proposal: what it says, as plain text (the reader escapes it). */ |
| 1130 | 1143 | proposal?: { id: string; title: string; why: string; issues: string[] }; |
| 1131 | 1144 | items: string[]; |
| 1145 | /** | |
| 1146 | * For a row of several: each change or issue in it, so a client opens the group without a preview | |
| 1147 | * per change. | |
| 1148 | */ | |
| 1149 | changes?: { item: string; number: number; numberOf: "pull" | "issue"; title: string }[]; | |
| 1132 | 1150 | /** When the oldest ask in the row began to wait (ISO), for how long it has waited. */ |
| 1133 | 1151 | since: string; |
| 1134 | 1152 | /** The decision, its options and what happens if nobody acts (`ASK_WORDS`). */ |
| @@ -1164,6 +1182,8 @@ export function askLinesFor( | ||
| 1164 | 1182 | if (only === undefined) |
| 1165 | 1183 | return { |
| 1166 | 1184 | ...about, |
| 1185 | // A client opens the group without a preview call per change (#17960). | |
| 1186 | changes: row.items.flatMap((c) => changeOf(c)), | |
| 1167 | 1187 | line: `${row.repo.name}: ${rowLine(row.kind, row.items.length)}`, |
| 1168 | 1188 | link: `/#${askAnchor(row.id)}`, |
| 1169 | 1189 | }; |
| @@ -1200,6 +1220,17 @@ export function askLinesFor( | ||
| 1200 | 1220 | }); |
| 1201 | 1221 | } |
| 1202 | 1222 | |
| 1223 | /** | |
| 1224 | * What a group row lists of one ask in it: the change or issue it is about, none for a pause or a | |
| 1225 | * wave. | |
| 1226 | */ | |
| 1227 | function changeOf(c: AskCandidate): { item: string; number: number; numberOf: "pull" | "issue"; title: string }[] { | |
| 1228 | const about = c.pull ?? c.issue; | |
| 1229 | return about === undefined | |
| 1230 | ? [] | |
| 1231 | : [{ item: c.id, number: about.number, numberOf: c.pull !== undefined ? "pull" : "issue", title: about.title }]; | |
| 1232 | } | |
| 1233 | ||
| 1203 | 1234 | /** |
| 1204 | 1235 | * What the forge itself needs, for a site admin: `forgeNeedList`, the very |
| 1205 | 1236 | * list the health answer and the board's forge strip print, each as one ask. |
| @@ -1276,7 +1307,7 @@ export function askItemsOf(issue: Issue): string[] { | ||
| 1276 | 1307 | `ask:waiting:${issue.id}`, |
| 1277 | 1308 | `ask:assigned:${issue.id}`, |
| 1278 | 1309 | ] |
| 1279 | : [`ask:parked:${issue.id}`, `ask:assigned:${issue.id}`]; | |
| 1310 | : [`ask:parked:${issue.id}`, `ask:assigned:${issue.id}`, `ask:${DECLINED_OF}${issue.id}`]; | |
| 1280 | 1311 | } |
| 1281 | 1312 | |
| 1282 | 1313 | /** |
| @@ -1308,11 +1339,31 @@ function pullCause(db: Database, issue: Issue): string { | ||
| 1308 | 1339 | return check > again ? check : again; |
| 1309 | 1340 | } |
| 1310 | 1341 | |
| 1342 | /** | |
| 1343 | * Why a wave proposal is not dismissed in bulk: it is a decision with four answers, and putting it | |
| 1344 | * aside (`later`) is its "not now", which `again` takes back (#17960). | |
| 1345 | */ | |
| 1346 | const PROPOSAL_NOT_DISMISSED = | |
| 1347 | "a wave proposal is approved, redirected or put aside (POST /api/v1/asks/proposal/<id>/later), not dismissed"; | |
| 1348 | ||
| 1349 | /** | |
| 1350 | * Every key a snooze may name for this viewer: each ask's id and the row it collapses into, for the | |
| 1351 | * asks that ask them now (a dismissed or snoozed one included, so it can be snoozed again). | |
| 1352 | */ | |
| 1353 | export function askKeysFor(db: Database, user: User): Set<string> { | |
| 1354 | const keys = new Set<string>(); | |
| 1355 | for (const a of askCandidatesFor(db, user, listReposVisibleTo(db, user, { limit: 200, withoutArchived: true }))) { | |
| 1356 | keys.add(a.id); | |
| 1357 | keys.add(groupId(a)); | |
| 1358 | } | |
| 1359 | return keys; | |
| 1360 | } | |
| 1361 | ||
| 1311 | 1362 | /** |
| 1312 | 1363 | * Ask ids, as `GET /api/v1/asks` hands them out (a row's `items`), to the |
| 1313 | 1364 | * issues and pulls a bulk action works on — only those that ask the viewer |
| 1314 | 1365 | * now, whether or not they dismissed them. The rest are named with why: |
| 1315 | * a ceiling and a planner's decline are decided where they live. | |
| 1366 | * a ceiling is raised where it lives and a proposal is answered on its card. | |
| 1316 | 1367 | */ |
| 1317 | 1368 | export function askTargetsFor( |
| 1318 | 1369 | db: Database, |
| @@ -1340,9 +1391,7 @@ export function askTargetsFor( | ||
| 1340 | 1391 | else if (ask.kind === "paused") |
| 1341 | 1392 | refused.push({ item, reason: "a ceiling is raised in the app's settings" }); |
| 1342 | 1393 | else if (ask.kind === "proposal") |
| 1343 | refused.push({ item, reason: "a proposal is approved, redirected or put aside on its card" }); | |
| 1344 | else if (ask.kind === "declined") | |
| 1345 | refused.push({ item, reason: "a planner's decline is answered on its issue" }); | |
| 1394 | refused.push({ item, reason: PROPOSAL_NOT_DISMISSED }); | |
| 1346 | 1395 | else issueIds.push((ask.pull ?? ask.issue)!.id); |
| 1347 | 1396 | } |
| 1348 | 1397 | return { issueIds: [...new Set(issueIds)], refused }; |
test/asks-clear-queue.test.ts added +248
| @@ -0,0 +1,248 @@ | ||
| 1 | /** | |
| 2 | * What a client needs to clear the whole queue (#17960): a group row lists its changes, one ask is | |
| 3 | * snoozed until a time on every door, a planner's decline is dismissed in bulk (and undone), and a | |
| 4 | * paused ask raises the crew's share of the week. The refusals come with their sentences. | |
| 5 | */ | |
| 6 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | |
| 7 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 8 | import { tmpdir } from "node:os"; | |
| 9 | import { join } from "node:path"; | |
| 10 | import { addToCrew, createAgent } from "../src/actions/crew.ts"; | |
| 11 | import { openIssue } from "../src/actions/issues.ts"; | |
| 12 | import { openPull } from "../src/actions/pulls.ts"; | |
| 13 | import { commitToBranch, createRepo, updateRepoSettings } from "../src/actions/repos.ts"; | |
| 14 | import { raisePausedAsk, AT_WHOLE_WEEK } from "../src/actions/asks_raise.ts"; | |
| 15 | import { snoozeAsk } from "../src/actions/asks_snooze.ts"; | |
| 16 | import { createApp, type App } from "../src/app.ts"; | |
| 17 | import { askSnoozes, BAD_UNTIL, parseSnoozeUntil, setAskSnooze } from "../src/core/ask_snooze.ts"; | |
| 18 | import { setCapacity, weekUse } from "../src/core/capacity.ts"; | |
| 19 | import type { Issue } from "../src/core/issues.ts"; | |
| 20 | import { noteMeasure } from "../src/core/measure.ts"; | |
| 21 | import type { Pull } from "../src/core/pulls.ts"; | |
| 22 | import type { Repo } from "../src/core/repos.ts"; | |
| 23 | import { claimRun, createRun, finishRun } from "../src/core/runs.ts"; | |
| 24 | import { addSubscription, setGrants } from "../src/core/subscriptions.ts"; | |
| 25 | import { createUser, getUserByName, type User } from "../src/core/users.ts"; | |
| 26 | import { forgetWeek } from "../src/crew/week_read.ts"; | |
| 27 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 28 | import { askLinesFor } from "../src/web/studio/asks.ts"; | |
| 29 | import { quietLogs } from "./helpers/globals.ts"; | |
| 30 | import { tokenFor } from "./helpers/tokens.ts"; | |
| 31 | ||
| 32 | quietLogs(); | |
| 33 | ||
| 34 | describe("clearing the whole queue from a client", () => { | |
| 35 | let dataDir = ""; | |
| 36 | let app: App; | |
| 37 | let servers: Servers; | |
| 38 | let alice: User; | |
| 39 | let bob: User; | |
| 40 | let repo: Repo; | |
| 41 | /** Not autonomous: its green pulls ask a person for a look. */ | |
| 42 | let plain: Repo; | |
| 43 | let direction: Issue; | |
| 44 | let pulls: Pull[] = []; | |
| 45 | let runId = ""; | |
| 46 | let n = 0; | |
| 47 | ||
| 48 | const rows = () => askLinesFor(app.db, alice); | |
| 49 | const kinds = () => rows().map((r) => r.kind); | |
| 50 | const tomorrow = () => new Date(Date.now() + 86_400_000).toISOString(); | |
| 51 | ||
| 52 | const post = async (who: string, path: string, payload: unknown, scope: "rw" | "ro" = "rw") => { | |
| 53 | const res = await fetch(`${servers.url}${path}`, { | |
| 54 | method: "POST", | |
| 55 | headers: { authorization: `Bearer ${tokenFor(app, who, scope)}`, "content-type": "application/json" }, | |
| 56 | body: JSON.stringify(payload), | |
| 57 | }); | |
| 58 | return { status: res.status, body: (await res.json()) as any }; | |
| 59 | }; | |
| 60 | ||
| 61 | const greenPull = async (title: string): Promise<Pull> => { | |
| 62 | n++; | |
| 63 | await commitToBranch(app, alice, plain, { branch: `bot/${n}`, base: "main", message: title, files: [{ path: `F${n}.md`, content: `${n}\n` }] }); | |
| 64 | const opened = await openPull(app, getUserByName(app.db, "bot")!, plain, { title, body: "", baseBranch: "main", headBranch: `bot/${n}` }); | |
| 65 | if (!opened.ok) throw new Error(String(opened.error)); | |
| 66 | const run = createRun(app.db, { repoId: plain.id, kind: "check", issueId: opened.value.id, env: `pull-${opened.value.number}`, commitOid: opened.value.headOid, reason: "pull" }); | |
| 67 | claimRun(app.db, run.id); | |
| 68 | finishRun(app.db, run.id, { state: "ok", summary: "ok" }); | |
| 69 | return opened.value; | |
| 70 | }; | |
| 71 | ||
| 72 | beforeAll(async () => { | |
| 73 | dataDir = await mkdtemp(join(tmpdir(), "forge-asks-clear-")); | |
| 74 | app = createApp({ dataDir, port: 0 }); | |
| 75 | servers = await serve(app); | |
| 76 | const a = await createUser(app.db, { origin: "seed", trusted: true, username: "alice", email: "[email protected]", password: "a-good-passphrase", adminIfFirst: true }); | |
| 77 | const b = await createUser(app.db, { origin: "seed", trusted: true, username: "bob", email: "[email protected]", password: "a-good-passphrase" }); | |
| 78 | if (!a.ok || !b.ok) throw new Error("users"); | |
| 79 | alice = a.value; | |
| 80 | bob = b.value; | |
| 81 | await createAgent(app, alice, { username: "bot" }); | |
| 82 | const made = await createRepo(app, alice, { name: "garden", visibility: "public" }); | |
| 83 | if (!made.ok) throw new Error(String(made.error)); | |
| 84 | repo = made.value; | |
| 85 | await commitToBranch(app, alice, repo, { message: "seed", files: [{ path: "README.md", content: "# garden\n" }] }); | |
| 86 | addToCrew(app, alice, repo, "bot"); | |
| 87 | const orchard = await createRepo(app, alice, { name: "orchard", visibility: "public" }); | |
| 88 | if (!orchard.ok) throw new Error(String(orchard.error)); | |
| 89 | plain = orchard.value; | |
| 90 | await commitToBranch(app, alice, plain, { message: "seed", files: [{ path: "README.md", content: "# orchard\n" }] }); | |
| 91 | addToCrew(app, alice, plain, "bot"); | |
| 92 | const on = await updateRepoSettings(app, alice, repo, { autonomy: "autonomous", autonomyDirection: "grow", autonomySlots: 1, autonomyBy: alice.id }); | |
| 93 | if (!on.ok) throw new Error("autonomy"); | |
| 94 | const opened = openIssue(app, alice, repo, { title: "Direction: grow food" }); | |
| 95 | if (!opened.ok) throw new Error(String(opened.error)); | |
| 96 | direction = opened.value; | |
| 97 | app.db.query("UPDATE repo SET direction_issue_id = ?1 WHERE id = ?2").run(direction.id, repo.id); | |
| 98 | const run = createRun(app.db, { repoId: repo.id, kind: "agent", issueId: direction.id, reason: "planning" }); | |
| 99 | claimRun(app.db, run.id); | |
| 100 | finishRun(app.db, run.id, { state: "failed", summary: "declined: nothing to plan" }); | |
| 101 | runId = run.id; | |
| 102 | pulls = [await greenPull("First change"), await greenPull("Second change")]; | |
| 103 | }, 30_000); | |
| 104 | ||
| 105 | afterAll(async () => { | |
| 106 | await servers.stop(); | |
| 107 | app.close(); | |
| 108 | await rm(dataDir, { recursive: true, force: true }); | |
| 109 | }); | |
| 110 | ||
| 111 | test("a group row lists each change's number and title", async () => { | |
| 112 | const res = await fetch(`${servers.url}/api/v1/asks`, { headers: { authorization: `Bearer ${tokenFor(app, "alice", "ro")}` } }); | |
| 113 | const row = ((await res.json()) as any).rows.find((r: any) => r.id === `look:${plain.id}`); | |
| 114 | expect(row.items).toHaveLength(2); | |
| 115 | expect(row.changes.map((c: any) => [c.number, c.numberOf, c.title]).sort()).toEqual( | |
| 116 | pulls.map((p) => [p.number, "pull", p.title]).sort(), | |
| 117 | ); | |
| 118 | }); | |
| 119 | ||
| 120 | test("snooze: one ask leaves the queue on every door until it wakes", async () => { | |
| 121 | const lone = `look:${pulls[0]!.id}`; | |
| 122 | expect(rows().find((r) => r.id === "look:" + plain.id)?.items).toContain(lone); | |
| 123 | const done = await post("alice", `/api/v1/asks/${encodeURIComponent(lone)}/snooze`, { until: tomorrow() }); | |
| 124 | expect(done.status).toBe(201); | |
| 125 | expect(done.body.key).toBe(lone); | |
| 126 | expect(rows().flatMap((r) => r.items)).not.toContain(lone); | |
| 127 | expect(rows().flatMap((r) => r.items)).toContain(`look:${pulls[1]!.id}`); | |
| 128 | // The terminal's On you pane reads the same rows: a past snooze is over, and the ask is back. | |
| 129 | setAskSnooze(app.db, alice.id, lone, new Date(Date.now() - 1000).toISOString()); | |
| 130 | expect(askSnoozes(app.db, alice.id).has(lone)).toBe(false); | |
| 131 | expect(rows().flatMap((r) => r.items)).toContain(lone); | |
| 132 | }); | |
| 133 | ||
| 134 | test("snooze: a group's key puts the whole row away, and null wakes it", async () => { | |
| 135 | const group = `look:${plain.id}`; | |
| 136 | expect((await post("alice", `/api/v1/asks/${encodeURIComponent(group)}/snooze`, { until: tomorrow() })).status).toBe(201); | |
| 137 | expect(kinds()).not.toContain("look"); | |
| 138 | const woke = await post("alice", `/api/v1/asks/${encodeURIComponent(group)}/snooze`, { until: null }); | |
| 139 | expect(woke.status).toBe(201); | |
| 140 | expect(woke.body.until).toBeNull(); | |
| 141 | expect(kinds()).toContain("look"); | |
| 142 | }); | |
| 143 | ||
| 144 | test("snooze: a group's key holds the asks waiting when it was set; a change that asks later shows", async () => { | |
| 145 | const group = `look:${plain.id}`; | |
| 146 | expect((await post("alice", `/api/v1/asks/${encodeURIComponent(group)}/snooze`, { until: tomorrow() })).status).toBe(201); | |
| 147 | expect(kinds()).not.toContain("look"); | |
| 148 | const later = await greenPull("Third change"); | |
| 149 | // Alone in its row, the row carries the ask's own id. | |
| 150 | expect(rows().filter((r) => r.kind === "look").flatMap((r) => r.items)).toEqual([`look:${later.id}`]); | |
| 151 | expect((await post("alice", `/api/v1/asks/${encodeURIComponent(group)}/snooze`, { until: null })).status).toBe(201); | |
| 152 | expect(rows().find((r) => r.id === group)?.items).toHaveLength(3); | |
| 153 | }); | |
| 154 | ||
| 155 | test("snooze: refusals say why", async () => { | |
| 156 | const lone = encodeURIComponent(`look:${pulls[0]!.id}`); | |
| 157 | const past = await post("alice", `/api/v1/asks/${lone}/snooze`, { until: "2020-01-01" }); | |
| 158 | expect(past.status).toBe(422); | |
| 159 | expect(past.body.message).toBe(BAD_UNTIL); | |
| 160 | expect((await post("alice", `/api/v1/asks/${lone}/snooze`, { until: "soon" })).status).toBe(422); | |
| 161 | expect((await post("alice", `/api/v1/asks/${lone}/snooze`, {})).status).toBe(422); | |
| 162 | expect((await post("alice", "/api/v1/asks/look%3Anope/snooze", { until: tomorrow() })).status).toBe(404); | |
| 163 | expect((await post("alice", `/api/v1/asks/${lone}/snooze`, { until: tomorrow() }, "ro")).status).toBe(403); | |
| 164 | // Another person's key is no ask of theirs. | |
| 165 | expect((await post("bob", `/api/v1/asks/${lone}/snooze`, { until: tomorrow() })).status).toBe(404); | |
| 166 | expect(askSnoozes(app.db, alice.id).has(`look:${pulls[0]!.id}`)).toBe(false); | |
| 167 | }); | |
| 168 | ||
| 169 | test("until is read as an instant or a day, past or over a year refused", () => { | |
| 170 | const now = new Date("2026-12-03T10:00:00Z"); | |
| 171 | expect(parseSnoozeUntil("2026-12-05", now)).toEqual({ ok: true, value: "2026-12-05T00:00:00.000Z" }); | |
| 172 | expect(parseSnoozeUntil("2026-12-03T12:30:00+02:00", now)).toEqual({ ok: true, value: "2026-12-03T10:30:00.000Z" }); | |
| 173 | for (const bad of ["2026-12-03T09:00:00Z", "2026-02-30", "2028-01-01", 5, null, "tomorrow"]) | |
| 174 | expect(parseSnoozeUntil(bad, now)).toEqual({ ok: false, error: BAD_UNTIL }); | |
| 175 | }); | |
| 176 | ||
| 177 | test("the terminal's snooze is the same action: it needs a person who is asked", () => { | |
| 178 | expect(snoozeAsk(app, undefined, `look:${pulls[0]!.id}`, tomorrow()).ok).toBe(false); | |
| 179 | expect(snoozeAsk(app, alice, `look:${pulls[0]!.id}`, tomorrow()).ok).toBe(true); | |
| 180 | expect(snoozeAsk(app, alice, `look:${pulls[0]!.id}`, null).ok).toBe(true); | |
| 181 | }); | |
| 182 | ||
| 183 | test("a planner's decline is dismissed in bulk, and undo asks again", async () => { | |
| 184 | expect(kinds()).toContain("declined"); | |
| 185 | const done = await post("alice", "/api/v1/asks/bulk", { action: "dismiss", items: [`declined:${runId}`], preview: false }); | |
| 186 | expect(done.status).toBe(201); | |
| 187 | expect(done.body.skipped).toEqual([]); | |
| 188 | expect(kinds()).not.toContain("declined"); | |
| 189 | const undo = await post("alice", `/api/v1/asks/bulk/${done.body.id}/undo`, {}); | |
| 190 | expect(undo.status).toBe(201); | |
| 191 | expect(kinds()).toContain("declined"); | |
| 192 | }); | |
| 193 | ||
| 194 | test("a dismissed decline holds for the issue until the planner declines it again", async () => { | |
| 195 | const done = await post("alice", "/api/v1/asks/bulk", { action: "dismiss", items: [`declined:${runId}`], preview: false }); | |
| 196 | expect(done.status).toBe(201); | |
| 197 | expect(kinds()).not.toContain("declined"); | |
| 198 | const again = createRun(app.db, { repoId: repo.id, kind: "agent", issueId: direction.id, reason: "planning" }); | |
| 199 | claimRun(app.db, again.id); | |
| 200 | finishRun(app.db, again.id, { state: "failed", summary: "declined: still nothing to plan" }); | |
| 201 | expect(rows().filter((r) => r.kind === "declined").flatMap((r) => r.items)).toEqual([`declined:${again.id}`]); | |
| 202 | }); | |
| 203 | ||
| 204 | describe("a paused ask", () => { | |
| 205 | const paused = () => `paused:${repo.id}`; | |
| 206 | let subId = ""; | |
| 207 | ||
| 208 | beforeAll(() => { | |
| 209 | const added = addSubscription(app.db, dataDir, { name: "acct", token: "sk-ant-oat01-" + "a".repeat(40) }); | |
| 210 | if (!added.ok) throw new Error(String(added.error)); | |
| 211 | subId = added.value.id; | |
| 212 | setGrants(app.db, repo.id, "", [subId]); | |
| 213 | setCapacity(app.db, "week.use", "50", alice.id, "for the test"); | |
| 214 | noteMeasure(app.db, added.value.id, { window: "week", usedPct: 55, resetsAt: new Date(Date.now() + 86_400_000).toISOString(), observedAt: new Date().toISOString() }); | |
| 215 | forgetWeek(); | |
| 216 | }); | |
| 217 | ||
| 218 | test("the pause is an ask; a person who is not a forge admin may not raise it", async () => { | |
| 219 | expect(rows().map((r) => r.id)).toContain(paused()); | |
| 220 | // Bob is not asked by the pause (an owner's fact), and the route is an admin's. | |
| 221 | expect(raisePausedAsk(app, bob, paused()).ok).toBe(false); | |
| 222 | expect((await post("bob", "/api/v1/asks/raise", { item: paused() })).status).toBe(403); | |
| 223 | expect(weekUse(app.db)).toBe(50); | |
| 224 | }); | |
| 225 | ||
| 226 | test("an ask that is not a pause is not raised", async () => { | |
| 227 | expect((await post("alice", "/api/v1/asks/raise", { item: `look:${plain.id}` })).status).toBe(404); | |
| 228 | expect((await post("alice", "/api/v1/asks/raise", {})).status).toBe(404); | |
| 229 | expect((await post("alice", "/api/v1/asks/raise", { item: paused() }, "ro")).status).toBe(403); | |
| 230 | }); | |
| 231 | ||
| 232 | test("a forge admin's Raise adds ten points and the pause lifts; at the whole week it says so", async () => { | |
| 233 | const done = await post("alice", "/api/v1/asks/raise", { item: paused() }); | |
| 234 | expect(done.status).toBe(201); | |
| 235 | expect(done.body).toEqual({ item: paused(), from: 50, to: 60 }); | |
| 236 | expect(weekUse(app.db)).toBe(60); | |
| 237 | forgetWeek(); | |
| 238 | expect(rows().map((r) => r.id)).not.toContain(paused()); | |
| 239 | setCapacity(app.db, "week.use", "100", alice.id, "for the test"); | |
| 240 | // 55% used of the whole week is not a pause: the ask is gone, so there is nothing to raise. | |
| 241 | expect(raisePausedAsk(app, alice, paused()).ok).toBe(false); | |
| 242 | noteMeasure(app.db, subId, { window: "week", usedPct: 100, resetsAt: new Date(Date.now() + 86_400_000).toISOString(), observedAt: new Date().toISOString() }); | |
| 243 | forgetWeek(); | |
| 244 | const full = raisePausedAsk(app, alice, paused()); | |
| 245 | expect(full.ok ? "" : full.error.message).toBe(AT_WHOLE_WEEK); | |
| 246 | }); | |
| 247 | }); | |
| 248 | }); |
test/tui-onyou.test.ts +23
| @@ -13,6 +13,7 @@ import { assignIssue, openIssue } from "../src/actions/issues.ts"; | ||
| 13 | 13 | import { createRepo } from "../src/actions/repos.ts"; |
| 14 | 14 | import { signUp } from "../src/actions/users.ts"; |
| 15 | 15 | import { createApp, type App as Forge } from "../src/app.ts"; |
| 16 | import { askSnoozes } from "../src/core/ask_snooze.ts"; | |
| 16 | 17 | import { askFiltersOf } from "../src/core/ask_filters.ts"; |
| 17 | 18 | import { chipsOf, setChip } from "../src/core/feed_chips.ts"; |
| 18 | 19 | import { createIssue, getIssue } from "../src/core/issues.ts"; |
| @@ -125,6 +126,28 @@ describe("terminal On you: mutes and many in one move", () => { | ||
| 125 | 126 | h.stop(); |
| 126 | 127 | }); |
| 127 | 128 | |
| 129 | test("z snoozes the marked rows by their own ask ids: they leave the pane and the toast counts them (#17960)", async () => { | |
| 130 | const one = issueIn(lamp, "Snooze one"); | |
| 131 | const two = issueIn(lamp, "Snooze two"); | |
| 132 | const keep = issueIn(lamp, "Snooze kept"); | |
| 133 | const h = await boot(); | |
| 134 | expect(h.text()).toContain("Snooze one"); | |
| 135 | await h.press("v", "j", "v"); | |
| 136 | await h.press("z"); | |
| 137 | expect(h.text()).toContain("snoozed 2 until tomorrow"); | |
| 138 | const ids = [one, two, keep].map((i) => i.id); | |
| 139 | const woken = [...askSnoozes(forge.db, alice.id).keys()]; | |
| 140 | const snoozedIds = ids.filter((id) => woken.some((k) => k.endsWith(`:${id}`))); | |
| 141 | expect(woken.length).toBe(2); | |
| 142 | expect(snoozedIds.length).toBe(2); | |
| 143 | for (const i of [one, two, keep]) { | |
| 144 | expect(h.text().includes(i.title)).toBe(!snoozedIds.includes(i.id)); | |
| 145 | } | |
| 146 | h.stop(); | |
| 147 | for (const i of [one, two, keep]) forge.db.run("DELETE FROM issue WHERE id = ?", [i.id]); | |
| 148 | forge.db.run("DELETE FROM ask_snooze"); | |
| 149 | }); | |
| 150 | ||
| 128 | 151 | test("mute hides the repository, says so, and listen again brings it back", async () => { |
| 129 | 152 | issueIn(vault, "Vault door sticks"); |
| 130 | 153 | const h = await boot(); |
new above
offline
The route answers 422 for a bad
untilbutrefusesomits it, so the contract is incomplete for a client. Declare it or make the probe able to hit it.