Public: anyone can read this; the crew can change it.
An app's first build's draft deploys at its opening and each push, and the pane swaps to it in place #16388
Check · Review · Land · Live done — Landed and live in production.
talk/draft-preview → main 0 commits 1 thread · 1 unresolved
11 files
changed +125
−33
docs/design/size-budget.json +1 −1
| @@ -68,7 +68,7 @@ | ||
| 68 | 68 | "css": 48640 |
| 69 | 69 | }, |
| 70 | 70 | "/talk": { |
| 71 | "js": 40704, | |
| 71 | "js": 40960, | |
| 72 | 72 | "css": 56064 |
| 73 | 73 | }, |
| 74 | 74 | "/:owner/:name/pulls/:number": { |
docs/features/talk.md +1 −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 18,100 B, the script under 52,900 B, and a page with a code reply under 54,000 B (its own page: one question and a code reply; the widgets' rules ride every page, so a chart drawn in a live reply is styled at once). | |
| 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 18,100 B, the script under 53,500 B, and a page with a code reply under 54,000 B (its own page: one question and a code reply; the widgets' rules ride every page, so a chart drawn in a live reply is styled at once). | |
| 140 | 140 | |
| 141 | 141 | ## Following |
| 142 | 142 |
src/actions/talk_workspace.ts +11 −1
| @@ -123,6 +123,8 @@ export function paneQuery(at: PaneAt): string { | ||
| 123 | 123 | /** At most this many repositories in the address bar's first picker, and previews per repository. */ |
| 124 | 124 | export const PANE_REPOS = 8; |
| 125 | 125 | export const PANE_PREVIEWS = 5; |
| 126 | /** How many pulls' previews ahead the conversation's own repository names in `frame-src`. */ | |
| 127 | export const PANE_AHEAD = 3; | |
| 126 | 128 | |
| 127 | 129 | /** |
| 128 | 130 | * What the pane's address bar offers this person: the repositories (the conversation's first, then |
| @@ -142,14 +144,22 @@ export function paneOffer(app: App, user: User, current: string | undefined): Pa | ||
| 142 | 144 | // Every open pull of those repositories in one read; a sealed one only for its author here. |
| 143 | 145 | const open = openPullTitles(app.db, names.map((r) => r.id), user.id); |
| 144 | 146 | const origins = new Set<string>(); |
| 147 | // Counted from the highest number a reader can see, never the issue counter (a sealed report moves | |
| 148 | // it): a gap past the window draws the page once instead, as before. | |
| 149 | const nextUp = (app.db.query<{ n: number | null }, [string]>("SELECT MAX(number) AS n FROM issue WHERE repo_id = ?1 AND sealed = 0").get(first.id)?.n ?? 0) + 1; | |
| 145 | 150 | const repos = names.map((repo) => { |
| 146 | 151 | const record = records.get(repo.id); |
| 147 | 152 | // A preview is offered only while it runs, as the runtime knows it (no read); a private app's |
| 148 | 153 | // only to someone who may enter it, as `envsFor` decides for the conversation's. |
| 149 | 154 | const up = record === undefined ? new Set<string>() : new Set((repo.id === first.id ? envsFor(app, user, record) : (runtime?.status(record) ?? [])).map((s) => s.env as string)); |
| 150 | 155 | const previews = (open.get(repo.id) ?? []).filter((p) => up.has(previewEnv(p.number))).slice(0, PANE_PREVIEWS); |
| 156 | // The conversation's own repository also names the next few pulls' previews ahead (exact | |
| 157 | // origins, numbered on from the highest one a reader sees): the crew's | |
| 158 | // draft opens one, and the pane swaps to it in place when it answers, without drawing the page | |
| 159 | // again. | |
| 160 | const ahead = repo.id === first.id && record !== undefined ? Array.from({ length: PANE_AHEAD }, (_, i) => previewEnv(nextUp + i)) : []; | |
| 151 | 161 | if (record !== undefined && runtime !== undefined) |
| 152 | for (const env of ["production" as EnvName, ...previews.map((p) => previewEnv(p.number))]) { | |
| 162 | for (const env of ["production" as EnvName, ...previews.map((p) => previewEnv(p.number)), ...ahead]) { | |
| 153 | 163 | const o = originOf(runtime.urlFor(record, env)); |
| 154 | 164 | if (o !== undefined) origins.add(o); |
| 155 | 165 | } |
src/apps/prepared.ts +5 −2
| @@ -9,19 +9,22 @@ | ||
| 9 | 9 | * - `check`: the head declares no `check`, or this forge runs none (`FORGE_CHECKS=0`), so the |
| 10 | 10 | * preview's deploy (install, start, health, `app.test`) is the only verdict its pull gets; |
| 11 | 11 | * - `look`: the pull changes a page the forge pictures (`checks/look_pages.ts`), and a picture |
| 12 | * is taken of a preview that serves. | |
| 12 | * is taken of a preview that serves; | |
| 13 | * - `draft`: the pull is an app's first build still being written (`crew/early.ts`): its | |
| 14 | * preview is how the person watches the build, so it is never left asleep. | |
| 13 | 15 | * |
| 14 | 16 | * Plain data in, plain data out. |
| 15 | 17 | */ |
| 16 | 18 | |
| 17 | 19 | /** What asks for a preview at the push. */ |
| 18 | export type PushAsker = "eager" | "check" | "look"; | |
| 20 | export type PushAsker = "eager" | "check" | "look" | "draft"; | |
| 19 | 21 | |
| 20 | 22 | /** What a prepared preview's log and pages call each asker. */ |
| 21 | 23 | export const ASKER_WORDS: Readonly<Record<PushAsker, string>> = { |
| 22 | 24 | eager: 'forge.json says app.previews: "eager"', |
| 23 | 25 | check: "its deploy is the pull's check", |
| 24 | 26 | look: "the pull changes a page the forge pictures", |
| 27 | draft: "it is a draft its builder is still writing, watched as it is built", | |
| 25 | 28 | }; |
| 26 | 29 | |
| 27 | 30 | /** The values `app.previews` takes; unset is `asleep`. */ |
src/apps/runtime_events.ts +6
| @@ -389,6 +389,12 @@ export function prepare(rt: AppsRuntime, record: AppRecord, repo: Repo, pull: Pu | ||
| 389 | 389 | |
| 390 | 390 | /** What asks for this pull's preview at the push, if anything does (`apps/prepared.ts`). */ |
| 391 | 391 | export async function pushAsker(rt: AppsRuntime, repo: Repo, pull: Pull, head: string, pictured: boolean): Promise<PushAsker | undefined> { |
| 392 | // A draft its builder is still writing is watched as it is built: its preview deploys at its | |
| 393 | // opening and at each push (#16345), never asleep until asked for. | |
| 394 | if (pull.draftRun !== null) { | |
| 395 | log.info("preview deploys at the push", { repo: repo.name, pull: pull.number, why: ASKER_WORDS.draft }); | |
| 396 | return "draft"; | |
| 397 | } | |
| 392 | 398 | // A forge that runs no checks (`FORGE_CHECKS=0`) judges every pull by its deploy. |
| 393 | 399 | if (checksFor(rt.app) === undefined) return "check"; |
| 394 | 400 | const dir = await pullDir(rt.app.db, rt.app.reposRoot, repo, pull); |
src/core/talk_work.ts +11 −2
| @@ -248,6 +248,8 @@ export function paneInfo(db: Database, repo: { readonly id: string; readonly def | ||
| 248 | 248 | } |
| 249 | 249 | const pull = getPull(db, repo.id, shows); |
| 250 | 250 | if (pull === undefined) return `#${String(shows)}`; |
| 251 | // A draft its builder is still writing (`crew/early.ts`): what is framed is the build as it goes. | |
| 252 | if (pull.draftRun !== null) return `Preview of #${String(pull.number)} (draft, still building) · ${pull.title}`; | |
| 251 | 253 | const who = getUserById(db, pull.authorId)?.username; |
| 252 | 254 | const checks = PULL_CHECKS[checkSummary(db, pull.id, pull.headOid).state] ?? "no checks yet"; |
| 253 | 255 | const review = reviewSummary(db, pull.id, pull.headOid, pull.authorId); |
| @@ -283,7 +285,7 @@ export function conversationPulls(db: Database, repoId: string, issues: readonly | ||
| 283 | 285 | } |
| 284 | 286 | |
| 285 | 287 | /** The words of the work line, in one place. */ |
| 286 | const WORK_WORDS = { closed: "Done: it is closed.", landed: "landed", ready: "is ready: waiting for you to land it.", checksRunning: "checks running", checksFailed: "checks failed", pushed: "pushed", queued: "Queued for", working: "has been working on it", failed: "'s run did not finish.", finished: "finished.", assigned: "Assigned to", crew: "The crew" } as const; | |
| 288 | const WORK_WORDS = { closed: "Done: it is closed.", landed: "landed", ready: "is ready: waiting for you to land it.", checksRunning: "checks running", checksFailed: "checks failed", pushed: "pushed", queued: "Queued for", working: "has been working on it", failed: "'s run did not finish.", finished: "finished.", assigned: "Assigned to", crew: "The crew", building: "is building", previewLive: "its preview is live." } as const; | |
| 287 | 289 | |
| 288 | 290 | /** |
| 289 | 291 | * What the crew is doing on an issue now, in one line, read when it is asked for: the pull its run |
| @@ -295,10 +297,17 @@ export function workLine(db: Database, issue: Issue, now: number): string { | ||
| 295 | 297 | const named = issue.assigneeId === null ? undefined : getUserById(db, issue.assigneeId)?.username; |
| 296 | 298 | const who = named ?? WORK_WORDS.crew; |
| 297 | 299 | const run = lastRun(db, issue); |
| 298 | const pull = run === null || run.branch === "" ? null : db.query<{ id: string; number: number; merged_at: string | null }, [string, string]>("SELECT i.id, i.number, p.merged_at FROM pull p JOIN issue i ON i.id = p.issue_id WHERE p.head_branch = ?1 AND i.repo_id = ?2 ORDER BY i.number DESC LIMIT 1").get(run.branch, issue.repoId); | |
| 300 | const pull = run === null || run.branch === "" ? null : db.query<{ id: string; number: number; merged_at: string | null; draft_run: string | null }, [string, string]>("SELECT i.id, i.number, p.merged_at, p.draft_run FROM pull p JOIN issue i ON i.id = p.issue_id WHERE p.head_branch = ?1 AND i.repo_id = ?2 ORDER BY i.number DESC LIMIT 1").get(run.branch, issue.repoId); | |
| 299 | 301 | // A landed pull says so even once it closed its issue: "landed #2" is the news, "closed" is not. |
| 300 | 302 | if (pull !== null && pull.merged_at !== null) return `${who} ${WORK_WORDS.landed} #${pull.number}.`; |
| 301 | 303 | if (issue.state === "closed") return WORK_WORDS.closed; |
| 304 | // A draft its builder is still writing (`crew/early.ts`): no check runs yet, and its preview is | |
| 305 | // what there is to see. | |
| 306 | if (pull !== null && pull.draft_run !== null) { | |
| 307 | const builder = db.query<{ actor_id: string | null }, [string]>("SELECT actor_id FROM run WHERE id = ?1").get(pull.draft_run)?.actor_id; | |
| 308 | const by = (builder === null || builder === undefined ? undefined : getUserById(db, builder)?.username) ?? named ?? WORK_WORDS.crew; | |
| 309 | return `${by} ${WORK_WORDS.building} #${pull.number}: ${WORK_WORDS.previewLive}`; | |
| 310 | } | |
| 302 | 311 | if (pull !== null) { |
| 303 | 312 | const check = db.query<{ state: string }, [string]>("SELECT state FROM run WHERE issue_id = ?1 AND kind = 'check' ORDER BY id DESC LIMIT 1").get(pull.id); |
| 304 | 313 | if (check?.state === "ok") return `${who} ${WORK_WORDS.pushed} #${pull.number}, which ${WORK_WORDS.ready}`; |
src/web/pages/talk_client.ts +16 −9
| @@ -950,17 +950,24 @@ ${dictateJs} | ||
| 950 | 950 | document.addEventListener("forge:event", (e) => { |
| 951 | 951 | const d = e.detail, pane = document.querySelector("[data-pane-of]"), stage = pane && pane.querySelector("[data-stage][data-env]"); |
| 952 | 952 | if (!d || !stage || d.kind !== "run.finished" || !d.payload || d.payload.kind !== "deploy" || d.payload.state !== "ok" || d.repo !== pane.dataset.paneOf) return; |
| 953 | if (d.payload.env === stage.dataset.env) reframe(); | |
| 954 | else if (answering || box.value.trim()) return; | |
| 955 | else if (stage.dataset.env === "production") window.location.reload(); | |
| 956 | // A pull's preview framed when production deploys: the pane is asked what it frames now. Still the | |
| 957 | // open pull, the frame stays; the pull landed, production is its change, and the page draws once | |
| 958 | // for production's origin. | |
| 959 | else if (d.payload.env === "production") fetch(paneFragment(), { headers: { accept: "text/html" } }).then((r) => r.text()).then((text) => { | |
| 953 | if (d.payload.env === stage.dataset.env) { reframe(); return; } | |
| 954 | if (answering || box.value.trim()) return; | |
| 955 | // Another of the repository's environments came up (a draft's preview as its builder pushes, or | |
| 956 | // production once the pull lands): the pane is read again. When it now frames another | |
| 957 | // environment on an origin this page may frame, it swaps in place; on any other origin the page | |
| 958 | // draws once, since frame-src cannot change; framing the same one, nothing moves. | |
| 959 | fetch(paneFragment(), { headers: { accept: "text/html" } }).then((r) => r.text()).then((text) => { | |
| 960 | 960 | const t = document.createElement("template"); |
| 961 | 961 | t.innerHTML = text; |
| 962 | const now = t.content.querySelector("[data-stage][data-env]"); | |
| 963 | if (now && now.dataset.env !== stage.dataset.env && !answering && !box.value.trim()) window.location.reload(); | |
| 962 | const fresh = t.content.querySelector(".talk-pane"), now = fresh && fresh.querySelector("[data-stage][data-env]"), f = now && now.querySelector("[data-frame]"); | |
| 963 | if (!now || now.dataset.env === stage.dataset.env || answering || box.value.trim()) return; | |
| 964 | const shell = document.querySelector("[data-shell]"), here = pane.isConnected && pane; | |
| 965 | const may = (shell ? shell.dataset.frameOrigins || "" : "").split(" "); | |
| 966 | if (!f || !here || !may.includes(new URL(f.getAttribute("src"), window.location.href).origin)) { window.location.reload(); return; } | |
| 967 | here.replaceWith(fresh); | |
| 968 | codePane(); | |
| 969 | fresh.querySelectorAll("[data-frame]").forEach(watchFrame); | |
| 970 | fresh.dispatchEvent(new Event("forge:swapped", { bubbles: true })); | |
| 964 | 971 | }).catch(() => {}); |
| 965 | 972 | }); |
| 966 | 973 | // A reply that set the crew on an app opens the pane in place: the page is read again and its head |
test/apps-idle.test.ts +16
| @@ -241,6 +241,22 @@ describe("previews of idle pulls sleep", () => { | ||
| 241 | 241 | expect(deploys(number).map((r) => r.reason).sort()).toEqual(["push", "wake"]); |
| 242 | 242 | }, 120_000); |
| 243 | 243 | |
| 244 | test("a draft its builder is still writing deploys at its opening and at each push, never asleep (#16345)", async () => { | |
| 245 | // Invariant: an app's first build's draft is watched as it is built: its preview is up at the | |
| 246 | // opening and moves with each push, as the pane frames it. | |
| 247 | const head = await push("draft", [{ path: "draft.md", content: "one\n" }]); | |
| 248 | const opened = await openPull(app, alice, repo, { title: "draft", baseBranch: "main", headBranch: "feature/draft", draftRun: "r-draft" }); | |
| 249 | if (!opened.ok) throw new Error(String(opened.error)); | |
| 250 | const n = opened.value.number; | |
| 251 | await running(n); | |
| 252 | expect(envOf(n)?.dormant).toBeUndefined(); | |
| 253 | expect(envOf(n)?.commitOid).toBe(head); | |
| 254 | expect(deploys(n).map((r) => r.reason)).toEqual(["opened"]); | |
| 255 | const next = await push("draft", [{ path: "draft.md", content: "two\n" }]); | |
| 256 | await until(() => (envOf(n)?.state === "running" && envOf(n)?.commitOid === next ? true : undefined)); | |
| 257 | expect(deploys(n).length).toBe(2); | |
| 258 | }, 120_000); | |
| 259 | ||
| 244 | 260 | test("what asks at the push still gets its preview: a pictured page changed, and app.previews eager", async () => { |
| 245 | 261 | // Invariant: a pull that changes a rendered file is deployed at the push so its look is |
| 246 | 262 | // taken; a head that says app.previews "eager" is deployed as before. |
test/talk-page.test.ts +24 −15
| @@ -454,7 +454,7 @@ describe("the page", () => { | ||
| 454 | 454 | test("the page's own bytes are held: stylesheet and script stay small", async () => { |
| 455 | 455 | const { talkCss, talkJs } = await import("../src/web/pages/talk_client.ts"); |
| 456 | 456 | expect(Buffer.byteLength(talkCss)).toBeLessThan(18_100); |
| 457 | expect(Buffer.byteLength(talkJs)).toBeLessThan(52_900); | |
| 457 | expect(Buffer.byteLength(talkJs)).toBeLessThan(53_500); | |
| 458 | 458 | // A page of its own, so what other tests said to alice never counts: one question and a code reply. |
| 459 | 459 | const sizer = await createUser(app.db, { origin: "seed", trusted: true, username: "sizer", email: "[email protected]", password: "a-good-passphrase" }); |
| 460 | 460 | if (!sizer.ok) throw new Error(sizer.error); |
| @@ -1273,7 +1273,7 @@ describe("the page", () => { | ||
| 1273 | 1273 | expect([redraws, u.doc.querySelector("body > [data-shell]").hasAttribute("data-split")]).toEqual([1, false]); |
| 1274 | 1274 | }); |
| 1275 | 1275 | |
| 1276 | test("the crew's own words join its steps as text; a deploy that turns running reloads the frame it serves, a pull's preview draws the page once, and production after a framed pull lands draws it once", async () => { | |
| 1276 | test("the crew's own words join its steps as text; a deploy that turns running reloads the frame it serves; another environment coming up swaps the pane in place where the page may frame it, and draws the page once where it may not", async () => { | |
| 1277 | 1277 | const t = await boot(); |
| 1278 | 1278 | let reloads = 0; |
| 1279 | 1279 | Object.defineProperty(t.window.location, "reload", { value: () => { reloads += 1; }, configurable: true }); |
| @@ -1299,23 +1299,32 @@ describe("the page", () => { | ||
| 1299 | 1299 | deploy("production"); |
| 1300 | 1300 | await pollUntil(() => !t.doc.querySelector("[data-stage]").hasAttribute("data-busy"), "the note taken down"); |
| 1301 | 1301 | expect(frame.getAttribute("src")).toBe("http://app.test/__forge/grant?t=fresh"); |
| 1302 | deploy("pull-2"); | |
| 1303 | expect(reloads).toBe(1); | |
| 1302 | // Another environment comes up (the builder's draft preview, then production once it lands): the | |
| 1303 | // pane is read again and swaps in place when it frames it on an origin this page may frame. | |
| 1304 | t.doc.body.setAttribute("data-shell", ""); | |
| 1305 | t.doc.body.setAttribute("data-frame-origins", "http://app.test http://app--2.test"); | |
| 1306 | const stageEnv = () => t.doc.querySelector("[data-stage][data-env]")?.getAttribute("data-env"); | |
| 1307 | const asked = () => t.urls.filter((u: string) => u === "?pane=preview&fragment=pane").length; | |
| 1304 | 1308 | t.urls.length = 0; |
| 1305 | // A pull's preview framed when production deploys: the pane is asked what it frames now. The | |
| 1306 | // pull still open, it frames the pull and nothing moves; the pull landed, production is framed | |
| 1307 | // and the page draws once for its origin. | |
| 1308 | t.doc.querySelector("[data-stage]").setAttribute("data-env", "pull-2"); | |
| 1309 | t.page.html = '<aside class="talk-pane"><div class="talk-stage" data-stage data-env="pull-2"></div></aside>'; | |
| 1309 | t.page.html = '<aside class="talk-pane" data-pane-of="alice/x"><div class="talk-stage" data-stage data-env="pull-2"><iframe data-frame src="http://app--2.test/__forge/grant?t=d"></iframe></div></aside>'; | |
| 1310 | deploy("pull-2"); | |
| 1311 | await pollUntil(() => stageEnv() === "pull-2", "the draft's preview swapped in"); | |
| 1312 | expect(reloads).toBe(0); | |
| 1313 | // The pull still open, production deploying moves nothing: the pane still frames the pull. | |
| 1310 | 1314 | deploy("production"); |
| 1311 | await pollUntil(() => t.urls.filter((u: string) => u === "?pane=preview&fragment=pane").length === 1, "the pane asked once"); | |
| 1312 | // Its answer read and judged: a few turns of the microtask queue, no clock. | |
| 1315 | await pollUntil(() => asked() === 2, "the pane asked again"); | |
| 1313 | 1316 | for (let i = 0; i < 10; i++) await Promise.resolve(); |
| 1314 | expect(reloads).toBe(1); | |
| 1315 | t.page.html = '<aside class="talk-pane"><div class="talk-stage" data-stage data-env="production"></div></aside>'; | |
| 1317 | expect([stageEnv(), reloads]).toEqual(["pull-2", 0]); | |
| 1318 | // Landed: production frames its change, in place. | |
| 1319 | t.page.html = '<aside class="talk-pane" data-pane-of="alice/x"><div class="talk-stage" data-stage data-env="production"><iframe data-frame src="http://app.test/__forge/grant?t=l"></iframe></div></aside>'; | |
| 1316 | 1320 | deploy("production"); |
| 1317 | await pollUntil(() => reloads === 2, "the page drawn once for production"); | |
| 1318 | expect(t.urls.filter((u: string) => u === "?pane=preview&fragment=pane")).toHaveLength(2); | |
| 1321 | await pollUntil(() => stageEnv() === "production", "back to Live in place"); | |
| 1322 | expect(reloads).toBe(0); | |
| 1323 | // An origin this page may not frame (a pull past the ones it named ahead): the page draws once. | |
| 1324 | t.page.html = '<aside class="talk-pane" data-pane-of="alice/x"><div class="talk-stage" data-stage data-env="pull-9"><iframe data-frame src="http://app--9.test/__forge/grant?t=n"></iframe></div></aside>'; | |
| 1325 | deploy("pull-9"); | |
| 1326 | await pollUntil(() => reloads === 1, "the page drawn once for an origin it may not frame"); | |
| 1327 | expect(asked()).toBe(4); | |
| 1319 | 1328 | }); |
| 1320 | 1329 | |
| 1321 | 1330 | test("a code block in a streamed turn gets its Copy button too", async () => { |
test/talk-pane-bar.test.ts +17 −2
| @@ -17,6 +17,7 @@ import { | ||
| 17 | 17 | paneQuery, |
| 18 | 18 | } from "../src/actions/talk_workspace.ts"; |
| 19 | 19 | import { AppsRuntime } from "../src/apps/runtime.ts"; |
| 20 | import { previewEnv } from "../src/apps/data.ts"; | |
| 20 | 21 | import { createApp, type App } from "../src/app.ts"; |
| 21 | 22 | import { getAppByRepo } from "../src/core/apps.ts"; |
| 22 | 23 | import { appendTurn, createConversation } from "../src/core/conversations.ts"; |
| @@ -214,16 +215,26 @@ describe("what it offers", () => { | ||
| 214 | 215 | |
| 215 | 216 | test("the page's frame-src is exactly the origins the bar offers, and a repository it does not offer is never framed", async () => { |
| 216 | 217 | const mine = await page(alice, talkOn(alice, "alice/one")); |
| 218 | // Each offered app's production, and the conversation's own app's next pulls' previews ahead, | |
| 219 | // counted on from the highest number a reader sees, so the crew's draft swaps in in place. | |
| 220 | const ahead = (name: string, from: number) => [0, 1, 2].map((i) => new URL(runtime.urlFor(getAppByRepo(app.db, repos[name]!.id)!, previewEnv(from + i))).origin); | |
| 221 | const seen = app.db.query<{ n: number | null }, [string]>("SELECT MAX(number) AS n FROM issue WHERE repo_id = ?1 AND sealed = 0").get(repos["alice/one"]!.id)!.n ?? 0; | |
| 217 | 222 | expect(mine.frameSrc).toEqual( |
| 218 | [live("alice/one"), live("alice/two"), live("team/shared")].sort(), | |
| 223 | [live("alice/one"), live("alice/two"), live("team/shared"), ...ahead("alice/one", seen + 1)].sort(), | |
| 219 | 224 | ); |
| 225 | // A sealed report takes a number nobody else sees: the previews named ahead do not move for it. | |
| 226 | const sealed = createIssue(app.db, { repoId: repos["alice/one"]!.id, authorId: alice.id, title: "A sealed report", body: "s" }); | |
| 227 | if (!sealed.ok) throw new Error("issue"); | |
| 228 | app.db.run("UPDATE issue SET sealed = 1 WHERE id = ?1", [sealed.value.id]); | |
| 229 | expect((await page(alice, talkOn(alice, "alice/one"))).frameSrc).toEqual(mine.frameSrc); | |
| 220 | 230 | expect(mine.html).toContain('<select name="repo" aria-label="Repository">'); |
| 221 | 231 | expect(mine.html).toContain( |
| 222 | 232 | '<option value="alice/one" selected>alice/one</option>', |
| 223 | 233 | ); |
| 224 | 234 | // bob asks for alice's private app by its address: his own is shown, alice's origin never named. |
| 225 | 235 | const his = await page(bob, talkOn(bob, "bob/mine"), "?repo=alice/one"); |
| 226 | expect(his.frameSrc).toEqual([live("bob/mine")]); | |
| 236 | const bobSeen = app.db.query<{ n: number | null }, [string]>("SELECT MAX(number) AS n FROM issue WHERE repo_id = ?1 AND sealed = 0").get(repos["bob/mine"]!.id)!.n ?? 0; | |
| 237 | expect(his.frameSrc).toEqual([live("bob/mine"), ...ahead("bob/mine", bobSeen + 1)].sort()); | |
| 227 | 238 | expect(his.html).toContain('data-pane-of="bob/mine"'); |
| 228 | 239 | expect(his.html).not.toContain("alice/one"); |
| 229 | 240 | // carol, a member, may point the bar at the team's app. |
| @@ -286,6 +297,10 @@ describe("the line under the bar", () => { | ||
| 286 | 297 | "INSERT INTO pull (issue_id, base_branch, head_branch, base_oid, head_oid) VALUES (?1, 'main', 'crew/dark', '', 'abc')", |
| 287 | 298 | [pr.value.id], |
| 288 | 299 | ); |
| 300 | // A draft its builder is still writing says so, first. | |
| 301 | app.db.run("UPDATE pull SET draft_run = 'r-draft' WHERE issue_id = ?1", [pr.value.id]); | |
| 302 | expect(paneInfo(app.db, repo, pr.value.number)).toBe(`Preview of #${String(pr.value.number)} (draft, still building) · Dark theme`); | |
| 303 | app.db.run("UPDATE pull SET draft_run = NULL WHERE issue_id = ?1", [pr.value.id]); | |
| 289 | 304 | expect(paneInfo(app.db, repo, pr.value.number)).toBe( |
| 290 | 305 | `alice · #${String(pr.value.number)} Dark theme · no checks yet · not reviewed yet`, |
| 291 | 306 | ); |
test/talk-receipt-follow.test.ts +17
| @@ -161,6 +161,23 @@ test("its live line walks the build: waiting, working, pushed with checks runnin | ||
| 161 | 161 | expect(page).toContain(`The crew landed #${String(pull.value.number)}.`); |
| 162 | 162 | }); |
| 163 | 163 | |
| 164 | test("a draft its builder is still writing says who builds it and that its preview is live; ready, the line is the pull's again", () => { | |
| 165 | const filed = createIssue(app.db, { repoId, authorId: alice.id, title: "Build a habit streak", body: "b" }); | |
| 166 | if (!filed.ok) throw new Error("issue"); | |
| 167 | const run = createRun(app.db, { repoId, kind: "agent", issueId: filed.value.id, reason: "assigned", branch: "crew/streak", actorId: alice.id }); | |
| 168 | claimRun(app.db, run.id); | |
| 169 | const pull = createIssue(app.db, { repoId, authorId: alice.id, title: "Habit streak", body: "b", kind: "pull" }); | |
| 170 | if (!pull.ok) throw new Error("pull"); | |
| 171 | app.db.run("INSERT INTO pull (issue_id, base_branch, head_branch, base_oid, head_oid, draft_run) VALUES (?1, 'main', 'crew/streak', '', '', ?2)", [pull.value.id, run.id]); | |
| 172 | const text = JSON.stringify({ filed: true, done: true, receipt: { verb: "New app", object: "alice/tip-calculator", href: `/alice/tip-calculator/issues/${String(filed.value.number)}` } }); | |
| 173 | const line = () => liveReceipts(app.db, dir, alice, [{ id: "t-draft", role: "tool", text }]).get("t-draft")?.line.says; | |
| 174 | // No check runs on a draft: never "checks running", which would be false. | |
| 175 | expect(line()).toBe(`alice is building #${String(pull.value.number)}: its preview is live.`); | |
| 176 | // Marked ready, its check runs as for any pull. | |
| 177 | app.db.run("UPDATE pull SET draft_run = NULL WHERE issue_id = ?1", [pull.value.id]); | |
| 178 | expect(line()).toBe(`The crew pushed #${String(pull.value.number)}: checks running.`); | |
| 179 | }); | |
| 180 | ||
| 164 | 181 | test("the brief: the line under the receipt follows the build; never a moment's queued, never a pull for them to land", () => { |
| 165 | 182 | const brief = conversationBrief([]); |
| 166 | 183 | expect(brief).toContain( |
new above
offline
The 3 origins named ahead widen frame-src to hosts that may not exist yet. They are exact origins on the app's own domain, so I accept it. If a gap past the window is common, count from the pull's number instead.