Public: anyone can read this; the crew can change it.
A link in a Talk message to an issue, a pull or a repository peeks: a small card on hover, focus or a long press #16291
Check · Review · Land · Live done — Landed and live in production.
talk/look-3b-peek → main 0 commits 5 threads · 5 unresolved
docs/design/areas/talk.md +2
| @@ -120,3 +120,5 @@ Prior art: Claude and ChatGPT (one centred column, the person's words in a quiet | ||
| 120 | 120 | - `.talk-figures`: the spend and context lines inside the conversation menu. |
| 121 | 121 | - `.talk-time`: a centred quiet time before the first turn and wherever the conversation paused 30 minutes or more; the time is said once a group, not under every message (a person's message keeps its time for a screen reader). |
| 122 | 122 | - `.talk-display`: Display, at the end of the conversation menu: the person's Talk preferences (spacing, motion, Enter, steps) as one plain form of selects (`core/settings.ts`). |
| 123 | - `.talk-peek`: a peek at what a message links to on this forge (an issue, a pull, a repository), a small card placed under the link (above it near the foot of the screen) on hover, focus or a long press (`src/web/talk_peek.ts`); on touch the same card opens through the overlay host as a `.dialog` with `.talk-peek-sheet`. | |
| 124 | - `.talk-peek-card`, `.talk-peek-kind`, `.talk-peek-title`, `.talk-peek-body`, `.talk-peek-acts`: the card's kind and number with its state, its title, three lines of its body as plain text, and at most two actions (Open; Talk about this for an issue or a repository). |
docs/design/size-budget.json +2 −2
| @@ -68,8 +68,8 @@ | ||
| 68 | 68 | "css": 48384 |
| 69 | 69 | }, |
| 70 | 70 | "/talk": { |
| 71 | "js": 34304, | |
| 72 | "css": 52992 | |
| 71 | "js": 35328, | |
| 72 | "css": 53504 | |
| 73 | 73 | }, |
| 74 | 74 | "/:owner/:name/pulls/:number": { |
| 75 | 75 | "js": 32000, |
docs/features/talk.md +9 −1
| @@ -136,7 +136,7 @@ A reply is drawn by the README renderer and then, for Talk alone, by `linkTalk` | ||
| 136 | 136 | |
| 137 | 137 | An agent reply is Markdown, drawn on the server by the same renderer as a README: fenced code is highlighted, tables and links render, and everything else is escaped (a `<script>` in a reply shows as text). A table wider than the column scrolls inside it; the page does not. The reply sits in the column like a person's turn, with none of the README's padding or line measure. |
| 138 | 138 | |
| 139 | A reply grows in one live element while it is written (see "Live") and is then stored as one finished turn; the page only appends a turn whose id it has not drawn (a repeat is ignored). Turns already on the page are not touched, so nothing above a new reply moves, and the page follows the end only if you were already there (otherwise "Latest" appears). An unfinished fence in a stored reply is closed for drawing. The page's own bytes are held by a test (`test/talk-page.test.ts`): the stylesheet under 14,700 B, the script under 29,700 B, and a page with a code reply under 43,000 B (its own page: one question and a code reply). | |
| 139 | A reply grows in one live element while it is written (see "Live") and is then stored as one finished turn; the page only appends a turn whose id it has not drawn (a repeat is ignored). Turns already on the page are not touched, so nothing above a new reply moves, and the page follows the end only if you were already there (otherwise "Latest" appears). An unfinished fence in a stored reply is closed for drawing. The page's own bytes are held by a test (`test/talk-page.test.ts`): the stylesheet under 14,700 B, the script under 34,000 B, and a page with a code reply under 43,000 B (its own page: one question and a code reply). | |
| 140 | 140 | |
| 141 | 141 | ## Following |
| 142 | 142 | |
| @@ -188,3 +188,11 @@ The terminal's Talk screen reads the same file: `d` on the list, or `d` or `x` i | ||
| 188 | 188 | Four preferences of the person's own, at the end of the conversation menu (⋯ → Display), one plain form that works without the script (`POST /talk/display`, signed in, same origin): spacing (comfortable or compact: the spacing scale only, never the type size), motion (as the system says, or reduced: Talk's arrivals, the head's slide and the shimmer stop whatever the system says), what Enter does (sends, or adds a line with Ctrl or Cmd+Enter sending) and whether a reply's steps start folded or open. They are the person's `user_setting` rows (`talk.density`, `talk.motion`, `talk.enter`, `talk.steps`, read by `talkDisplay` in `src/core/settings.ts`), applied by the server so the first paint is right; a value that is not one of a preference's own choices is never kept. No theme builder, no colours. The terminal honours the same steps choice: a conversation opened in `forge talk` shows a run of steps as one line ("3 steps") or each step, and `v` there flips the choice for both places, while `D` opens Talk display to set all four (docs/features/talk-display.md); spacing, motion and Enter are the page's own (the terminal has its own rows, no animation, and its `s` prompt always sends on Enter). |
| 189 | 189 | |
| 190 | 190 | **Motion.** One vocabulary: a thing arriving (a sent message, a step, a receipt, the follow control, a version chip) fades and rises 4 px over `--dur-3` (200 ms) with `--ease`, once; the live block's new paragraphs only fade, and the stored reply that takes its place does not move. Opacity and transform only, so nothing on screen shifts; none under `prefers-reduced-motion` or the person's reduced. Proof: `test/talk-display.test.ts`, `test/talk-page.test.ts`. |
| 191 | ||
| 192 | ## Peek (#15734) | |
| 193 | ||
| 194 | A link in a message to an issue, a pull or a repository on this forge peeks: on a pointer device a small card after a 300 ms hover (it leaves 150 ms after the pointer does, and stays while the pointer is on it), on keyboard focus, and on touch after a 500 ms long press, as a dialog through the overlay host. A tap or a click still follows the link. Escape or a press outside closes it; the link is described by the card (`aria-describedby`), and focus is never trapped by the hover card. | |
| 195 | ||
| 196 | The card is `GET /talk/peek?href=<rooted path>` (`src/web/talk_peek.ts`), signed in only: the kind and number with its state in a word and an icon (Open, Closed, Merged; for a pull its checks in words), the title, who it is assigned to and whether the crew works on it now ("working on it for 4 min", from the live run), the first lines of its body as escaped plain text (never Markdown, never a link), when it last changed, and at most two actions (Open, and Talk about this, which opens Talk with that subject). Read exactly as the link is: a repository the person cannot read, a sealed issue they may not see, a number that is not there, a pull asked as an issue, or any other path answers not found, and no card appears. Cached by the browser for 5 seconds. Proof: `test/talk-peek.test.ts`. | |
| 197 | ||
| 198 | **In the terminal** there is no hover: a conversation names the same links as `owner/repo#12` and `owner/repo`, which the terminal's issue and repository screens open. |
src/http/server.ts +2
| @@ -172,6 +172,7 @@ import { | ||
| 172 | 172 | } from "../web/pages/site.ts"; |
| 173 | 173 | import { talkBuild, talkPublish, talkRestore } from "../web/talk_build.ts"; |
| 174 | 174 | import { talkAct, talkAgainSend, talkArchive, talkConfirm, talkDisplaySave, talkDownload, talkNew, talkPin, talkQueueCancel, talkRename, talkSend, talkUndo, talkStream, talkView } from "../web/pages/talk.ts"; |
| 175 | import { talkPeek } from "../web/talk_peek.ts"; | |
| 175 | 176 | import { |
| 176 | 177 | recoverFinish, |
| 177 | 178 | recoverOptions, |
| @@ -1247,6 +1248,7 @@ export function buildRouter(): Router<Handler> { | ||
| 1247 | 1248 | router.add("GET", "/talk", talkView); |
| 1248 | 1249 | router.add("POST", "/talk", talkSend); |
| 1249 | 1250 | router.add("GET", "/talk/stream", talkStream); |
| 1251 | router.add("GET", "/talk/peek", talkPeek); | |
| 1250 | 1252 | router.add("POST", "/talk/again/:how", talkAgainSend); |
| 1251 | 1253 | router.add("POST", "/talk/queue/:id/cancel", talkQueueCancel); |
| 1252 | 1254 | router.add("POST", "/talk/confirm/:id", talkConfirm); |
src/tui/screens/talk_chats.ts +8 −1
| @@ -83,6 +83,13 @@ function downloadScreen(f: Session, ctx: Ctx, chat: Conversation): Screen { | ||
| 83 | 83 | }; |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | /** | |
| 87 | * A link a reply makes to this forge, named as a person says it and as the page's peek shows it: | |
| 88 | * `owner/repo#12` for an issue or a pull, `owner/repo` for a repository; any other link stays. | |
| 89 | */ | |
| 90 | const forgeNames = (text: string): string => | |
| 91 | text.replace(/\[[^\]]*\]\(\/([A-Za-z0-9][\w.-]*)\/([A-Za-z0-9][\w.-]*)(?:\/(?:issues|pulls)\/(\d+))?\/?\)/g, (_a, o: string, r: string, n?: string) => (n === undefined ? `${o}/${r}` : `${o}/${r}#${n}`)); | |
| 92 | ||
| 86 | 93 | /** |
| 87 | 94 | * One conversation, newest turns last: j/k scroll, s says something in it, r |
| 88 | 95 | * reloads. `hit` is a search result's turn: the view opens on the page around |
| @@ -159,7 +166,7 @@ function chatScreen(f: Session, ctx: Ctx, chat: Conversation, hit?: string): Scr | ||
| 159 | 166 | n += 2; |
| 160 | 167 | return [[{ text: run === 1 ? step.label : `${String(run)} steps`, style: style(c.mutedFg, c.bg) }], []]; |
| 161 | 168 | } |
| 162 | const said = t.role === "agent" ? pathRefs(plainVoice(t.text, cards), refs) : t.text; | |
| 169 | const said = t.role === "agent" ? pathRefs(forgeNames(plainVoice(t.text, cards)), refs) : t.text; | |
| 163 | 170 | const own = (step === undefined ? said : [step.label, ...step.details.map((d) => ` ${d}`)].join("\n")).split("\n").flatMap((l) => wrap(l, Math.max(10, width - 2))); |
| 164 | 171 | n += own.length + 2; |
| 165 | 172 | return [ |
src/web/pages/talk.ts +2 −1
| @@ -70,6 +70,7 @@ import { agentHtml, liveHtml, voiceCss, voiceOf, type Voice } from "../talk_part | ||
| 70 | 70 | import { badge, btn, icon, iconBtn, menu, meter, row, time } from "../ui.ts"; |
| 71 | 71 | import { inlineIcons } from "../icons.ts"; |
| 72 | 72 | import { DISPLAY_NAMES, setTalkDisplay, TALK_DISPLAY, talkDisplay, type TalkDisplay } from "../../core/settings.ts"; |
| 73 | import { peekCss } from "../talk_peek.ts"; | |
| 73 | 74 | import { buildCss, chosenTemplate, panelFor, templateChips } from "../talk_build.ts"; |
| 74 | 75 | import type { User } from "../../core/users.ts"; |
| 75 | 76 | import { chatBuildOf } from "../../core/chat_build.ts"; |
| @@ -582,7 +583,7 @@ async function talkPage(ctx: Ctx, conversation: Conversation, before0: string | | ||
| 582 | 583 | </div> |
| 583 | 584 | ${split ? html`<div class="talk-work">${panel}${framed || panel === null ? pane.html : html`<aside class="talk-pane" aria-label="Preview"><div class="talk-stage talk-stage-wait" data-stage><p class="talk-stage-note small" data-stage-note>${pending ? "Starting the preview…" : running ? "Making the first version…" : "Your app appears here as soon as the first change is made."}</p></div></aside>`}</div>` : null} |
| 584 | 585 | </div>`; |
| 585 | return page({ ctx, title: conversation.title === "" ? "Talk" : `${conversation.title} · Talk`, body, styleCss: talkCss + (split ? paneCss : "") + (panel === null ? "" : buildCss) + voiceCss, scriptJs: `${talkJs}\n${liveRegionsJs}`, description: "Talk to the forge.", wide: true, ...(pane.frame === undefined || !framed ? {} : { frameSrc: pane.frame }) }); | |
| 586 | return page({ ctx, title: conversation.title === "" ? "Talk" : `${conversation.title} · Talk`, body, styleCss: talkCss + peekCss + (split ? paneCss : "") + (panel === null ? "" : buildCss) + voiceCss, scriptJs: `${talkJs}\n${liveRegionsJs}`, description: "Talk to the forge.", wide: true, ...(pane.frame === undefined || !framed ? {} : { frameSrc: pane.frame }) }); | |
| 586 | 587 | } |
| 587 | 588 | |
| 588 | 589 | /** |
src/web/pages/talk_client.ts +59 −1
| @@ -31,6 +31,10 @@ | ||
| 31 | 31 | * the stored reply that takes the live block's place); the live block's new blocks only fade. |
| 32 | 32 | * None under prefers-reduced-motion, or when the person chose reduced (Display). Opacity and |
| 33 | 33 | * transform only, so nothing on screen moves. |
| 34 | * - A link to an issue, a pull or a repository on this forge peeks (`web/talk_peek.ts`): a card after | |
| 35 | * a 300 ms hover (150 ms to leave, kept while the pointer is on it), on keyboard focus, or on a | |
| 36 | * 500 ms long press on touch, as a sheet at the foot of the screen; never on a tap or a click, which | |
| 37 | * still follow the link. Escape or a press outside closes it; the link is described by the card. | |
| 34 | 38 | * - The conversation's head slides away while the reader scrolls down and comes back on the way up. |
| 35 | 39 | * - Copy buttons are drawn by the script, not the server: without the script |
| 36 | 40 | * they would do nothing. |
| @@ -102,7 +106,7 @@ body:has(.talk-page) .foot { display: none; } | ||
| 102 | 106 | .talk-turn p { margin: 0 0 8px; } |
| 103 | 107 | .talk-turn p:last-child { margin-bottom: 0; } |
| 104 | 108 | .talk-turn pre { max-width: 100%; overflow-x: auto; } |
| 105 | .talk-body a { overflow-wrap: anywhere; } | |
| 109 | .talk-body a { overflow-wrap: anywhere; -webkit-touch-callout: none; } | |
| 106 | 110 | .talk-body.prose { padding: 0; font-size: inherit; line-height: inherit; } |
| 107 | 111 | .talk-body.prose > * { max-width: none; } |
| 108 | 112 | .talk-body.prose table { display: block; width: fit-content; max-width: 100%; overflow-x: auto; } |
| @@ -817,6 +821,60 @@ ${dictateJs} | ||
| 817 | 821 | } catch (_) {} |
| 818 | 822 | }; |
| 819 | 823 | document.addEventListener("click", (e) => { if (e.target.closest && e.target.closest(".talk-reload")) reframe(); }); |
| 824 | const PEEK = /^\\/[^/]+\\/[^/]+(\\/(issues|pulls)\\/\\d+)?\\/?$/; | |
| 825 | const peekOf = (t) => { const a = t && t.closest && t.closest(".talk-log a[href^='/']"); return a && !a.closest(".talk-peek, .talk-acts, .talk-meta") && PEEK.test(a.getAttribute("href")) ? a : null; }; | |
| 826 | let peek = null, peekAt = null, peekIn = 0, peekOut = 0, pressT = 0, pressed = null; | |
| 827 | const unpeek = () => { clearTimeout(peekIn); if (peek) peek.remove(); if (peekAt) peekAt.removeAttribute("aria-describedby"); peek = peekAt = null; }; | |
| 828 | const showPeek = async (a, sheet) => { | |
| 829 | peekAt = a; | |
| 830 | try { | |
| 831 | const res = await fetch("/talk/peek?href=" + encodeURIComponent(a.getAttribute("href"))); | |
| 832 | const body = res.ok ? await res.text() : ""; | |
| 833 | if (!body || peekAt !== a) return; | |
| 834 | if (peek) peek.remove(); | |
| 835 | if (sheet && window.forgeOverlay) { | |
| 836 | const d = Object.assign(document.createElement("dialog"), { className: "dialog talk-peek-sheet", innerHTML: '<div class="dialog-body">' + body + "</div>" }); | |
| 837 | d.setAttribute("aria-label", a.textContent); | |
| 838 | document.body.append(d); | |
| 839 | d.addEventListener("close", () => { d.remove(); pressed = null; }); | |
| 840 | window.forgeOverlay.open(d, { opener: a, name: "peek" }); | |
| 841 | peekAt = null; | |
| 842 | return; | |
| 843 | } | |
| 844 | peek = Object.assign(document.createElement("div"), { className: "talk-peek", id: "talk-peek", innerHTML: body }); | |
| 845 | peek.setAttribute("role", "region"); | |
| 846 | peek.setAttribute("aria-label", a.textContent); | |
| 847 | document.body.append(peek); | |
| 848 | { | |
| 849 | // Below the link while it fits on screen (over the composer at worst, never over what is | |
| 850 | // being read above it), else above; held inside the screen by the stylesheet, so no width is read. | |
| 851 | const r = a.getBoundingClientRect(), h = peek.offsetHeight, vh = window.innerHeight; | |
| 852 | const head = document.querySelector(".topbar"), top = (head ? head.getBoundingClientRect().bottom : 0) + 8; | |
| 853 | const y = r.bottom + 6 + h <= vh - 8 ? r.bottom + 6 : r.top - h - 6; | |
| 854 | peek.style.top = Math.max(top, Math.min(y, vh - h - 8)) + window.scrollY + "px"; | |
| 855 | peek.style.left = "clamp(16px, " + (r.left + window.scrollX) + "px, calc(100% - min(22rem, 100vw - 32px) - 16px))"; | |
| 856 | } | |
| 857 | a.setAttribute("aria-describedby", "talk-peek"); | |
| 858 | peek.addEventListener("pointerenter", () => clearTimeout(peekOut)); | |
| 859 | peek.addEventListener("pointerleave", () => { peekOut = setTimeout(unpeek, 150); }); | |
| 860 | } catch (_) {} | |
| 861 | }; | |
| 862 | log.addEventListener("pointerover", (e) => { const a = e.pointerType === "mouse" && peekOf(e.target); if (!a) return; clearTimeout(peekOut); if (a !== peekAt) { clearTimeout(peekIn); peekIn = setTimeout(() => showPeek(a), 300); } }); | |
| 863 | log.addEventListener("pointerout", (e) => { if (peekOf(e.target)) { clearTimeout(peekIn); peekOut = setTimeout(unpeek, 150); } }); | |
| 864 | log.addEventListener("focusin", (e) => { const a = peekOf(e.target); if (a && a.matches(":focus-visible")) showPeek(a); }); | |
| 865 | log.addEventListener("focusout", (e) => { if (peekOf(e.target)) peekOut = setTimeout(unpeek, 150); }); | |
Low. |
||
| 866 | log.addEventListener("touchstart", (e) => { const a = peekOf(e.target); if (a) pressT = setTimeout(() => { pressed = a; showPeek(a, true); }, 500); }, { passive: true }); | |
| 867 | // The click a long press swallows comes at once or never (a callout, a closed sheet): the flag | |
| 868 | // never outlives the touch, so the next plain tap on the link still follows it. | |
| 869 | const unpress = () => { clearTimeout(pressT); pressed = null; }; | |
| 870 | log.addEventListener("touchend", () => { clearTimeout(pressT); if (pressed) setTimeout(unpress, 400); }); | |
| 871 | log.addEventListener("touchmove", unpress, { passive: true }); | |
| 872 | log.addEventListener("touchcancel", unpress); | |
| 873 | log.addEventListener("pointercancel", unpress); | |
| 874 | window.addEventListener("scroll", unpress, { passive: true }); | |
| 875 | log.addEventListener("click", (e) => { if (pressed && e.target.closest("a") === pressed) { e.preventDefault(); pressed = null; } }, true); | |
| 876 | document.addEventListener("pointerdown", (e) => { if (peek && !peek.contains(e.target) && !peekOf(e.target)) unpeek(); }); | |
| 877 | document.addEventListener("keydown", (e) => { if (e.key === "Escape" && peek) { e.preventDefault(); e.stopImmediatePropagation(); unpeek(); } }, true); | |
| 820 | 878 | document.addEventListener("click", async (e) => { |
| 821 | 879 | const a = e.target.closest("[data-shell] :is(.talk-tabs, .talk-pane nav) a:not(.talk-back)"), shell = a && a.closest("[data-shell]"); |
| 822 | 880 | if (!a || e.metaKey || e.ctrlKey || e.shiftKey) return; |
src/web/talk_peek.ts added +200
| @@ -0,0 +1,200 @@ | ||
| 1 | /** | |
| 2 | * A peek at a thing a Talk message links to (#15734): `GET /talk/peek?href=/owner/name/issues/3` | |
| 3 | * answers a small card the page shows on hover, focus or a long press: the kind and number, the | |
| 4 | * title, the state in a word, who it is assigned to and whether the crew works on it now, the first | |
| 5 | * lines of its body as plain text, when it last changed, and at most two safe actions. An issue, | |
| 6 | * a pull or a repository; anything else, and anything the viewer cannot read, answers not found | |
| 7 | * exactly as the link itself would, so no card says what a page would not. | |
| 8 | * | |
| 9 | * The body is someone else's words: escaped plain text, never Markdown, never a link. | |
| 10 | */ | |
| 11 | ||
| 12 | import type { Ctx } from "../http/context.ts"; | |
| 13 | import { getIssue } from "../core/issues.ts"; | |
| 14 | import { canRead, getRepo } from "../core/repos.ts"; | |
| 15 | import { mayView } from "../core/sealed.ts"; | |
| 16 | import { getUserById } from "../core/users.ts"; | |
| 17 | import { html, type Html } from "./html.ts"; | |
| 18 | import { icon, time } from "./ui.ts"; | |
| 19 | import { inlineIcons } from "./icons.ts"; | |
| 20 | ||
| 21 | /** The paths a peek reads: a repository, or one of its issues or pulls. */ | |
| 22 | const PEEK = | |
| 23 | /^\/([A-Za-z0-9][A-Za-z0-9_.-]{0,63})\/([A-Za-z0-9][A-Za-z0-9_.-]{0,99})(?:\/(issues|pulls)\/([1-9]\d{0,8}))?\/?$/; | |
| 24 | /** How much of a body the card shows, in characters. */ | |
| 25 | const BODY_SHOWN = 240; | |
| 26 | ||
| 27 | /** The card's words, in one place. */ | |
| 28 | const PEEK_WORDS = { | |
| 29 | open: "Open", | |
| 30 | talk: "Talk about this", | |
| 31 | working: "working on it", | |
| 32 | queued: "queued to work on it", | |
| 33 | changed: "Changed", | |
| 34 | assigned: "Assigned to", | |
| 35 | merged: "Merged", | |
| 36 | open_: "Open", | |
| 37 | closed: "Closed", | |
| 38 | checksOk: "checks passed", | |
| 39 | checksFailed: "checks failed", | |
| 40 | checksRunning: "checks running", | |
| 41 | } as const; | |
| 42 | ||
| 43 | const notFound = (): Response => | |
| 44 | new Response("not found", { | |
| 45 | status: 404, | |
| 46 | headers: { "cache-control": "private, no-store" }, | |
| 47 | }); | |
| 48 | ||
| 49 | /** Minutes since an ISO time, as "running for N min". */ | |
| 50 | const forMinutes = (at: string | null, now: number): string => | |
| 51 | at === null | |
| 52 | ? "" | |
| 53 | : ` for ${Math.max(1, Math.round((now - Date.parse(at)) / 60_000))} min`; | |
| 54 | ||
| 55 | // GET /talk/peek?href=<a rooted path on this forge> | |
| 56 | export function talkPeek(ctx: Ctx): Response { | |
| 57 | if (ctx.auth.user === undefined) | |
| 58 | return new Response("sign in", { status: 401 }); | |
| 59 | const m = PEEK.exec(ctx.url.searchParams.get("href") ?? ""); | |
| 60 | if (m === null) return notFound(); | |
| 61 | const [, owner = "", name = "", kind, number] = m; | |
| 62 | const repo = getRepo(ctx.app.db, owner, name); | |
| 63 | if (repo === undefined || !canRead(ctx.app.db, repo, ctx.auth.user)) | |
| 64 | return notFound(); | |
| 65 | const db = ctx.app.db; | |
| 66 | let card: Html; | |
| 67 | if (kind === undefined) { | |
| 68 | card = html`<p class="talk-peek-kind small muted"> | |
| 69 | ${icon("repo")} Repository | |
| 70 | </p> | |
| 71 | <p class="talk-peek-title">${repo.ownerName}/${repo.name}</p> | |
| 72 | ${repo.description === "" | |
| 73 | ? null | |
| 74 | : html`<p class="talk-peek-body small"> | |
| 75 | ${repo.description.slice(0, BODY_SHOWN)} | |
| 76 | </p>`} | |
| 77 | <div class="talk-peek-acts"> | |
| 78 | <a class="btn" data-size="sm" href="/${repo.ownerName}/${repo.name}" | |
| 79 | >${PEEK_WORDS.open}</a | |
| 80 | ><a | |
| 81 | class="btn" | |
| 82 | data-size="sm" | |
| 83 | href="/talk?about=${encodeURIComponent( | |
| 84 | `${repo.ownerName}/${repo.name}`, | |
| 85 | )}" | |
| 86 | >${PEEK_WORDS.talk}</a | |
| 87 | > | |
| 88 | </div>`; | |
| 89 | } else { | |
| 90 | const issue = getIssue(db, repo.id, Number(number)); | |
| 91 | if ( | |
| 92 | issue === undefined || | |
| 93 | !mayView(db, repo, issue, ctx.auth.user) || | |
| 94 | (issue.kind === "pull") !== (kind === "pulls") | |
| 95 | ) | |
| 96 | return notFound(); | |
| 97 | const pull = | |
| 98 | issue.kind === "pull" | |
| 99 | ? db | |
| 100 | .query< | |
| 101 | { merged_at: string | null }, | |
| 102 | [string] | |
| 103 | >("SELECT merged_at FROM pull WHERE issue_id = ?1") | |
| 104 | .get(issue.id) | |
| 105 | : null; | |
| 106 | const check = | |
| 107 | issue.kind === "pull" | |
| 108 | ? db | |
| 109 | .query< | |
| 110 | { state: string }, | |
| 111 | [string] | |
| 112 | >("SELECT state FROM run WHERE issue_id = ?1 AND kind = 'check' ORDER BY id DESC LIMIT 1") | |
| 113 | .get(issue.id) | |
| 114 | : null; | |
| 115 | const run = db | |
| 116 | .query< | |
| 117 | { state: string; started_at: string | null }, | |
| 118 | [string] | |
| 119 | >("SELECT state, started_at FROM run WHERE issue_id = ?1 AND kind = 'agent' AND state IN ('queued','running') ORDER BY id DESC LIMIT 1") | |
| 120 | .get(issue.id); | |
| 121 | const assignee = | |
| 122 | issue.assigneeId === null ? undefined : getUserById(db, issue.assigneeId); | |
| 123 | const state = pull?.merged_at | |
| 124 | ? (["merge", PEEK_WORDS.merged] as const) | |
| 125 | : issue.state === "open" | |
| 126 | ? ([ | |
| 127 | issue.kind === "pull" ? "pull" : "issue", | |
| 128 | PEEK_WORDS.open_, | |
| 129 | ] as const) | |
| 130 | : (["issueClosed", PEEK_WORDS.closed] as const); | |
| 131 | const checks = | |
| 132 | check === null || check === undefined | |
| 133 | ? null | |
| 134 | : check.state === "ok" | |
| 135 | ? PEEK_WORDS.checksOk | |
| 136 | : check.state === "failed" | |
| 137 | ? PEEK_WORDS.checksFailed | |
| 138 | : PEEK_WORDS.checksRunning; | |
| 139 | const body = issue.body.replace(/\s+/g, " ").trim(); | |
| 140 | const path = `/${repo.ownerName}/${repo.name}/${kind}/${issue.number}`; | |
| 141 | card = html`<p class="talk-peek-kind small muted"> | |
Untested branches: the merged state, closed state, checks words (ok, failed, running), the assignee line, the queued line and the sealed-issue 404 (mayView). The pull card is never fetched in test/talk-peek.test.ts, and nothing asserts that a pull has no Talk action. Add a test for each: a pull merged, one with a failed check, a closed issue, an assigned issue, and a sealed issue seen by bob. |
||
| 142 | ${icon(state[0])} ${repo.ownerName}/${repo.name}#${String(issue.number)} | |
| 143 | · ${state[1]}${checks === null ? null : html` · ${checks}`} | |
| 144 | </p> | |
| 145 | <p class="talk-peek-title">${issue.title}</p> | |
| 146 | ${assignee === undefined && run === null | |
| 147 | ? null | |
| 148 | : html`<p class="small muted"> | |
| 149 | ${assignee === undefined | |
| 150 | ? null | |
| 151 | : html`${PEEK_WORDS.assigned} ${assignee.username}`}${run === null | |
| 152 | ? null | |
| 153 | : html`${assignee === undefined ? null : " · "}<strong | |
| 154 | >${run.state === "running" | |
| 155 | ? `${PEEK_WORDS.working}${forMinutes(run.started_at, Date.now())}` | |
| 156 | : PEEK_WORDS.queued}</strong | |
| 157 | >`} | |
| 158 | </p>`} | |
| 159 | ${body === "" | |
| 160 | ? null | |
| 161 | : html`<p class="talk-peek-body small"> | |
| 162 | ${body.length > BODY_SHOWN ? `${body.slice(0, BODY_SHOWN)}…` : body} | |
| 163 | </p>`} | |
| 164 | <p class="small muted">${PEEK_WORDS.changed} ${time(issue.updatedAt)}</p> | |
| 165 | <div class="talk-peek-acts"> | |
| 166 | <a class="btn" data-size="sm" href="${path}">${PEEK_WORDS.open}</a | |
| 167 | ><a | |
| 168 | class="btn" | |
| 169 | data-size="sm" | |
| 170 | href="/talk?about=${encodeURIComponent( | |
| 171 | `${repo.ownerName}/${repo.name}#${issue.number}`, | |
| 172 | )}" | |
| 173 | >${PEEK_WORDS.talk}</a | |
| 174 | > | |
| 175 | </div>`; | |
| 176 | } | |
| 177 | // A fragment lands in a page whose sprite it does not know: its icons are drawn inline. | |
| 178 | return new Response(inlineIcons(html`<div class="talk-peek-card">${card}</div>`.text), { | |
| 179 | headers: { | |
| 180 | "content-type": "text/html; charset=utf-8", | |
| 181 | "cache-control": "private, max-age=5", | |
| 182 | }, | |
| 183 | }); | |
| 184 | } | |
| 185 | ||
| 186 | /** The card's own styles, part of the page's sheet. Spacing is the scale. */ | |
| 187 | export const peekCss = /* css */ ` | |
| 188 | .talk-peek { position: absolute; width: min(22rem, calc(100vw - 32px)); padding: 12px; border-radius: var(--radius-lg); background: var(--card); box-shadow: var(--shadow-2); } | |
| 189 | .talk-peek[hidden] { display: none; } | |
| 190 | .talk-peek-card { display: grid; gap: 4px; } | |
| 191 | .talk-peek-card p { margin: 0; } | |
| 192 | .talk-peek-kind { display: flex; align-items: center; gap: 6px; } | |
| 193 | .talk-peek-title { font-weight: 600; overflow-wrap: anywhere; } | |
| 194 | .talk-peek-body { color: var(--fg); overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; } | |
| 195 | .talk-peek-acts { display: flex; gap: 8px; margin-top: 4px; } | |
| 196 | .talk-peek-acts .btn { position: relative; } | |
outdated
Principle 6 and 7. The card has a full border plus a shadow, which is a box around a thing. A floating layer needs separation, but shadow alone ( |
||
| 197 | .talk-peek-acts .btn::after { content: ""; position: absolute; inset: -6px -2px; } | |
| 198 | .talk-peek-sheet .dialog-body { padding: 16px; } | |
| 199 | (prefers-reduced-motion: no-preference) { .talk-peek:not([hidden]) { animation: talk-in var(--dur-2) var(--ease); } } | |
| 200 | `; |
test/design-audit.test.ts +1 −1
| @@ -17,7 +17,7 @@ const doc = readFileSync("docs/design/audit.md", "utf8"); | ||
| 17 | 17 | |
| 18 | 18 | /** Routes that answer a file, a fragment, a redirect hop or a callback. */ |
| 19 | 19 | const NOT_PAGES = |
| 20 | /^\/(design\/theme\.css|design\/theme\/|assets\/|\.well-known\/|icons\/|og\/|live\/|__forge\/|go\/|new\/issue$|events$|system\/stream$|talk\/stream$|settings\/teams\/stream$|sw\.js$|offline$|robots\.txt$|favicon\.ico$|apple-touch-icon(-precomposed)?\.png$|sitemap\.xml$|edition$|oembed$|manifest\.webmanifest$|opensearch\.xml$|llms(-full)?\.txt$|openapi\.json$|releases\.json$|templates\.json$|maintenance\.json$|changelog\.atom$|explore\.(atom|json)$|feed\.json$|docs(\/[^/]*)?$|audit\.csv$|settings\/traffic\/scrapes\/export$|settings\/payments\.csv$|fleet\/graph\/live$|fleet\/graph\.csv$|forges\/export\.csv$|settings\/origins\/callback$|broker\/origins\/start$|home\/archived\/|settings\/backups\/live$|api\/v1(\/|$))/; | |
| 20 | /^\/(design\/theme\.css|design\/theme\/|assets\/|\.well-known\/|icons\/|og\/|live\/|__forge\/|go\/|new\/issue$|events$|system\/stream$|talk\/stream$|talk\/peek$|settings\/teams\/stream$|sw\.js$|offline$|robots\.txt$|favicon\.ico$|apple-touch-icon(-precomposed)?\.png$|sitemap\.xml$|edition$|oembed$|manifest\.webmanifest$|opensearch\.xml$|llms(-full)?\.txt$|openapi\.json$|releases\.json$|templates\.json$|maintenance\.json$|changelog\.atom$|explore\.(atom|json)$|feed\.json$|docs(\/[^/]*)?$|audit\.csv$|settings\/traffic\/scrapes\/export$|settings\/payments\.csv$|fleet\/graph\/live$|fleet\/graph\.csv$|forges\/export\.csv$|settings\/origins\/callback$|broker\/origins\/start$|home\/archived\/|settings\/backups\/live$|api\/v1(\/|$))/; | |
| 21 | 21 | |
| 22 | 22 | const getRoutes = [ |
| 23 | 23 | ...server.matchAll(/router\.add\(\s*"GET",\s*"([^"]+)"/g), |
test/talk-page.test.ts +30 −4
| @@ -252,7 +252,7 @@ describe("the page", () => { | ||
| 252 | 252 | expect(out).toContain(`<pre><code>${code}`); |
| 253 | 253 | expect(out).toContain(url); |
| 254 | 254 | expect(talkCss).toContain(".talk-turn pre { max-width: 100%; overflow-x: auto; }"); |
| 255 | expect(talkCss).toContain(".talk-body a { overflow-wrap: anywhere; }"); | |
| 255 | expect(talkCss).toContain(".talk-body a { overflow-wrap: anywhere;"); | |
| 256 | 256 | expect(talkJs).toContain('copyButton("Copy this code")'); |
| 257 | 257 | expect(talkJs).toContain("wrap.append(head, pre)"); |
| 258 | 258 | expect(talkJs).toContain("pre.tabIndex = 0"); |
| @@ -406,7 +406,7 @@ describe("the page", () => { | ||
| 406 | 406 | test("the page's own bytes are held: stylesheet and script stay small", async () => { |
| 407 | 407 | const { talkCss, talkJs } = await import("../src/web/pages/talk_client.ts"); |
| 408 | 408 | expect(Buffer.byteLength(talkCss)).toBeLessThan(14_700); |
| 409 | expect(Buffer.byteLength(talkJs)).toBeLessThan(29_700); | |
| 409 | expect(Buffer.byteLength(talkJs)).toBeLessThan(34_000); | |
| 410 | 410 | // A page of its own, so what other tests said to alice never counts: one question and a code reply. |
| 411 | 411 | const sizer = await createUser(app.db, { origin: "seed", trusted: true, username: "sizer", email: "[email protected]", password: "a-good-passphrase" }); |
| 412 | 412 | if (!sizer.ok) throw new Error(sizer.error); |
| @@ -499,7 +499,7 @@ describe("the page", () => { | ||
| 499 | 499 | expect(t.sent.filter((s) => s === "Stop it")).toHaveLength(1); |
| 500 | 500 | }); |
| 501 | 501 | |
| 502 | const boot = async (user = "u1", store: Record<string, string> = {}, conv = "c1") => { | |
| 502 | const boot = async (user = "u1", store: Record<string, string> = {}, conv = "c1", timers: { setTimeout: typeof setTimeout; clearTimeout: typeof clearTimeout } = { setTimeout, clearTimeout }) => { | |
| 503 | 503 | const sources: Array<{ on: Record<string, (e: { data: string }) => void> }> = []; |
| 504 | 504 | const { Window } = await import("happy-dom"); |
| 505 | 505 | const { talkJs } = await import("../src/web/pages/talk_client.ts"); |
| @@ -533,7 +533,7 @@ describe("the page", () => { | ||
| 533 | 533 | const grows: Array<() => void> = []; |
| 534 | 534 | (window as any).ResizeObserver = class { els: unknown[] = []; constructor(f: (seen: { target: unknown }[]) => void) { grows.push(() => f(this.els.map((target) => ({ target })))); } observe(el: unknown) { this.els.push(el); } }; |
| 535 | 535 | const view = scrollable(doc.scrollingElement ?? doc.documentElement, 5000, 800); |
| 536 | new Function("document", "window", "EventSource", "fetch", "localStorage", "navigator", talkJs)(doc, window, ES, fetchStub, local, nav); | |
| 536 | new Function("document", "window", "EventSource", "fetch", "localStorage", "navigator", "setTimeout", "clearTimeout", talkJs)(doc, window, ES, fetchStub, local, nav, timers.setTimeout, timers.clearTimeout); | |
| 537 | 537 | const box = doc.querySelector("textarea"); |
| 538 | 538 | const key = (init: object) => box.dispatchEvent(new window.KeyboardEvent("keydown", { key: "Enter", bubbles: true, cancelable: true, ...init })); |
| 539 | 539 | const emit = (id: string, html: string) => sources.at(-1)!.on["turn"]!({ data: JSON.stringify({ id, html }) }); |
| @@ -864,6 +864,32 @@ describe("the page", () => { | ||
| 864 | 864 | expect(t.copied).toEqual(["let a = 1;"]); |
| 865 | 865 | }); |
| 866 | 866 | |
| 867 | test("a long press never swallows a later tap: the flag ends with the touch, a scroll or a cancel", async () => { | |
| 868 | // A hand-run clock: the long press and its short grace run when the test says. | |
| 869 | const due: (() => void)[] = []; | |
| 870 | const timers = { setTimeout: ((f: () => void) => due.push(f)) as unknown as typeof setTimeout, clearTimeout: (() => {}) as unknown as typeof clearTimeout }; | |
| 871 | const run = () => { for (const f of due.splice(0)) f(); }; | |
| 872 | const t = await boot("u1", {}, "c1", timers); | |
| 873 | t.doc.querySelector("#t-1 .talk-body").insertAdjacentHTML("beforeend", '<a href="/alice/harbor/issues/1">#1</a>'); | |
| 874 | const a = t.doc.querySelector("#t-1 .talk-body a"); | |
| 875 | const tap = () => { const e = new t.window.MouseEvent("click", { bubbles: true, cancelable: true }); a.dispatchEvent(e); return e.defaultPrevented; }; | |
| 876 | const press = () => { a.dispatchEvent(new t.window.Event("touchstart", { bubbles: true })); run(); }; | |
| 877 | // The click that ends a long press is swallowed; the grace then passes and a tap follows the link. | |
| 878 | press(); | |
| 879 | a.dispatchEvent(new t.window.Event("touchend", { bubbles: true })); | |
| 880 | expect(tap()).toBe(true); | |
| 881 | press(); | |
| 882 | a.dispatchEvent(new t.window.Event("touchend", { bubbles: true })); | |
| 883 | run(); | |
| 884 | expect(tap()).toBe(false); | |
| 885 | // No click at all (the callout took it), then a scroll, a cancel or a move: the next tap follows. | |
| 886 | for (const end of ["scroll", "touchcancel", "pointercancel", "touchmove"]) { | |
| 887 | press(); | |
| 888 | (end === "scroll" ? t.window : a).dispatchEvent(new t.window.Event(end, { bubbles: true })); | |
| 889 | expect([end, tap()]).toEqual([end, false]); | |
| 890 | } | |
| 891 | }); | |
| 892 | ||
| 867 | 893 | test("with steps set to start open (Display), a step that streams in opens its fold as the first paint does", async () => { |
| 868 | 894 | const t = await boot(); |
| 869 | 895 | t.doc.querySelector("[data-talk]").dataset.fold = "open"; |
test/talk-peek.test.ts added +218
| @@ -0,0 +1,218 @@ | ||
| 1 | /** | |
| 2 | * A peek at what a Talk message links to (#15734): `GET /talk/peek` answers a small card for an | |
| 3 | * issue, a pull or a repository the viewer can read, and not found for anything else, exactly as | |
| 4 | * the link would; the body is escaped plain text; a live crew run shows as working now. In a real | |
| 5 | * Chromium (skipped, and says so, where none starts): a hover on a link opens the card after its | |
| 6 | * intent delay, Escape closes it, and a plain click still follows the link. | |
| 7 | */ | |
| 8 | import { afterAll, beforeAll, expect, test } from "bun:test"; | |
| 9 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 10 | import { tmpdir } from "node:os"; | |
| 11 | import { join } from "node:path"; | |
| 12 | import { createRepo } from "../src/actions/repos.ts"; | |
| 13 | import { createApp, type App } from "../src/app.ts"; | |
| 14 | import { appendTurn, openConversation } from "../src/core/conversations.ts"; | |
| 15 | import { createIssue, setAssignee, setIssueState } from "../src/core/issues.ts"; | |
| 16 | import { getRepo } from "../src/core/repos.ts"; | |
| 17 | import { claimRun, createRun } from "../src/core/runs.ts"; | |
| 18 | import { createSession } from "../src/core/sessions.ts"; | |
| 19 | import { createUser, type User } from "../src/core/users.ts"; | |
| 20 | import { findChromium } from "../src/looks/capture.ts"; | |
| 21 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 22 | import { chromiumRuns, evaluateLoaded } from "./helpers/chrome.ts"; | |
| 23 | import { quietLogs } from "./helpers/globals.ts"; | |
| 24 | import { promote } from "./helpers/members.ts"; | |
| 25 | ||
| 26 | quietLogs(); | |
| 27 | ||
| 28 | const found = findChromium(); | |
| 29 | const chromium = found !== undefined && chromiumRuns(found) ? found : undefined; | |
| 30 | if (chromium === undefined) | |
| 31 | console.log( | |
| 32 | "SKIPPING: no chromium that starts on this machine, so the hover is not driven", | |
| 33 | ); | |
| 34 | ||
| 35 | let dir: string; | |
| 36 | let app: App; | |
| 37 | let servers: Servers; | |
| 38 | let alice: User; | |
| 39 | let bob: User; | |
| 40 | const token = (u: User) => createSession(app.db, u.id).token; | |
| 41 | const peek = (href: string, u: User | null = alice) => | |
| 42 | fetch(`${servers.url}/talk/peek?href=${encodeURIComponent(href)}`, { | |
| 43 | headers: u === null ? {} : { cookie: `forge_session=${token(u)}` }, | |
| 44 | }); | |
| 45 | ||
| 46 | beforeAll(async () => { | |
| 47 | dir = await mkdtemp(join(tmpdir(), "forge-talk-peek-")); | |
| 48 | app = createApp({ dataDir: dir, port: 0 }); | |
| 49 | servers = await serve(app); | |
| 50 | for (const name of ["alice", "bob"]) { | |
| 51 | const made = await createUser(app.db, { | |
| 52 | origin: "seed", | |
| 53 | trusted: true, | |
| 54 | username: name, | |
| 55 | email: `${name}@forge.local`, | |
| 56 | password: "a-good-passphrase", | |
| 57 | adminIfFirst: name === "alice", | |
| 58 | }); | |
| 59 | if (!made.ok) throw new Error(made.error); | |
| 60 | promote(app.db, made.value); | |
| 61 | if (name === "alice") alice = made.value; | |
| 62 | else bob = made.value; | |
| 63 | } | |
| 64 | const open = await createRepo(app, alice, { | |
| 65 | name: "harbor", | |
| 66 | visibility: "public", | |
| 67 | description: "The harbor site", | |
| 68 | }); | |
| 69 | const secret = await createRepo(app, alice, { | |
| 70 | name: "vault", | |
| 71 | visibility: "private", | |
| 72 | }); | |
| 73 | if (!open.ok || !secret.ok) throw new Error("repo"); | |
| 74 | const issue = createIssue(app.db, { | |
| 75 | repoId: open.value.id, | |
| 76 | authorId: alice.id, | |
| 77 | title: "Hero image is <b>6 MB</b>", | |
| 78 | body: "The hero is a 6 MB PNG.\n\n<script>alert(1)</script> [x](javascript:alert(1)) needs WebP.", | |
| 79 | }); | |
| 80 | if (!issue.ok) throw new Error("issue"); | |
| 81 | claimRun( | |
| 82 | app.db, | |
| 83 | createRun(app.db, { | |
| 84 | repoId: open.value.id, | |
| 85 | kind: "agent", | |
| 86 | issueId: issue.value.id, | |
| 87 | reason: "work", | |
| 88 | }).id, | |
| 89 | ); | |
| 90 | createIssue(app.db, { | |
| 91 | repoId: secret.value.id, | |
| 92 | authorId: alice.id, | |
| 93 | title: "Private plan", | |
| 94 | body: "x", | |
| 95 | }); | |
| 96 | const c = openConversation(app.db, alice.id); | |
| 97 | appendTurn(app.db, alice.id, c.id, { | |
| 98 | role: "person", | |
| 99 | text: "what about the hero?", | |
| 100 | }); | |
| 101 | appendTurn(app.db, alice.id, c.id, { | |
| 102 | role: "agent", | |
| 103 | text: "It is [#1](/alice/harbor/issues/1): a 6 MB PNG.", | |
| 104 | }); | |
| 105 | }); | |
| 106 | afterAll(async () => { | |
| 107 | servers.stop(); | |
| 108 | app.close(); | |
| 109 | await rm(dir, { recursive: true, force: true }); | |
| 110 | }); | |
| 111 | ||
| 112 | test("an issue's card: kind, number, state, title, who works on it now, its body as plain text, two safe actions", async () => { | |
| 113 | const res = await peek("/alice/harbor/issues/1"); | |
| 114 | expect(res.status).toBe(200); | |
| 115 | expect(res.headers.get("cache-control")).toBe("private, max-age=5"); | |
| 116 | const card = (await res.text()).replace(/\s+/g, " "); | |
| 117 | expect(card).toContain("alice/harbor#1 · Open"); | |
| 118 | expect(card).toContain("Hero image is <b>6 MB</b>"); | |
| 119 | expect(card).toContain("working on it for 1 min"); | |
| 120 | expect(card).toContain("<script>alert(1)</script>"); | |
| 121 | expect(card).not.toContain("<script>"); | |
| 122 | expect(card).not.toContain('href="javascript:'); | |
| 123 | expect(card).toContain(`href="/alice/harbor/issues/1">Open</a`); | |
| 124 | expect(card).toContain( | |
| 125 | 'href="/talk?about=alice%2Fharbor%231" >Talk about this</a', | |
| 126 | ); | |
| 127 | expect(await (await peek("/alice/harbor")).text()).toContain( | |
| 128 | "The harbor site", | |
| 129 | ); | |
| 130 | }); | |
| 131 | ||
| 132 | test("anything not readable, not a forge path, or of the wrong kind answers not found, as the link would; signed out is asked to sign in", async () => { | |
| 133 | expect((await peek("/alice/vault/issues/1", bob)).status).toBe(404); | |
| 134 | expect((await peek("/alice/vault", bob)).status).toBe(404); | |
| 135 | expect((await peek("/alice/vault/issues/1", alice)).status).toBe(200); | |
| 136 | expect((await peek("/alice/harbor/pulls/1")).status).toBe(404); | |
| 137 | expect((await peek("/alice/harbor/issues/9")).status).toBe(404); | |
| 138 | expect((await peek("https://evil.example/alice/harbor")).status).toBe(404); | |
| 139 | expect((await peek("//evil.example/x")).status).toBe(404); | |
| 140 | expect((await peek("/alice/harbor/issues/1", null)).status).toBe(401); | |
| 141 | }); | |
| 142 | ||
| 143 | test("each state and line a card can carry: merged, closed, checks in words, assigned, queued; a pull is talked about too; a sealed issue is not found to whoever may not see it", async () => { | |
| 144 | const repo = getRepo(app.db, "alice", "harbor")!; | |
| 145 | const made = (title: string, more: { kind?: "pull"; sealed?: boolean } = {}) => { | |
| 146 | const i = createIssue(app.db, { repoId: repo.id, authorId: alice.id, title, body: "b", ...more }); | |
| 147 | if (!i.ok) throw new Error("issue"); | |
| 148 | return i.value; | |
| 149 | }; | |
| 150 | const pullOf = (title: string, merged: string | null) => { | |
| 151 | const p = made(title, { kind: "pull" }); | |
| 152 | app.db.run("INSERT INTO pull (issue_id, base_branch, head_branch, base_oid, head_oid, merged_at) VALUES (?1, 'main', ?2, '', 'h', ?3)", [p.id, `b${String(p.number)}`, merged]); | |
| 153 | return p; | |
| 154 | }; | |
| 155 | const checked = (p: { id: string }, state: string) => app.db.run("UPDATE run SET state = ?1 WHERE id = ?2", [state, createRun(app.db, { repoId: repo.id, kind: "check", issueId: p.id }).id]); | |
| 156 | const text = async (href: string, u: User = alice) => (await (await peek(href, u)).text()).replace(/\s+/g, " "); | |
| 157 | ||
| 158 | const merged = pullOf("Ship WebP", new Date().toISOString()); | |
| 159 | checked(merged, "ok"); | |
| 160 | const card = await text(`/alice/harbor/pulls/${String(merged.number)}`); | |
| 161 | expect(card).toContain(`alice/harbor#${String(merged.number)} · Merged · checks passed`); | |
| 162 | expect(card).toContain(`href="/alice/harbor/pulls/${String(merged.number)}">Open</a`); | |
| 163 | expect(card).toContain(`href="/talk?about=alice%2Fharbor%23${String(merged.number)}"`); | |
| 164 | expect(card).toContain("Talk about this"); | |
| 165 | ||
| 166 | const red = pullOf("Try AVIF", null); | |
| 167 | checked(red, "failed"); | |
| 168 | expect(await text(`/alice/harbor/pulls/${String(red.number)}`)).toContain("· Open · checks failed"); | |
| 169 | const going = pullOf("Try JPEG XL", null); | |
| 170 | checked(going, "running"); | |
| 171 | expect(await text(`/alice/harbor/pulls/${String(going.number)}`)).toContain("· Open · checks running"); | |
| 172 | ||
| 173 | const done = made("Old banner"); | |
| 174 | setIssueState(app.db, done.id, "closed"); | |
| 175 | expect(await text(`/alice/harbor/issues/${String(done.number)}`)).toContain(`alice/harbor#${String(done.number)} · Closed`); | |
| 176 | ||
| 177 | const owned = made("Footer links"); | |
| 178 | setAssignee(app.db, owned.id, bob.id); | |
| 179 | createRun(app.db, { repoId: repo.id, kind: "agent", issueId: owned.id, reason: "work" }); | |
| 180 | expect(await text(`/alice/harbor/issues/${String(owned.number)}`)).toContain("Assigned to bob · <strong >queued to work on it</strong"); | |
| 181 | ||
| 182 | const sealed = made("A hole", { sealed: true }); | |
| 183 | expect((await peek(`/alice/harbor/issues/${String(sealed.number)}`, bob)).status).toBe(404); | |
| 184 | expect((await peek(`/alice/harbor/issues/${String(sealed.number)}`, alice)).status).toBe(200); | |
| 185 | }); | |
| 186 | ||
| 187 | test.skipIf(chromium === undefined)( | |
| 188 | "a hover opens the card after its intent delay and Escape closes it; the link stays a link", | |
| 189 | async () => { | |
| 190 | const c = openConversation(app.db, alice.id); | |
| 191 | const seen = JSON.parse( | |
| 192 | await evaluateLoaded( | |
| 193 | chromium!, | |
| 194 | `${servers.url}/talk/${c.id}`, | |
| 195 | { width: 1280, height: 800 }, | |
| 196 | [{ name: "forge_session", value: token(alice) }], | |
| 197 | `(async () => { | |
| 198 | const a = document.querySelector(".talk-body a[href='/alice/harbor/issues/1']"); | |
| 199 | const opened = new Promise((done) => new MutationObserver(() => document.querySelector(".talk-peek") && done()).observe(document.body, { childList: true })); | |
| 200 | a.dispatchEvent(new PointerEvent("pointerover", { bubbles: true, pointerType: "mouse" })); | |
| 201 | await opened; | |
| 202 | const card = document.querySelector(".talk-peek"); | |
| 203 | const out = { text: card.textContent.replace(/\\s+/g, " ").trim(), described: a.getAttribute("aria-describedby"), role: card.getAttribute("role") }; | |
| 204 | document.dispatchEvent(new KeyboardEvent("keydown", { key: "Escape", bubbles: true })); | |
| 205 | out.closed = !document.querySelector(".talk-peek") && !a.hasAttribute("aria-describedby"); | |
| 206 | out.href = a.getAttribute("href"); | |
| 207 | return JSON.stringify(out); | |
| 208 | })()`, | |
| 209 | ), | |
| 210 | ); | |
| 211 | expect(seen.text).toContain("Hero image is <b>6 MB</b>"); | |
| 212 | expect(seen.described).toBe("talk-peek"); | |
| 213 | expect(seen.role).toBe("region"); | |
| 214 | expect(seen.closed).toBe(true); | |
| 215 | expect(seen.href).toBe("/alice/harbor/issues/1"); | |
| 216 | }, | |
| 217 | 30_000, | |
| 218 | ); |
test/tui-talk-chats.test.ts +11
| @@ -209,6 +209,17 @@ describe("the terminal's conversations screen", () => { | ||
| 209 | 209 | setTalkDisplay(app.db, bob.id, { density: "comfortable" }); |
| 210 | 210 | }); |
| 211 | 211 | |
| 212 | test("a link the page peeks at reads in the terminal as owner/repo#n, the name its issue screens open by", async () => { | |
| 213 | const made = createConversation(app.db, bob.id); | |
| 214 | if (!made.ok) throw new Error(made.error); | |
| 215 | appendTurn(app.db, bob.id, made.value.id, { role: "person", text: "which one?" }); | |
| 216 | appendTurn(app.db, bob.id, made.value.id, { role: "agent", text: "It is [#1](/bob/site/issues/1), the drift." }); | |
| 217 | renameConversation(app.db, bob.id, made.value.id, "Peek here"); | |
| 218 | const text = await drive(bob, [...open, "/", "Peek here", "\r", "\r"]); | |
| 219 | expect(text).toContain("bob/site#1"); | |
| 220 | expect(text).not.toContain("](/bob/site/issues/1)"); | |
| 221 | }); | |
| 222 | ||
| 212 | 223 | test("p shows what the chat works on, as the web's pane does; a repository it cannot read shows nothing of it", async () => { |
| 213 | 224 | const made = createConversation(app.db, alice.id); |
| 214 | 225 | if (!made.ok) throw new Error(made.error); |
Medium.
pressedis set when the long press fires and cleared only by a following click. On iOS the long-press callout, or a close of the sheet, often yields no click. The user's next ordinary tap on that link is then preventDefault-ed and does nothing. Fix: clearpressedon touchend after a short timeout, or on the sheet's close event, and test it.