Public: anyone can read this; the crew can change it.

A person deletes one of their imported sessions from its page, by typing its name #18371

opened this

Merged 1h 40m ago, live in production

scout/forge:scout/18359-a-person-deletes-one-of-their-imported-s → main 0 commits fork 3 threads · 3 unresolved

  • Merged. scout/18359-a-person-deletes-one-of-their-imported-s was merged into main as 3d2fa7b.

Review

Sign in to review this change.
9 files changed +245 −10
docs/features/traces.md +1 −1
@@ -58,7 +58,7 @@ For Codex, point the same command at a rollout: `--data-binary @"$(ls -t ~/.code
5858
5959 A new source is one file implementing `ImportAdapter` (`src/trace/import_adapter.ts`, see `import_claude_code.ts`) and one line in `ADAPTERS`; Codex rollouts are taken the same way (`import_codex.ts`).
outdated

"Imported sessions are never shared by link, so there is none to end" is false. Say that deleting a session also ends its share link.

6060
61 `DELETE /api/v1/traces/<id>` (#18388) deletes one imported session, with `{ "confirm": "<the session's title>" }` as its body (at most 4 KiB; `traceDelete` in `src/kernel/body_caps.ts`). Nothing is removed unless the title is sent exactly: a wrong or missing one is a 422 (`name_mismatch`) and the file and rows stay. Only the importer may: another person's or an unknown id is a 404, a crew run or Talk turn is a 403 (`record_kept`, its record is kept), a session caller's cross-origin request is a 403, and a session with a live share link is a 409 (`shared`: stop sharing first). A right name removes `traces/imported/<id>.jsonl.gz`, the index row and its touched tools and files (`deleteImported` in `src/trace/import.ts`), frees the quota, and answers `{ removed, title, bytes }`. Not yet: a button on the page and a terminal screen.
61 `DELETE /api/v1/traces/<id>` (#18388) deletes one imported session, with `{ "confirm": "<the session's title>" }` as its body (at most 4 KiB; `traceDelete` in `src/kernel/body_caps.ts`). Nothing is removed unless the title is sent exactly: a wrong or missing one is a 422 (`name_mismatch`) and the file and rows stay. Only the importer may: another person's or an unknown id is a 404, a crew run or Talk turn is a 403 (`record_kept`, its record is kept), a session caller's cross-origin request is a 403, and a session with a live share link is a 409 (`shared`: stop sharing first). A right name removes `traces/imported/<id>.jsonl.gz`, the index row and its touched tools and files (`deleteImported` in `src/trace/import.ts`), frees the quota, and answers `{ removed, title, bytes }`. The red Delete on the session's page (the title typed exactly, a plain click does nothing) and `X` in the terminal's Traces list do the same and answer a receipt (#18359); on a shared session they say to stop sharing first, so deleting never leaves a link that a re-import of the same session would bring back. Not yet: an undo.
6262
6363 `/traces/<id>` of an imported trace (#18357) is the same tree and strip a crew run has, read from the stored file (`src/trace/imported_read.ts`, `src/web/pages/trace_imported.ts`), with `#step-N` permalinks and each step's raw lines (the file's lines that name it) on demand at `/traces/<id>/steps/<n>`. Only the importer reads it; anyone else gets the not-found an unknown id gets. Each step line shows the tokens its file held for it (`5 in, 7 cached, 9 out`; a reply split across records is counted once) and the total is their sum; a session holds no cost, and sometimes no tokens: the page says "not recorded in this file" rather than zero. Steps are capped at 20,000. `GET /api/v1/traces/<id>` answers the same tree for an imported id.
6464 ## One trace as a tree (#18022)
src/http/lazy_lists.ts +1
@@ -736,6 +736,7 @@ export const OPERATIONS_ROUTES = [
736736 ["GET", "/traces/:id/compare/:other"],
737737 ["POST", "/traces/:id/share"],
738738 ["POST", "/traces/:id/unshare"],
739 ["POST", "/traces/:id/delete"],
739740 ["GET", "/traces/shared/:token"],
740741 ] as const;
741742
src/http/routes/operations.ts +2
@@ -24,6 +24,7 @@ import { resiliencePage, nightlyOutputPage } from "../../web/pages/resilience.ts
2424 import { runRedirect } from "../../web/pages/runs.ts";
2525 import { tracePage, traceStep } from "../../web/pages/trace.ts";
2626 import { traceComparePage } from "../../web/pages/trace_compare.ts";
27 import { traceDelete } from "../../web/pages/trace_imported.ts";
2728 import { traceShare, traceShared, traceUnshare } from "../../web/pages/trace_share.ts";
2829 import { tracesPage } from "../../web/pages/traces.ts";
2930 import { traceImport } from "../../web/pages/trace_import.ts";
@@ -135,5 +136,6 @@ export function operationsRoutes(router: Router<Handler>, knownPatterns: () => s
135136 router.add("GET", "/traces/:id/compare/:other", traceComparePage);
136137 router.add("POST", "/traces/:id/share", traceShare);
137138 router.add("POST", "/traces/:id/unshare", traceUnshare);
139 router.add("POST", "/traces/:id/delete", traceDelete);
138140 router.add("GET", "/traces/shared/:token", traceShared);
139141 }
src/trace/import.ts +9
@@ -60,6 +60,15 @@ export function removeImported(dataDir: string, ids: readonly string[]): void {
6060 for (const id of ids) rmSync(fileOf(dataDir, id), { force: true });
6161 }
6262
63 /** The words a deleted session's receipt says, the page's and the terminal's too. */
64 export const deletedWords = (title: string, bytes: number): string => `Removed the imported session "${title}" (${bytes} bytes freed).`;
65
66 /** Why a crew run or Talk turn is never deleted. */
67 export const KEPT_WORDS = "a crew run's or Talk turn's record is kept forever: only an imported session can be deleted";
68
69 /** Why a shared session is not deleted yet. */
70 export const SHARED_WORDS = "this session has a live share link: stop sharing it first";
71
6372 /** What a removal answers: the session's title and the stored bytes it frees. */
6473 export type Removal =
6574 | { readonly ok: true; readonly title: string; readonly bytes: number }
src/tui/screens/traces.ts +31 −6
@@ -10,9 +10,10 @@
1010 * page's own `readFilter`. `b` types the name of a saved search (the page's links) and opens the
1111 * first that starts with it, `w` names the filters on screen and keeps them, `x` removes the saved
1212 * search last opened (the search only: no trace is touched); a facet a saved search holds that no
13 * longer exists is dropped and said. On an imported session `s` makes its share link (shown once;
14 * a second press confirms when one is live, as it ends the old) and `z` ends it (#18377). Esc
15 * closes. The lines are `traceLine`, the page's own row.
13 * longer exists is dropped and said. `X` on an imported session asks for its title typed and
14 * deletes it (#18359). On an imported session `s` makes its share link (shown once; a second press
15 * confirms when one is live, as it ends the old) and `z` ends it (#18377). Esc closes. The lines
16 * are `traceLine`, the page's own row.
1617 */
1718 import { binding } from "../app/keys.ts";
1819 import type { Ctx, Screen } from "../app/app.ts";
@@ -23,7 +24,8 @@ import { openedSaved, removeSaved, SAVE_WORDS, saveSearch, savedWords, NAME_MAX,
2324 import { sameIssue } from "../../trace/compare.ts";
2425 import { traceScreen } from "./trace.ts";
2526 import { importedSharedNow, sharedHref, shareImported, unshareImported } from "../../actions/trace_share.ts";
26 import { Scroll, openOnWeb } from "./common.ts";
27 import { Scroll, openOnWeb, promptScreen } from "./common.ts";
28 import { deletedWords, deleteImported, SHARED_WORDS } from "../../trace/import.ts";
2729 import { style } from "../term/style.ts";
2830 import { truncate } from "../term/width.ts";
2931 import { emptyState } from "../ui/widgets.ts";
@@ -31,6 +33,8 @@ import type { Session } from "../session.ts";
3133 import type { PaletteEntry } from "./entries.ts";
3234
3335 function tracesScreen(f: Session, ctx: Ctx): Screen {
36 // eslint-disable-next-line prefer-const
37 let screen: Screen;
3438 const scroll = new Scroll();
3539 // What the page holds in its URL, as strings; `readFilter` is the one validator of them.
3640 const facet: { [K in "q" | "kind" | "repo" | "model" | "outcome" | "by" | "tool" | "file" | "from" | "to"]?: string } = {};
@@ -83,9 +87,9 @@ function tracesScreen(f: Session, ctx: Ctx): Screen {
8387 const held = marked.length === 0 ? "" : ` marked ${marked.length}/2 (*)`;
8488 return `${on.length === 0 ? "" : ` [${on.map(([k, v]) => `${k}=${v}`).join(" ")}]`}${held}`;
8589 };
86 return {
90 screen = {
8791 title: "Traces",
88 keys: [binding(["j", "k"], "move"), binding(["enter"], "open the trace"), binding(["v"], "mark"), binding(["d"], "compare marked"), binding(["n"], "older"), binding(["/"], "search"), binding(["i", "r", "m", "o", "p"], "kind, repo, model, outcome, person"), binding(["u", "e"], "tool used, file touched"), binding(["f", "t"], "from, to day"), binding(["b", "w", "x"], "open, save, remove a saved search"), binding(["y"], "import a session on the web"), binding(["s", "z"], "share an imported session, stop sharing"), binding(["c"], "clear filters"), binding(["esc"], "close")],
92 keys: [binding(["j", "k"], "move"), binding(["enter"], "open the trace"), binding(["v"], "mark"), binding(["d"], "compare marked"), binding(["X"], "delete an imported session"), binding(["n"], "older"), binding(["/"], "search"), binding(["i", "r", "m", "o", "p"], "kind, repo, model, outcome, person"), binding(["u", "e"], "tool used, file touched"), binding(["f", "t"], "from, to day"), binding(["b", "w", "x"], "open, save, remove a saved search"), binding(["y"], "import a session on the web"), binding(["s", "z"], "share an imported session, stop sharing"), binding(["c"], "clear filters"), binding(["esc"], "close")],
8993 render(area, s) {
9094 const c = ctx.theme.c;
9195 s.text(area.x, area.y, truncate(`${typing === undefined ? "/ to search" : typing === "q" ? "Search" : typing === "from" ? "From (YYYY-MM-DD)" : typing === "to" ? "To (YYYY-MM-DD)" : typing === "tool" ? "Tool (Edit, Bash…)" : "File (path)"}: ${typing === undefined || typing === "q" ? (facet.q ?? "") : (facet[typing] ?? "")}${typing === undefined ? "" : "_"}${summary()}`, area.w), style(c.fg, c.bg), area.x + area.w);
@@ -160,6 +164,26 @@ function tracesScreen(f: Session, ctx: Ctx): Screen {
160164 if (repo === undefined || !sameIssue(ra, rb)) ctx.toast("those two are not runs of one issue", "attn");
161165 else ctx.push(traceScreen(f, ctx, repo, ra.id, rb.id));
162166 }
167 } else if (e.key === "X") {
168 // The page's red Delete: the title typed exactly, then the session goes (#18359).
169 const r = list.rows[at];
170 if (r === undefined || r.source !== "imported") ctx.toast("only an imported session can be deleted: a run's or Talk turn's record is kept forever", "attn");
171 else {
172 const row = screen;
173 ctx.push(
174 promptScreen(ctx, row, {
175 title: "Delete this session for good",
176 label: `type its title exactly: ${r.title}`,
177 onSubmit: (typed) => {
178 const done = deleteImported(f.app.db, f.app.config.dataDir, f.user?.id ?? "", r.id, typed);
179 if (!done.ok) return done.error === "shared" ? SHARED_WORDS : "that is not its title: nothing was removed";
180 ctx.toast(deletedWords(done.title, done.bytes), "success");
181 read();
182 return undefined;
183 },
184 }),
185 );
186 }
163187 } else if (e.key === "y") openOnWeb(f, ctx, "/traces#traces-import", "the import form (a file input)");
164188 else if (e.key === "s" || e.key === "z") {
165189 const r = list.rows[at];
@@ -190,6 +214,7 @@ function tracesScreen(f: Session, ctx: Ctx): Screen {
190214 return true;
191215 },
192216 };
217 return screen;
193218 }
194219
195220 export const entry: PaletteEntry = {
src/web/pages/trace_imported.ts +27 −3
@@ -7,16 +7,17 @@
77 import { importedSharedNow } from "../../actions/trace_share.ts";
88 import type { Ctx } from "../../http/context.ts";
99 import { securityFloor } from "../../http/respond.ts";
10 import { importedLines } from "../../trace/import.ts";
10 import { deletedWords, deleteImported, importedLines, KEPT_WORDS, SHARED_WORDS } from "../../trace/import.ts";
1111 import { parseImported, rawLinesOf } from "../../trace/imported_read.ts";
1212 import type { TraceRow } from "../../trace/index_table.ts";
1313 import { stepsOf } from "../../trace/model.ts";
1414 import { spanWords, stepLine } from "../../trace/read.ts";
1515 import { stepNumber } from "../../trace/run_log.ts";
1616 import { seenTraceRow } from "../../trace/tree.ts";
17 import { notFoundPage, pageHead } from "../chrome.ts";
17 import { forbiddenPage, notFoundPage, pageHead } from "../chrome.ts";
18 import { readForm } from "../form.ts";
1819 import { html } from "../html.ts";
19 import { page } from "../layout.ts";
20 import { flashTo, page } from "../layout.ts";
2021 import { behaviorsJs } from "../behaviors.ts";
2122 import { strip, TRACE_CSS, TRACE_JS, treeRows } from "./trace.ts";
2223
@@ -47,6 +48,11 @@ export function importedTracePage(ctx: Ctx, row: TraceRow): Response {
4748 <div><dt>Cost</dt><dd id="trace-cost">${row.costUsd > 0 ? `$${row.costUsd.toFixed(2)}` : "not recorded in this file"}</dd></div>
4849 </dl>
4950 <nav class="bar small" id="trace-links" aria-label="Where this trace is"><a href="/traces">All traces</a></nav>
51 <form method="post" class="bar small" id="trace-delete" action="${base}/delete" autocomplete="off">
52 <label for="trace-delete-name" class="muted">Delete this session for good: type its title exactly to confirm.</label>
53 <input class="input" id="trace-delete-name" name="name" required autocomplete="off" spellcheck="false" placeholder="${row.title}" />
54 <button type="submit" class="btn" data-variant="danger">Delete</button>
55 </form>
5056 ${shared === undefined ? null : html`<form method="post" class="bar small" id="trace-share" action="${base}/${shared ? "unshare" : "share"}">
5157 <span class="muted">${shared ? "A share link is live: anyone holding it reads this session, secrets redacted." : "Not shared. A link lets anyone who holds it read this session. The forge hides the credentials it knows, but a file can hold others, so share only what you have read."}</span>
5258 <button type="submit">${shared ? "Stop sharing" : "Make a share link"}</button>
@@ -71,3 +77,21 @@ export function importedStep(ctx: Ctx, row: TraceRow): Response {
7177 }),
7278 );
7379 }
80
81 // POST /traces/:id/delete — the form on an imported session's page: the title typed, then it goes.
82 export async function traceDelete(ctx: Ctx): Promise<Response> {
83 const form = await readForm(ctx, "rw");
84 if (form instanceof Response) return form;
85 const user = ctx.auth.user;
86 const id = ctx.params.id ?? "";
87 const seen = user === undefined ? undefined : seenTraceRow(ctx.app, user, id);
88 if (user === undefined || seen === undefined) return notFoundPage(ctx);
89 if (seen.kind !== "imported") return forbiddenPage(ctx, `${KEPT_WORDS[0]!.toUpperCase()}${KEPT_WORDS.slice(1)}.`);
90 const name = form.get("name");
91 const done = deleteImported(ctx.app.db, ctx.app.config.dataDir, user.id, id, name);
92 if (!done.ok) {
93 const message = done.error === "shared" ? `${SHARED_WORDS[0]!.toUpperCase()}${SHARED_WORDS.slice(1)}.` : "That is not the session's title: nothing was removed.";
94 return flashTo(ctx, `/traces/${id}`, { message, tone: "danger" });
95 }
96 return flashTo(ctx, "/traces", { message: deletedWords(done.title, done.bytes) });
97 }
test/trace-delete.test.ts added +121
@@ -0,0 +1,121 @@
1 /**
2 * An imported session is deleted by its owner, with its title typed, and by no one else (#18359).
3 */
4 import { afterAll, beforeAll, expect, test } from "bun:test";
5 import { existsSync } from "node:fs";
6 import { mkdtemp, rm } from "node:fs/promises";
7 import { tmpdir } from "node:os";
8 import { join } from "node:path";
9 import { createApp, type App } from "../src/app.ts";
10 import { createSession } from "../src/core/sessions.ts";
11 import { createToken } from "../src/core/tokens.ts";
12 import { createUser, type User } from "../src/core/users.ts";
13 import { serve, type Servers } from "../src/http/server.ts";
14 import { createRepo } from "../src/actions/repos.ts";
15 import { indexRun, putTraceRow } from "../src/trace/index_table.ts";
16 import { seedAdmin } from "./helpers/admin.ts";
17
18 const rec = (o: object): string => JSON.stringify({ sessionId: "sess-d", cwd: "/w", ...o });
19 const SESSION = [
20 rec({ type: "user", timestamp: "2026-12-01T09:00:00Z", message: { role: "user", content: "fix the login bug" } }),
21 rec({ type: "assistant", timestamp: "2026-12-01T09:00:01Z", message: { id: "m1", model: "claude-x", role: "assistant", content: [{ type: "text", text: "Done" }] } }),
22 ].join("\n");
23 const TITLE = "fix the login bug";
24
25 let dir = "";
26 let app: App, servers: Servers;
27 let alice0: User;
28 let alice = "", bob = "", id = "", aliceCookie = "";
29
30 const api = (path: string, token: string, init: RequestInit = {}) => fetch(`${servers.url}${path}`, { ...init, headers: { authorization: `Bearer ${token}`, ...(init.headers ?? {}) } });
31 const del = (token: string, name: unknown, target = id) => api(`/api/v1/traces/${target}`, token, { method: "DELETE", body: JSON.stringify({ confirm: name }) });
32 const list = async (token: string) => ((await (await api("/api/v1/traces?kind=imported", token)).json()) as { items: { id: string }[] }).items.map((i) => i.id);
33 const stored = () => existsSync(join(dir, "traces", "imported", `${id}.jsonl.gz`));
34
35 beforeAll(async () => {
36 dir = await mkdtemp(join(tmpdir(), "forge-trace-delete-"));
37 app = createApp({ dataDir: dir, port: 0 });
38 servers = await serve(app);
39 const a = await seedAdmin(app, { username: "alice", email: "[email protected]", password: "correct-horse-battery" });
40 if (!a.ok) throw new Error(a.error);
41 const b = await createUser(app.db, { origin: "seed", trusted: true, username: "bob", email: "[email protected]", password: "a-good-passphrase" });
42 if (!b.ok) throw new Error(b.error);
43 alice0 = a.value;
44 alice = createToken(app.db, a.value.id, "t", "rw").token;
45 bob = createToken(app.db, b.value.id, "t", "rw").token;
46 aliceCookie = `forge_session=${createSession(app.db, a.value.id).token}`;
47 const sent = await api("/api/v1/traces/import", alice, { method: "POST", body: SESSION });
48 id = ((await sent.json()) as { id: string }).id;
49 putTraceRow(app.db, { id: "f".repeat(32), kind: "talk", repository: "", title: "a talk turn", model: "", account: "", steps: 0, errors: 0, tokensIn: 0, tokensCached: 0, tokensOut: 0, costUsd: 0, outcome: "ok", started: "2026-12-01T00:00:00.000Z", ended: "2026-12-01T00:00:00.000Z" }, "");
50 }, 30_000);
51
52 afterAll(async () => {
53 await servers.stop();
54 await rm(dir, { recursive: true, force: true });
55 });
56
57 test("the page offers a Delete asking for the title; a wrong name, a cross-site post and a stranger remove nothing", async () => {
58 const page = await (await fetch(`${servers.url}/traces/${id}`, { headers: { cookie: aliceCookie } })).text();
59 expect(page).toContain(`action="/traces/${id}/delete"`);
60 expect(page).toContain('data-variant="danger"');
61
62 const form = (name: string) => ({ method: "POST", redirect: "manual" as const, headers: { cookie: aliceCookie, "content-type": "application/x-www-form-urlencoded", origin: servers.url }, body: new URLSearchParams({ name }) });
63 const wrong = await fetch(`${servers.url}/traces/${id}/delete`, form("fix the login"));
64 expect(wrong.status).toBe(303);
65 expect(stored()).toBe(true);
66 expect(await list(alice)).toContain(id);
67
68 const cross = await fetch(`${servers.url}/traces/${id}/delete`, { ...form(TITLE), headers: { cookie: aliceCookie, "content-type": "application/x-www-form-urlencoded", origin: "https://evil.example" } });
69 expect(cross.status).toBe(403);
70 expect(stored()).toBe(true);
71
72 const crossApi = await fetch(`${servers.url}/api/v1/traces/${id}`, { method: "DELETE", headers: { cookie: aliceCookie, origin: "https://evil.example" }, body: JSON.stringify({ confirm: TITLE }) });
73 expect(crossApi.status).toBe(403);
74 expect(stored()).toBe(true);
75 });
76
77 test("a wrong or missing name is a 422 and removes nothing; another user gets 404; a crew or Talk record is a 403 with the reason", async () => {
78 expect((await del(alice, "fix")).status).toBe(422);
79 expect((await del(alice, "")).status).toBe(422);
80 expect((await del(alice, 7)).status).toBe(422);
81 expect((await api(`/api/v1/traces/${id}`, alice, { method: "DELETE" })).status).toBe(422);
82 expect(stored()).toBe(true);
83 expect(await list(alice)).toContain(id);
84
85 expect((await del(bob, TITLE)).status).toBe(404);
86 expect((await del(alice, TITLE, "0".repeat(32))).status).toBe(404);
87 expect(stored()).toBe(true);
88
89 // A crew run alice may read is kept: the 403 says why, and the row stays.
90 const repo = await createRepo(app, alice0, { name: "mix", visibility: "public", description: "" });
91 if (!repo.ok) throw new Error("repo failed");
92 app.db.prepare("INSERT INTO run (id, repo_id, kind, state, summary, model, actor_id, cost_usd, created_at) VALUES ('run1', ?1, 'agent', 'ok', 'crew run', 'm', ?2, 0, '2026-12-03T10:00:00.000Z')").run(repo.value.id, alice0.id);
93 expect(indexRun(app.db, dir, "run1")).toBe(true);
94 const kept = await del(alice, "crew run", "run1");
95 expect(kept.status).toBe(403);
96 expect(JSON.stringify(await kept.json())).toContain("record_kept");
97 expect(app.db.query("SELECT 1 FROM trace_index WHERE id = 'run1'").get()).not.toBeNull();
98 });
99
100 test("the right name removes the file and the row, frees the quota, and answers a receipt; the list no longer shows it", async () => {
101 const res = await del(alice, TITLE);
102 expect(res.status).toBe(200);
103 const body = (await res.json()) as { removed: boolean; title: string; bytes: number };
104 expect(body.removed).toBe(true);
105 expect(body.bytes).toBeGreaterThan(0);
106 expect(body.title).toBe(TITLE);
107 expect(stored()).toBe(false);
108 expect(await list(alice)).not.toContain(id);
109 expect((await api(`/api/v1/traces/${id}`, alice)).status).toBe(404);
110 expect((await del(alice, TITLE)).status).toBe(404);
111 // The same session can be imported again: the quota and the id are free.
112 expect((await api("/api/v1/traces/import", alice, { method: "POST", body: SESSION })).status).toBe(201);
113 });
114
115 test("the page's form removes it too and says what went", async () => {
116 const again = ((await (await api("/api/v1/traces?kind=imported", alice)).json()) as { items: { id: string }[] }).items[0]!.id;
117 const res = await fetch(`${servers.url}/traces/${again}/delete`, { method: "POST", redirect: "manual", headers: { cookie: aliceCookie, "content-type": "application/x-www-form-urlencoded", origin: servers.url }, body: new URLSearchParams({ name: TITLE }) });
118 expect(res.status).toBe(303);
119 expect(res.headers.get("location")).toContain("/traces");
120 expect(await list(alice)).not.toContain(again);
121 });
test/trace-imported-share.test.ts +13
@@ -102,6 +102,19 @@ test("a deleted session's link is the not-found, and a link never made is too",
102102 expect((await call(sharedHref("a".repeat(43)), undefined)).status).toBe(404);
103103 });
104104
105 test("a shared session is not deleted until sharing stops; the old link stays dead when the same file is sent again", async () => {
106 await fetch(`${servers.url}/api/v1/traces/import`, { method: "POST", headers: { authorization: `Bearer ${alice}` }, body: SESSION });
107 const link = await linkOf(await call(`/traces/${id}/share`, alice, "POST"));
108 const del = () => fetch(`${servers.url}/api/v1/traces/${id}`, { method: "DELETE", headers: { authorization: `Bearer ${alice}` }, body: JSON.stringify({ confirm: "deploy it" }) });
109 expect((await del()).status).toBe(409);
110 expect((await call(link, undefined)).status).toBe(200);
111 await call(`/traces/${id}/unshare`, alice, "POST");
112 expect((await del()).status).toBe(200);
113 const again = await fetch(`${servers.url}/api/v1/traces/import`, { method: "POST", headers: { authorization: `Bearer ${alice}` }, body: SESSION });
114 expect(((await again.json()) as { id: string }).id).toBe(id);
115 expect((await call(link, undefined)).status).toBe(404);
116 });
117
105118 test("one address opens at most 60 shared pages a minute", () => {
106119 let refused = 0;
107120 for (let i = 0; i < 70; i++) if (!sharedTurn(app, "203.0.113.77").allowed) refused++;
test/traces-tui.test.ts +40
@@ -88,6 +88,46 @@ test("i cycles the kind: runs, then only Talk, then only imported; Enter on an i
8888 app.stop();
8989 });
9090
91 test("X on an imported session asks for its title: a wrong one removes nothing, the right one does; on a run it says it is kept (#18359)", async () => {
92 const gone = "a".repeat(32);
93 putTraceRow(
94 forge.db,
95 { id: gone, kind: "imported", repository: "", title: "doomed session", model: "m", account: "", steps: 1, errors: 0, tokensIn: 0, tokensCached: 0, tokensOut: 0, costUsd: 0, outcome: "ok", started: "2026-12-05T10:00:00.000Z", ended: "2026-12-05T10:01:00.000Z" },
96 alice.id,
97 );
98 const { app, session } = createForgeApp(forge, { sshUsername: "alice", remoteAddress: "127.0.0.1", user: alice }, { terminal: headlessTerminal(120, 30), exitHooks: false });
99 app.start();
100 await settleApp(app);
101 entry.run(session, app.ctx);
102 await settleApp(app);
103 const press = async (key: string): Promise<string> => {
104 app.dispatch({ type: "key", key, ctrl: false, alt: false, shift: false });
105 await settleApp(app);
106 return app.screen.toText();
107 };
108 const type = async (text: string): Promise<void> => {
109 for (const ch of text) await press(ch);
110 };
111 await press("j");
112 await press("j");
113 await press("j"); // the crew run
114 expect(await press("X")).toContain("is kept forever");
115 await press("k");
116 await press("k");
117 await press("k"); // the newest is "doomed session"
118 const asked = await press("X");
119 expect(asked).toContain("doomed session");
120 await type("doomed");
121 expect(await press("enter")).toContain("nothing was removed");
122 expect(forge.db.query("SELECT 1 FROM trace_index WHERE id = ?1").get(gone)).not.toBeNull();
123 await type(" session");
124 const after = await press("enter");
125 expect(forge.db.query("SELECT 1 FROM trace_index WHERE id = ?1").get(gone)).toBeNull();
126 expect(after).toContain("Removed the imported session");
127 expect(after).not.toContain("doomed session · imported");
128 app.stop();
129 });
130
91131 test("y says where the import form is on the web, and the key is listed", async () => {
92132 const { app, session } = createForgeApp(forge, { sshUsername: "alice", remoteAddress: "127.0.0.1", user: alice }, { terminal: headlessTerminal(120, 30), exitHooks: false });
93133 app.start();

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs