Public: anyone can read this; the crew can change it.
Talk on a phone (#16442): pull #16532's three red checks were the shared inst… #16552
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/16551-talk-on-a-phone-16442-pull-16532-s-three → main 0 commits fork
7 files
changed +212
−25
scripts/phone-persona/brief.md added +15
| @@ -0,0 +1,15 @@ | ||
| 1 | # The phone persona (#16442) | |
| 2 | ||
| 3 | One more experiment beside the forge-to-forge one (#16407): a person who has only a phone. | |
| 4 | ||
| 5 | **Doors.** The phone UI only: a browser at 390 x 844 CSS px, touch input (taps and swipes, no hover, no keyboard shortcuts, the on-screen keyboard taking the bottom third while a field is focused). It may not use the API, the MCP, git or the terminal, and it may not read the page's source: only what a thumb and an eye can reach. | |
| 6 | ||
| 7 | **The run.** | |
| 8 | 1. Open the forge's address, sign up with a name, an address and a passphrase. | |
| 9 | 2. Open Talk. Ask for one small change to an app ("make the title bigger"). | |
| 10 | 3. When a confirm appears in the dock above the box, read it and answer it with one thumb. | |
| 11 | 4. Read the result in the thread: the receipt, the link, the preview. | |
| 12 | ||
| 13 | **What counts as stuck.** A control under 44 px, a button without a name, a sideways scroll, text under the keyboard, a line that never goes ("answering" after the answer), a box that moves while the thread grows, a list that opens at its far end, a top bar that wraps, or a step it cannot finish without leaving the phone. | |
| 14 | ||
| 15 | **What it hands back.** Every stuck place becomes one issue: the page, the width, what it did with its thumb, what it saw, what it expected. Each issue is fixed with a test at its route; `test/talk-phone.test.ts` is where Talk's own land, measured at 360 px with touch emulation (`evaluateLoaded(..., touch = true)` in `test/helpers/chrome.ts`). |
src/web/pages/talk.ts +4 −3
| @@ -496,13 +496,14 @@ function displayForm(display: TalkDisplay, back: string): Html { | ||
| 496 | 496 | * The open conversation's head: on a phone the way to the list, then its name, what it has cost, |
| 497 | 497 | * and one menu for Rename, Download, Pin and Archive, each a plain form or link. |
| 498 | 498 | */ |
| 499 | function hereBar(ctx: Ctx, conversation: Conversation, context: Context | undefined, display: TalkDisplay, tabs: Html | null): Html { | |
| 499 | function hereBar(ctx: Ctx, conversation: Conversation, context: Context | undefined, display: TalkDisplay, tabs: Html | null, picker: Html | null = null): Html { | |
| 500 | 500 | const archived = conversation.archivedAt !== null; |
| 501 | 501 | const item = (action: string, field: string, value: string, label: string, ic: "pin" | "history" | "trash"): Html => |
| 502 | 502 | html`<form method="post" action="${urlOf(conversation)}/${action}"><input type="hidden" name="${field}" value="${value}" /><button class="menu-item" type="submit">${icon(ic)}<span class="grow">${label}</span></button></form>`; |
| 503 | 503 | return html`<header class="talk-head"> |
| 504 | 504 | <a class="btn btn-icon talk-back" data-variant="ghost" href="${urlOf(conversation)}?chats=1" aria-label="Conversations" title="Conversations">${icon("comment")}</a> |
| 505 | 505 | <h2 class="talk-title">${nameOf(conversation)}${archived ? " (archived)" : ""}</h2> |
| 506 | ${picker} | |
| 506 | 507 | ${tabs} |
| 507 | 508 | ${context !== undefined && context.share >= CONTEXT_SHOWN ? html`<span class="talk-fill small muted" title="${contextText(context)}">${meter(context.share * 100, contextText(context))} context used</span>` : null} |
| 508 | 509 | ${menu({ |
| @@ -642,7 +643,7 @@ async function talkPage(ctx: Ctx, conversation: Conversation, before0: string | | ||
| 642 | 643 | const body = html`<div class="talk-page" data-shell${!split ? null : html` data-frame-origins="${frames.join(" ")}"`} data-pane="${shown}"${listing ? raw(" data-view=\"list\"") : null}${split ? raw(" data-split") : null}><h1 class="sr-only">Talk</h1> |
| 643 | 644 | <div class="talk-side">${chats(ctx, conversation, showArchived, typed)}</div> |
| 644 | 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"}"> |
| 645 | ${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)} | |
| 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)} | |
| 646 | 647 | ${turns.length === DEFAULT_PAGE && turns[0] !== undefined |
| 647 | 648 | ? html`<p class="talk-more small"><a href="${here}?before=${turns[0].id}">Earlier</a></p>` |
| 648 | 649 | : null} |
| @@ -676,7 +677,7 @@ async function talkPage(ctx: Ctx, conversation: Conversation, before0: string | | ||
| 676 | 677 | <button type="submit" class="btn btn-icon talk-send" data-variant="primary" aria-label="${buildMode ? "Build it" : editing === undefined ? "Send" : "Resend"}" title="${buildMode ? "Build it" : editing === undefined ? "Send" : "Resend"}">${icon("arrowUp")}</button> |
| 677 | 678 | </div> |
| 678 | 679 | </div> |
| 679 | ${buildMode ? html`<p class="talk-foot small"><a href="${here}">Talk instead</a></p>` : picker} | |
| 680 | ${buildMode ? html`<p class="talk-foot small"><a href="${here}">Talk instead</a></p>` : null} | |
| 680 | 681 | <p class="talk-error small" id="talk-error" data-error hidden></p> |
| 681 | 682 | <p class="talk-status small muted" role="status">${running ? "The forge is answering…" : ""}</p> |
| 682 | 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> |
src/web/pages/talk_client.ts +17 −14
| @@ -59,10 +59,10 @@ body:has(.talk-page) .foot { display: none; } | ||
| 59 | 59 | .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 | 60 | .talk-side, .talk-work, [data-view="list"] :is(.talk, .talk-work) { display: none; } |
| 61 | 61 | [data-view="list"] .talk-side { display: block; padding: 12px 0; } |
| 62 | .talk-head { position: sticky; top: var(--topbar-h); z-index: 8; display: flex; align-items: center; gap: 4px; min-height: 2.5rem; background: var(--bg); transition: transform var(--dur-2) var(--ease); } | |
| 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 | 63 | .talk-head[data-away] { transform: translateY(-110%); } |
| 64 | 64 | .talk-head[data-away]:is(:focus-within, :has(details[open])) { transform: none; } |
| 65 | .talk-title { flex: 1 1 8rem; min-width: 0; margin: 0; font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } | |
| 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 | 66 | .talk-fill { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; } |
| 67 | 67 | .talk-fill meter { width: 3rem; } |
| 68 | 68 | .talk-figures { display: grid; gap: 2px; padding: 8px 12px; border-bottom: 1px solid var(--border); } |
| @@ -82,7 +82,7 @@ body:has(.talk-page) .foot { display: none; } | ||
| 82 | 82 | .talk-display form { display: grid; gap: 8px; padding: 8px 12px; } |
| 83 | 83 | .talk-display label { display: grid; gap: 4px; } |
| 84 | 84 | .talk-display select { font-size: 16px; } |
| 85 | .talk-head .btn-icon, .talk-head summary.btn { position: relative; min-width: 2.5rem; min-height: 2.5rem; } | |
| 85 | .talk-head .btn-icon, .talk-head summary.btn { position: relative; flex: none; min-width: 2.75rem; min-height: 2.75rem; } | |
| 86 | 86 | .talk-head .btn-icon::after, .talk-head summary.btn::after, .talk-tools .btn-icon::after, .talk-copy::after, .talk-act::after, .talk-fold summary::after, .talk-more a::after { content: ""; position: absolute; inset: -6px; } |
| 87 | 87 | .talk-rename { display: flex; gap: 8px; padding: 8px; } |
| 88 | 88 | .talk-rename .input { min-width: 0; flex: 1; font-size: 16px; } |
| @@ -100,8 +100,7 @@ body:has(.talk-page) .foot { display: none; } | ||
| 100 | 100 | .talk-chats .row { min-height: 2.75rem; border-radius: var(--radius-sm); } |
| 101 | 101 | .talk-chats .row-main { min-width: 0; } |
| 102 | 102 | .talk-chats .row-title { overflow: hidden; text-overflow: ellipsis; } |
| 103 | .talk-chats .row-meta { overflow-wrap: anywhere; } | |
| 104 | .talk-chats .row-meta { font-variant-numeric: tabular-nums; } | |
| 103 | .talk-chats .row-meta { overflow-wrap: anywhere; font-variant-numeric: tabular-nums; } | |
| 105 | 104 | .talk-archived { padding: 8px; } |
| 106 | 105 | @media (min-width: 56.25rem) { |
| 107 | 106 | .talk-page { grid-template-columns: 16rem minmax(0, 1fr); } |
| @@ -234,12 +233,11 @@ body:has(.talk-page) .foot { display: none; } | ||
| 234 | 233 | .talk-send[hidden], .talk-stop[hidden], .talk-steer[hidden], .talk-dictate[hidden], [data-attach][hidden], .talk-jump[hidden] { display: none; } |
| 235 | 234 | .talk-steer { border-radius: 999px; } |
| 236 | 235 | .talk-dictate[aria-pressed="true"] { background: var(--accent); color: var(--bg); } |
| 237 | .talk-foot, .talk-model { margin: 6px 16px 0; } | |
| 238 | .talk-model { display: flex; align-items: center; gap: 8px; } | |
| 239 | .talk-model select { width: auto; } | |
| 240 | .talk-status { margin: 6px 16px 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } | |
| 241 | .talk-status:empty { display: none; } | |
| 242 | [data-answering] .talk-status { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); } | |
| 236 | .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; } | |
| 238 | .talk-model select { width: 100%; min-width: 0; min-height: 2.5rem; font-size: 16px; text-overflow: ellipsis; } | |
| 239 | .talk-status { margin: 4px 16px 0; min-height: 1.25rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } | |
| 240 | [data-answering] .talk-status { background: none; animation: none; color: transparent; } | |
| 243 | 241 | .talk-error { margin: 6px 4px 0; color: var(--danger); } |
| 244 | 242 | .talk-error[hidden] { display: none; } |
| 245 | 243 | .talk-jump { position: absolute; bottom: calc(100% + 12px); left: 50%; transform: translateX(-50%); min-height: 2.75rem; border-radius: 999px; box-shadow: var(--shadow-2); gap: 6px; } |
| @@ -416,13 +414,14 @@ if (root) { | ||
| 416 | 414 | let retry = 0; |
| 417 | 415 | const paged = root.dataset.paged === "1"; |
| 418 | 416 | const { c: cid, here } = root.dataset; |
| 417 | const ANSWERING = "The forge is answering…"; | |
| 419 | 418 | const say = (words) => { status.textContent = words; }; |
| 420 | 419 | const head = root.querySelector(".talk-head"); |
| 421 | 420 | if (head) head.addEventListener("focusin", () => head.removeAttribute("data-away")); |
| 422 | 421 | const jump = form.querySelector("[data-jump]"); |
| 423 | 422 | const err = form.querySelector("[data-error]"); |
| 424 | 423 | const pick = form.querySelector("[data-model-pick]"); |
| 425 | if (pick) { form.querySelector("[data-model-use]").hidden = true; pick.onchange = () => pick.form.requestSubmit(); } | |
| 424 | if (pick) { root.querySelector("[data-model-use]").hidden = true; pick.onchange = () => pick.form.requestSubmit(); } | |
| 426 | 425 | box.required = false; |
| 427 | 426 | const fail = (words) => { say(""); err.textContent = words; err.hidden = false; box.setAttribute("aria-invalid", "true"); }; |
| 428 | 427 | // The keyboard covers the layout viewport on phones: lift the composer by what it hides. |
| @@ -463,7 +462,9 @@ if (root) { | ||
| 463 | 462 | const page = document.scrollingElement || document.documentElement; |
| 464 | 463 | const sc = () => /auto|scroll/.test(window.getComputedStyle(root).overflowY) && root.scrollHeight > root.clientHeight ? root : page; |
| 465 | 464 | const atEnd = () => { const s = sc(); return follows(s.scrollHeight, s.scrollTop, s.clientHeight); }; |
| 466 | let stuck = true, fresh = false, lastTop = 0, lastH = 0, grown = 0, hand = -1e9; | |
| 465 | let stuck = !document.querySelector('[data-view="list"]'), fresh = false, lastTop = 0, lastH = 0, grown = 0, hand = -1e9; | |
| 466 | // The chat list opens at its top, whatever the browser restored or a late layout moved. | |
| 467 | if (!stuck) { window.scrollTo({ top: 0, behavior: "instant" }); window.addEventListener("load", () => { if (!stuck && hand < 0) window.scrollTo({ top: 0, behavior: "instant" }); }); } | |
| 467 | 468 | const touched = () => { hand = performance.now(); }; |
| 468 | 469 | const followWords = { pause: ["Pause", "Pause scrolling and keep this place"], resume: ["Resume", "Resume following the reply"], latest: ["Latest", "Jump to the latest message"] }; |
| 469 | 470 | const draw = () => { |
| @@ -647,6 +648,8 @@ if (root) { | ||
| 647 | 648 | }; |
| 648 | 649 | const mode = (on) => { |
| 649 | 650 | answering = on; |
| 651 | // The answer ended, however it ended (replied, failed, stopped, a confirm answered): its line goes. | |
| 652 | if (!on && status.textContent === ANSWERING) say(""); | |
| 650 | 653 | form.toggleAttribute("data-answering", on); |
| 651 | 654 | paint(); |
| 652 | 655 | // The composer and the thread's end strip just changed: a follower stays at the end now, in |
| @@ -704,7 +707,7 @@ if (root) { | ||
| 704 | 707 | log.querySelectorAll("[data-queued]").forEach((q) => q.remove()); |
| 705 | 708 | for (const q of JSON.parse(e.data).items) log.insertAdjacentHTML("beforeend", q.html); |
| 706 | 709 | }); |
| 707 | source.addEventListener("running", () => { dropActs(); mode(true); log.setAttribute("aria-busy", "true"); say("The forge is answering…"); }); | |
| 710 | source.addEventListener("running", () => { dropActs(); mode(true); log.setAttribute("aria-busy", "true"); say(ANSWERING); }); | |
| 708 | 711 | // The agent pointed the pane: its Preview tab draws it again where it points, or it opens. |
| 709 | 712 | source.addEventListener("pane", () => { const a = document.querySelector("[data-split] .talk-pane nav.seg a"); if (a) a.click(); else openPane(); }); |
| 710 | 713 | source.addEventListener("done", (e) => { |
src/web/talk_model.ts +9 −6
| @@ -1,8 +1,8 @@ | ||
| 1 | 1 | /** |
| 2 | * Talk's model picker, in the composer (`core/model_choice.ts`): a select of every model the person | |
| 3 | * may use on a working connection, and the forge's own, saved for the conversation. A plain form | |
| 4 | * post (`POST /talk/:id/model`), so it works with the script off; the script sends it on change. | |
| 5 | * Absent when no connection offers a model, so a forge without connections looks as before. | |
| 2 | * Talk's model picker, in the conversation's head (`core/model_choice.ts`): a select of every model | |
| 3 | * the person may use on a working connection, and the forge's own, saved for the conversation. A | |
| 4 | * plain form post (`POST /talk/:id/model`), so it works with the script off; the script sends it on | |
| 5 | * change. Absent when no connection offers a model, so a forge without connections looks as before. | |
| 6 | 6 | */ |
| 7 | 7 | import { choiceLabel, choiceOf, choiceValue, FORGE_MODEL, offers, setChoice } from "../core/model_choice.ts"; |
| 8 | 8 | import { connectionFor } from "../core/connections.ts"; |
| @@ -15,7 +15,10 @@ import { field, readForm } from "./form.ts"; | ||
| 15 | 15 | import { html, type Html } from "./html.ts"; |
| 16 | 16 | import { flashTo } from "./layout.ts"; |
| 17 | 17 | |
| 18 | /** The picker's line under the composer, its form outside it (`form=`), or null with nothing to offer. */ | |
| 18 | /** | |
| 19 | * The picker, in the conversation's head, its form outside it (`form=`), or null with nothing to | |
| 20 | * offer. | |
| 21 | */ | |
| 19 | 22 | export function modelPicker(ctx: Ctx, user: User, conversationId: string): Html | null { |
| 20 | 23 | // A forge with no connection Talk could run on draws no picker and reads nothing for it. |
| 21 | 24 | if (!anyTalkConnection(ctx.app.db)) return null; |
| @@ -28,7 +31,7 @@ export function modelPicker(ctx: Ctx, user: User, conversationId: string): Html | ||
| 28 | 31 | // A choice whose connection stopped answering stays shown as the conversation's, never offered anew. |
| 29 | 32 | const stale = now === undefined || listed ? undefined : connectionFor(ctx.app.db, user.id, now.connectionId); |
| 30 | 33 | return html`<p class="talk-model small"> |
| 31 | <label for="talk-model-pick">Model</label> | |
| 34 | <label class="sr-only" for="talk-model-pick">Model</label> | |
| 32 | 35 | <select class="input" id="talk-model-pick" name="model" form="talk-model" data-model-pick> |
| 33 | 36 | <option value=""${current === "" ? html` selected` : null}>${FORGE_MODEL}</option> |
| 34 | 37 | ${now !== undefined && !listed ? html`<option value="${current}" selected>${choiceLabel(stale ?? { name: "a removed connection" }, now.model)} (not answering)</option>` : null} |
test/talk-model-choice.test.ts +5
| @@ -381,6 +381,11 @@ describe("the page's picker", () => { | ||
| 381 | 381 | await fetch(`${servers.url}/talk/${c}`, { headers: { cookie } }) |
| 382 | 382 | ).text(); |
| 383 | 383 | expect(page).toContain('id="talk-model-pick"'); |
| 384 | // On a phone it is in the head's one row (#16442), not under the composer. | |
| 385 | const from = page.indexOf('<header class="talk-head">'); | |
| 386 | const head = page.slice(from, page.indexOf("</header>", from)); | |
| 387 | expect(head).toContain('id="talk-model-pick"'); | |
| 388 | expect(page.slice(page.indexOf('class="talk-compose"'))).not.toContain('id="talk-model-pick"'); | |
| 384 | 389 | expect(page).toContain( |
| 385 | 390 | '<form id="talk-model" method="post" action="/talk/' + |
| 386 | 391 | c + |
test/talk-page.test.ts +2 −2
| @@ -143,8 +143,8 @@ describe("the page", () => { | ||
| 143 | 143 | expect(html).toMatch(/talk-back" data-variant="ghost" href="\/talk\/[^"?]+\?chats=1"/); |
| 144 | 144 | expect(talkCss).toContain('.talk-side, .talk-work, [data-view="list"] :is(.talk, .talk-work) { display: none; }'); |
| 145 | 145 | expect(talkCss).toMatch(/\.talk-compose \{[^}]*position: sticky; bottom: var\(--kb, 0px\)/); |
| 146 | // The head is 40 px; its buttons reach 44 px through a hit area that overlaps the head's own room. | |
| 147 | expect(talkCss).toMatch(/\.talk-head \.btn-icon[^{]*\{[^}]*min-height: 2\.5rem/); | |
| 146 | // The head is one 44 px row, its buttons 44 px themselves. | |
| 147 | expect(talkCss).toMatch(/\.talk-head \.btn-icon[^{]*\{[^}]*min-height: 2\.75rem/); | |
| 148 | 148 | expect(talkCss).toMatch(/\.talk-head \.btn-icon::after[^{]*\{ content: ""; position: absolute; inset: -6px; \}/); |
| 149 | 149 | expect(talkCss).toMatch(/\.talk-tools \.btn-icon \{[^}]*min-height: 2\.75rem/); |
| 150 | 150 | expect(talkCss).toMatch(/\.talk-input \{[^}]*min-height: 2\.75rem/); |
test/talk-phone.test.ts added +160
| @@ -0,0 +1,160 @@ | ||
| 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. | |
| 6 | */ | |
| 7 | import { afterAll, beforeAll, expect, test } from "bun:test"; | |
| 8 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 9 | import { tmpdir } from "node:os"; | |
| 10 | import { join } from "node:path"; | |
| 11 | import { createApp, type App } from "../src/app.ts"; | |
| 12 | import { appendTurn, openConversation, createConversation, renameConversation } from "../src/core/conversations.ts"; | |
| 13 | import { createSession } from "../src/core/sessions.ts"; | |
| 14 | import { createUser } from "../src/core/users.ts"; | |
| 15 | import { findChromium } from "../src/looks/capture.ts"; | |
| 16 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 17 | import { clock } from "../src/web/pages/talk.ts"; | |
| 18 | import { chromiumRuns, evaluateLoaded } from "./helpers/chrome.ts"; | |
| 19 | import { quietLogs } from "./helpers/globals.ts"; | |
| 20 | import { promote } from "./helpers/members.ts"; | |
| 21 | ||
| 22 | quietLogs(); | |
| 23 | const found = findChromium(); | |
| 24 | 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"); | |
| 26 | ||
| 27 | let dir: string; | |
| 28 | let app: App; | |
| 29 | let servers: Servers; | |
| 30 | let token: string; | |
| 31 | let shortId: string; | |
| 32 | let manyId: string; | |
| 33 | let listToken: string; | |
| 34 | ||
| 35 | const toolTurns = (userId: string, id: string, n: number): void => { | |
| 36 | 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}` }); | |
| 38 | appendTurn(app.db, userId, id, { role: "agent", text: "Done." }); | |
| 39 | }; | |
| 40 | ||
| 41 | beforeAll(async () => { | |
| 42 | dir = await mkdtemp(join(tmpdir(), "forge-talk-phone-")); | |
| 43 | app = createApp({ dataDir: dir, port: 0 }); | |
| 44 | 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 }); | |
| 46 | if (!made.ok) throw new Error(made.error); | |
| 47 | promote(app.db, made.value); | |
| 48 | token = createSession(app.db, made.value.id).token; | |
| 49 | const a = openConversation(app.db, made.value.id); | |
| 50 | shortId = a.id; | |
| 51 | toolTurns(made.value.id, a.id, 1); | |
| 52 | const b = createConversation(app.db, made.value.id); | |
| 53 | if (!b.ok) throw new Error(b.error); | |
| 54 | manyId = b.value.id; | |
| 55 | toolTurns(made.value.id, manyId, 9); | |
| 56 | // 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" }); | |
| 58 | if (!bob.ok) throw new Error(bob.error); | |
| 59 | promote(app.db, bob.value); | |
| 60 | for (let i = 0; i < 20; i++) { | |
| 61 | const c = createConversation(app.db, bob.value.id); | |
| 62 | if (!c.ok) throw new Error(c.error); | |
| 63 | 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" }); | |
| 65 | } | |
| 66 | listToken = createSession(app.db, bob.value.id).token; | |
| 67 | }, 30_000); | |
| 68 | afterAll(async () => { | |
| 69 | servers.stop(); | |
| 70 | app.close(); | |
| 71 | await rm(dir, { recursive: true, force: true }); | |
| 72 | }); | |
| 73 | ||
| 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)); | |
| 76 | ||
| 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); | |
| 125 | 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); }); | |
| 128 | const st = document.querySelector(".talk-status"); | |
| 129 | await wait(() => st.textContent.includes("answering")); | |
| 130 | const seen = st.textContent; | |
| 131 | // A confirm answered while the answer runs: the page reads the outcome and stays quiet. | |
| 132 | window.fetch = async () => new Response(JSON.stringify({ message: "Already answered" }), { status: 409 }); | |
| 133 | const dock = document.querySelector(".talk-confirm-list"); | |
| 134 | dock.insertAdjacentHTML("beforeend", '<div class="talk-confirm"><button type="button" data-answer formaction="/x" value="yes">Yes</button></div>'); | |
| 135 | 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 | }); |
new above
offline