Public: anyone can read this; the crew can change it.
Talk on a phone: the owner's notes (#16442 items 1–4, #16560), proven in Chromium at 360 and 390 #16585
Check · Review · Land · Live done — Landed and live in production.
talk-phone-notes → main 0 commits
5 files
changed +508
−106
docs/features/talk.md +2 −2
| @@ -18,9 +18,9 @@ The agent reaches the forge only through its MCP, as you. Its `tools/list` is th | ||
| 18 | 18 | |
| 19 | 19 | ## On the web: `/talk` |
| 20 | 20 | |
| 21 | Reached from the Talk icon in every page's top bar, "Talk to the forge" in the palette (`Ctrl/Cmd+K`), `g t`, and the Talk button beside the tell box on home. Signed out, it sends you to /signin and back. It shows your own conversation (the last 50 turns, "Earlier" pages back) and a composer; Enter sends and Shift+Enter breaks a line. `/` jumps to the composer from anywhere on the page except inside a field (and with no Ctrl, Cmd or Alt held); the composer carries `aria-keyshortcuts="/"`. It is a web shortcut only: the terminal door (`ssh <forge> talk`, `forge talk`) takes its words as typed and has no shortcut keys, so `/` there is just a character. | |
| 21 | Reached from the Talk icon in every page's top bar, "Talk to the forge" in the palette (`Ctrl/Cmd+K`), `g t`, and the Talk button beside the tell box on home. Signed out, it sends you to /signin and back. It shows your own conversation (the last 50 turns, oldest at the top, opened on the newest; "Earlier" puts the 50 before them above, in order, and keeps the turn being read where it was, or opens them as a page of their own without the script) and a composer; Enter sends and Shift+Enter breaks a line. `/` jumps to the composer from anywhere on the page except inside a field (and with no Ctrl, Cmd or Alt held); the composer carries `aria-keyshortcuts="/"`. It is a web shortcut only: the terminal door (`ssh <forge> talk`, `forge talk`) takes its words as typed and has no shortcut keys, so `/` there is just a character. | |
| 22 | 22 | |
| 23 | On a phone the composer is sticky and lifts above the on-screen keyboard (the script sets `--kb` from `visualViewport`); the log is a `role=log` (polite, additions only) and the status line `role=status`, each already a polite live region, so a reply is announced once. | |
| 23 | On a phone the composer is sticky and lifts above the on-screen keyboard (the script sets `--kb` from `visualViewport`); the head is one row (the list, the title, the model picker, Chat and Preview beside a preview, the menu and New) that never wraps, and a wide table scrolls inside its message, never the page. `test/talk-phone.test.ts` measures these at 360 and 390 px in Chromium with touch; in the forge's own check a missing Chromium fails it rather than skipping; the log is a `role=log` (polite, additions only) and the status line `role=status`, each already a polite live region, so a reply is announced once. | |
| 24 | 24 | |
| 25 | 25 | A reply streams in over `GET /talk/stream?after=<turn id>` (server-sent events, one `turn` frame per stored turn, each carrying the server-rendered markup, and `live` frames for the block being written, see "Live" below). The stream ends with the turn (`done`), or after 40 seconds (`more`), well inside the edge's timeout; the page then reconnects from the last turn id it saw (`Last-Event-ID` works too). Without the script the composer is a plain form and a reload shows the answer. |
| 26 | 26 |
src/web/pages/talk.ts +2 −2
| @@ -645,7 +645,7 @@ async function talkPage(ctx: Ctx, conversation: Conversation, before0: string | | ||
| 645 | 645 | <div class="talk" data-talk data-density="${display.density}" data-motion="${display.motion}" data-enter="${display.enter}" data-fold="${display.steps}" data-user="${user.id}" data-c="${conversation.id}" data-here="${here}" data-paged="${paged ? "1" : "0"}" data-running="${running && !paged ? "1" : "0"}"> |
| 646 | 646 | ${hereBar(ctx, conversation, context, display, split ? html`<nav class="seg talk-tabs" aria-label="Chat or preview"><a href="?pane=chat${paneQ === "" ? "" : `&${paneQ}`}"${shown === "chat" ? raw(' aria-current="page"') : null}>Chat</a><a href="?pane=preview${paneQ === "" ? "" : `&${paneQ}`}"${shown !== "chat" ? raw(' aria-current="page"') : null}>Preview</a></nav>` : null, picker)} |
| 647 | 647 | ${turns.length === DEFAULT_PAGE && turns[0] !== undefined |
| 648 | ? html`<p class="talk-more small"><a href="${here}?before=${turns[0].id}">Earlier</a></p>` | |
| 648 | ? html`<p class="talk-more small"><a href="${here}?before=${turns[0].id}" data-earlier>Earlier</a></p>` | |
| 649 | 649 | : null} |
| 650 | 650 | ${!paged ? null : html`<p class="talk-more small"><a href="${here}">Latest</a></p>`} |
| 651 | 651 | <ol class="talk-log" role="log" data-last="${last}" aria-label="Conversation with the forge"> |
| @@ -679,7 +679,7 @@ async function talkPage(ctx: Ctx, conversation: Conversation, before0: string | | ||
| 679 | 679 | </div> |
| 680 | 680 | ${buildMode ? html`<p class="talk-foot small"><a href="${here}">Talk instead</a></p>` : null} |
| 681 | 681 | <p class="talk-error small" id="talk-error" data-error hidden></p> |
| 682 | <p class="talk-status small muted" role="status">${running ? "The forge is answering…" : ""}</p> | |
| 682 | <p class="talk-status small muted" role="status">${running && !paged ? "The forge is answering…" : ""}</p> | |
| 683 | 683 | <button type="button" class="btn talk-jump" data-jump hidden title="Jump to the latest message">${icon("pause")}${icon("arrowDown")}<span data-word></span><i class="talk-dot"></i></button> |
| 684 | 684 | </form> |
| 685 | 685 | ${picker === null ? null : modelForm(urlOf(conversation))} |
src/web/pages/talk_client.ts +43 −6
| @@ -55,14 +55,15 @@ import { plainStep, plainThought, STEPS_SHOWN } from "../../core/talk_work.ts"; | ||
| 55 | 55 | export const talkCss = /* css */ ` |
| 56 | 56 | #main:has(> .talk-page) { padding-top: 0; padding-bottom: 0; } |
| 57 | 57 | body:has(.talk-page) .foot { display: none; } |
| 58 | body:has(.talk-page) .topbar { background: var(--bg); backdrop-filter: none; -webkit-backdrop-filter: none; } | |
| 58 | 59 | .talk-page { display: grid; grid-template-columns: minmax(0, 1fr); } |
| 59 | 60 | .talk { display: flex; flex-direction: column; width: 100%; max-width: 46rem; margin: 0 auto; min-width: 0; min-height: calc(100dvh - var(--topbar-h)); } |
| 60 | 61 | .talk-side, .talk-work, [data-view="list"] :is(.talk, .talk-work) { display: none; } |
| 61 | 62 | [data-view="list"] .talk-side { display: block; padding: 12px 0; } |
| 62 | .talk-head { position: sticky; top: var(--topbar-h); z-index: 8; display: flex; flex-wrap: nowrap; align-items: center; gap: 4px; min-height: 2.75rem; background: var(--bg); transition: transform var(--dur-2) var(--ease); } | |
| 63 | .talk-head { position: sticky; top: var(--topbar-h); z-index: 8; display: flex; flex-wrap: nowrap; align-items: center; gap: 4px; min-height: 2.75rem; padding-block: 2px; background: var(--bg); transition: transform var(--dur-2) var(--ease); } | |
| 63 | 64 | .talk-head[data-away] { transform: translateY(-110%); } |
| 64 | 65 | .talk-head[data-away]:is(:focus-within, :has(details[open])) { transform: none; } |
| 65 | .talk-title { flex: 1 1 0; min-width: 0; margin: 0; font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } | |
| 66 | .talk-title { flex: 1 1 0; min-width: 3rem; margin: 0; font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } | |
| 66 | 67 | .talk-fill { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; } |
| 67 | 68 | .talk-fill meter { width: 3rem; } |
| 68 | 69 | .talk-figures { display: grid; gap: 2px; padding: 8px 12px; border-bottom: 1px solid var(--border); } |
| @@ -87,8 +88,10 @@ body:has(.talk-page) .foot { display: none; } | ||
| 87 | 88 | .talk-rename { display: flex; gap: 8px; padding: 8px; } |
| 88 | 89 | .talk-rename .input { min-width: 0; flex: 1; font-size: 16px; } |
| 89 | 90 | .talk-tabs { flex: none; } |
| 91 | .talk-head .talk-tabs { padding-block: 0; } | |
| 90 | 92 | [data-split] .talk-head > form { display: none; } |
| 91 | 93 | .talk-tabs a { min-height: 2.75rem; display: inline-flex; align-items: center; } |
| 94 | @media (max-width: 30rem) { .talk-tabs a { padding-inline: 6px; } .talk-head > .talk-fill { display: none; } } | |
| 92 | 95 | .talk-body table { display: block; max-width: 100%; overflow-x: auto; overscroll-behavior-x: contain; background: linear-gradient(to right, var(--bg) 30%, transparent) left / 24px 100% no-repeat local, linear-gradient(to left, var(--bg) 30%, transparent) right / 24px 100% no-repeat local, linear-gradient(to right, var(--border-strong), transparent) left / 8px 100% no-repeat scroll, linear-gradient(to left, var(--border-strong), transparent) right / 8px 100% no-repeat scroll; } |
| 93 | 96 | .talk-body :is(td, th) { overflow-wrap: normal; word-break: normal; } |
| 94 | 97 | .talk-body td code { white-space: nowrap; } |
| @@ -130,7 +133,7 @@ body:has(.talk-page) .foot { display: none; } | ||
| 130 | 133 | .talk-body.prose { padding: 0; font-size: inherit; line-height: inherit; } |
| 131 | 134 | .talk-body.prose > * { max-width: none; } |
| 132 | 135 | .talk-body.prose table { display: block; width: fit-content; max-width: 100%; overflow-x: auto; } |
| 133 | .talk-body .table-scroll { --cover: var(--bg); width: fit-content; margin: 0 0 12px; } | |
| 136 | .talk-body .table-scroll { --cover: var(--bg); width: fit-content; max-width: 100%; margin: 0 0 12px; } | |
| 134 | 137 | .talk-body .table-scroll table { display: table; overflow: visible; } |
| 135 | 138 | .talk-body.prose :is(p, ul, ol, pre, table, blockquote) { margin: 0 0 12px; } |
| 136 | 139 | .talk-body.prose > :last-child { margin-bottom: 0; } |
| @@ -234,7 +237,7 @@ body:has(.talk-page) .foot { display: none; } | ||
| 234 | 237 | .talk-steer { border-radius: 999px; } |
| 235 | 238 | .talk-dictate[aria-pressed="true"] { background: var(--accent); color: var(--bg); } |
| 236 | 239 | .talk-foot { margin: 6px 16px 0; } |
| 237 | .talk-model { flex: 0 1 9rem; min-width: 0; margin: 0; display: flex; align-items: center; gap: 4px; } | |
| 240 | .talk-model { flex: 0 1 7rem; min-width: 4rem; margin: 0; display: flex; align-items: center; gap: 4px; } | |
| 238 | 241 | .talk-model select { width: 100%; min-width: 0; min-height: 2.5rem; font-size: 16px; text-overflow: ellipsis; } |
| 239 | 242 | .talk-status { margin: 4px 16px 0; min-height: 1.25rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } |
| 240 | 243 | [data-answering] .talk-status { background: none; animation: none; color: transparent; } |
| @@ -424,12 +427,20 @@ if (root) { | ||
| 424 | 427 | if (pick) { root.querySelector("[data-model-use]").hidden = true; pick.onchange = () => pick.form.requestSubmit(); } |
| 425 | 428 | box.required = false; |
| 426 | 429 | const fail = (words) => { say(""); err.textContent = words; err.hidden = false; box.setAttribute("aria-invalid", "true"); }; |
| 427 | // The keyboard covers the layout viewport on phones: lift the composer by what it hides. | |
| 430 | // The keyboard covers the layout viewport on phones: lift the composer by what it hides. Only | |
| 431 | // while something is typed into at the page's own scale: a pinch or a page wider than the phone | |
| 432 | // shrinks the visual viewport too, and lifting then floats the composer off the screen. | |
| 428 | 433 | const vv = window.visualViewport; |
| 429 | 434 | if (vv) { |
| 430 | const lift = () => { document.documentElement.style.setProperty("--kb", Math.max(0, window.innerHeight - vv.height - vv.offsetTop) + "px"); }; | |
| 435 | const lift = () => { | |
| 436 | const a = document.activeElement, typing = !!a && (/^(INPUT|TEXTAREA|SELECT)$/.test(a.tagName) || a.isContentEditable); | |
| 437 | const kb = typing && Math.abs(vv.scale - 1) < 0.01 ? Math.max(0, window.innerHeight - vv.height - vv.offsetTop) : 0; | |
| 438 | document.documentElement.style.setProperty("--kb", kb + "px"); | |
| 439 | }; | |
| 431 | 440 | vv.addEventListener("resize", lift); |
| 432 | 441 | vv.addEventListener("scroll", lift); |
| 442 | document.addEventListener("focusin", lift); | |
| 443 | document.addEventListener("focusout", () => setTimeout(lift)); | |
| 433 | 444 | } |
| 434 | 445 | document.addEventListener("keydown", (e) => { |
| 435 | 446 | if (e.key === "/" && !e.metaKey && !e.ctrlKey && !e.altKey && !/^(INPUT|TEXTAREA|SELECT)$/.test(document.activeElement.tagName) && !document.activeElement.isContentEditable) { e.preventDefault(); box.focus(); } |
| @@ -595,6 +606,32 @@ if (root) { | ||
| 595 | 606 | ? (done === 1 ? "1 thing done" : done + " things done") + (steps ? ", " + (steps === 1 ? "1 step" : steps + " steps") : "") |
| 596 | 607 | : steps === 1 ? items[0].querySelector("summary").firstChild.textContent.trim() : steps + " steps"; |
| 597 | 608 | }; |
| 609 | // Earlier: the older page is fetched and put above what is read, oldest first, and the place being | |
| 610 | // read stays where it is; without the script the link opens that page by itself. | |
| 611 | const more = root.querySelector("a[data-earlier]"); | |
| 612 | if (more) more.addEventListener("click", async (e) => { | |
| 613 | if (e.button || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) return; | |
| 614 | e.preventDefault(); | |
| 615 | if (more.hasAttribute("aria-busy")) return; | |
| 616 | more.setAttribute("aria-busy", "true"); | |
| 617 | try { | |
| 618 | const res = await fetch(more.href, { credentials: "same-origin", headers: { accept: "text/html" } }); | |
| 619 | if (!res.ok) throw new Error("earlier"); | |
| 620 | const doc = new DOMParser().parseFromString(await res.text(), "text/html"); | |
| 621 | const older = doc.querySelector(".talk-log"); | |
| 622 | if (!older) throw new Error("earlier"); | |
| 623 | const anchor = log.firstElementChild, was = anchor ? anchor.getBoundingClientRect().top : 0; | |
| 624 | stuck = false; | |
| 625 | log.prepend(...[...older.children].map((n) => document.importNode(n, true))); | |
| 626 | decorate(log); | |
| 627 | // Measured after the copy buttons are drawn: the turn being read stays where it was. | |
| 628 | if (anchor) { const d = anchor.getBoundingClientRect().top - was; if (d) sc().scrollBy({ top: d, behavior: "instant" }); } | |
| 629 | lastTop = sc().scrollTop; lastH = grown = sc().scrollHeight; | |
| 630 | const next = doc.querySelector("a[data-earlier]"); | |
| 631 | if (next) { more.href = next.getAttribute("href"); more.removeAttribute("aria-busy"); } else more.parentElement.remove(); | |
| 632 | draw(); | |
| 633 | } catch (_) { more.removeAttribute("aria-busy"); location.href = more.href; } | |
| 634 | }); | |
| 598 | 635 | const decorate = (scope) => { |
| 599 | 636 | scope.querySelectorAll(".talk-body pre:not([data-c])").forEach((pre) => { |
| 600 | 637 | pre.dataset.c = "1"; |
test/talk-page.test.ts +6 −3
| @@ -454,7 +454,9 @@ describe("the page", () => { | ||
| 454 | 454 | |
| 455 | 455 | test("the page's own bytes are held: stylesheet and script stay small", async () => { |
| 456 | 456 | const { talkCss, talkJs } = await import("../src/web/pages/talk_client.ts"); |
| 457 | expect(Buffer.byteLength(talkCss)).toBeLessThan(18_100); | |
| 457 | // 18,100 to 18,500 for the phone (#16442): one head row with the picker and tabs, a table that | |
| 458 | // scrolls in its bubble, an opaque top bar over the head: 18,294 measured. | |
| 459 | expect(Buffer.byteLength(talkCss)).toBeLessThan(18_500); | |
| 458 | 460 | expect(Buffer.byteLength(talkJs)).toBeLessThan(54_800); |
| 459 | 461 | // A page of its own, so what other tests said to alice never counts: one question and a code reply. |
| 460 | 462 | const sizer = await createUser(app.db, { origin: "seed", trusted: true, username: "sizer", email: "[email protected]", password: "a-good-passphrase" }); |
| @@ -469,8 +471,9 @@ describe("the page", () => { | ||
| 469 | 471 | // Raised from 47,000 by the widgets' rules and no more (widgetCss, 2,495 B raw): they ride every |
| 470 | 472 | // Talk page, because a chart can arrive in a live reply, and a page drawn without them would |
| 471 | 473 | // show it unstyled until a reload. 48,328 measured. Then to 50,000 by the reply's one last line |
| 472 | // and the pane's first-version words: 49,466 measured. | |
| 473 | expect(size).toBeLessThan(54_100); | |
| 474 | // and the pane's first-version words: 49,466 measured. Then to 54,600 by the same phone rules | |
| 475 | // (#16442), which ride inline: 54,393 measured. | |
| 476 | expect(size).toBeLessThan(54_600); | |
| 474 | 477 | }); |
| 475 | 478 | |
| 476 | 479 | describe("the script, driven against a DOM", () => { |
test/talk-phone.test.ts +455 −93
| @@ -1,15 +1,29 @@ | ||
| 1 | 1 | /** |
| 2 | * Talk on a phone (#16442), measured in a real Chromium at 360 px with a finger: the head is one | |
| 3 | * row of the list, the title, the connection picker, the menu and New; the composer does not move | |
| 4 | * as the tool-call count grows; the chat list opens at its top; the "answering" line ends with the | |
| 5 | * answer. Skipped, and says so, where no Chromium starts. | |
| 2 | * Talk on a phone (#16442, #16560), measured in a real Chromium at 360 and 390 px with a finger: | |
| 3 | * the head is one row (the list, the title, the model picker, the tabs, the menu and New) and | |
| 4 | * nothing in it wraps; the composer does not move as the status line or the tool-call count change; | |
| 5 | * the chat list opens at its top on the newest chat; the "answering" line ends with the answer; a | |
| 6 | * long chat reads oldest to newest and opens on the newest; Earlier puts the older turns above in | |
| 7 | * order and keeps the turn being read where it was, even while a reply arrives; a wide table | |
| 8 | * scrolls inside its bubble, never the page; the top bar is opaque with the head clear below it, and | |
| 9 | * the composer stays on screen at the newest end and halfway up. | |
| 10 | * | |
| 11 | * Skipped, and says so, where no Chromium starts, except in the forge's own check (`FORGE_CHECK`): | |
| 12 | * there a missing Chromium fails every browser test, so a green check means they ran (#16560). | |
| 6 | 13 | */ |
| 7 | 14 | import { afterAll, beforeAll, expect, test } from "bun:test"; |
| 8 | 15 | import { mkdtemp, rm } from "node:fs/promises"; |
| 9 | 16 | import { tmpdir } from "node:os"; |
| 10 | 17 | import { join } from "node:path"; |
| 11 | 18 | import { createApp, type App } from "../src/app.ts"; |
| 12 | import { appendTurn, openConversation, createConversation, renameConversation } from "../src/core/conversations.ts"; | |
| 19 | import { saveConnection } from "../src/core/connections.ts"; | |
| 20 | import { | |
| 21 | appendTurn, | |
| 22 | openConversation, | |
| 23 | createConversation, | |
| 24 | listTurns, | |
| 25 | renameConversation, | |
| 26 | } from "../src/core/conversations.ts"; | |
| 13 | 27 | import { createSession } from "../src/core/sessions.ts"; |
| 14 | 28 | import { createUser } from "../src/core/users.ts"; |
| 15 | 29 | import { findChromium } from "../src/looks/capture.ts"; |
| @@ -22,46 +36,102 @@ import { promote } from "./helpers/members.ts"; | ||
| 22 | 36 | quietLogs(); |
| 23 | 37 | const found = findChromium(); |
| 24 | 38 | const chromium = found !== undefined && chromiumRuns(found) ? found : undefined; |
| 25 | if (chromium === undefined) console.log("SKIPPING: no chromium that starts on this machine, so Talk on a phone is not measured"); | |
| 39 | /** The forge's own check names its run: there a browser test runs or fails, it never skips. */ | |
| 40 | const inCheck = (process.env["FORGE_CHECK"] ?? "") !== ""; | |
| 41 | const skip = chromium === undefined && !inCheck; | |
| 42 | if (skip) | |
| 43 | console.log( | |
| 44 | "SKIPPING: no chromium that starts on this machine, so Talk on a phone is not measured", | |
| 45 | ); | |
| 26 | 46 | |
| 47 | const WIDTHS = [360, 390] as const; | |
| 27 | 48 | let dir: string; |
| 28 | 49 | let app: App; |
| 29 | 50 | let servers: Servers; |
| 30 | 51 | let token: string; |
| 52 | let aliceId: string; | |
| 31 | 53 | let shortId: string; |
| 32 | 54 | let manyId: string; |
| 55 | let longId: string; | |
| 33 | 56 | let listToken: string; |
| 34 | 57 | |
| 35 | 58 | const toolTurns = (userId: string, id: string, n: number): void => { |
| 36 | 59 | appendTurn(app.db, userId, id, { role: "person", text: "change the title" }); |
| 37 | for (let i = 0; i < n; i++) appendTurn(app.db, userId, id, { role: "tool", text: `step ${i}` }); | |
| 60 | for (let i = 0; i < n; i++) | |
| 61 | appendTurn(app.db, userId, id, { role: "tool", text: `step ${i}` }); | |
| 38 | 62 | appendTurn(app.db, userId, id, { role: "agent", text: "Done." }); |
| 39 | 63 | }; |
| 64 | const TABLE = | |
| 65 | "| Pull | What it does |\n|---|---|\n| #16552 | `a-very-long-identifier-that-never-wraps-anywhere-on-a-phone` and more words |\n| #16561 | Earlier keeps the place |"; | |
| 40 | 66 | |
| 41 | 67 | beforeAll(async () => { |
| 42 | 68 | dir = await mkdtemp(join(tmpdir(), "forge-talk-phone-")); |
| 43 | 69 | app = createApp({ dataDir: dir, port: 0 }); |
| 44 | 70 | servers = await serve(app); |
| 45 | const made = await createUser(app.db, { origin: "seed", trusted: true, username: "alice", email: "[email protected]", password: "a-good-passphrase", adminIfFirst: true }); | |
| 71 | const made = await createUser(app.db, { | |
| 72 | origin: "seed", | |
| 73 | trusted: true, | |
| 74 | username: "alice", | |
| 75 | email: "[email protected]", | |
| 76 | password: "a-good-passphrase", | |
| 77 | adminIfFirst: true, | |
| 78 | }); | |
| 46 | 79 | if (!made.ok) throw new Error(made.error); |
| 47 | 80 | promote(app.db, made.value); |
| 48 | token = createSession(app.db, made.value.id).token; | |
| 49 | const a = openConversation(app.db, made.value.id); | |
| 81 | aliceId = made.value.id; | |
| 82 | token = createSession(app.db, aliceId).token; | |
| 83 | // A connection that offers models, so the head carries the picker as it does for the owner. | |
| 84 | const spark = saveConnection(app.db, app.config.dataDir, { | |
| 85 | name: "Spark", | |
| 86 | protocol: "openai", | |
| 87 | base: "http://127.0.0.1:9/v1", | |
| 88 | key: "sk-spark", | |
| 89 | scope: "forge", | |
| 90 | userId: aliceId, | |
| 91 | models: [{ id: "canned/small" }, { id: "canned/large-model" }], | |
| 92 | said: "2 models listed", | |
| 93 | }); | |
| 94 | if (!spark.ok) throw new Error(spark.error); | |
| 95 | const a = openConversation(app.db, aliceId); | |
| 50 | 96 | shortId = a.id; |
| 51 | toolTurns(made.value.id, a.id, 1); | |
| 52 | const b = createConversation(app.db, made.value.id); | |
| 97 | renameConversation( | |
| 98 | app.db, | |
| 99 | aliceId, | |
| 100 | shortId, | |
| 101 | "A short chat whose title is longer than a phone", | |
| 102 | ); | |
| 103 | toolTurns(aliceId, a.id, 1); | |
| 104 | const b = createConversation(app.db, aliceId); | |
| 53 | 105 | if (!b.ok) throw new Error(b.error); |
| 54 | 106 | manyId = b.value.id; |
| 55 | toolTurns(made.value.id, manyId, 9); | |
| 107 | toolTurns(aliceId, manyId, 9); | |
| 108 | // A long chat: 120 turns, one of them a table wider than any phone. | |
| 109 | const c = createConversation(app.db, aliceId); | |
| 110 | if (!c.ok) throw new Error(c.error); | |
| 111 | longId = c.value.id; | |
| 112 | for (let i = 0; i < 120; i++) | |
| 113 | appendTurn(app.db, aliceId, longId, { | |
| 114 | role: i % 2 === 0 ? "person" : "agent", | |
| 115 | text: i === 101 ? TABLE : `message ${i}`, | |
| 116 | }); | |
| 56 | 117 | // A second person with twenty chats, to see where the list opens. |
| 57 | const bob = await createUser(app.db, { origin: "seed", trusted: true, username: "bob", email: "[email protected]", password: "a-good-passphrase" }); | |
| 118 | const bob = await createUser(app.db, { | |
| 119 | origin: "seed", | |
| 120 | trusted: true, | |
| 121 | username: "bob", | |
| 122 | email: "[email protected]", | |
| 123 | password: "a-good-passphrase", | |
| 124 | }); | |
| 58 | 125 | if (!bob.ok) throw new Error(bob.error); |
| 59 | 126 | promote(app.db, bob.value); |
| 60 | 127 | for (let i = 0; i < 20; i++) { |
| 61 | 128 | const c = createConversation(app.db, bob.value.id); |
| 62 | 129 | if (!c.ok) throw new Error(c.error); |
| 63 | 130 | renameConversation(app.db, bob.value.id, c.value.id, `Chat number ${i}`); |
| 64 | appendTurn(app.db, bob.value.id, c.value.id, { role: "person", text: "hello" }); | |
| 131 | appendTurn(app.db, bob.value.id, c.value.id, { | |
| 132 | role: "person", | |
| 133 | text: "hello", | |
| 134 | }); | |
| 65 | 135 | } |
| 66 | 136 | listToken = createSession(app.db, bob.value.id).token; |
| 67 | 137 | }, 30_000); |
| @@ -71,90 +141,382 @@ afterAll(async () => { | ||
| 71 | 141 | await rm(dir, { recursive: true, force: true }); |
| 72 | 142 | }); |
| 73 | 143 | |
| 74 | const phone = (path: string, as: string, expression: string): Promise<any> => | |
| 75 | evaluateLoaded(chromium!, `${servers.url}${path}`, { width: 360, height: 740 }, [{ name: "forge_session", value: as }], expression, "light", true).then((v) => JSON.parse(v)); | |
| 144 | const phone = ( | |
| 145 | width: number, | |
| 146 | path: string, | |
| 147 | as: string, | |
| 148 | expression: string, | |
| 149 | ): Promise<any> => { | |
| 150 | if (chromium === undefined) | |
| 151 | throw new Error( | |
| 152 | "no Chromium starts in this check, so Talk on a phone is not measured: the check's image must carry one (FORGE_CHROMIUM)", | |
| 153 | ); | |
| 154 | return evaluateLoaded( | |
| 155 | chromium, | |
| 156 | `${servers.url}${path}`, | |
| 157 | { width, height: 740 }, | |
| 158 | [{ name: "forge_session", value: as }], | |
| 159 | expression, | |
| 160 | "light", | |
| 161 | true, | |
| 162 | ).then((v) => JSON.parse(v)); | |
| 163 | }; | |
| 164 | /** In the page: wait for `f` to hold, checking every 25 ms, at most `ms`. */ | |
| 165 | const WAIT = | |
| 166 | "const wait = (f, ms = 6000) => new Promise((ok) => { const t0 = performance.now(); const t = setInterval(() => { if (f() || performance.now() - t0 > ms) { clearInterval(t); ok(); } }, 25); });"; | |
| 167 | /** In the page: the log's turns, in the order a person reads them. */ | |
| 168 | const IDS = | |
| 169 | "const ids = () => [...document.querySelectorAll('.talk-log li[id^=\"t-\"]')].map((l) => l.id);"; | |
| 76 | 170 | |
| 77 | test.skipIf(chromium === undefined)("the message box does not ride when the status line speaks, nor with the tool-call count", async () => { | |
| 78 | const at = `(async () => { | |
| 79 | const box = () => document.querySelector(".talk-box").getBoundingClientRect().bottom; | |
| 80 | const st = document.querySelector(".talk-status"), form = document.querySelector("form.talk-compose"); | |
| 81 | const quiet = box(); | |
| 82 | st.textContent = "The forge replied."; | |
| 83 | const spoke = box(); | |
| 84 | form.setAttribute("data-answering", ""); | |
| 85 | st.textContent = "The forge is answering…"; | |
| 86 | const busy = box(); | |
| 87 | return JSON.stringify({ quiet, spoke, busy, sw: document.documentElement.scrollWidth }); | |
| 88 | })()`; | |
| 89 | const few = await phone(`/talk/${shortId}`, token, at); | |
| 90 | const many = await phone(`/talk/${manyId}`, token, at); | |
| 91 | for (const s of [few, many]) { | |
| 92 | expect(Math.abs(s.spoke - s.quiet)).toBeLessThanOrEqual(1); | |
| 93 | expect(Math.abs(s.busy - s.quiet)).toBeLessThanOrEqual(1); | |
| 94 | expect(s.sw).toBeLessThanOrEqual(360); | |
| 95 | } | |
| 96 | expect(Math.abs(few.quiet - many.quiet)).toBeLessThanOrEqual(1); | |
| 97 | }, 30_000); | |
| 98 | ||
| 99 | test.skipIf(chromium === undefined)("the head is one compact row: list, title, new chat and menu inside it, nothing wrapped", async () => { | |
| 100 | const s = await phone(`/talk/${shortId}`, token, `(() => { | |
| 101 | const head = document.querySelector(".talk-head"), h = head.getBoundingClientRect(); | |
| 102 | const kids = [...head.querySelectorAll(":scope > *")].filter((e) => e.getBoundingClientRect().width > 0).map((e) => { const r = e.getBoundingClientRect(); return { top: r.top, bottom: r.bottom, left: r.left, right: r.right, w: r.width, h: r.height, cls: e.className }; }); | |
| 103 | return JSON.stringify({ h: h.height, right: h.right, kids, area: kids.filter((k) => /btn/.test(k.cls)).map((k) => [k.w, k.h]) }); | |
| 104 | })()`); | |
| 105 | expect(s.h).toBeLessThanOrEqual(48); | |
| 106 | for (const k of s.kids) { expect(k.top).toBeGreaterThanOrEqual(0); expect(k.right).toBeLessThanOrEqual(360); expect(k.bottom - 0).toBeLessThanOrEqual(s.kids[0].top + 48); } | |
| 107 | for (const [w, h] of s.area) { expect(w).toBeGreaterThanOrEqual(44); expect(h).toBeGreaterThanOrEqual(44); } | |
| 108 | }, 30_000); | |
| 109 | ||
| 110 | test.skipIf(chromium === undefined)("the chat list opens at its top, the newest chat in view", async () => { | |
| 111 | const s = await phone(`/talk?chats=1`, listToken, `(async () => { await new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(r))); const first = document.querySelector(".talk-list .row"); const r = first.getBoundingClientRect(); return JSON.stringify({ y: window.scrollY, tall: document.documentElement.scrollHeight > innerHeight, top: r.top, text: first.textContent }); })()`); | |
| 112 | const seen = JSON.stringify(s); | |
| 113 | expect(s.y, seen).toBe(0); | |
| 114 | expect(s.top, seen).toBeGreaterThanOrEqual(0); | |
| 115 | expect(s.text, seen).toContain("Chat number 19"); | |
| 116 | expect(s.tall, seen).toBe(true); | |
| 117 | }, 30_000); | |
| 118 | ||
| 119 | test.skipIf(chromium === undefined)("the answering line is gone when the answer ends, even after a confirm was answered meanwhile", async () => { | |
| 120 | const was = { tick: clock.tickMs, running: clock.running }; | |
| 121 | let on = true; | |
| 122 | clock.tickMs = 100; | |
| 123 | clock.running = () => on; | |
| 124 | setTimeout(() => { on = false; }, 1800); | |
| 171 | test("without a browser: a page of older turns never says the forge is answering, since nothing there follows the answer", async () => { | |
| 172 | const was = clock.running; | |
| 173 | clock.running = () => true; | |
| 125 | 174 | try { |
| 126 | const s = await phone(`/talk/${shortId}`, token, `(async () => { | |
| 127 | const wait = (f) => new Promise((ok) => { const t = setInterval(() => { if (f()) { clearInterval(t); ok(); } }, 25); setTimeout(() => { clearInterval(t); ok(); }, 4000); }); | |
| 175 | const latest = listTurns(app.db, aliceId, longId, { limit: 50 }); | |
| 176 | if (!latest.ok) throw new Error(latest.error); | |
| 177 | const get = (path: string) => | |
| 178 | fetch(`${servers.url}${path}`, { | |
| 179 | headers: { cookie: `forge_session=${token}` }, | |
| 180 | }).then((r) => r.text()); | |
| 181 | expect(await get(`/talk/${longId}`)).toContain("The forge is answering…"); | |
| 182 | const older = await get(`/talk/${longId}?before=${latest.value[0]!.id}`); | |
| 183 | expect(older).not.toContain("The forge is answering…"); | |
| 184 | expect(older).toContain('data-paged="1"'); | |
| 185 | } finally { | |
| 186 | clock.running = was; | |
| 187 | } | |
| 188 | }); | |
| 189 | ||
| 190 | test("without a browser: the latest page is the last fifty in order, Earlier the fifty before, and the chat list is newest first", async () => { | |
| 191 | const get = (path: string, as = token) => | |
| 192 | fetch(`${servers.url}${path}`, { | |
| 193 | headers: { cookie: `forge_session=${as}` }, | |
| 194 | }).then((r) => r.text()); | |
| 195 | const nums = (page: string) => | |
| 196 | [ | |
| 197 | ...page | |
| 198 | .slice(page.indexOf('class="talk-log"')) | |
| 199 | .matchAll(/>message (\d+)</g), | |
| 200 | ].map((m) => Number(m[1])); | |
| 201 | const latest = await get(`/talk/${longId}`); | |
| 202 | const first = listTurns(app.db, aliceId, longId, { limit: 50 }); | |
| 203 | if (!first.ok) throw new Error(first.error); | |
| 204 | expect(latest).toContain( | |
| 205 | `href="/talk/${longId}?before=${first.value[0]!.id}" data-earlier`, | |
| 206 | ); | |
| 207 | const a = nums(latest); | |
| 208 | expect(a[0]).toBe(70); | |
| 209 | expect(a).toEqual([...a].sort((x, y) => x - y)); | |
| 210 | const b = nums(await get(`/talk/${longId}?before=${first.value[0]!.id}`)); | |
| 211 | expect([b[0], b.at(-1)]).toEqual([20, 69]); | |
| 212 | expect(b).toEqual([...b].sort((x, y) => x - y)); | |
| 213 | const list = await get("/talk?chats=1", listToken); | |
| 214 | expect(list).toContain('data-view="list"'); | |
| 215 | expect(list.indexOf("Chat number 19")).toBeGreaterThan(-1); | |
| 216 | expect(list.indexOf("Chat number 19")).toBeLessThan( | |
| 217 | list.indexOf("Chat number 0"), | |
| 218 | ); | |
| 219 | }); | |
| 220 | ||
| 221 | for (const width of WIDTHS) { | |
| 222 | test.skipIf(skip)( | |
| 223 | `${width} px: the message box does not ride when the status line speaks, nor with the tool-call count`, | |
| 224 | async () => { | |
| 225 | const at = `(async () => { | |
| 226 | const box = () => document.querySelector(".talk-box").getBoundingClientRect().bottom; | |
| 227 | const st = document.querySelector(".talk-status"), form = document.querySelector("form.talk-compose"); | |
| 228 | const quiet = box(); | |
| 229 | st.textContent = "The forge replied."; | |
| 230 | const spoke = box(); | |
| 231 | form.setAttribute("data-answering", ""); | |
| 232 | st.textContent = "The forge is answering…"; | |
| 233 | const busy = box(); | |
| 234 | return JSON.stringify({ quiet, spoke, busy, sw: document.documentElement.scrollWidth, vh: innerHeight }); | |
| 235 | })()`; | |
| 236 | const few = await phone(width, `/talk/${shortId}`, token, at); | |
| 237 | const many = await phone(width, `/talk/${manyId}`, token, at); | |
| 238 | for (const s of [few, many]) { | |
| 239 | expect(Math.abs(s.spoke - s.quiet)).toBeLessThanOrEqual(1); | |
| 240 | expect(Math.abs(s.busy - s.quiet)).toBeLessThanOrEqual(1); | |
| 241 | expect(s.sw).toBeLessThanOrEqual(width); | |
| 242 | // A short chat's box sits at the foot of the screen, not under the last turn. | |
| 243 | expect(s.vh - s.quiet).toBeLessThanOrEqual(48); | |
| 244 | } | |
| 245 | expect(Math.abs(few.quiet - many.quiet)).toBeLessThanOrEqual(1); | |
| 246 | }, | |
| 247 | 30_000, | |
| 248 | ); | |
| 249 | ||
| 250 | test.skipIf(skip)( | |
| 251 | `${width} px: the head is one compact row with the picker and the tabs, nothing wrapped or past the edge`, | |
| 252 | async () => { | |
| 253 | const s = await phone( | |
| 254 | width, | |
| 255 | `/talk/${shortId}`, | |
| 256 | token, | |
| 257 | `(() => { | |
| 258 | const head = document.querySelector(".talk-head"); | |
| 259 | const measure = () => { | |
| 260 | const h = head.getBoundingClientRect(); | |
| 261 | const kids = [...head.querySelectorAll(":scope > *")].filter((e) => e.getBoundingClientRect().width > 0).map((e) => { const r = e.getBoundingClientRect(); return { top: r.top, bottom: r.bottom, left: r.left, right: r.right, w: r.width, h: r.height, cls: String(e.className || e.tagName) }; }); | |
| 262 | return { h: h.height, kids, sw: document.documentElement.scrollWidth }; | |
| 263 | }; | |
| 264 | const plain = measure(); | |
| 265 | // A chat beside a live preview: the page splits and the head carries Chat and Preview. | |
| 266 | document.querySelector(".talk-page").setAttribute("data-split", ""); | |
| 267 | head.querySelector(".talk-model").insertAdjacentHTML("afterend", '<nav class="seg talk-tabs" aria-label="Chat or preview"><a href="?pane=chat" aria-current="page">Chat</a><a href="?pane=preview">Preview</a></nav>'); | |
| 268 | return JSON.stringify({ plain, split: measure() }); | |
| 269 | })()`, | |
| 270 | ); | |
| 271 | for (const [how, m] of Object.entries(s) as [ | |
| 272 | string, | |
| 273 | { | |
| 274 | h: number; | |
| 275 | sw: number; | |
| 276 | kids: { | |
| 277 | top: number; | |
| 278 | bottom: number; | |
| 279 | left: number; | |
| 280 | right: number; | |
| 281 | w: number; | |
| 282 | h: number; | |
| 283 | cls: string; | |
| 284 | }[]; | |
| 285 | }, | |
| 286 | ][]) { | |
| 287 | const seen = `${how}: ${JSON.stringify(m)}`; | |
| 288 | expect(m.h, seen).toBeLessThanOrEqual(48); | |
| 289 | expect(m.sw, seen).toBeLessThanOrEqual(width); | |
| 290 | expect(m.kids.map((k) => k.cls).join(" "), seen).toContain( | |
| 291 | "talk-model", | |
| 292 | ); | |
| 293 | const top = Math.min(...m.kids.map((k) => k.top)); | |
| 294 | for (const k of m.kids) { | |
| 295 | expect(k.right, seen).toBeLessThanOrEqual(width); | |
| 296 | expect(k.bottom, seen).toBeLessThanOrEqual(top + 48); | |
| 297 | if (/btn-icon|menu|FORM/.test(k.cls)) | |
| 298 | expect(Math.min(k.w, k.h), seen).toBeGreaterThanOrEqual(44); | |
| 299 | } | |
| 300 | // The title keeps at least a few letters. | |
| 301 | expect( | |
| 302 | m.kids.find((k) => k.cls.includes("talk-title"))!.w, | |
| 303 | seen, | |
| 304 | ).toBeGreaterThanOrEqual(48); | |
| 305 | } | |
| 306 | expect( | |
| 307 | s.plain.kids.some((k: { cls: string }) => k.cls === "FORM"), | |
| 308 | "New is in the head", | |
| 309 | ).toBe(true); | |
| 310 | }, | |
| 311 | 30_000, | |
| 312 | ); | |
| 313 | ||
| 314 | test.skipIf(skip)( | |
| 315 | `${width} px: the chat list opens at its top, the newest chat in view`, | |
| 316 | async () => { | |
| 317 | const s = await phone( | |
| 318 | width, | |
| 319 | `/talk?chats=1`, | |
| 320 | listToken, | |
| 321 | `(async () => { await new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(r))); const first = document.querySelector(".talk-list .row"); const r = first.getBoundingClientRect(); return JSON.stringify({ y: window.scrollY, tall: document.documentElement.scrollHeight > innerHeight, top: r.top, text: first.textContent }); })()`, | |
| 322 | ); | |
| 323 | const seen = JSON.stringify(s); | |
| 324 | expect(s.y, seen).toBe(0); | |
| 325 | expect(s.top, seen).toBeGreaterThanOrEqual(0); | |
| 326 | expect(s.text, seen).toContain("Chat number 19"); | |
| 327 | expect(s.tall, seen).toBe(true); | |
| 328 | }, | |
| 329 | 30_000, | |
| 330 | ); | |
| 331 | ||
| 332 | test.skipIf(skip)( | |
| 333 | `${width} px: a long chat reads oldest to newest, opens on the newest, and a wide table scrolls in its bubble`, | |
| 334 | async () => { | |
| 335 | const s = await phone( | |
| 336 | width, | |
| 337 | `/talk/${longId}`, | |
| 338 | token, | |
| 339 | `(async () => { | |
| 340 | ${IDS} | |
| 341 | await new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(r))); | |
| 342 | const all = [...document.querySelectorAll(".talk-log li[id^='t-']")], last = all.at(-1).getBoundingClientRect(); | |
| 343 | const texts = all.map((l) => (l.querySelector(".talk-body")?.textContent ?? "").trim()); | |
| 344 | return JSON.stringify({ ids: ids(), texts, y: scrollY, max: document.scrollingElement.scrollHeight - innerHeight, lastBottom: last.bottom, vh: innerHeight, vw: innerWidth, sw: document.documentElement.scrollWidth, table: !!document.querySelector(".talk-body table") }); | |
| 345 | })()`, | |
| 346 | ); | |
| 347 | const seen = JSON.stringify({ | |
| 348 | ...s, | |
| 349 | ids: s.ids.length, | |
| 350 | texts: s.texts.slice(0, 3), | |
| 351 | }); | |
| 352 | expect(s.ids, seen).toEqual([...s.ids].sort()); | |
| 353 | expect(s.texts[0], seen).toBe("message 70"); | |
| 354 | expect(s.texts.at(-1), seen).toBe("message 119"); | |
| 355 | expect(s.table, seen).toBe(true); | |
| 356 | // The page is the phone's width: a wide table does not zoom the whole page out. | |
| 357 | expect(s.vw, seen).toBe(width); | |
| 358 | expect(s.sw, seen).toBeLessThanOrEqual(width); | |
| 359 | expect(s.max - s.y, seen).toBeLessThanOrEqual(2); | |
| 360 | expect(s.lastBottom, seen).toBeLessThanOrEqual(s.vh); | |
| 361 | }, | |
| 362 | 30_000, | |
| 363 | ); | |
| 364 | ||
| 365 | test.skipIf(skip)( | |
| 366 | `${width} px: the top bar is opaque with the head clear below it, and the composer stays on screen wherever the thread is`, | |
| 367 | async () => { | |
| 368 | const s = await phone( | |
| 369 | width, | |
| 370 | `/talk/${longId}`, | |
| 371 | token, | |
| 372 | `(async () => { | |
| 373 | const frame = () => new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(r))); | |
| 374 | await frame(); | |
| 375 | const bar = document.querySelector(".topbar"), head = document.querySelector(".talk-head"), box = document.querySelector(".talk-box"); | |
| 376 | const cs = getComputedStyle(bar); | |
| 377 | // A chat beside a live preview: the head carries Chat and Preview, the tallest thing in it. | |
| 378 | head.querySelector(".talk-model")?.insertAdjacentHTML("afterend", '<nav class="seg talk-tabs" aria-label="Chat or preview"><a href="?pane=chat" aria-current="page">Chat</a><a href="?pane=preview">Preview</a></nav>'); | |
| 379 | const kids = () => Math.min(...[...head.children].filter((e) => e.getBoundingClientRect().width > 0).map((e) => e.getBoundingClientRect().top)); | |
| 380 | const at = (where) => ({ where, barBottom: bar.getBoundingClientRect().bottom, headTop: head.getBoundingClientRect().top, kidsTop: kids(), boxTop: box.getBoundingClientRect().top, boxBottom: box.getBoundingClientRect().bottom, vh: innerHeight }); | |
| 381 | const end = at("end"); | |
| 382 | scrollTo({ top: document.scrollingElement.scrollHeight / 2, behavior: "instant" }); | |
| 383 | await frame(); | |
| 384 | const middle = at("middle"); | |
| 385 | // The visual viewport changing with nothing typed into (a pinch, a toolbar) is not a keyboard. | |
| 386 | visualViewport.dispatchEvent(new Event("resize")); | |
| 387 | await frame(); | |
| 388 | return JSON.stringify({ bg: cs.backgroundColor, blur: cs.backdropFilter, kb: getComputedStyle(document.documentElement).getPropertyValue("--kb").trim(), end, middle }); | |
| 389 | })()`, | |
| 390 | ); | |
| 391 | const seen = JSON.stringify(s); | |
| 392 | // Opaque: no alpha in the colour, nothing blurred through it. | |
| 393 | expect(s.bg, seen).not.toMatch(/\/ 0\.|rgba\(.*, 0\.\d+\)/); | |
| 394 | expect(s.blur, seen).toBe("none"); | |
| 395 | expect(["", "0px"], seen).toContain(s.kb); | |
| 396 | for (const p of [s.end, s.middle]) { | |
| 397 | expect(p.headTop, seen).toBeGreaterThanOrEqual(p.barBottom - 0.5); | |
| 398 | expect(p.kidsTop, seen).toBeGreaterThanOrEqual(p.barBottom + 1); | |
| 399 | expect(p.boxBottom, seen).toBeLessThanOrEqual(p.vh); | |
| 400 | expect(p.boxTop, seen).toBeGreaterThan(p.vh - 140); | |
| 401 | } | |
| 402 | }, | |
| 403 | 30_000, | |
| 404 | ); | |
| 405 | ||
| 406 | test.skipIf(skip)( | |
| 407 | `${width} px: Earlier puts the older turns above in order and the turn being read stays put`, | |
| 408 | async () => { | |
| 409 | const s = await phone( | |
| 410 | width, | |
| 411 | `/talk/${longId}`, | |
| 412 | token, | |
| 413 | `(async () => { | |
| 414 | ${WAIT} ${IDS} | |
| 415 | scrollTo({ top: 0, behavior: "instant" }); | |
| 416 | await new Promise((r) => requestAnimationFrame(r)); | |
| 417 | const first = document.querySelector(".talk-log li[id^='t-']"), topBefore = first.getBoundingClientRect().top, url = location.href; | |
| 418 | document.querySelector("a[data-earlier]").click(); | |
| 419 | await wait(() => ids().length >= 100); | |
| 420 | // How far the turn being read moved, in pixels: a place, not a time. | |
| 421 | const shift = Math.abs(first.getBoundingClientRect().top - topBefore); | |
| 422 | document.querySelector("a[data-earlier]").click(); | |
| 423 | await wait(() => ids().length >= 120); | |
| 424 | return JSON.stringify({ ids: ids(), shift, same: location.href === url, more: !!document.querySelector("a[data-earlier]"), latest: document.querySelector("[data-jump]").hidden === false }); | |
| 425 | })()`, | |
| 426 | ); | |
| 427 | const seen = JSON.stringify({ ...s, ids: s.ids.length }); | |
| 428 | expect(s.same, seen).toBe(true); | |
| 429 | expect(s.ids.length, seen).toBe(120); | |
| 430 | expect(s.ids, seen).toEqual([...s.ids].sort()); | |
| 431 | expect(new Set(s.ids).size, seen).toBe(120); | |
| 432 | expect(s.shift, seen).toBeLessThanOrEqual(2); | |
| 433 | expect(s.more, seen).toBe(false); | |
| 434 | expect(s.latest, seen).toBe(true); | |
| 435 | }, | |
| 436 | 30_000, | |
| 437 | ); | |
| 438 | } | |
| 439 | ||
| 440 | test.skipIf(skip)( | |
| 441 | "a reply arriving while Earlier loads lands at the end; nothing reorders", | |
| 442 | async () => { | |
| 443 | const was = { tick: clock.tickMs, running: clock.running }; | |
| 444 | let looks = 0; | |
| 445 | clock.tickMs = 100; | |
| 446 | // Drawn running, the page opens the stream; the reply is written on the stream's second look, | |
| 447 | // so once the page is up, and the answer ends a few looks later. | |
| 448 | clock.running = (_a, _u, c) => { | |
| 449 | if (c !== longId) return false; | |
| 450 | looks += 1; | |
| 451 | if (looks === 3) appendTurn(app.db, aliceId, longId, { role: "agent", text: "arrived while paging" }); | |
| 452 | return looks <= 8; | |
| 453 | }; | |
| 454 | try { | |
| 455 | const s = await phone( | |
| 456 | 390, | |
| 457 | `/talk/${longId}`, | |
| 458 | token, | |
| 459 | `(async () => { | |
| 460 | ${WAIT} ${IDS} | |
| 461 | const reply = () => [...document.querySelectorAll(".talk-log li[id^='t-']")].find((l) => l.textContent.includes("arrived while paging")); | |
| 462 | // Earlier is held until the reply has landed, so the two cross. | |
| 463 | const real = window.fetch; | |
| 464 | const landed = wait(() => !!reply(), 3000); | |
| 465 | window.fetch = async (u, o) => { if (String(u).includes("before=")) await landed; return real(u, o); }; | |
| 466 | scrollTo({ top: 0, behavior: "instant" }); | |
| 467 | document.querySelector("a[data-earlier]").click(); | |
| 468 | await landed; | |
| 469 | await wait(() => ids().length >= 101, 3000); | |
| 470 | return JSON.stringify({ ids: ids(), arrived: reply()?.id ?? "" }); | |
| 471 | })()`, | |
| 472 | ); | |
| 473 | const seen = JSON.stringify({ ...s, ids: s.ids.length }); | |
| 474 | expect(s.arrived, seen).not.toBe(""); | |
| 475 | expect(s.ids.length, seen).toBe(101); | |
| 476 | expect(s.ids, seen).toEqual([...s.ids].sort()); | |
| 477 | expect(s.ids.at(-1), seen).toBe(s.arrived); | |
| 478 | } finally { | |
| 479 | clock.tickMs = was.tick; | |
| 480 | clock.running = was.running; | |
| 481 | } | |
| 482 | }, | |
| 483 | 30_000, | |
| 484 | ); | |
| 485 | ||
| 486 | test.skipIf(skip)( | |
| 487 | "the answering line is gone when the answer ends, even after a confirm was answered meanwhile", | |
| 488 | async () => { | |
| 489 | const was = { tick: clock.tickMs, running: clock.running }; | |
| 490 | let looks = 0; | |
| 491 | clock.tickMs = 100; | |
| 492 | // Running for the page and the stream's first few looks, then ended: no clock decides it. | |
| 493 | clock.running = () => (looks += 1) <= 6; | |
| 494 | try { | |
| 495 | const s = await phone( | |
| 496 | 360, | |
| 497 | `/talk/${shortId}`, | |
| 498 | token, | |
| 499 | `(async () => { | |
| 500 | ${WAIT} | |
| 128 | 501 | const st = document.querySelector(".talk-status"); |
| 129 | await wait(() => st.textContent.includes("answering")); | |
| 130 | 502 | const seen = st.textContent; |
| 131 | 503 | // A confirm answered while the answer runs: the page reads the outcome and stays quiet. |
| 132 | 504 | window.fetch = async () => new Response(JSON.stringify({ message: "Already answered" }), { status: 409 }); |
| 133 | 505 | const dock = document.querySelector(".talk-confirm-list"); |
| 134 | 506 | dock.insertAdjacentHTML("beforeend", '<div class="talk-confirm"><button type="button" data-answer formaction="/x" value="yes">Yes</button></div>'); |
| 135 | 507 | dock.querySelector("[data-answer]").click(); |
| 136 | await wait(() => !document.querySelector("form[data-answering]")); | |
| 137 | await wait(() => document.querySelector("[data-confirms]").hidden); | |
| 138 | return JSON.stringify({ seen, after: st.textContent }); | |
| 139 | })()`); | |
| 140 | expect(s.seen).toContain("answering"); | |
| 141 | expect(s.after).not.toContain("answering"); | |
| 142 | } finally { | |
| 143 | clock.tickMs = was.tick; | |
| 144 | clock.running = was.running; | |
| 145 | } | |
| 146 | }, 30_000); | |
| 147 | ||
| 148 | test("without a browser: the page's script ends the answering line with the answer and does not follow the end in the chat list", async () => { | |
| 149 | const { talkJs } = await import("../src/web/pages/talk_client.ts"); | |
| 150 | // Every way an answer ends goes through mode(false), which takes the line away. | |
| 151 | expect(talkJs).toContain('if (!on && status.textContent === ANSWERING) say("")'); | |
| 152 | expect(talkJs).toContain("let stuck = !document.querySelector('[data-view=\"list\"]')"); | |
| 153 | const res = await fetch(`${servers.url}/talk?chats=1`, { headers: { cookie: `forge_session=${listToken}` } }); | |
| 154 | const page = await res.text(); | |
| 155 | expect(page).toContain('data-view="list"'); | |
| 156 | // Newest first: the list's first row is the latest chat. | |
| 157 | expect(page).toContain("Chat number 0"); | |
| 158 | expect(page.indexOf("Chat number 19")).toBeLessThan(page.indexOf("Chat number 0")); | |
| 159 | expect(page.indexOf("Chat number 19")).toBeGreaterThan(-1); | |
| 160 | }); | |
| 508 | await wait(() => !document.querySelector("form[data-answering]"), 3500); | |
| 509 | await wait(() => document.querySelector("[data-confirms]").hidden, 500); | |
| 510 | return JSON.stringify({ seen, after: st.textContent, ended: !document.querySelector("form[data-answering]") }); | |
| 511 | })()`, | |
| 512 | ); | |
| 513 | expect(s.seen).toContain("answering"); | |
| 514 | expect(s.ended).toBe(true); | |
| 515 | expect(s.after).not.toContain("answering"); | |
| 516 | } finally { | |
| 517 | clock.tickMs = was.tick; | |
| 518 | clock.running = was.running; | |
| 519 | } | |
| 520 | }, | |
| 521 | 30_000, | |
| 522 | ); |
new above
offline