diff --git a/pm-stack/console/edge/README.md b/pm-stack/console/edge/README.md index 114aeefca3..9f969e9fef 100644 --- a/pm-stack/console/edge/README.md +++ b/pm-stack/console/edge/README.md @@ -7,18 +7,18 @@ runs the fleet's tools can be reached. ## What runs where -| Thing | Where | When the laptop cannot be reached | -| -------------------------------------------------------------------------------- | ------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| The app's page, script and icons | edge | unchanged | -| Checking who is calling | edge, and again on the laptop | the edge still answers the owner; anyone it is unsure of gets nothing | -| State (in progress, next, needs me, prompts, pull…) | edge, from the laptop's report | the board, pull requests, ranked issues and prompts refresh from GitHub and the queue store after one minute of silence; the rest stays as of the last report | -| Notifications: keys, subscriptions, sending | edge | unchanged; and one says the laptop has gone quiet | -| Linked phones and the widget's summary | edge | unchanged | -| Actions safe to do late (prompts, answers, comments, …) | laptop, relayed at once | held at the edge, run once when it is back, dropped after a day and said so | -| Direct actions (reply to or close a prompt, comment, rank an issue, move a task) | edge, once the laptop has been quiet for a minute | run at the edge through the laptop's own classes, and never sent to the laptop, so they are not done twice; a new prompt is filed at the edge and only its queue task is held for the laptop | -| Actions not safe to do late (merge, units, unblock, …) | laptop, relayed at once | refused, saying why | -| The dashboard's own pages, logs, one pull request's page | laptop | a plain notice with a link to the app | -| The signed Android build (`/console/pm-console.apk`) | laptop, and a copy at the edge | the copy is served, and the app says so when the copy is older than the laptop's newest | +| Thing | Where | When the laptop cannot be reached | +| -------------------------------------------------------------------------------- | ----------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| The app's page, script and icons | edge | unchanged | +| Checking who is calling | edge, and again on the laptop | the edge still answers the owner; anyone it is unsure of gets nothing | +| State (in progress, next, needs me, prompts, pull…) | edge, from the laptop's report | the board, pull requests, ranked issues and prompts refresh from GitHub and the queue store after one minute of silence; the rest stays as of the last report | +| Notifications: keys, subscriptions, sending | edge | unchanged; and one says the laptop has gone quiet | +| Linked phones and the widget's summary | edge | unchanged | +| Actions safe to do late (prompts, answers, comments, …) | laptop, relayed at once | held at the edge, run once when it is back, dropped after a day and said so | +| Direct actions (reply to or close a prompt, comment, rank an issue, move a task) | edge, once the laptop has been quiet for a minute | run at the edge through the laptop's own classes, and never sent to the laptop, so they are not done twice; a new prompt is filed at the edge and only its queue task is held for the laptop | +| Actions not safe to do late (merge, units, unblock, …) | laptop, relayed at once | refused, saying why | +| The dashboard's own pages, logs, one pull request's page | laptop | a plain notice with a link to the app | +| The signed Android build (`/console/pm-console.apk`) | GitHub's release first; else laptop, and a copy at the edge | the release is served (checked against its own description of itself); with none published, the copy is, and the app says so when the copy is older than the laptop's newest | The list of actions that may be done late is `HOLDABLE` in `../src/edge-proto.ts`. @@ -47,6 +47,14 @@ laptop: pm-console (../src/server.ts), reporting through ../src/sync.ts has. So a mistake at the edge can cost the edge's speed, never the owner's way in, and a stranger gets from the laptop exactly what a stranger got before. +- **The app's own files are not downloaded twice.** The platform's file + store tags each file by its content; the Worker passes the tag on and + answers a browser that names it with "still that" (304) and nothing + else. They are still asked for every time (`no-cache`), so a deploy + shows at once. `/console/health` says, to anyone, which release of the + Android app this side knows of (`androidRelease`), beside the copy of + the laptop's build (`androidBuild`): that is how either arriving here + is checked from outside. - **The laptop reports** to `POST /console/edge/sync`: the sections of state that changed, how current each unchanged one is, and what became of anything held for it. The answer says whether anyone is looking, and diff --git a/pm-stack/console/edge/src/edge.ts b/pm-stack/console/edge/src/edge.ts index 2d6f91bd49..6f59c6fea0 100644 --- a/pm-stack/console/edge/src/edge.ts +++ b/pm-stack/console/edge/src/edge.ts @@ -283,6 +283,14 @@ export class Edge { return this.released.found; } + /** What is said of the released build: its name, its code and when it + * was built. Null when none is published, or before the host has said + * which repository this is. */ + private async releaseSaid(cfg: EdgeConfig | null): Promise<{ name: string; code: number; built: string } | null> { + const release = cfg ? await this.androidRelease(cfg) : null; + return release && { name: release.name, code: release.code, built: release.built }; + } + /** The released build, as a download, or null if it did not arrive as * its description says (GitHub out of reach, or the description read * while a new build was being put up). */ @@ -946,6 +954,11 @@ export class Edge { // The copy of the Android build kept here: when it was built, // and whether it is the host's newest. Null if there is none. androidBuild: await this.apkState(), + // The newest build of the app GitHub has released, as last read + // here (within ten minutes): what a download is, when there is + // one. The release is public; this is how its arrival here is + // checked from outside. Null when none is published. + androidRelease: await this.releaseSaid(cfg), // Since this object last started: requests it answered as the // owner's, and requests it left to the host to judge. answered: this.sure, @@ -1047,11 +1060,7 @@ export class Edge { if (seg.length === 1 && seg[0] === "android") { // Where a download would come from: the build GitHub released, // if there is one, and the copy of the laptop's build kept here. - const release = await this.androidRelease(cfg); - return json({ - release: release && { name: release.name, code: release.code, built: release.built }, - copy: await this.apkState(), - }); + return json({ release: await this.releaseSaid(cfg), copy: await this.apkState() }); } if (seg.length === 1 && seg[0] === "push") return json(await this.push.status()); if (seg.length === 1 && seg[0] === "devices") return json(await this.phones.devices.list()); diff --git a/pm-stack/console/edge/src/entry.ts b/pm-stack/console/edge/src/entry.ts index 1f49eaeed2..ae5252a298 100644 --- a/pm-stack/console/edge/src/entry.ts +++ b/pm-stack/console/edge/src/entry.ts @@ -7,7 +7,7 @@ // file of the app, fetch the host's key, or pass the request to the host // behind the tunnel. If the host cannot be reached, an action that may // be done late is handed back to the state to hold. -import { SECURITY } from "../../src/http.ts"; +import { SECURITY, sameEntity } from "../../src/http.ts"; export interface Io { /** The object with the state (edge.ts). */ @@ -134,9 +134,21 @@ export async function route(request: Request, io: Io): Promise { if (what === "asset") { const file = await io.asset(String(detail.path)); if (!file.ok) return new Response("not found", { status: 404, headers: SECURITY }); - return new Response(request.method === "HEAD" ? null : file.body, { - headers: { "Content-Type": String(detail.type), "Cache-Control": "no-cache", ...SECURITY }, - }); + // "no-cache" is "ask before using your copy". The file's tag is what + // the browser asks with; when its copy is still the file, the answer + // is that and nothing else, so a visit does not download the app again. + const headers: Record = { + "Content-Type": String(detail.type), + "Cache-Control": "no-cache", + ...SECURITY, + }; + const etag = file.headers.get("etag"); + if (etag) headers.ETag = etag; + if (sameEntity(request.headers.get("if-none-match"), etag)) { + await file.body?.cancel(); + return new Response(null, { status: 304, headers }); + } + return new Response(request.method === "HEAD" ? null : file.body, { headers }); } // Everything below is for the host. Away from the routed hostname diff --git a/pm-stack/console/public/app.css b/pm-stack/console/public/app.css index 266901c087..821674d8a0 100644 --- a/pm-stack/console/public/app.css +++ b/pm-stack/console/public/app.css @@ -27,6 +27,12 @@ --quiet: #5b6777; --accent: #0b63ce; --accent-ink: #ffffff; + /* The status colours above are made for a dark page: on a light one + they are too faint to read (2.2 to 3.4 to 1). These are at least + 5 to 1 on every light surface here. */ + --good: #18753a; + --warn: #8a5a00; + --bad: #c5222c; } } * { @@ -42,8 +48,17 @@ body { padding: calc(var(--top-h) + env(safe-area-inset-top)) 0 calc(var(--tab-h) + env(safe-area-inset-bottom) + 12px); -webkit-tap-highlight-color: transparent; } +/* A link in running text is underlined: its colour alone is too close + to the text's to tell it by. Links drawn as rows or buttons say what + they are by their shape. */ a { color: var(--accent); + text-decoration: underline; + text-decoration-thickness: 1px; + text-underline-offset: 2px; +} +a.link, +a.button { text-decoration: none; } [hidden] { @@ -133,7 +148,9 @@ main { min-width: 18px; padding: 0 5px; border-radius: 9px; - background: var(--bad); + /* White on the theme's own red is too faint in either theme; this + red carries white at 5.4 to 1. */ + background: #cf222e; color: #fff; font-size: 0.68rem; font-weight: 700; diff --git a/pm-stack/console/public/app.js b/pm-stack/console/public/app.js index 81ebe4ee6a..520ed48f92 100644 --- a/pm-stack/console/public/app.js +++ b/pm-stack/console/public/app.js @@ -1632,6 +1632,19 @@ function go(to) { else location.hash = to; } +/** A card's title is a third-level heading, under a section's + * second-level one. On a screen with no section above it, it comes + * straight after the screen's title: it is then said to be second-level, + * so that someone listening does not hear a level skipped. It looks the + * same. `headings` are the screen's h2 and h3 elements, in order. */ +export function levelHeadings(headings) { + let sectioned = false; + for (const el of headings) { + if (el.tagName === "H2") sectioned = true; + else if (!sectioned) el.setAttribute("aria-level", "2"); + } +} + function drawTabs() { const n = needCounts(); const fresh = (docs.core?.asks || []).filter((a) => a.status === "answered").length; @@ -1688,6 +1701,7 @@ async function draw() { const nodes = await render(sub); if (seq !== drawSeq) return; view.replaceChildren(...nodes.filter(Boolean)); + levelHeadings(view.querySelectorAll("h2, h3")); if (moved) scrollTo(0, 0); drawn = route; } catch (error) { @@ -1695,6 +1709,7 @@ async function draw() { view.replaceChildren( card(h("h3", {}, "This section could not load"), h("p", { class: "why" }, error.message), h("div", { class: "row end" }, h("button", { onclick: () => (signedOut ? location.reload() : draw()) }, signedOut ? "Reload" : "Try again"))), ); + levelHeadings(view.querySelectorAll("h2, h3")); if (moved) scrollTo(0, 0); drawn = route; } finally { diff --git a/pm-stack/console/public/index.html b/pm-stack/console/public/index.html index c0f9993cd4..f8bac08f82 100644 --- a/pm-stack/console/public/index.html +++ b/pm-stack/console/public/index.html @@ -10,6 +10,7 @@ PM + diff --git a/pm-stack/console/scripts/edge-demo.ts b/pm-stack/console/scripts/edge-demo.ts index 51b14840ae..ea2d4c5937 100644 --- a/pm-stack/console/scripts/edge-demo.ts +++ b/pm-stack/console/scripts/edge-demo.ts @@ -72,7 +72,10 @@ const io: Io = { asset: async (path) => { try { const name = path.startsWith("/console/") ? path.slice("/console/".length) : ""; - return name ? new Response(readFileSync(join(publicDir, name))) : new Response("", { status: 404 }); + if (!name) return new Response("", { status: 404 }); + // The platform's file store tags each file by its content; so does this. + const bytes = readFileSync(join(publicDir, name)); + return new Response(bytes, { headers: { ETag: `"${Bun.hash(bytes).toString(16)}"` } }); } catch { return new Response("", { status: 404 }); } diff --git a/pm-stack/console/scripts/edge-smoke.ts b/pm-stack/console/scripts/edge-smoke.ts index 97ed224fbe..e38279eda9 100644 --- a/pm-stack/console/scripts/edge-smoke.ts +++ b/pm-stack/console/scripts/edge-smoke.ts @@ -125,6 +125,21 @@ try { icon.status === 200 && icon.headers.get("content-type") === "image/png" && bytes[1] === 0x50, `${bytes.length} bytes`, ); + // The platform's file store tags each file; the Worker has to pass the + // tag on and answer a browser that names it with "still that", or + // every visit downloads the app again. Only this runtime has the store. + const tag = icon.headers.get("etag"); + const again = tag ? await get("/icons/icon-192.png", { "If-None-Match": tag }) : null; + const other = await get("/icons/icon-192.png", { "If-None-Match": '"some-other-version"' }); + check( + "a file says which version of itself it is, and a browser that has it is sent nothing", + Boolean(tag) && + again?.status === 304 && + (await again.arrayBuffer()).byteLength === 0 && + other.status === 200 && + (await other.arrayBuffer()).byteLength === bytes.byteLength, + `tag ${tag}, with it ${again?.status}, with another ${other.status}`, + ); await docs.touch(Object.keys(data)); const first = await link.once(); @@ -204,6 +219,17 @@ try { ); const still = (await (await get("/console/health")).json()) as Record; check("the edge itself is still up", still.ok === true && Number(still.deferred) >= 3, JSON.stringify(still)); + // The Android app's release is read from GitHub itself, in this + // runtime, over the real network. There may be none, and GitHub may + // not answer a runner: either is said as null, and neither is a + // failure of this Worker. A release that is there must read as one. + const release = still.androidRelease as { name?: unknown; code?: unknown; built?: unknown } | null | undefined; + check( + "health says which release of the Android app it knows of, or that it knows of none", + release === null || + (typeof release?.name === "string" && Number.isInteger(release.code) && typeof release.built === "string"), + JSON.stringify(release), + ); } catch (error) { failed++; console.log(`FAIL the run stopped: ${(error as Error).message}`); diff --git a/pm-stack/console/src/http.ts b/pm-stack/console/src/http.ts index d1bb3438a0..65ec77f297 100644 --- a/pm-stack/console/src/http.ts +++ b/pm-stack/console/src/http.ts @@ -12,6 +12,9 @@ export const MANIFEST = { name: "PM", short_name: "PM", description: "What the fleet is doing, what is next, what needs you, and a place to say what you want.", + // What an installed copy is known by. It is the address the app opens + // at, said outright, so that it stays one app if that address moves. + id: "/console/", start_url: "/console/", scope: "/", display: "standalone", @@ -34,8 +37,23 @@ export const SECURITY = { "default-src 'self'; img-src 'self' data:; frame-ancestors 'none'; base-uri 'none'; form-action 'self'", "X-Content-Type-Options": "nosniff", "Referrer-Policy": "same-origin", + // This site is only ever HTTPS: a browser that has been here does not + // try plain HTTP again for a year. (Over plain HTTP, as on the host's + // own loopback port, browsers ignore it.) + "Strict-Transport-Security": "max-age=31536000", }; +/** Whether a browser's copy of a file is still the file: its + * If-None-Match names this entity tag. The comparison is the weak one + * of RFC 9110 (a W/ prefix on either side does not matter), which is + * the one a conditional GET uses. */ +export function sameEntity(ifNoneMatch: string | null, etag: string | null): boolean { + if (!ifNoneMatch || !etag) return false; + const bare = (tag: string) => tag.trim().replace(/^W\//, ""); + const mine = bare(etag); + return ifNoneMatch.split(",").some((tag) => tag.trim() === "*" || bare(tag) === mine); +} + export function json(body: unknown, status = 200): Response { return new Response(JSON.stringify(body), { status, diff --git a/pm-stack/console/src/server.ts b/pm-stack/console/src/server.ts index 3db3645503..e7cad9f596 100644 --- a/pm-stack/console/src/server.ts +++ b/pm-stack/console/src/server.ts @@ -9,6 +9,7 @@ // (the install manifest, its icons, the Android asset links) are public. // Two more paths carry their own check instead of the sign-in: a linked // phone's widget presents its own token there to read a short summary. +import { createHash } from "node:crypto"; import { mkdirSync, readFileSync } from "node:fs"; import { appendFile } from "node:fs/promises"; import { dirname, join } from "node:path"; @@ -30,6 +31,7 @@ import { manifest, type Phones, SECURITY, + sameEntity, sameSiteWrite, } from "./http.ts"; import { Notifier } from "./notify.ts"; @@ -73,14 +75,19 @@ const IDLE_TIMEOUT_SECONDS = 120; // The page's four files, read once: nothing on the request path touches // the disk synchronously after the first hit. -const fileCache = new Map(); -function file(name: string, type: string): Response { - let bytes = fileCache.get(name); - if (!bytes) { - bytes = readFileSync(join(PUBLIC_DIR, name)); - fileCache.set(name, bytes); +const fileCache = new Map(); +function file(req: Request, name: string, type: string): Response { + let kept = fileCache.get(name); + if (!kept) { + const bytes = readFileSync(join(PUBLIC_DIR, name)); + kept = { bytes, etag: `"${createHash("sha256").update(bytes).digest("base64url").slice(0, 22)}"` }; + fileCache.set(name, kept); } - return new Response(bytes, { headers: { "Content-Type": type, "Cache-Control": "no-cache", ...SECURITY } }); + // "no-cache" is "ask before using your copy": the tag is what the + // browser asks with, and a copy that is still the file is not sent again. + const headers = { "Content-Type": type, "Cache-Control": "no-cache", ETag: kept.etag, ...SECURITY }; + if (sameEntity(req.headers.get("if-none-match"), kept.etag)) return new Response(null, { status: 304, headers }); + return new Response(kept.bytes, { headers }); } export { assetLinks, type Phones }; @@ -219,10 +226,10 @@ export async function handle(req: Request, deps: Deps, peer: string | null = nul const rest = path.slice(BASE.length).replace(/^\/+/, ""); if (method === "GET" && rest === "") { if (path === BASE) return Response.redirect(`${BASE}/`, 308); - return file("index.html", "text/html; charset=utf-8"); + return file(req, "index.html", "text/html; charset=utf-8"); } const type = method === "GET" ? STATIC.get(rest) : undefined; - if (type !== undefined) return file(rest, type); + if (type !== undefined) return file(req, rest, type); // The Android app, for the signed-in owner: the phone gets it from the // site it opens, and nothing has to be published anywhere else. if (method === "GET" && rest === APK_NAME) { diff --git a/pm-stack/console/test/app.test.ts b/pm-stack/console/test/app.test.ts index c931135a0a..6f175a4231 100644 --- a/pm-stack/console/test/app.test.ts +++ b/pm-stack/console/test/app.test.ts @@ -13,6 +13,7 @@ import { deviceLabel, deviceState, endpointMark, + levelHeadings, prCheck, subscriptionState, testSaid, @@ -280,3 +281,24 @@ test("what came of the last notification is said in plain words, and never as 'd expect(testSaid({ sent: 0, gone: 0, failed: 1 })).toBe("The push service did not take the test"); expect(testSaid({ sent: 0, gone: 1, failed: 0 })).toBe("No device took the test"); }); + +test("a card's title is not announced as a skipped heading level", () => { + // The screen's title is level one. Card titles are h3: fine under a + // section's h2, a skipped level when the screen has no section above them. + const heading = (tagName: string) => { + const attrs: Record = {}; + return { tagName, attrs, setAttribute: (k: string, v: string) => void (attrs[k] = v) }; + }; + const levels = (tags: string[]) => { + const els = tags.map(heading); + levelHeadings(els); + return els.map((e) => e.attrs["aria-level"] ?? null); + }; + // No sections: every card title is said to be level two. + expect(levels(["H3", "H3"])).toEqual(["2", "2"]); + // Cards before the first section are level two; under a section they stay level three. + expect(levels(["H3", "H2", "H3", "H3", "H2", "H3"])).toEqual(["2", null, null, null, null, null]); + // Sections first: nothing is changed. + expect(levels(["H2", "H3"])).toEqual([null, null]); + expect(levels([])).toEqual([]); +}); diff --git a/pm-stack/console/test/console.test.ts b/pm-stack/console/test/console.test.ts index 0177db9d1e..3db1b4d146 100644 --- a/pm-stack/console/test/console.test.ts +++ b/pm-stack/console/test/console.test.ts @@ -927,6 +927,30 @@ describe("HTTP surface", () => { expect(page.headers.get("content-security-policy")).toContain("default-src 'self'"); expect(await page.text()).toContain('src="/console/app.js"'); expect((await handle(get("/console/app.css"), d)).headers.get("content-type")).toContain("text/css"); + // The site is only ever HTTPS, and says so. + expect(page.headers.get("strict-transport-security")).toBe("max-age=31536000"); + // A visit does not download the app again: each file says which + // version of itself it is, and a browser that names it is sent nothing. + const style = await handle(get("/console/app.css"), d); + const tag = style.headers.get("etag") as string; + expect(tag).toMatch(/^"[A-Za-z0-9_-]{22}"$/); + expect(tag).not.toBe(page.headers.get("etag")); // a file's tag is of its own content + expect((await handle(get("/console/app.css"), d)).headers.get("etag")).toBe(tag); // and does not change by itself + const asked = (named: string) => + handle( + new Request("https://pm.security.cab/console/app.css", { + headers: { host: "pm.security.cab", "if-none-match": named }, + }), + d, + ); + for (const named of [tag, `W/${tag}`, `"other", ${tag}`]) { + const still = await asked(named); + expect([named, still.status, await still.text()]).toEqual([named, 304, ""]); + expect(still.headers.get("etag")).toBe(tag); + } + const sent = await asked('"an-older-version"'); + expect(sent.status).toBe(200); + expect(await sent.text()).toBe(await style.text()); expect((await handle(get("/console"), d)).status).toBe(308); // A path that climbs out of /console is the dashboard's to answer, never a file of this service. expect(await (await handle(get("/console/../src/server.ts"), d)).text()).toBe("dash"); @@ -1049,7 +1073,12 @@ describe("HTTP surface", () => { // The install manifest is the app's own: public, and it opens the app. const manifest = await handle(get("/manifest.webmanifest"), out); expect(manifest.headers.get("content-type")).toContain("application/manifest+json"); - expect(await manifest.json()).toMatchObject({ start_url: "/console/", scope: "/", display: "standalone" }); + expect(await manifest.json()).toMatchObject({ + id: "/console/", + start_url: "/console/", + scope: "/", + display: "standalone", + }); expect((await handle(post("/manifest.webmanifest", {}), out)).status).toBe(401); expect(out.sent.length).toBe(PUBLIC.length); }); diff --git a/pm-stack/console/test/edge.test.ts b/pm-stack/console/test/edge.test.ts index b4a39713ff..20929237a9 100644 --- a/pm-stack/console/test/edge.test.ts +++ b/pm-stack/console/test/edge.test.ts @@ -618,7 +618,12 @@ async function setup(options: { direct?: boolean } = {}) { ]); const io: Io = { state: (r) => edge.now.fetch(r), - asset: async (path) => (files.has(path) ? new Response(files.get(path)) : new Response("", { status: 404 })), + // The platform's file store tags each file by its content; the icon + // here has none, as a store that sent no tag would not. + asset: async (path) => + files.has(path) + ? new Response(files.get(path), path.startsWith("/icons/") ? {} : { headers: { ETag: `"tag-of-${path}"` } }) + : new Response("", { status: 404 }), host: async (r) => { if (!net.hostUp) return null; hostSaw.push(`${r.method} ${new URL(r.url).pathname}`); @@ -804,6 +809,7 @@ describe("before the host's first report", () => { hostSeen: null, hostVersion: null, androidBuild: null, + androidRelease: null, answered: 0, deferred: 0, version: "test", @@ -898,6 +904,28 @@ describe("the owner, at the edge", () => { expect(await page.text()).toContain("PM"); expect(page.headers.get("content-security-policy")).toContain("default-src 'self'"); expect((await w.browse("/console/app.js")).headers.get("content-type")).toBe("text/javascript; charset=utf-8"); + // A visit does not download the app again. Each file says which + // version of itself it is; a browser that names that version is told + // "still that" and sent nothing, and any other is sent the file. + const script = await w.browse("/console/app.js"); + const tag = script.headers.get("etag"); + expect(tag).toBe('"tag-of-/console/app.js"'); + expect(script.headers.get("cache-control")).toBe("no-cache"); // it always asks, so a deploy shows at once + for (const named of [tag, `W/${tag}`, `"something-else", ${tag}`, "*"]) { + const still = await w.browse("/console/app.js", { headers: { "if-none-match": named as string } }); + expect([named, still.status, await still.text()]).toEqual([named, 304, ""]); + expect(still.headers.get("etag")).toBe(tag); + expect(still.headers.get("content-security-policy")).toContain("default-src 'self'"); + } + for (const named of ['"an-older-version"', '"tag-of-/console/app.css"', "", "tag-of-/console/app.js"]) { + const sent = await w.browse("/console/app.js", { headers: { "if-none-match": named } }); + expect([named, sent.status, await sent.text()]).toEqual([named, 200, "// app"]); + } + const stillPage = await w.browse("/console/", { headers: { "if-none-match": '"tag-of-/console/index.html"' } }); + expect(stillPage.status).toBe(304); + // A file the store gave no tag for is always sent: nothing is made up. + const icon = await w.browse("/icons/icon-192.png", { headers: { "if-none-match": "*" } }); + expect([icon.status, icon.headers.get("etag"), await icon.text()]).toEqual([200, null, "PNG"]); expect((await w.browse("/console")).status).toBe(308); const home = await w.browse("/"); expect([home.status, home.headers.get("location")]).toEqual([302, `https://${HOST}/console/`]); @@ -1585,6 +1613,7 @@ describe("the Android build", () => { expect((await download(w)).bytes).toEqual(apk(1)); let said = (await (await w.browse("/console/api/android")).json()) as Record; expect(said).toEqual({ release: null, copy: { at: w.build.at, current: true } }); + expect(((await (await w.browse("/console/health", { token: null })).json()) as any).androidRelease).toBeNull(); // GitHub Actions releases a build. The edge asks again within ten minutes and hands that out. w.github.apk = apk(9, 450_000); w.github.version = await described(w.github.apk, "2026.11.23-a3a547e", 21755935); @@ -1599,6 +1628,15 @@ describe("the Android build", () => { expect(w.hostSaw).toEqual([]); said = (await (await w.browse("/console/api/android")).json()) as Record; expect(said.release).toEqual({ name: "2026.11.23-a3a547e", code: 21755935, built: "2026-11-22T11:00:00.000Z" }); + // Health says which release this side knows of, to anyone (the + // release is public): it is how its arrival here is checked from + // outside. Asking does not send the edge to GitHub each time. + const askedBefore = w.github.asked.length; + for (let i = 0; i < 3; i++) { + const health = (await (await w.browse("/console/health", { token: null })).json()) as Record; + expect(health.androidRelease).toEqual(said.release); + } + expect(w.github.asked.length).toBe(askedBefore); // The laptop gone, the edge restarted, and no copy of the laptop's build at all: still handed out. w.net.hostUp = false; w.stored.delete("apk");