diff --git a/docs/DESIGN.md b/docs/DESIGN.md index e5600f0c..998ffd54 100644 --- a/docs/DESIGN.md +++ b/docs/DESIGN.md @@ -621,6 +621,7 @@ Exit codes: 0 ok, 3 nothing live, 64 usage, 65 a vocabulary term fails validatio | `GET /calls/{id\|live\|last}` | Header, parts, roster, health, final state. `live` gives 404 `no_live_call {last}` when nothing is recording | | `PATCH /calls/{id\|live\|last}` `{title?, workspace?}` | Renames the call at any time with a `call.renamed` event, and an export akou wrote takes the new name; 422 on an empty title, and the old name stays. `workspace` moves a finished call's folder into that workspace and writes `call.moved`; 409 `live_call` while it records | | `DELETE /calls/{id}` · `POST /calls/{id}/restore` | Moves a finished call to `.trash//` under the recordings folder, out of every list, deleted for good at the first start after 30 days; 409 `live_call` while it records. Restore brings it back to its workspace unchanged | +| `GET /trash` · `DELETE /trash` | The calls in the trash, newest first; Empty trash deletes every one for good at once, through the same purge as the start, and touches nothing outside `.trash/` | | `PATCH /calls/{id}/segments/{sid}` `{spk}` | Who spoke one line: `seg rev+1` with the new `spk` and `by`; the text, its raw form and every earlier revision stay. 422 for a microphone line. The words of a line are fixed with `POST /calls/{id}/fix` | | `POST /calls/{id}/{stop,pause,resume,mute,unmute,restart}` | Controls. `restart` takes `{force}` | | `GET /calls/{id}/events?after=SEQ&wait=25` | Raw log, long-poll | diff --git a/docs/TRAPS.md b/docs/TRAPS.md index 7896dd7f..d0bc7a69 100644 --- a/docs/TRAPS.md +++ b/docs/TRAPS.md @@ -213,6 +213,7 @@ Every number here comes from our vocabulary measurements: a synthetic TTS set an - **What macOS WebKit does differently with buttons and an early pause** [WK-3] (M1). Given macOS WebKit never focuses a button on a click, and moves Tab only between text fields unless the user turned on Keyboard navigation (Option+Tab reaches buttons either way), a test must not take a click to leave focus on the button it clicked; it puts the focus there itself. Given that in its first few hundred ms of playback macOS WebKit reports a position ahead of what it has played, and a pause there drops the position back to it (as far as 0), a test of pause and resume lets the line play past its first second first. Neither is an akou bug. Test: the W5.2 Space test and the W5.6 PageUp test; the `ui (webkit, macOS)` job runs the player bar tests in macOS WebKit. - **A redraw that drops the selection** [W4.9, CI flake] (M1). Given a line on screen is drawn again with the same text, setting its `.text` element's `textContent` anyway replaces the text node, and a selection inside it goes with it. The stream sends the app's `read` for the corrected lines on its own 250 ms tick, so after a fix (or any vocabulary change) both lines it corrected are redrawn about 150 ms later, whatever the user is doing. A double-click whose second press lands before that redraw and whose release lands after it selects nothing: WebKit fires no `dblclick` and Chromium fires one with an empty selection, so the fix never opens. That failed `tests/ui/fix-word.test.ts` three times in about 290 `ui (webkit)` runs from 2026-10-24 to 2026-10-31, each time as `waitForSelector('#popover .fix-learned')` timing out on a double-click made within a second of a fix; the Mac never showed it (0 in 120 runs). `fillRow` sets the text only when it changed. Test: `[W4.9] a line the stream redraws mid double-click keeps the word, and the fix still opens` holds the second press while a word is added to the vocabulary file, waits for the `read` it sends, and checks that the same text node is still there and the fix opens with the word selected; the positive control replaces the text node during the press, as the old redraw did, and nothing opens. - **An Undo the next message takes away** [W13.3] (M1). Given the window had one `#toast` element and every message rewrote it, a second Move to Trash, a copy or an error within 10 s of a Move to Trash removed that call's Undo button long before its 10 s were up; the window has no Trash page yet, so the call could then come back only through the API or the file manager. A fix's Undo (W4.8) went the same way. akou must move an Undo that a newer message would replace into `#toast-held`, where it stays for what is left of its own 10 s and still works, and must not bring back an Undo whose time is up. Test: `[W13.3] a second toast inside the Undo's 10 s moves the first Undo aside` in `tests/ui/call-menu.test.ts` trashes two calls and restores the first from the held Undo, then the second from its own; the single rewritten `#toast` is the positive control and finds no held Undo. +- **A trash that frees no space** [TRASH-1] (M1). Given a call moved to the Trash only goes to `.trash/` under the recordings folder, which Finder hides, and the purge ran only at the start of akou for calls trashed 30 days before, deleting calls to free a full disk freed nothing, and an app that ran for weeks kept even older ones. akou must offer Empty trash on every door: `DELETE /trash` (with `GET /trash` to count what is there), `akou calls empty-trash` (it asks on a terminal and needs `--yes` elsewhere) and Empty Trash… in a call row's menu, which asks first, naming how many calls go and that it cannot be undone. Only the calls the question counted go: the window and the CLI send `upTo`, the newest `trashedAt` of the `GET /trash` they asked about, so a call trashed while the question is open stays, with its Undo. It runs the same purge the start runs, with no age limit, and touches only folders under `.trash/`. Test: `tests/empty-trash.e2e.test.ts` `[TRASH-1]` trashes calls (one today, one 10 days before) and empties them over the API and the CLI; the call never trashed stays listed with its folder byte for byte, a live call stays recording, and the trashed folders are on disk before the empty as the positive control; a call trashed after the `GET /trash` stays through `DELETE /trash?upTo=` and through the CLI's question, and goes with a bare `DELETE /trash` as the positive control. `tests/ui/call-menu.test.ts` `[TRASH-1]` asks, keeps the calls on Dismiss, and on Empty Trash deletes only them, not a call trashed while the question was open. ## Kept from closed traps, as invariants diff --git a/docs/api/openapi.json b/docs/api/openapi.json index b59343ec..17a73516 100644 --- a/docs/api/openapi.json +++ b/docs/api/openapi.json @@ -47,6 +47,9 @@ { "name": "segments" }, + { + "name": "trash" + }, { "name": "devices" }, @@ -1432,7 +1435,7 @@ "tags": [ "calls" ], - "description": "Move a finished call to the trash: its folder goes to `.trash/` under the recordings folder, no list shows it, and it is deleted for good after 30 days. A call that is recording answers 409 `live_call`. Exports already written are the user's and stay. `POST /calls/{id}/restore` brings it back.", + "description": "Move a finished call to the trash: its folder goes to `.trash/` under the recordings folder, no list shows it, and it is deleted for good at the first start of akou after 30 days, or at once by `DELETE /trash`. A call that is recording answers 409 `live_call`. Exports already written are the user's and stay. `POST /calls/{id}/restore` brings it back.", "parameters": [ { "name": "id", @@ -1655,6 +1658,103 @@ "x-akou-access": "admin" } }, + "/v1/trash": { + "get": { + "operationId": "trash.list", + "tags": [ + "trash" + ], + "description": "The calls in the trash, newest first: each one's `id`, the `workspace` it came from and `trashedAt` (ms). `POST /calls/{id}/restore` brings one back; `DELETE /trash` deletes them all for good.", + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "type": "object" + } + } + } + }, + "401": { + "$ref": "#/components/responses/401.unauthorized" + }, + "403": { + "$ref": "#/components/responses/403.bad_host.browser_request.forbidden" + }, + "413": { + "$ref": "#/components/responses/413.body_too_large" + }, + "500": { + "$ref": "#/components/responses/500.internal" + }, + "default": { + "$ref": "#/components/responses/Error" + } + }, + "x-akou-modes": [ + "app" + ], + "x-akou-access": "admin" + }, + "delete": { + "operationId": "trash.empty", + "tags": [ + "trash" + ], + "description": "Empty the trash: every call in it is deleted for good now, folder and audio, instead of 30 days after it was trashed. This cannot be undone. Calls that are not in the trash are never touched, and exports already written stay. With `upTo`, only the calls trashed at that time or before go, so a client that asked about the calls of a `GET /trash` deletes only those. Answers how many calls were deleted.", + "parameters": [ + { + "name": "upTo", + "in": "query", + "required": false, + "description": "Delete only the calls trashed at this time (ms) or before: the newest `trashedAt` of the `GET /trash` the user was asked about. Default: all of them.", + "schema": { + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + } + } + ], + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "type": "object" + } + } + } + }, + "400": { + "$ref": "#/components/responses/400.bad_param" + }, + "401": { + "$ref": "#/components/responses/401.unauthorized" + }, + "403": { + "$ref": "#/components/responses/403.bad_host.browser_request.forbidden" + }, + "413": { + "$ref": "#/components/responses/413.body_too_large" + }, + "415": { + "$ref": "#/components/responses/415.json_required" + }, + "500": { + "$ref": "#/components/responses/500.internal" + }, + "default": { + "$ref": "#/components/responses/Error" + } + }, + "x-akou-modes": [ + "app" + ], + "x-akou-access": "admin" + } + }, "/v1/calls/{id}/stop": { "post": { "operationId": "calls.stop", diff --git a/docs/cli.md b/docs/cli.md index 04dd7597..e1c4ceda 100644 --- a/docs/cli.md +++ b/docs/cli.md @@ -161,20 +161,24 @@ example: akou open last ## calls ```text -akou calls: List calls by date, title and duration (no content search), or rename one +akou calls: List calls by date, title and duration (no content search), rename one, or empty the trash -usage: akou calls [-w WORKSPACE] [--limit N] [--failed] [--json] | akou calls rename CALL TITLE… [--json] +usage: akou calls [-w WORKSPACE] [--limit N] [--failed] [--json] | akou calls rename CALL TITLE… [--json] | akou calls empty-trash [--yes] [--json] -w, --workspace WS only calls in this workspace --limit N at most N calls, newest first --failed only calls whose start failed (nothing was recorded), instead of the others -c, --call CALL live, last or a call id (default: none; name one) + --yes with empty-trash: delete without asking (needed when stdin is not a terminal) --json print the answer as JSON, errors included -h, --help show this help --restart if akou takes the connection and never answers, restart it first, even for a command that only reads +calls empty-trash deletes every call in the trash for good, now, instead of 30 days after it was trashed; it cannot be undone. On a terminal it asks first; elsewhere it needs --yes. + example: akou calls -w work --limit 5 example: akou calls rename last Weekly sync +example: akou calls empty-trash --yes ``` ## workspaces @@ -940,6 +944,7 @@ example: akou serve | List calls | `calls` | `GET /calls` | `akou_list_calls` | `src/ui/app.ts` | | Rename a call | `calls` | `PATCH /calls/:id` | `akou_rename_call` | `src/ui/app.ts` | | Trash and restore a call | none: missing: CLI-26 adds calls delete and calls restore | `DELETE /calls/:id`, `POST /calls/:id/restore` | none: missing: PG-M4 names move, delete and restore (CLI.md doors table) | `src/ui/app.ts` | +| Empty the trash: delete trashed calls for good, now | `calls` | `GET /trash`, `DELETE /trash` | none: deleting calls for good is the user's, behind a confirmation; PG-M4 names no tool for it | `src/ui/app.ts` | | Change who spoke one line | none: missing: CLI-29 adds edit SEG --speaker | `PATCH /calls/:id/segments/:sid` | none: no tool yet, and no design item names one | none: missing: W4.10 adds the speaker picker on a line | | List and add workspaces | `workspaces`, `workspace` | `GET /workspaces`, `POST /workspaces` | none: not one call's: akou_start names the workspace and makes its folder, and akou_list_calls shows each call's | `src/ui/workspaces.ts` | | Share a live link | `share` | `GET /share`, `POST /share`, `DELETE /share` | `akou_share_on`, `akou_share_off`, `akou_share_status` | `src/ui/app.ts` | diff --git a/docs/ux/CLI.md b/docs/ux/CLI.md index 5870fc52..91b71d93 100644 --- a/docs/ux/CLI.md +++ b/docs/ux/CLI.md @@ -74,7 +74,7 @@ The tree stays flat: one verb per action, with subcommands only where a noun has | During the call | `name SPK NAME` · `name --merge A B` · `name --unmerge SPK` · `note "TEXT"` · `note --edit ID "TEXT"` · `note --del ID` · `remember "TEXT"` · `remember --del ID` · `mark [LABEL]` **new** (CLI-34) | has, except `mark` | | Vocabulary | `vocab list\|add\|fix\|remove\|approve\|reject\|suggest\|check\|import\|pass` | has | | After the call | `enhance [--template T]` · `finalize [CALL] [--force] [--engine E]` · `export [CALL] [--to DIR]` · `hooks run CALL [--stage S]` · `hooks test` **new** (PG-H2) · `show CALL [--layer best\|live\|final] [--format md\|json\|txt]` | has, except `--engine` (TRN-16) and `hooks test` | -| Calls | `calls [-w WS] [--limit N] [--failed]` · `calls rename CALL TITLE…` · `calls move\|delete\|restore CALL …` **new** (CLI-26) · `workspaces` · `workspace add NAME` · `import hark-viewer DIR… [-w WS]` | has, except `move`, `delete` and `restore` | +| Calls | `calls [-w WS] [--limit N] [--failed]` · `calls rename CALL TITLE…` · `calls empty-trash [--yes]` · `calls move\|delete\|restore CALL …` **new** (CLI-26) · `workspaces` · `workspace add NAME` · `import hark-viewer DIR… [-w WS]` | has, except `move`, `delete` and `restore` | | Share | `share on\|off\|status [-c CALL] [--bind tailnet\|lan\|IP] [--notes] [--expires 3h]` | has | | Setup | `config show\|get\|set\|unset\|path` · `models list\|pull [PRESET\|MODEL]\|delete MODEL\|import\|select` (`pull` and `import` need no running app, SV-P3; `delete` asks the running akou, which refuses the default model and one in use) · `devices` · `apps` · `templates list\|show` (PG-F3) · `token path\|rotate` · `doctor [--grant] [--capture-test]` · `demo [--clean]` **new** (SET-10) · `completion SHELL` **new** (CLI-08) | partial: `devices` and `apps` exit 69 "not built"; no `get`, `path`, `models select` (SET-06), `doctor --capture-test` (DK-O1), `demo`, `completion` | | Dictation | `dictate FILE [--engine E] [--language L]` **new** (DICTATION.md DC-G3: a clip through the dictation path) · `dictate start\|stop\|toggle\|cancel` · `dictations list\|show\|retry\|delete` **new** (DC-G3) | has every command in this row ([dictate.ts](../../src/main/cli/commands/dictate.ts)) | diff --git a/docs/ux/WINDOW.md b/docs/ux/WINDOW.md index 47609138..707d5cf4 100644 --- a/docs/ux/WINDOW.md +++ b/docs/ux/WINDOW.md @@ -402,7 +402,7 @@ The sidebar is the window's left column, the full height of the window: the word |---|---|---|---|---|---| | W13.1 | The sidebar's calls: grouped by workspace, each group folding with the mouse or the keyboard and showing its count; newest first inside a group, the live call on top with a red dot, the group with the newest call first; each row the title and a line with the day (Today, Yesterday, the weekday within a week, then the date), the local start time and how long it ran ("live", "failed"); a search that narrows the list by title or workspace as you type, never by what was said, and Escape or clearing it brings every group back; switch without reload | done | DESIGN 7; design-explorations | `tests/ui/parity.test.ts` "Sidebar list of calls by workspace and day…", with a positive control on the search; `tests/ui-model.test.ts` "the calls list" | has | | W13.2 | Rename a call and move it to another workspace | P1 | Audit: no rename anywhere | Rename goes through PG-A4 and writes a `call.renamed` event (W3.16); moving a call to another workspace moves its folder; the export file is found again by `akou_id` and renamed on the next export | partial: rename (W3.16) and move from a call row's menu (right-click, `Shift+F10` or the Menu key: Rename…, Move to workspace…), `tests/ui/call-menu.test.ts` "[W13.2]"; the export's new file name missing | -| W13.3 | Delete a call to the Trash, restore from it, empty it now | P1 | Granola, Minutes; audit: no delete in any surface | Delete follows PG-A4 (refused for a live call, folder moved to `trash/`, purged after 30 days); the call leaves the list; Restore brings it back intact; "Empty trash now" asks for confirmation. Exports already written are the user's and are not touched | partial: Move to Trash from a call row's menu ([dark](design-explorations/built/calls-row-menu-dark.png)), the row gone at once and Undo for 10 s (`POST /calls/{id}/restore`); a recording call's item stays, greyed with the reason; the sidebar selects no text and never shows the webview's own menu, `tests/ui/call-menu.test.ts` "[W13.3]". A Trash page to restore from later and "Empty trash now" are missing: the API has no list of the trash and no empty | +| W13.3 | Delete a call to the Trash, restore from it, empty it now | P1 | Granola, Minutes; audit: no delete in any surface | Delete follows PG-A4 (refused for a live call, folder moved to `trash/`, purged after 30 days); the call leaves the list; Restore brings it back intact; "Empty trash now" asks for confirmation. Exports already written are the user's and are not touched | partial: Move to Trash from a call row's menu ([dark](design-explorations/built/calls-row-menu-dark.png)), the row gone at once and Undo for 10 s (`POST /calls/{id}/restore`); a recording call's item stays, greyed with the reason; the sidebar selects no text and never shows the webview's own menu, `tests/ui/call-menu.test.ts` "[W13.3]". Empty Trash… in the same menu asks first, naming how many calls go and that it cannot be undone, then deletes them for good (`GET /trash`, `DELETE /trash`), `tests/ui/call-menu.test.ts` "[TRASH-1]". A Trash page to restore from later is missing | | W13.4 | Suggested title for a call started without one, applied only on the user's yes | P2 | heed | After the final pass, an untitled call shows "Title: Budget review? Use it" | missing | | W13.6 | Open on a workspace: `akou open -w WS`, `POST /window {workspace}` and the page's `?workspace=` put that workspace first in the picker, even before any call is filed under it | P2 | hark-viewer `?workspace=` (carried) | Opening with `?workspace=ops` on an empty home shows "ops" selected in the picker; Record starts a call in it | missing | | W13.7 | The main panes (the calls list, the transcript, the notes) share one scrollbar: thin, hidden at rest, shown on hover or while scrolled by hand, then it fades; its gutter is always kept, so the calls never narrow when the list starts to scroll and line up with the rows under it ([before](design-explorations/built/calls-list-before-dark.png), [at rest](design-explorations/built/calls-list-after-rest-dark.png), [on hover](design-explorations/built/calls-list-after-hover-dark.png)) | done | Owner: the default bar always showed and took the rows' width | `tests/ui/window.test.ts` "[W13.7]": the calls keep the width of the rows under them, no pane shows a bar at rest, a scroll the code makes shows nothing, hover and a wheel scroll show it and it goes after | has | diff --git a/src/main/api/routes/calls.ts b/src/main/api/routes/calls.ts index c713468b..def32090 100644 --- a/src/main/api/routes/calls.ts +++ b/src/main/api/routes/calls.ts @@ -8,7 +8,8 @@ * The live controls refuse `last` with 400; `restart` and a rename accept it. `PATCH /calls/{id}` * renames a call at any time, live or saved, with a `call.renamed` event, and moves a finished one * to another workspace with `call.moved`. `DELETE /calls/{id}` moves a finished call to the trash - * and `POST /calls/{id}/restore` brings it back (PROGRAMMABILITY PG-A4). + * and `POST /calls/{id}/restore` brings it back (PROGRAMMABILITY PG-A4); `GET /trash` lists the + * trash and `DELETE /trash` empties it for good (WINDOW W13.3). */ import { formatWall } from "../../../core/log/clock.ts"; @@ -483,7 +484,7 @@ export function callRoutes(r: Router): void { "/calls/:id", { id: "calls.delete", - doc: "Move a finished call to the trash: its folder goes to `.trash/` under the recordings folder, no list shows it, and it is deleted for good after 30 days. A call that is recording answers 409 `live_call`. Exports already written are the user's and stay. `POST /calls/{id}/restore` brings it back.", + doc: "Move a finished call to the trash: its folder goes to `.trash/` under the recordings folder, no list shows it, and it is deleted for good at the first start of akou after 30 days, or at once by `DELETE /trash`. A call that is recording answers 409 `live_call`. Exports already written are the user's and stay. `POST /calls/{id}/restore` brings it back.", access: "admin", modes: ["app"], params: { id: CALL_ID }, @@ -518,6 +519,41 @@ export function callRoutes(r: Router): void { }, ); + r.add( + "GET", + "/trash", + { + id: "trash.list", + doc: "The calls in the trash, newest first: each one's `id`, the `workspace` it came from and `trashedAt` (ms). `POST /calls/{id}/restore` brings one back; `DELETE /trash` deletes them all for good.", + access: "admin", + modes: ["app"], + ok: 200, + }, + async (c) => json(200, { calls: await c.app.manager.trashList() }), + ); + + r.add( + "DELETE", + "/trash", + { + id: "trash.empty", + doc: "Empty the trash: every call in it is deleted for good now, folder and audio, instead of 30 days after it was trashed. This cannot be undone. Calls that are not in the trash are never touched, and exports already written stay. With `upTo`, only the calls trashed at that time or before go, so a client that asked about the calls of a `GET /trash` deletes only those. Answers how many calls were deleted.", + access: "admin", + modes: ["app"], + query: { + upTo: { + type: "integer", + min: 0, + max: Number.MAX_SAFE_INTEGER, + doc: "Delete only the calls trashed at this time (ms) or before: the newest `trashedAt` of the `GET /trash` the user was asked about. Default: all of them.", + }, + }, + ok: 200, + }, + async (c) => + json(200, { ok: true, deleted: await c.app.manager.emptyTrash(c.query.int("upTo")) }), + ); + for (const name of LIVE_CONTROLS) { r.add( "POST", diff --git a/src/main/call/manager.ts b/src/main/call/manager.ts index 9f5ef003..93a58f35 100644 --- a/src/main/call/manager.ts +++ b/src/main/call/manager.ts @@ -14,8 +14,9 @@ * on a finished call (TRAPS T3.14). `last` never names a failed start. * - **Move, trash, restore (PROGRAMMABILITY PG-A4).** A finished call's folder moves to another * workspace's folder, or to the trash, `/.trash//` with a - * `.json` beside it saying when; `init()` purges what has been there 30 days. A restore - * moves the folder back, untouched. A live or busy call never moves. + * `.json` beside it saying when; `init()` purges what has been there 30 days, and + * `emptyTrash()` purges all of it at once. A restore moves the folder back, untouched. A live or + * busy call never moves. */ import { @@ -23,7 +24,6 @@ import { mkdirSync, readdirSync, readFileSync, - renameSync, rmSync, statSync, writeFileSync, @@ -37,6 +37,7 @@ import { legacyLive } from "../asr/live-setups.ts"; import { type CaptureEngine, type Clock, realClock } from "../capture/engine.ts"; import type { IngestOptions, PartIngest } from "../capture/ingest.ts"; import type { Packet } from "../capture/protocol.ts"; +import { renameReplacing } from "../vocab/files.ts"; import { CallController, type CaptureChoice, type StartOk } from "./call.ts"; import { checkWorkspace, createCallFolderAsync, ulid } from "./folder.ts"; import { @@ -131,7 +132,7 @@ export const TRASH_DIR = ".trash"; export const TRASH_DAYS = 30; /** What the trash keeps beside a trashed call's folder. */ -interface Trashed { +export interface Trashed { id: string; workspace: string; trashedAt: number; @@ -684,7 +685,9 @@ export class CallManager { } mkdirSync(parent, { recursive: true }); try { - renameSync(s.dir, dir); + // On Windows a folder does not move while a reader (the start's final catch-up, a GET) has + // a file in it open; that lasts a moment, so the rename is retried as a file replace is. + await renameReplacing(s.dir, dir); } catch (err) { return fail(409, "busy", `the call's folder cannot move now: ${(err as Error).message}`, { call: id, @@ -740,22 +743,43 @@ export class CallManager { const dir = join(this.o.root, t.workspace, basename(t.dir)); if (existsSync(dir)) return fail(409, "folder_taken", `${dir} already exists`, { call: id }); mkdirSync(join(this.o.root, t.workspace), { recursive: true }); - renameSync(t.dir, dir); + await renameReplacing(t.dir, dir); rmSync(`${t.dir}.json`, { force: true }); await this.reindex(dir, t.workspace); return { ok: true, dir, workspace: t.workspace }; } - /** Deletes what has been in the trash for `TRASH_DAYS` days. */ - private purgeTrash(): void { - const cutoff = this.clock.now() - TRASH_DAYS * 24 * 3600_000; + /** What is in the trash now, newest first: each call's id, its workspace and when it went. */ + async trashList(): Promise { + await this.init(); + return this.trashed() + .map(({ id, workspace, trashedAt }) => ({ id, workspace, trashedAt })) + .sort((a, b) => b.trashedAt - a.trashedAt); + } + + /** + * Empty trash: deletes every call in the trash for good, now, through the same purge the start + * runs after 30 days. With `upTo`, only calls trashed at that time or before go: the user was + * asked about those, and a call trashed since then stays. Only folders under `.trash/` are + * touched. Returns how many went. + */ + async emptyTrash(upTo = Number.POSITIVE_INFINITY): Promise { + await this.init(); + return this.purgeTrash(upTo); + } + + /** Deletes what has been in the trash since `cutoff` or before (`TRASH_DAYS` days by default). */ + private purgeTrash(cutoff = this.clock.now() - TRASH_DAYS * 24 * 3600_000): number { + let n = 0; for (const t of this.trashed()) { if (t.trashedAt > cutoff) continue; try { rmSync(t.dir, { recursive: true, force: true }); rmSync(`${t.dir}.json`, { force: true }); + n++; } catch {} } + return n; } /** The folder and workspace of a known call, loaded or not. */ diff --git a/src/main/cli/commands/calls.ts b/src/main/cli/commands/calls.ts index d64e18a7..bf1d8d55 100644 --- a/src/main/cli/commands/calls.ts +++ b/src/main/cli/commands/calls.ts @@ -8,7 +8,7 @@ import { processAlive } from "../../../core/log/writer.ts"; import { finalText } from "../../asr/final-text.ts"; import { shortModelName } from "../../asr/model-text.ts"; import { REVIEW_EVERY_MAX, REVIEW_EVERY_MIN } from "../../asr/upgrade.ts"; -import { bool, int, list, str } from "../args.ts"; +import { bool, int, list, type Parsed, str } from "../args.ts"; import { EXIT, Hung, StoppedHung, Unreachable } from "../client.ts"; import { healthWord } from "../color.ts"; import { @@ -19,6 +19,7 @@ import { callFlag, enc, finish, + type Keys, objectCall, ref, wall, @@ -241,11 +242,70 @@ function minutes(from: number, to: number | null): string { return `${Math.max(0, Math.round((to - from) / 60_000))} min`; } +const plural = (n: number) => `${n} call${n === 1 ? "" : "s"}`; + +/** A yes-or-no question asked on the terminal; any key but y is no. */ +async function askYes(ctx: Ctx, keys: Keys, question: string): Promise { + ctx.io.err(`${question} [y/N]`); + try { + for await (const chunk of keys.read()) return /^y/i.test(chunk); + return false; + } finally { + keys.close(); + } +} + +/** + * Empty trash (WINDOW W13.3): deletes every call in the trash for good. It asks on a terminal, and + * anywhere else needs `--yes`; without it, it only says how many calls the trash holds. + */ +async function emptyTrash(ctx: Ctx, p: Parsed): Promise { + if ( + p.positional.length > 1 || + str(p, "call") !== undefined || + str(p, "workspace") !== undefined + ) { + return usage( + ctx, + "calls empty-trash takes no call and no workspace: it empties the whole trash", + ); + } + // Only the calls the question counted go: one trashed while it waits for y stays (TRASH-1). + let path = "/trash"; + if (!bool(p, "yes")) { + const r = await api(ctx, "GET", "/trash"); + if (r.status !== 200) return finish(ctx, r, () => ""); + const listed = r.body.calls as Body[]; + const n = listed.length; + if (n === 0) return finish(ctx, r, () => "The trash is empty."); + path = `/trash?upTo=${Math.max(...listed.map((c) => c.trashedAt as number))}`; + const question = `Delete the ${plural(n)} in the trash for good? This cannot be undone.`; + const keys = ctx.json ? undefined : ctx.io.keys; + if (!keys) { + return usage( + ctx, + `the trash holds ${plural(n)}; calls empty-trash --yes deletes them for good, which cannot be undone`, + ); + } + if (!(await askYes(ctx, keys, question))) { + ctx.io.err("akou: nothing was deleted"); + return EXIT.ok; + } + } + const r = await api(ctx, "DELETE", path); + return finish(ctx, r, (b) => + b.deleted === 0 + ? "The trash is empty." + : `Deleted ${plural(b.deleted)} from the trash for good`, + ); +} + const calls: Command = { name: "calls", - summary: "List calls by date, title and duration (no content search), or rename one", + summary: + "List calls by date, title and duration (no content search), rename one, or empty the trash", usage: - "akou calls [-w WORKSPACE] [--limit N] [--failed] [--json] | akou calls rename CALL TITLE… [--json]", + "akou calls [-w WORKSPACE] [--limit N] [--failed] [--json] | akou calls rename CALL TITLE… [--json] | akou calls empty-trash [--yes] [--json]", flags: { workspace: { type: "string", short: "w", value: "WS", desc: "only calls in this workspace" }, limit: { type: "string", value: "N", desc: "at most N calls, newest first" }, @@ -254,10 +314,23 @@ const calls: Command = { desc: "only calls whose start failed (nothing was recorded), instead of the others", }, call: callFlag("none; name one"), + yes: { + type: "boolean", + desc: "with empty-trash: delete without asking (needed when stdin is not a terminal)", + }, }, - examples: ["akou calls -w work --limit 5", "akou calls rename last Weekly sync"], + notes: [ + "calls empty-trash deletes every call in the trash for good, now, instead of 30 days after it was trashed; it cannot be undone. On a terminal it asks first; elsewhere it needs --yes.", + ], + examples: [ + "akou calls -w work --limit 5", + "akou calls rename last Weekly sync", + "akou calls empty-trash --yes", + ], run: async (ctx, p) => { const [sub, ...rest] = p.positional; + if (sub === "empty-trash") return emptyTrash(ctx, p); + if (bool(p, "yes")) return usage(ctx, "--yes goes with calls empty-trash"); if (sub === "rename") { // The call is `-c CALL` or the first word; every word after it is the title. const call = str(p, "call") ?? rest.shift(); @@ -271,7 +344,8 @@ const calls: Command = { const r = await api(ctx, "PATCH", `/calls/${enc(call)}`, { body: { title } }); return finish(ctx, r, (b) => `${b.call} is now "${b.title}"`); } - if (sub !== undefined) return usage(ctx, `calls has no ${sub}; try: calls rename CALL TITLE`); + if (sub !== undefined) + return usage(ctx, `calls has no ${sub}; try: calls rename CALL TITLE, or calls empty-trash`); if (str(p, "call") !== undefined) { return usage(ctx, "-c names the call to rename: calls rename -c CALL TITLE"); } diff --git a/src/ui/app.ts b/src/ui/app.ts index f8f60911..819f92b4 100644 --- a/src/ui/app.ts +++ b/src/ui/app.ts @@ -1148,9 +1148,55 @@ class App { disabled: live ? "Stop the recording to move it to the Trash." : undefined, run: () => void this.trashCall(id), }, + { + id: "trash.empty", + label: "Empty Trash…", + danger: true, + run: () => void this.askEmptyTrash(), + }, ]; } + /** + * Empty Trash… (W13.3): asks first, naming how many calls go and that it cannot be undone, then + * deletes every call in the trash for good (`DELETE /trash`). Calls in the list are not touched. + */ + private async askEmptyTrash(): Promise { + const r = await this.t + .request<{ calls?: { trashedAt: number }[] }>("GET", "/trash") + .catch(() => null); + if (!r || r.status >= 400) { + toast(message(r?.body, "the Trash could not be read")); + return; + } + const listed = r.body.calls ?? []; + const n = listed.length; + if (n === 0) { + toast("The Trash is empty.", "info"); + return; + } + // Only the calls the question counts go: one trashed while it is open stays (TRASH-1). + const upTo = Math.max(...listed.map((c) => c.trashedAt)); + const calls = `${n} call${n === 1 ? "" : "s"}`; + this.confirm( + `Delete the ${calls} in the Trash for good? This cannot be undone.`, + "Empty Trash", + () => void this.emptyTrash(upTo), + ); + } + + private async emptyTrash(upTo: number): Promise { + const r = await this.t + .request<{ deleted?: number }>("DELETE", `/trash?upTo=${upTo}`) + .catch(() => null); + if (!r || r.status >= 400) { + toast(message(r?.body, "the Trash was not emptied")); + return; + } + const n = r.body.deleted ?? 0; + toast(`${n} call${n === 1 ? "" : "s"} deleted for good.`, "info"); + } + private async moveCall(id: string, workspace: string): Promise { const r = await this.t .request("PATCH", `/calls/${encodeURIComponent(id)}`, { workspace }) diff --git a/tests/contracts/parity.ts b/tests/contracts/parity.ts index d87e80bf..8bf4437b 100644 --- a/tests/contracts/parity.ts +++ b/tests/contracts/parity.ts @@ -370,6 +370,16 @@ export const PARITY: readonly Row[] = [ ], note: "Moving a call to another workspace is `PATCH /calls/:id {workspace}`, the rename row's route.", }, + { + action: "Empty the trash: delete trashed calls for good, now", + cli: ["calls"], + api: ["GET /trash", "DELETE /trash"], + mcp: { + none: "deleting calls for good is the user's, behind a confirmation; PG-M4 names no tool for it", + }, + window: [app('"GET", "/trash"'), app('"DELETE", `/trash?upTo=#{upTo}`')], + note: "`akou calls empty-trash` asks on a terminal and needs `--yes` elsewhere; the window asks first, naming how many calls go (W13.3).", + }, { action: "Change who spoke one line", cli: { none: "missing: CLI-29 adds edit SEG --speaker" }, diff --git a/tests/empty-trash.e2e.test.ts b/tests/empty-trash.e2e.test.ts new file mode 100644 index 00000000..fe3a3c07 --- /dev/null +++ b/tests/empty-trash.e2e.test.ts @@ -0,0 +1,272 @@ +/** + * Empty trash (docs/ux/WINDOW.md W13.3, TRAPS TRASH-1): every call in the trash deleted for good, + * now, over the API and the CLI, through the same purge the start runs after 30 days. A headless + * app with saved calls written before it starts; calls that are not in the trash are never touched. + */ + +import { afterAll, beforeAll, describe, expect, test } from "bun:test"; +import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs"; +import { join } from "node:path"; +import { TRASH_DIR } from "../src/main/call/manager.ts"; +import { runCli } from "../src/main/cli/cli.ts"; +import type { Io, Keys } from "../src/main/cli/context.ts"; +import { type AppRig, appRig } from "./api-helpers.ts"; +import { LogBuilder, T0, tempDir } from "./helpers.ts"; + +const DAY = 24 * 3600_000; +const KEEP = "01J8Z6Q4M2VX0K7B3D4E5TRSHKP"; +const GONE_A = "01J8Z6Q4M2VX0K7B3D4E5TRSHAA"; +const GONE_B = "01J8Z6Q4M2VX0K7B3D4E5TRSHBB"; +const EARLIER = "01J8Z6Q4M2VX0K7B3D4E5TRSHCC"; +/** Calls the CLI tests trash and empty. */ +const CLI_CALLS = [ + "01J8Z6Q4M2VX0K7B3D4E5TRSHD1", + "01J8Z6Q4M2VX0K7B3D4E5TRSHD2", + "01J8Z6Q4M2VX0K7B3D4E5TRSHD3", + "01J8Z6Q4M2VX0K7B3D4E5TRSHD4", +] as const; +/** Calls the `upTo` test trashes: one before the question is asked, one after. */ +const ASKED = "01J8Z6Q4M2VX0K7B3D4E5TRSHE1"; +const LATER = "01J8Z6Q4M2VX0K7B3D4E5TRSHE2"; + +/** A saved call under `//`. */ +function seed(root: string, workspace: string, folder: string, id: string, title: string): string { + const b = new LogBuilder(); + b.created({ id, title, workspace }, T0); + b.partStarted(1, T0); + b.seg({ id: "l000001", ch: "call", w0: T0 + 1000, text: `the ${title} line` }); + b.partEnded(1, "stop", 2); + b.add({ type: "call.ended", reason: "stop" }); + const dir = join(root, workspace, folder); + mkdirSync(join(dir, "audio"), { recursive: true }); + writeFileSync(join(dir, "audio", "part-001.opus"), "not really audio"); + writeFileSync( + join(dir, "events.jsonl"), + `${b.events.map((e) => JSON.stringify(e)).join("\n")}\n`, + ); + return dir; +} + +let rig: AppRig; +let home: { dir: string; cleanup: () => void }; +let kept: string; +const root = () => join(home.dir, "Recordings", "akou"); +const listed = async () => + ((await rig.api("GET", "/calls")).body.calls as { id: string }[]).map((c) => c.id); +const inTrash = async () => + ((await rig.api("GET", "/trash")).body.calls as { id: string }[]).map((c) => c.id); + +beforeAll(async () => { + home = tempDir("akou-empty-trash-"); + kept = seed(root(), "work", "2026-09-23_153612_keep", KEEP, "Keep me"); + seed(root(), "work", "2026-09-24_1000_aa", GONE_A, "Alpha"); + seed(root(), "hiring", "2026-09-24_1100_bb", GONE_B, "Beta"); + for (const [i, id] of CLI_CALLS.entries()) { + seed(root(), "work", `2026-09-25_100${i}_d${i}`, id, `Cli ${i}`); + } + seed(root(), "work", "2026-09-26_1000_e1", ASKED, "Asked"); + seed(root(), "work", "2026-09-26_1100_e2", LATER, "Later"); + // A call trashed 10 days ago, by an earlier run: inside the 30 days, so the start keeps it. + const earlier = seed(join(root(), TRASH_DIR), "work", "2026-09-01_0900_cc", EARLIER, "Earlier"); + writeFileSync( + `${earlier}.json`, + JSON.stringify({ id: EARLIER, workspace: "work", trashedAt: Date.now() - 10 * DAY }), + ); + // The seeded calls have no final layer, so the start would run their final passes one by one, + // and a call in its pass refuses the trash with 409 `busy`. Which call that is depends on the + // order the disk lists the folders in. No audio for the final pass: no pass starts. + rig = await appRig({ home: home.dir, finalAudio: () => null }); +}); + +afterAll(async () => { + await rig?.close(); + home?.cleanup(); +}); + +describe("[TRASH-1] Empty trash deletes trashed calls for good, now, and nothing else", () => { + test("GET /trash lists the trash, newest first; DELETE /trash empties it at once", async () => { + for (const id of [GONE_A, GONE_B]) { + expect((await rig.api("DELETE", `/calls/${id}`)).body).toEqual({ + ok: true, + call: id, + trashed: true, + }); + } + const trash = (await rig.api("GET", "/trash")).body.calls as { + id: string; + workspace: string; + trashedAt: number; + }[]; + expect(trash.map((c) => c.id).sort()).toEqual([EARLIER, GONE_A, GONE_B].sort()); + expect(trash.at(-1)).toMatchObject({ id: EARLIER, workspace: "work" }); + expect(trash.find((c) => c.id === GONE_B)?.workspace).toBe("hiring"); + // Positive control: the trashed folders are on disk before the empty, so their absence after + // means something; the call trashed today would wait 30 days without it. + const trashA = join(root(), TRASH_DIR, "work", "2026-09-24_1000_aa"); + const trashB = join(root(), TRASH_DIR, "hiring", "2026-09-24_1100_bb"); + const trashC = join(root(), TRASH_DIR, "work", "2026-09-01_0900_cc"); + for (const d of [trashA, trashB, trashC]) { + expect(existsSync(join(d, "events.jsonl"))).toBe(true); + expect(existsSync(`${d}.json`)).toBe(true); + } + const keptLog = readFileSync(join(kept, "events.jsonl"), "utf8"); + + const r = await rig.api("DELETE", "/trash"); + expect([r.status, r.body]).toEqual([200, { ok: true, deleted: 3 }]); + for (const d of [trashA, trashB, trashC]) { + expect(existsSync(d)).toBe(false); + expect(existsSync(`${d}.json`)).toBe(false); + } + expect(await inTrash()).toEqual([]); + // Gone for good: no restore brings one back. + expect((await rig.api("POST", `/calls/${GONE_A}/restore`)).status).toBe(404); + + // The call that was never trashed is untouched: listed, readable, its folder byte for byte. + expect((await listed()).sort()).toEqual([KEEP, ...CLI_CALLS, ASKED, LATER].sort()); + expect(readFileSync(join(kept, "events.jsonl"), "utf8")).toBe(keptLog); + expect(existsSync(join(kept, "audio", "part-001.opus"))).toBe(true); + expect((await rig.api("GET", `/calls/${KEEP}/transcript`)).text).toContain("the Keep me line"); + + // An empty trash empties to nothing. + expect((await rig.api("DELETE", "/trash")).body).toEqual({ ok: true, deleted: 0 }); + }); + + test("with upTo, a call trashed after the question was asked stays in the trash", async () => { + expect((await rig.api("DELETE", `/calls/${ASKED}`)).status).toBe(200); + // The question the user answers: what GET /trash held then. + const asked = (await rig.api("GET", "/trash")).body.calls as { trashedAt: number }[]; + expect(asked.length).toBe(1); + const upTo = Math.max(...asked.map((c) => c.trashedAt)); + await Bun.sleep(20); + // While the question is open, another call goes to the trash (its Undo still on screen). + expect((await rig.api("DELETE", `/calls/${LATER}`)).status).toBe(200); + + expect((await rig.api("DELETE", `/trash?upTo=${upTo}`)).body).toEqual({ ok: true, deleted: 1 }); + expect(await inTrash()).toEqual([LATER]); + // Its Undo still works. + expect((await rig.api("POST", `/calls/${LATER}/restore`)).status).toBe(200); + expect(await listed()).toContain(LATER); + + // A bad upTo deletes nothing. + expect((await rig.api("DELETE", `/calls/${LATER}`)).status).toBe(200); + expect((await rig.api("DELETE", "/trash?upTo=soon")).status).toBe(400); + expect(await inTrash()).toEqual([LATER]); + // Positive control: without upTo the same call goes, so its staying above was upTo's doing. + expect((await rig.api("DELETE", "/trash")).body).toEqual({ ok: true, deleted: 1 }); + expect(await inTrash()).toEqual([]); + }); + + test("a live call is never touched by an empty", async () => { + const live = await rig.startCall({ title: "Live one" }); + try { + expect((await rig.api("DELETE", "/trash")).body).toEqual({ ok: true, deleted: 0 }); + expect((await rig.api("GET", `/calls/${live}`)).body.state).toBe("recording"); + } finally { + await rig.api("POST", "/calls/live/stop"); + } + expect(await listed()).toContain(live); + }, 30_000); +}); + +/** A terminal that answers the question with `answer`, and records that it was asked. */ +function terminal( + answer: string, + meanwhile?: () => Promise, +): Keys & { asked: boolean; closed: boolean } { + const k = { + asked: false, + closed: false, + columns: () => 80, + close() { + k.closed = true; + }, + async *read() { + k.asked = true; + await meanwhile?.(); + yield answer; + }, + }; + return k; +} + +describe("[TRASH-1] akou calls empty-trash", () => { + const run = async (argv: string[], keys?: Keys) => { + const out: string[] = []; + const err: string[] = []; + const io: Io = { + env: { ...process.env, ...rig.env }, + out: (t) => out.push(t), + err: (t) => err.push(t), + keys, + }; + const code = await runCli(argv, io, { launch: null }); + return { code, out, err }; + }; + + test("without --yes and no terminal it deletes nothing and says how to; --yes deletes", async () => { + const [d1, d2, d3] = CLI_CALLS; + for (const id of [d1, d2]) { + expect((await rig.api("DELETE", `/calls/${id}`)).status).toBe(200); + } + + const refused = await run(["calls", "empty-trash"]); + expect(refused.code).toBe(64); + expect(refused.err.join("\n")).toContain("the trash holds 2 calls; calls empty-trash --yes"); + expect((await inTrash()).sort()).toEqual([d1, d2].sort()); + + // A person at a terminal who answers anything but y keeps them. + const no = terminal("n"); + const kept2 = await run(["calls", "empty-trash"], no); + expect([kept2.code, no.asked, no.closed]).toEqual([0, true, true]); + expect(kept2.err.join("\n")).toContain( + "Delete the 2 calls in the trash for good? This cannot be undone.", + ); + expect((await inTrash()).length).toBe(2); + + // While the question waits for y, another call goes to the trash: it is not one the user + // was asked about, so it stays. + const d4 = CLI_CALLS[3]; + const yes = terminal("y", async () => { + await Bun.sleep(20); + expect((await rig.api("DELETE", `/calls/${d4}`)).status).toBe(200); + }); + const deleted = await run(["calls", "empty-trash"], yes); + expect([deleted.code, deleted.out]).toEqual([0, ["Deleted 2 calls from the trash for good"]]); + expect(await inTrash()).toEqual([d4]); + expect((await rig.api("POST", `/calls/${d4}/restore`)).status).toBe(200); + expect(await inTrash()).toEqual([]); + // The live test's call is listed too; what matters is the untrashed calls stay, the others don't. + const left = await listed(); + expect([left.includes(KEEP), left.includes(d3), left.includes(d1), left.includes(d2)]).toEqual([ + true, + true, + false, + false, + ]); + + // Nothing left: said so, with or without --yes. + expect((await run(["calls", "empty-trash"])).out).toEqual(["The trash is empty."]); + expect((await run(["calls", "empty-trash", "--yes"])).out).toEqual(["The trash is empty."]); + expect((await run(["calls", "empty-trash", "--yes", "--json"])).out).toEqual([ + JSON.stringify({ ok: true, deleted: 0 }), + ]); + // It names no call: one given is a usage error, and --yes means nothing elsewhere. + expect((await run(["calls", "empty-trash", KEEP, "--yes"])).code).toBe(64); + expect((await run(["calls", "--yes"])).code).toBe(64); + expect(await listed()).toContain(KEEP); + }, 30_000); + + test("--yes deletes without asking", async () => { + const d3 = CLI_CALLS[2]; + expect((await rig.api("DELETE", `/calls/${d3}`)).status).toBe(200); + const asked = terminal("n"); + const r = await run(["calls", "empty-trash", "--yes"], asked); + expect([r.code, r.out, asked.asked]).toEqual([ + 0, + ["Deleted 1 call from the trash for good"], + false, + ]); + expect(await inTrash()).toEqual([]); + expect(await listed()).toContain(KEEP); + }, 30_000); +}); diff --git a/tests/fixtures/route-access.ts b/tests/fixtures/route-access.ts index d29f54f8..d040df97 100644 --- a/tests/fixtures/route-access.ts +++ b/tests/fixtures/route-access.ts @@ -47,6 +47,8 @@ export const ACCESS: Readonly> = { "PATCH /v1/calls/{id}": "admin", "DELETE /v1/calls/{id}": "admin", "POST /v1/calls/{id}/restore": "admin", + "GET /v1/trash": "admin", + "DELETE /v1/trash": "admin", "PATCH /v1/calls/{id}/segments/{sid}": "admin", "GET /v1/devices": "admin", "GET /v1/apps": "admin", diff --git a/tests/ui/call-menu.test.ts b/tests/ui/call-menu.test.ts index a8a1a8d5..15305800 100644 --- a/tests/ui/call-menu.test.ts +++ b/tests/ui/call-menu.test.ts @@ -2,7 +2,8 @@ * The sidebar's call menu (docs/ux/WINDOW.md W13.2, W13.3) on the real page: a right-click or the * keyboard on a call row opens akou's own menu, never the webview's text menu, and the sidebar * selects no text. Rename opens the call's title field (W3.16), Move to workspace moves its folder, - * Move to Trash takes it out of the list with Undo, and a recording call cannot be trashed. + * Move to Trash takes it out of the list with Undo, and a recording call cannot be trashed. Empty + * Trash… asks, naming how many calls go, before it deletes them for good. * * Run with `bun run test:ui`. */ @@ -93,7 +94,7 @@ async function listed(rig: UiRig): Promise { return (r.body.calls as { id: string }[]).map((c) => c.id); } -const ITEMS = ["Rename…", "Move to workspace…", "Move to Trash"]; +const ITEMS = ["Rename…", "Move to workspace…", "Move to Trash", "Empty Trash…"]; describe("[W13.3] a call row has akou's own menu, never the webview's", () => { test( @@ -206,7 +207,10 @@ describe("[W13.3] a call row has akou's own menu, never the webview's", () => { await page.keyboard.press("ArrowDown"); expect((await menu(page)).focused).toBe("Move to workspace…"); await page.keyboard.press("End"); + expect((await menu(page)).focused).toBe("Empty Trash…"); + await page.keyboard.press("ArrowUp"); expect((await menu(page)).focused).toBe("Move to Trash"); + await page.keyboard.press("End"); await page.keyboard.press("ArrowDown"); expect((await menu(page)).focused).toBe("Rename…"); await page.keyboard.press("Escape"); @@ -377,6 +381,7 @@ describe("[W13.3] Move to Trash, with Undo", () => { expect((await menu(page)).open).toBe(true); // Enter on it, from the keyboard, does nothing either. await page.keyboard.press("End"); + await page.keyboard.press("ArrowUp"); expect((await menu(page)).focused).toBe("Move to Trash"); await page.keyboard.press("Enter"); expect((await menu(page)).open).toBe(true); @@ -398,6 +403,70 @@ describe("[W13.3] Move to Trash, with Undo", () => { ); }); +describe("[TRASH-1] Empty Trash… from a call row", () => { + test( + "it asks first, naming how many calls go and that it cannot be undone; Empty Trash deletes only those, not a call trashed while it asked", + async () => { + await withRig({ seed: seedThree }, async (rig) => { + const page = await rig.open(C); + await page.waitForSelector("#calls li >> nth=2"); + const inTrash = async () => + ((await rig.api("GET", "/trash")).body.calls as unknown[]).length; + // An empty trash says so and asks nothing. + await page.click(`${row(B)} .what`, { button: "right" }); + await page.click('#calls-menu [data-action="trash.empty"]'); + await until( + async () => (await page.textContent("#toast"))?.includes("The Trash is empty.") === true, + 5000, + "empty said", + ); + expect(await page.locator("#confirm .confirm-row").count()).toBe(0); + + for (const id of [A, B]) { + await page.click(`${row(id)} .what`, { button: "right" }); + await page.click('#calls-menu [data-action="call.trash"]'); + await until(async () => !(await listed(rig)).includes(id), 5000, `${id} trashed`); + } + expect(await inTrash()).toBe(2); + + await page.click(`${row(C)} .what`, { button: "right" }); + await page.click('#calls-menu [data-action="trash.empty"]'); + await page.waitForSelector("#confirm .confirm-row"); + expect(await page.textContent("#confirm .confirm-row span")).toBe( + "Delete the 2 calls in the Trash for good? This cannot be undone.", + ); + // Dismiss keeps them: the question is the only way in. + await page.click("#confirm .confirm-row button:not(.go)"); + await Bun.sleep(300); + expect(await inTrash()).toBe(2); + + await page.click(`${row(C)} .what`, { button: "right" }); + await page.click('#calls-menu [data-action="trash.empty"]'); + await page.waitForSelector("#confirm .confirm-row"); + // While the question is open, C goes to the trash too. The user was asked about 2 calls, + // so only those 2 go: C stays in the trash and its Undo still works. + await Bun.sleep(20); + expect((await rig.api("DELETE", `/calls/${C}`)).status).toBe(200); + await page.click("#confirm .confirm-row .go"); + await until( + async () => + (await page.textContent("#toast"))?.includes("2 calls deleted for good.") === true, + 5000, + "deleted said", + ); + expect( + ((await rig.api("GET", "/trash")).body.calls as { id: string }[]).map((c) => c.id), + ).toEqual([C]); + expect((await rig.api("POST", `/calls/${C}/restore`)).status).toBe(200); + // The call that was not counted is back, in the list and on screen. + expect(await listed(rig)).toEqual([C]); + await page.waitForSelector(row(C)); + }); + }, + UI_TIMEOUT, + ); +}); + describe("[W13.2] Rename and Move to workspace from a call row", () => { test( "Rename… opens that call with its title field; Enter saves the new name",