Public: anyone can read this; the crew can change it.
Talk: "Allow it" does nothing when pressed; every button on a held action answers at once #18261
Merged 5h 37m ago, live in production
scout/forge:scout/18251-talk-allow-it-does-nothing-when-pressed → main 0 commits fork 4 threads · 4 unresolved
docs/features/talk-wall.md +1 −1
| @@ -6,7 +6,7 @@ row: Answer the access wall from Talk or the terminal: Allow it, or Send it back | ||
| 6 | 6 | |
| 7 | 7 | When a pull would let more people in than before (anyone signed out reading an app's records, say), the access wall holds it for a person, whoever approved it. Talk now says so where you are, in the wall's own words, and you answer there. |
| 8 | 8 | |
| 9 | - **The receipt in Talk**: the line under it reads "The crew pushed #2. The access wall holds it for you to decide: anyone signed out could read counter records; …", with two buttons, **Allow it** and **Send it back**. Each is its own form posting to `/talk/wall` (same origin only, no script needed). Someone who reads the repository but may not write it sees the reason and no buttons. | |
| 9 | - **The receipt in Talk**: the line under it reads "The crew pushed #2. The access wall holds it for you to decide: anyone signed out could read counter records; …", with two buttons, **Allow it** and **Send it back**. Each is its own form posting to `/talk/wall` (same origin only, no script needed). With the script, a press shows "Allowed" on the button at once, posts in the background and says the result, or why it was refused, on the row; a second press is ignored. The held-action buttons (Do it, Not now) and a receipt's Undo answer the same way. Someone who reads the repository but may not write it sees the reason and no buttons. | |
| 10 | 10 | - **Talk's agent**: asked, it puts the decision to you with `wall { repo, number, answer: "allow" | "send_back", why? }`, always as a confirm whose sentence is the wall's own words, read from the forge: "Allow it and merge pull #2 in owner/counter: anyone signed out could read counter records; …". A pull you may not read is never named in it. An agent can never answer. |
| 11 | 11 | - **The terminal**: on the conversation's screen, the receipt's line carries `A: allow it · S: send it back` and the pull's page; `A` and `S` answer after a confirm. |
| 12 | 12 | - **What an answer does**: Allow it is the pull page's Merge (a merge commit, as its button does); Send it back is the page's request for changes, with the wall's words as the reason unless you give one. Every door goes through `answerWall` (`src/actions/pulls.ts`), so who may merge, the checks and a draft hold the same everywhere. |
src/web/act_now.ts +4 −1
| @@ -8,6 +8,8 @@ | ||
| 8 | 8 | * |
| 9 | 9 | * data-now="Word" what the form's buttons say the moment it is sent |
| 10 | 10 | * data-now-once the action is done for good: the buttons stay so |
| 11 | * data-now-lock with data-now-once: once one such form in the same | |
| 12 | * parent succeeds, its siblings' buttons are spent too | |
| 11 | 13 | * data-now-into="#id" an element that shows the new value at once, and |
| 12 | 14 | * data-now-from="name" the field it is read from (a select's option, or |
| 13 | 15 | * the chips of the ticked boxes) |
| @@ -18,7 +20,7 @@ | ||
| 18 | 20 | * held by `test/act-now.test.ts`. |
| 19 | 21 | */ |
| 20 | 22 | |
| 21 | export const ACT_NOW_BUDGET = 3000; | |
| 23 | export const ACT_NOW_BUDGET = 3300; | |
| 22 | 24 | |
| 23 | 25 | export const actNowJs = /* js */ ` |
| 24 | 26 | (function () { |
| @@ -57,6 +59,7 @@ export const actNowJs = /* js */ ` | ||
| 57 | 59 | say(said); |
| 58 | 60 | if (!ok) return undo.reverse().forEach(function (u) { u(); }); |
| 59 | 61 | var flip = f.getAttribute('data-now-flip'), once = f.hasAttribute('data-now-once'); |
| 62 | if (once && f.hasAttribute('data-now-lock')) all(f.parentNode.querySelectorAll('form[data-now-lock]')).forEach(function (g) { g.__busy = 1; all(g.querySelectorAll('button')).forEach(function (b) { b.setAttribute('aria-disabled', 'true'); }); }); | |
| 60 | 63 | if (flip && f.elements[flip]) { |
| 61 | 64 | f.elements[flip].value = f.elements[flip].value === '1' ? '0' : '1'; |
| 62 | 65 | f.setAttribute('data-now', f.getAttribute('data-now-alt')); |
src/web/pages/talk.ts +5 −6
| @@ -62,7 +62,7 @@ import { eventStream } from "../../http/sse.ts"; | ||
| 62 | 62 | import { signInFirst, forbiddenPage, notFoundPage } from "../chrome.ts"; |
| 63 | 63 | import { field, readForm } from "../form.ts"; |
| 64 | 64 | import { html, raw, type Html } from "../html.ts"; |
| 65 | import { flashTo, fragment, page, redirect } from "../layout.ts"; | |
| 65 | import { flashOrJson, flashTo, fragment, page, redirect } from "../layout.ts"; | |
| 66 | 66 | import { QUEUED_WORDS } from "./talk_client.ts"; |
| 67 | 67 | import { canRead, getRepo, getRepoById } from "../../core/repos.ts"; |
| 68 | 68 | import { getPull } from "../../core/pulls.ts"; |
| @@ -204,7 +204,7 @@ function receiptCard(id: string, turnId: string, receipt: Receipt, at: string, s | ||
| 204 | 204 | ? null |
| 205 | 205 | : undone |
| 206 | 206 | ? html`<span class="small muted">Undone.</span>` |
| 207 | : html`<form method="post" action="${HERE}/undo/${turnId}">${btn(receipt.undo.label, { icon: "history", label: receipt.undo.label, size: "sm", variant: "ghost" })}</form>`; | |
| 207 | : html`<form method="post" action="${HERE}/undo/${turnId}" data-now="Undone" data-now-once>${btn(receipt.undo.label, { icon: "history", label: receipt.undo.label, size: "sm", variant: "ghost" })}</form>`; | |
Undo's JSON branch (in talkUndo) answers {ok:false,message}, but act_now.ts reads j.error || j.flash, not message. A refused Undo therefore shows the generic 'That did not go through (422). Nothing changed.' instead of the reason. Return |
||
| 208 | 208 | return html`<li class="talk-turn talk-receipt${set}" id="${id}" data-done> |
| 209 | 209 | <p class="talk-receipt-line">${icon("check")}<span><strong>${receipt.verb}</strong> <a href="${receipt.href}">${receipt.object}</a>${title === "" ? null : html` <span class="muted">${title}</span>`} <span class="talk-when">${time(at)}</span></span></p> |
| 210 | 210 | ${issue === null ? null : html`<div class="talk-work-line small muted" id="w-${turnId}" data-live="run.*,issue.*,pull.*,comment.*" data-live-repo="${issue[1]}/${issue[2]}" data-live-src="/live/talk-work?href=${encodeURIComponent(receipt.href)}&id=w-${turnId}">${workLineHtml(line)}</div>`} |
| @@ -847,9 +847,8 @@ export async function talkWall(ctx: Ctx): Promise<Response> { | ||
| 847 | 847 | const answer = field(form, "answer"); |
| 848 | 848 | if (repo === undefined || pull === undefined || (answer !== "allow" && answer !== "send_back")) return notFoundPage(ctx); |
| 849 | 849 | const done = await answerWall(ctx.app, user, repo, pull, answer); |
| 850 | if (!done.ok) | |
| 851 | return flashTo(ctx, `${HERE}`, { tone: "danger", message: wallFailure(done.error) }); | |
| 852 | return flashTo(ctx, `${HERE}`, { tone: "success", message: done.value === "merged" ? `Allowed and merged #${pull.number}.` : `Sent #${pull.number} back to its builder.` }); | |
| 850 | if (!done.ok) return flashOrJson(ctx, `${HERE}`, { tone: "danger", message: wallFailure(done.error) }); | |
| 851 | return flashOrJson(ctx, `${HERE}`, { tone: "success", message: done.value === "merged" ? `Allowed and merged #${pull.number}.` : `Sent #${pull.number} back to its builder.` }); | |
| 853 | 852 | } |
| 854 | 853 | |
| 855 | 854 | // POST /talk/new — an empty conversation, opened at its own URL. |
| @@ -1029,7 +1028,7 @@ export async function talkUndo(ctx: Ctx): Promise<Response> { | ||
| 1029 | 1028 | const done = await undoReceipt(ctx, user, ctx.params["turn"] ?? ""); |
| 1030 | 1029 | const status = done.ok ? 200 : done.error === "failed" ? 422 : UNDO_REFUSED[done.error][0]; |
| 1031 | 1030 | if ((ctx.request.headers.get("accept") ?? "").includes("application/json")) |
| 1032 | return json(done.ok ? { ok: true } : { ok: false, message: done.message }, status); | |
| 1031 | return json(done.ok ? { ok: true, flash: "Undone." } : { ok: false, error: `Nothing was undone: ${done.message}`, message: done.message }, status); | |
| 1033 | 1032 | return flashTo(ctx, `${HERE}#end`, done.ok ? { tone: "success", message: "Undone." } : { tone: "danger", message: `Nothing was undone: ${done.message}` }); |
| 1034 | 1033 | } |
| 1035 | 1034 |
src/web/pages/talk_client.ts +7 −4
| @@ -907,17 +907,20 @@ if (root) { | ||
| 907 | 907 | const answerConfirm = async (b) => { |
| 908 | 908 | const a = b.closest(".talk-confirm"), yes = b.value === "yes", buttons = a.querySelectorAll("button"); |
| 909 | 909 | // Said without a visible line, so answering moves nothing; a refusal is said on the confirm itself. |
| 910 | const refused = (why) => { const p = a.querySelector(".talk-confirm-left"); p.hidden = false; p.textContent = why; tell(why); buttons.forEach((x) => { x.disabled = false; }); }; | |
| 911 | const spent = (why) => { tell(why); dropConfirm(a); hush = !paged; follow(); }; | |
| 910 | const was = b.innerHTML; | |
| 911 | const refused = (why) => { const p = a.querySelector(".talk-confirm-left"); p.hidden = false; p.textContent = why; tell(why); b.innerHTML = was; b.removeAttribute("aria-busy"); buttons.forEach((x) => { x.disabled = false; }); }; | |
| 912 | const spent = (why, label) => { tell(why); const p = a.querySelector(".talk-confirm-left"); p.hidden = false; p.textContent = why; b.textContent = label; dropConfirm(a); hush = !paged; follow(); }; | |
spent() sets the button to 'Done' for any yes, including the 409 'already answered' path, which is not a success. Pick the label from the outcome, and show the server's words on the row. |
||
| 913 | // Pressed shows at once, on the button itself: its working word, and no second press. | |
| 914 | b.textContent = yes ? "Doing it\u2026" : "Dropping\u2026"; b.setAttribute("aria-busy", "true"); | |
| 912 | 915 | buttons.forEach((x) => { x.disabled = true; }); |
| 913 | 916 | try { |
| 914 | 917 | const res = await fetch(b.getAttribute("formaction"), { method: "POST", headers: { accept: "application/json" }, body: new URLSearchParams({ answer: b.value }) }); |
| 915 | 918 | const out = await res.json().catch(() => ({})); |
| 916 | 919 | if (res.status === 410) { window.location.reload(); return; } |
| 917 | 920 | // 409: spent (already answered, or a delete that never runs here). |
| 918 | if (res.status === 409) return spent(out.message || "Already answered: nothing more to do."); | |
| 921 | if (res.status === 409) return spent(out.message || "Already answered: nothing more to do.", "Already answered"); | |
| 919 | 922 | if (!res.ok) return refused(out.message || "Nothing was done."); |
| 920 | spent(yes ? "Done." : "Not now: nothing was done."); | |
| 923 | spent(yes ? "Done." : "Not now: nothing was done.", yes ? "Done" : "Not now"); | |
| 921 | 924 | } catch (_) { |
| 922 | 925 | refused("That was not sent: no connection."); |
| 923 | 926 | } |
src/web/talk_lines.ts +1 −1
| @@ -62,7 +62,7 @@ export const workLineHtml = (l: WorkLine): Html => | ||
| 62 | 62 | /** "Allow it" and "Send it back", each its own form: the answer is in the form, never a query. */ |
| 63 | 63 | const wallAnswers = (w: { readonly repo: string; readonly number: number }): Html => { |
| 64 | 64 | const form = (answer: "allow" | "send_back", words: string, variant: "primary" | "ghost") => |
| 65 | html`<form method="post" action="/talk/wall" class="inline-form"> | |
| 65 | html`<form method="post" action="/talk/wall" class="inline-form" data-now="${answer === "allow" ? "Allowed" : "Sent back"}" data-now-once data-now-lock> | |
| 66 | 66 | <input type="hidden" name="repo" value="${w.repo}" /><input type="hidden" name="number" value="${String(w.number)}" /><input type="hidden" name="answer" value="${answer}" /> |
| 67 | 67 | ${btn(words, { size: "sm", variant })} |
| 68 | 68 | </form>`; |
test/talk-page.test.ts +56
| @@ -1332,6 +1332,62 @@ describe("the page", () => { | ||
| 1332 | 1332 | expect([t.doc.querySelector("[data-confirms]").hidden, t.doc.querySelector("[data-confirms-said]").textContent]).toEqual([true, t.answer.message]); |
| 1333 | 1333 | }); |
| 1334 | 1334 | |
| 1335 | test("Do it shows its pressed word at once, posts, and says the result on the row: after a fresh load and after a streamed turn", async () => { | |
| 1336 | const { confirmItem } = await import("../src/web/pages/talk.ts"); | |
| 1337 | const held = () => confirmItem("h1", "archive", "Archive alice/site.", new Date(Date.now() + 600_000).toISOString()).text; | |
| 1338 | for (const streamed of [false, true]) { | |
| 1339 | const t = await boot(); | |
| 1340 | if (streamed) t.emit("t-9", '<li class="talk-turn talk-agent" id="t-9"><div class="talk-body"><p>Held for you.</p></div></li>'); | |
| 1341 | t.emitConfirm("5", held()); | |
| 1342 | const yes = t.doc.querySelector('#confirm-h1 button[value="yes"]'); | |
| 1343 | t.doc.querySelector("form.talk-compose").requestSubmit(yes); | |
| 1344 | // Before any reply: the pressed word is on the button and no second press is possible. | |
| 1345 | expect([yes.textContent, yes.getAttribute("aria-busy"), yes.disabled]).toEqual(["Doing it\u2026", "true", true]); | |
| 1346 | await tick(); | |
| 1347 | expect(t.sent).toEqual(["answer:/talk/confirm/h1:answer=yes"]); | |
| 1348 | expect([yes.textContent, t.doc.querySelector("[data-confirms-said]").textContent]).toEqual(["Done", "Done."]); | |
| 1349 | } | |
| 1350 | }); | |
| 1351 | ||
| 1352 | test("an already-answered Do it says the server's words on the row, not Done", async () => { | |
| 1353 | const { confirmItem } = await import("../src/web/pages/talk.ts"); | |
| 1354 | const t = await boot(); | |
| 1355 | t.emitConfirm("5", confirmItem("h1", "archive", "Archive alice/site.", new Date(Date.now() + 600_000).toISOString()).text); | |
| 1356 | const row = t.doc.querySelector("#confirm-h1"); | |
| 1357 | const yes = row.querySelector('button[value="yes"]'); | |
| 1358 | t.answer.status = 409; | |
| 1359 | t.doc.querySelector("form.talk-compose").requestSubmit(yes); | |
| 1360 | await tick(); | |
| 1361 | expect(yes.textContent).toBe("Already answered"); | |
| 1362 | expect(row.querySelector(".talk-confirm-left").textContent).toBe(t.answer.message); | |
| 1363 | }); | |
| 1364 | ||
| 1365 | test("Allow it, fresh or in a streamed turn, shows Allowed at once, posts the answer, says the result on the row, and spends Send it back", async () => { | |
| 1366 | const { workLineHtml } = await import("../src/web/talk_lines.ts"); | |
| 1367 | const { actNowJs } = await import("../src/web/act_now.ts"); | |
| 1368 | const line = workLineHtml({ says: "Waiting for you to land it.", wall: { repo: "alice/site", number: 7 } }).text; | |
| 1369 | for (const streamed of [false, true]) { | |
| 1370 | const t = await boot(); | |
| 1371 | const posts: string[] = []; | |
| 1372 | let reply: (r: unknown) => void = () => {}; | |
| 1373 | const hold = (u: string, init: { body: URLSearchParams }) => { posts.push(u + ":" + String(init.body)); return new Promise((r) => { reply = r; }); }; | |
| 1374 | new Function("document", "window", "fetch", "FormData", "URLSearchParams", actNowJs)(t.doc, t.window, hold, t.window.FormData, URLSearchParams); | |
| 1375 | if (streamed) t.emit("t-9", `<li class="talk-turn talk-agent" id="t-9"><div class="talk-body">${line}</div></li>`); | |
| 1376 | else t.doc.querySelector(".talk-log").insertAdjacentHTML("beforeend", `<li class="talk-turn" id="t-0">${line}</li>`); | |
| 1377 | const [allow, back] = [...t.doc.querySelectorAll('form[action="/talk/wall"]')]; | |
| 1378 | allow.requestSubmit(); | |
| 1379 | expect(allow.querySelector("button").textContent).toBe("Allowed"); | |
| 1380 | expect(posts).toEqual(["http://localhost/talk/wall:repo=alice%2Fsite&number=7&answer=allow"]); | |
| 1381 | reply({ ok: true, status: 200, json: async () => ({ ok: true, flash: "Allowed and merged #7." }) }); | |
| 1382 | await pollUntil(() => allow.querySelector("p[role=status]")?.textContent === "Allowed and merged #7.", "the result on the row"); | |
| 1383 | expect(allow.querySelector("p[role=status]").textContent).toBe("Allowed and merged #7."); | |
| 1384 | // The other answer cannot be pressed on a merged pull. | |
| 1385 | expect(back.querySelector("button").getAttribute("aria-disabled")).toBe("true"); | |
| 1386 | back.requestSubmit(); | |
| 1387 | expect(posts).toHaveLength(1); | |
| 1388 | } | |
| 1389 | }); | |
| 1390 | ||
| 1335 | 1391 | test("a refused answer keeps the confirm, says why, and gives the buttons back", async () => { |
| 1336 | 1392 | const t = await boot(); |
| 1337 | 1393 | const { confirmItem } = await import("../src/web/pages/talk.ts"); |
test/talk-wall-says.test.ts +41
| @@ -233,6 +233,9 @@ describe("the access wall, said where the person is", () => { | ||
| 233 | 233 | expect(forms.length).toBe(2); |
| 234 | 234 | expect(forms[0]).toContain('name="answer" value="allow"'); |
| 235 | 235 | expect(forms[0]).toContain("Allow it"); |
| 236 | // Pressed shows at once (act-now's working word, once), never a silent post. | |
| 237 | expect(forms[0]).toContain('data-now="Allowed" data-now-once'); | |
| 238 | expect(forms[1]).toContain('data-now="Sent back" data-now-once'); | |
| 236 | 239 | expect(forms[1]).toContain('name="answer" value="send_back"'); |
| 237 | 240 | expect(forms[1]).toContain("Send it back"); |
| 238 | 241 | expect(html).not.toContain('<a href="/alice/counter/pulls'); |
| @@ -281,6 +284,44 @@ describe("the access wall, said where the person is", () => { | ||
| 281 | 284 | expect(merged(pull)).toBe(false); |
| 282 | 285 | }); |
| 283 | 286 | |
| 287 | test("pressed in place (JSON), Allow it merges and says so, and a second press says why in words on the row", async () => { | |
| 288 | const pull = await wallPull(repo, "crew/inplace", OPENS); | |
| 289 | const press = () => | |
| 290 | fetch(`${servers.url}/talk/wall`, { | |
| 291 | method: "POST", | |
| 292 | headers: { | |
| 293 | cookie: `forge_session=${createSession(app.db, alice.id).token}`, | |
| 294 | origin: servers.url, | |
| 295 | accept: "application/json", | |
| 296 | "content-type": "application/x-www-form-urlencoded", | |
| 297 | }, | |
| 298 | body: new URLSearchParams({ repo: "alice/counter", number: String(pull.number), answer: "allow" }).toString(), | |
| 299 | }); | |
| 300 | const first = await press(); | |
| 301 | expect([first.status, await first.json()]).toEqual([200, { ok: true, flash: `Allowed and merged #${pull.number}.` }]); | |
| 302 | expect(merged(pull)).toBe(true); | |
| 303 | const again = await press(); | |
| 304 | const said = (await again.json()) as { ok: boolean; error: string }; | |
| 305 | expect(again.status).toBe(422); | |
| 306 | expect(said.ok).toBe(false); | |
| 307 | expect(said.error.length).toBeGreaterThan(10); | |
| 308 | }); | |
| 309 | ||
| 310 | test("Undo pressed twice: the second refusal's reason reaches the row as `error`", async () => { | |
| 311 | const undo = (turn: string) => | |
| 312 | fetch(`${servers.url}/talk/undo/${turn}`, { | |
| 313 | method: "POST", | |
| 314 | headers: { cookie: `forge_session=${createSession(app.db, alice.id).token}`, origin: servers.url, accept: "application/json", "content-type": "application/x-www-form-urlencoded" }, | |
| 315 | body: "", | |
| 316 | }); | |
| 317 | const r = await undo("no-such-turn"); | |
| 318 | const said = (await r.json()) as { ok: boolean; error: string }; | |
| 319 | expect(r.ok).toBe(false); | |
| 320 | expect(said.ok).toBe(false); | |
| 321 | expect(said.error).toStartWith("Nothing was undone: "); | |
| 322 | expect(said.error.length).toBeGreaterThan(25); | |
| 323 | }); | |
| 324 | ||
| 284 | 325 | test("Talk's agent puts the decision as a held confirm in the wall's own words; the person's yes allows it and it merges", async () => { |
| 285 | 326 | const pull = await wallPull(repo, "crew/held", OPENS); |
| 286 | 327 | const talk = talkOf(alice, "what is waiting?"); |
Non-blocking: the byte budget was raised to fit data-now-lock. Prefer trimming existing script next time over lifting the cap.