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

A Talk confirm already answered leaves the dock, instead of sticking on a 409 #16429

Merged opened this From outside

Check · Review · Land · Live done — Landed and live in production.

Merged

grokbot/forge:fix/talk-confirm-answered-409 → main 0 commits fork

  • Merged. fix/talk-confirm-answered-409 was merged into main as a8ec41c.

Review

Sign in to review this change.
5 files changed +78 −12
docs/features/talk.md +2 −2
@@ -246,11 +246,11 @@ A receipt is one calm line in the thread: a check, what was done and its link, t
246246
247247 A confirm (an action held for the person's yes) is never drawn in the scrolled thread, where a long reply could push it off screen. It waits in a dock directly above the composer, always in view: the engine's one sentence of what will happen and to what, **Do it**, and a quiet **Not now**, with the time left only when under two minutes. Several read as "2 waiting" and a stack, the first open and the rest one line each; the stack never grows past a third of the screen and scrolls inside itself beyond that. The dock is part of the composer, so the thread's end stays clear of it and following holds; its buttons come before the box in the Tab order, Enter on Do it answers, and Escape is never Not now. A new confirm is said once, politely.
248248
249 Its buttons belong to the composer's form and post to the confirm's own address (`formaction`), so the dock works without the script. Answered, the confirm collapses out of the dock (instantly where motion is reduced) and its outcome arrives in the thread where it happened: the receipt for Do it, or "Not now: nothing was done." Only a confirm that ran out says so in the thread, with Ask again.
249 Its buttons belong to the composer's form and post to the confirm's own address (`formaction`), so the dock works without the script. Answered, the confirm collapses out of the dock (instantly where motion is reduced) and its outcome arrives in the thread where it happened: the receipt for Do it, or "Not now: nothing was done." If it was already answered (in another tab, in Settings → Confirms, or cancelled by a new message or Stop), a second Do it says so and the card leaves the dock the same way, so it is not stuck; a destroying call that never runs from Talk does the same, and the thread names where to do it. Only a confirm that ran out says so in the thread, with Ask again.
250250
251251 **Things done fold:** a run of receipts and steps in one reply reads as one line with a check, "2 things done, 3 steps", opening to the list; one receipt alone stays as itself. Proof: `test/talk-page.test.ts`, `test/talk-live.test.ts`.
252252
253 **In the terminal** a confirm still waiting is never in the scrolled thread either: it waits at the foot of the conversation with its sentence, and `a` opens Confirms, where `y` does it and `n` says not now.
253 **In the terminal** a confirm still waiting is never in the scrolled thread either: it waits at the foot of the conversation with its sentence, and `a` opens Confirms, where `y` does it and `n` says not now. If it was already answered, y or n says so and the confirm leaves the list.
254254
255255 ## The pane's Code and Diff (#15734)
256256
src/tui/screens/confirms.ts +6 −2
@@ -19,6 +19,10 @@ import type { Session } from "../session.ts";
1919 import { fill, len, split } from "../ui/layout.ts";
2020 import { ListState, ago, confirmScreen, drawList, linkScreen, runAsync, type ListRow } from "./common.ts";
2121
22 /** A spent confirm's words, with no "nothing was done" when the yes already ran elsewhere. */
23 const spentNote = (error: keyof typeof REFUSED): string =>
24 error === "answered" || error === "delete" ? REFUSED[error][1] : `Nothing was done: ${REFUSED[error][1]}.`;
25
2226 export function confirmsScreen(f: Session, ctx: Ctx): Screen {
2327 const state = new ListState();
2428 let note = "";
@@ -57,7 +61,7 @@ export function confirmsScreen(f: Session, ctx: Ctx): Screen {
5761 onChoose: (i) => {
5862 if (i !== 1) return;
5963 const no = sayNo(f, user, w.id);
60 note = no.ok ? String(no.turn["says"]) : `Nothing was done: ${REFUSED[no.error][1]}.`;
64 note = no.ok ? String(no.turn["says"]) : spentNote(no.error);
6165 ctx.invalidate();
6266 },
6367 }),
@@ -85,7 +89,7 @@ export function confirmsScreen(f: Session, ctx: Ctx): Screen {
8589 user,
8690 w.id,
8791 );
88 if (!yes.ok) note = `Nothing was done: ${REFUSED[yes.error][1]}.`;
92 if (!yes.ok) note = spentNote(yes.error);
8993 else if (!yes.done) note = String(yes.turn["says"]);
9094 else {
9195 const undo = typeof yes.turn["undo"] === "string" ? ` To undo: ${yes.turn["undo"]}.` : "";
src/web/pages/talk_client.ts +4 −4
@@ -800,16 +800,16 @@ if (root) {
800800 const a = b.closest(".talk-confirm"), yes = b.value === "yes", buttons = a.querySelectorAll("button");
801801 // Said without a visible line, so answering moves nothing; a refusal is said on the confirm itself.
802802 const refused = (why) => { const p = a.querySelector(".talk-confirm-left"); p.hidden = false; p.textContent = why; tell(why); buttons.forEach((x) => { x.disabled = false; }); };
803 const spent = (why) => { tell(why); dropConfirm(a); hush = !paged; follow(); };
803804 buttons.forEach((x) => { x.disabled = true; });
804805 try {
805806 const res = await fetch(b.getAttribute("formaction"), { method: "POST", headers: { accept: "application/json" }, body: new URLSearchParams({ answer: b.value }) });
806807 const out = await res.json().catch(() => ({}));
807808 if (res.status === 410) { window.location.reload(); return; }
809 // 409: spent (already answered, or a delete that never runs here).
810 if (res.status === 409) return spent(out.message || "Already answered: nothing more to do.");
808811 if (!res.ok) return refused(out.message || "Nothing was done.");
809 tell(yes ? "Done." : "Not now: nothing was done.");
810 dropConfirm(a);
811 hush = !paged;
812 follow();
812 spent(yes ? "Done." : "Not now: nothing was done.");
813813 } catch (_) {
814814 refused("That was not sent: no connection.");
815815 }
test/conversation-confirm.test.ts +35
@@ -519,6 +519,41 @@ describe("a yes that fails, in the terminal", () => {
519519 tui.stop();
520520 }
521521 });
522
523 test("the terminal's Confirms: already answered leaves the list and says so", async () => {
524 const w = await world(alice);
525 const asked = JSON.parse((await call(w.token, "archive", { repo: w.repo, archived: true, dryRun: false })).text);
526 const terminal = headlessTerminal(160, 32);
527 const { app: tui } = createForgeApp(app, { sshUsername: "t", remoteAddress: "127.0.0.1", user: alice }, { terminal, exitHooks: false });
528 tui.start();
529 const key = (k: string, ctrl = false) => tui.dispatch({ type: "key", key: k, ctrl, alt: false, shift: false });
530 try {
531 key("k", true);
532 await settleApp(tui);
533 for (const ch of "Confirms") key(ch);
534 await settleApp(tui);
535 key("enter");
536 await settleApp(tui);
537 for (const h of waitingFor(app.db, alice.id)) if (h.id !== asked.needs_confirm) key("j");
538 await settleApp(tui);
539 expect(tui.screen.toText()).toContain(`Archive ${w.repo}.`);
540 key("y");
541 await settleApp(tui);
542 expect(tui.screen.toText()).toContain("Do it");
543 const answered = await yes(asked.needs_confirm, alice);
544 expect(answered.ok).toBe(true);
545 key("right");
546 key("enter");
547 expect(await waitFor(async () => (await settleApp(tui), tui.screen.toText().includes("already answered")))).toBe(true);
548 const shown = tui.screen.toText();
549 expect(shown).toContain("this confirm was already answered; it does nothing twice");
550 expect(shown).not.toContain("Nothing was done:");
551 expect(shown).not.toContain(`Archive ${w.repo}.`);
552 expect(waitingFor(app.db, alice.id).some((h) => h.id === asked.needs_confirm)).toBe(false);
553 } finally {
554 tui.stop();
555 }
556 });
522557 });
523558
524559 describe("one vocabulary for a proposed action", () => {
test/talk-page.test.ts +31 −4
@@ -566,7 +566,7 @@ describe("the page", () => {
566566 <form class="talk-compose"><div data-confirms hidden><p data-confirms-count></p><div class="talk-confirm-list"></div></div><p data-confirms-said></p><div class="talk-box"><div data-chips></div><p data-to-line hidden><span></span><button type="button" data-to-off>x</button></p><textarea name="text" required></textarea><div class="talk-tools"><button type="button" data-attach hidden aria-label="Attach files"></button><input type="file" multiple hidden data-files /><span data-compose-hint></span><button class="btn" type="button" data-steer hidden>Steer</button><button class="btn" type="button" data-stop hidden aria-label="Stop the answer">Stop</button><button class="btn talk-send" type="submit" aria-label="Send">Send</button></div></div><p data-error hidden></p><p class="talk-status" role="status"></p><button type="button" class="btn talk-jump" data-jump hidden><span data-word></span></button></form></div>`;
567567 const how = { value: "started" };
568568 const cancel = { status: 200 };
569 const answer = { status: 200 };
569 const answer = { status: 200, message: "this confirm was already answered; it does nothing twice" };
570570 const page = { html: "" };
571571 const sent: string[] = [];
572572 const urls: string[] = [];
@@ -578,7 +578,7 @@ describe("the page", () => {
578578 if (u.startsWith("?pane=") || u.includes("&fragment=pane") || u === "/talk" || u === "http://localhost/talk" || u.endsWith("?fragment=build")) return { ok: true, text: async () => page.html };
579579 if (u.endsWith("?fragment=1")) return { ok: true, text: async () => '<div class="blob">const a = 2;</div>' };
580580 if (u.endsWith("?fragment=explorer")) return { ok: true, text: async () => '<ul><li><a class="ex-file" data-ex-file tabindex="-1" title="src/a.ts" href="/erin/site/blob/b/src/a.ts">a.ts</a></li></ul>' };
581 if (u.includes("/confirm/")) { sent.push("answer:" + u + ":" + String(init.body)); return { ok: answer.status === 200, status: answer.status, json: async () => (answer.status === 200 ? { ok: true } : { ok: false, message: "this confirm was already answered; it does nothing twice" }) }; }
581 if (u.includes("/confirm/")) { sent.push("answer:" + u + ":" + String(init.body)); return { ok: answer.status === 200, status: answer.status, json: async () => (answer.status === 200 ? { ok: true } : { ok: false, message: answer.message }) }; }
582582 if (u.endsWith("/comments")) { sent.push("comment:" + u + ":" + String(init.body)); redirects.push(String((init as { redirect?: string }).redirect)); return cancel.status === 303 ? { ok: false, status: 0, type: "opaqueredirect" } : { ok: cancel.status === 200, status: cancel.status, text: async () => "" }; }
583583 if (u.endsWith("/files")) return { ok: true, json: async () => ({ id: "f1", name: "shot.png" }) };
584584 if (init.method === "DELETE") return { ok: true, json: async () => ({}) };
@@ -1212,16 +1212,43 @@ describe("the page", () => {
12121212 expect(t.status.textContent).toBe("The forge replied.");
12131213 });
12141214
1215 test("a refused answer keeps the confirm, says why, and gives the buttons back", async () => {
1215 test("an already-answered confirm leaves the dock, says why, and the thread is followed", async () => {
1216 const t = await boot();
1217 const { confirmItem } = await import("../src/web/pages/talk.ts");
1218 t.emitConfirm("5", confirmItem("h1", "archive", "Archive alice/site.", new Date(Date.now() + 600_000).toISOString()).text);
1219 const sources = t.sources.length;
1220 t.answer.status = 409;
1221 t.doc.querySelector("form.talk-compose").requestSubmit(t.doc.querySelector('#confirm-h1 button[value="yes"]'));
1222 await tick();
1223 const dock = t.doc.querySelector("[data-confirms]");
1224 const said = t.doc.querySelector("[data-confirms-said]");
1225 // The confirm is spent (answered in another tab, cancelled, or a destroying call that never
1226 // runs from Talk): drop it, say the server's words, and follow the thread for the outcome.
1227 expect([dock.hidden, dock.querySelectorAll(".talk-confirm").length, said.textContent, t.sources.length > sources]).toEqual([true, 0, "this confirm was already answered; it does nothing twice", true]);
1228 });
1229
1230 test("a destroying confirm that never runs from Talk also leaves the dock, with the thread's words", async () => {
12161231 const t = await boot();
12171232 const { confirmItem } = await import("../src/web/pages/talk.ts");
12181233 t.emitConfirm("5", confirmItem("h1", "archive", "Archive alice/site.", new Date(Date.now() + 600_000).toISOString()).text);
12191234 t.answer.status = 409;
1235 t.answer.message = "this destroys data, so it never runs from a conversation: do it yourself on its own page, which the thread now names";
1236 t.doc.querySelector("form.talk-compose").requestSubmit(t.doc.querySelector('#confirm-h1 button[value="yes"]'));
1237 await tick();
1238 expect([t.doc.querySelector("[data-confirms]").hidden, t.doc.querySelector("[data-confirms-said]").textContent]).toEqual([true, t.answer.message]);
1239 });
1240
1241 test("a refused answer keeps the confirm, says why, and gives the buttons back", async () => {
1242 const t = await boot();
1243 const { confirmItem } = await import("../src/web/pages/talk.ts");
1244 t.emitConfirm("5", confirmItem("h1", "archive", "Archive alice/site.", new Date(Date.now() + 600_000).toISOString()).text);
1245 t.answer.status = 403;
1246 t.answer.message = "this action is not yours to take";
12201247 const yes = t.doc.querySelector('#confirm-h1 button[value="yes"]');
12211248 t.doc.querySelector("form.talk-compose").requestSubmit(yes);
12221249 await tick();
12231250 const left = t.doc.querySelector("#confirm-h1 .talk-confirm-left");
1224 expect([t.doc.querySelectorAll(".talk-confirm").length, left.hidden, left.textContent, yes.disabled]).toEqual([1, false, "this confirm was already answered; it does nothing twice", false]);
1251 expect([t.doc.querySelectorAll(".talk-confirm").length, left.hidden, left.textContent, yes.disabled]).toEqual([1, false, "this action is not yours to take", false]);
12251252 });
12261253
12271254 test("things done in a row fold into one line as they stream in; one alone stays itself", async () => {

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs