From b41aa2e34bbc2fd8655eaefe1010d96e57606bb2 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 22 Nov 2026 19:35:53 -0600 Subject: [PATCH] fix(pm-console): the Android build never holds up a report, and a half-written copy is no copy Found by reading the last three commits of #12723 again after they merged unreviewed. The host's reports are how the edge knows the laptop is there. A report that carries the build is hundreds of kilobytes; on a connection too slow to send it in the twenty seconds a report is given it failed, and the next was built the same way, for as long as the edge lacked the build. Meanwhile nothing arrived, and the edge took the laptop for gone. - A report that carried the build and did not get through (cut off or turned away) is followed at once by one without it; the build is tried again ten minutes later. - A build file that cannot be read is left out the same way instead of stopping the report. - Whether the build and the changed sections fit one report is measured on the report as sent, in bytes. It was estimated in characters, and text outside ASCII is up to three bytes each. - When the build goes alone, the sections it displaced follow at once. - The edge removes the record of its copy before writing a new build over the copy's pieces, so a write that stops half-way cannot leave pieces of two builds to be handed out under the old record, and it removes a larger build's leftover pieces whether or not that record survived. Co-Authored-By: Claude Fable 5.2 Claude-Session: https://claude.ai/code/session_01YLT5K1QVuzZjfWGFhXSSNF --- ...T11-10-00Z_architecture_pm_console_edge.md | 38 ++++ pm-stack/console/edge/README.md | 10 + pm-stack/console/edge/src/edge.ts | 16 +- pm-stack/console/src/sync.ts | 92 ++++++--- pm-stack/console/test/edge.test.ts | 192 +++++++++++++++++- 5 files changed, 313 insertions(+), 35 deletions(-) diff --git a/doc/2026-11-22T11-10-00Z_architecture_pm_console_edge/2026-11-22T11-10-00Z_architecture_pm_console_edge.md b/doc/2026-11-22T11-10-00Z_architecture_pm_console_edge/2026-11-22T11-10-00Z_architecture_pm_console_edge.md index 25fc12eabd..719f0ff6f1 100644 --- a/doc/2026-11-22T11-10-00Z_architecture_pm_console_edge/2026-11-22T11-10-00Z_architecture_pm_console_edge.md +++ b/doc/2026-11-22T11-10-00Z_architecture_pm_console_edge/2026-11-22T11-10-00Z_architecture_pm_console_edge.md @@ -219,3 +219,41 @@ Still open, and why: staged in #12561 and needs two protected environments with their own tokens before it can run. - The Android project is still on androidbrowserhelper 2.5.0. + +## 2026-11-23T01:25Z Update: the build never holds up a report + +The last three commits of the Android-build change (#12723) merged +before any reviewer read them, so they were read again afterwards. Two +real faults came out of that: one in how the build travels, one in how +the edge keeps it. + +A report that carries the build is megabytes; every other report is +kilobytes. The laptop gives a report twenty seconds. On a connection +too slow to send the build in that time, the report failed, and the +next was built the same way and failed too, for as long as the edge +still lacked the build. In that time no report arrived at all, so the +edge took the laptop for gone while it was there. Nothing of the kind +could happen before the build was put into reports. + +- A report that carried the build and did not get through, whether cut + off or turned away, is followed at once by one without the build. + The build is tried again ten minutes later. At worst one report in + ten minutes is lost to it. +- A build file that cannot be read is left out the same way, where it + used to stop the report. +- Whether the build and the changed sections fit one report is now + measured on the report as sent, in bytes. It was estimated in + characters, and text outside ASCII is up to three bytes a character, + so the estimate could pass a report the edge then refused as too + large. +- When the build goes alone, the sections it displaced follow at once + instead of at the next ordinary report. + +- The edge wrote a new build over the pieces of the old one and only + then recorded the new build. A write that stopped half-way left + pieces of two builds under the old record, and with the laptop away + those were handed out as the old build. The old record is now removed + before its pieces are touched, so a half-written copy is no copy: the + edge says it has none, hands nothing out, and asks for the build + again. Pieces left by a larger build are removed whether or not its + record survived. diff --git a/pm-stack/console/edge/README.md b/pm-stack/console/edge/README.md index db9d4475eb..63282b8426 100644 --- a/pm-stack/console/edge/README.md +++ b/pm-stack/console/edge/README.md @@ -18,6 +18,7 @@ runs the fleet's tools can be reached. | 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 | The list of actions that may be done late is `HOLDABLE` in `../src/edge-proto.ts`. @@ -50,6 +51,15 @@ laptop: pm-console (../src/server.ts), reporting through ../src/sync.ts 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 carries the actions the owner took while it was away. +- **The signed Android build travels in a report**, once per build, when + the edge says it lacks it, and is kept only if it matches its + fingerprint. It never stands in the way of the reports themselves, + which are how the edge knows the laptop is there. Beside sections that + would take the report past its room (counted in bytes as sent) it goes + alone and they follow at once. If a report carrying it does not get + through (a slow connection runs out of time, or it is turned away), or + the file cannot be read, the reports after that go without it, and it + is tried again ten minutes later. - **An action for the laptop is relayed at once** when the laptop is in reach; its answer carries what it read again, so the edge's copy shows the change before the next report. diff --git a/pm-stack/console/edge/src/edge.ts b/pm-stack/console/edge/src/edge.ts index 492394a90e..365b055fbb 100644 --- a/pm-stack/console/edge/src/edge.ts +++ b/pm-stack/console/edge/src/edge.ts @@ -23,6 +23,7 @@ import { DIRECT_ACTIONS, DIRECT_READ_SECTIONS, directClasses, directRead } from import { Devices, KeyedLimiter, Limiter } from "../../src/devices.ts"; import { type Act, DOC_NAMES, type DocName, Docs, Stamped } from "../../src/docs.ts"; import { + APK_LIMIT, type ApkReport, apkReport, type EdgeConfig, @@ -90,6 +91,8 @@ const SIGNATURE = /^[A-Za-z0-9_-]{86}$/; const SYNC_REFUSALS = 20; /** The Android build is kept in pieces of this many bytes. */ const APK_CHUNK = 512 * 1024; +/** The most pieces a build that may be carried can take. */ +const APK_PIECES = Math.ceil(APK_LIMIT / APK_CHUNK); /** A build that could not be kept is asked for again no sooner than this. */ const APK_RETRY_MS = 10 * 60_000; /** With no report for this long, the laptop is not there to ask. */ @@ -270,10 +273,19 @@ export class Edge { const sha256 = [...digest].map((b) => b.toString(16).padStart(2, "0")).join(""); if (bytes.byteLength !== build.size || sha256 !== build.sha256) throw new Error("the build sent is not the build described"); - const before = await this.apkKept(); + // The record of the copy kept so far goes first. Its pieces are about + // to be written over, and a write that stops half-way must not leave + // pieces of two builds under a record that describes one of them. + // With no record there is no copy: nothing is handed out, and the + // build is asked for again. + if (await this.apkKept()) { + this.keptApk = null; + await this.kv.delete("apk"); + } const chunks = Math.ceil(bytes.byteLength / APK_CHUNK); for (let i = 0; i < chunks; i++) await this.kv.put(`apk:${i}`, bytes.slice(i * APK_CHUNK, (i + 1) * APK_CHUNK)); - for (let i = chunks; i < (before?.chunks ?? 0); i++) await this.kv.delete(`apk:${i}`); + // Pieces left by a larger build, whether or not its record survived. + for (let i = chunks; i < APK_PIECES; i++) await this.kv.delete(`apk:${i}`); this.keptApk = { sha256, size: build.size, at: build.at, chunks }; await this.kv.put("apk", this.keptApk); } diff --git a/pm-stack/console/src/sync.ts b/pm-stack/console/src/sync.ts index 7bbca73de9..1459101532 100644 --- a/pm-stack/console/src/sync.ts +++ b/pm-stack/console/src/sync.ts @@ -35,6 +35,9 @@ const FAST_MS = 5_000; const IDLE_MS = 30_000; const WATCHED_EVERY_MS = 60_000; const SYNC_TIMEOUT_MS = 20_000; +/** After a report that carried the Android build did not get through, + * the build is left out of the reports that follow for this long. */ +const APK_AGAIN_MS = 10 * 60_000; const DONE_KEPT = 300; type Fate = "started" | { ok: boolean; error?: string }; @@ -72,6 +75,12 @@ export class EdgeLink { private watchedAt = 0; private timer: ReturnType | null = null; private busy = false; + /** The Android build is not put in a report before this time. */ + private apkNotBefore = 0; + /** The last report left something out that the next should carry at + * once: the sections, when the build went alone, or everything but + * the build, when a report carrying it did not get through. */ + private more = false; /** Actions being done right now, by the name the edge gave them. */ private running = new Set(); private now: () => number; @@ -180,6 +189,14 @@ export class EdgeLink { this.acks.push({ id: held.id, ...fate }); } + /** The build could not be sent. It is left out of the reports that + * follow for a while: nothing about the build may stand in the way of + * an ordinary report, which is how the edge knows the host is there. */ + private holdBuild(why: string): void { + this.apkNotBefore = this.now() + APK_AGAIN_MS; + this.log(`${why}; reporting without it for ten minutes`); + } + /** One report to the edge. Returns its answer, or null if it could not * be reached or refused the report; nothing is lost either way. */ async once(): Promise { @@ -187,37 +204,63 @@ export class EdgeLink { this.busy = true; try { const pair = await this.keys(); + this.more = false; const snapshot = this.o.docs.snapshot(); let sections = snapshot.filter((s) => this.sent.get(s.name) !== s.hash || this.want.has(s.name)); const acks = [...this.acks]; const at = Math.max(this.now(), this.lastAt + 1); // The Android build: always what it is, and the build itself only - // when the edge has said it lacks this one. + // when the edge has said it lacks this one (and not for a while + // after it could not be sent). const build = (await this.o.apk?.().catch(() => null)) ?? null; const apk: ApkReport | null = build && build.size <= APK_LIMIT ? { sha256: build.sha256, size: build.size, at: build.at } : null; - if (apk && build && this.want.has("apk")) { - apk.data = Buffer.from(await build.read()).toString("base64"); - // The build and large sections together could pass what the edge - // takes in one report, and a report refused as too large would be - // built the same way again and again. So the build goes alone - // then; the sections are not marked sent and follow next time. - const others = sections.reduce((sum, s) => sum + JSON.stringify(s.data).length, 0); - if (apk.data.length + others > REPORT_ROOM) sections = []; + if (apk && build && this.want.has("apk") && this.now() >= this.apkNotBefore) { + try { + apk.data = Buffer.from(await build.read()).toString("base64"); + } catch (error) { + this.holdBuild(`the Android build could not be read (${(error as Error).message})`); + } + } + const config = await this.o.config(); + const have = Object.fromEntries(snapshot.map((s) => [s.name, { hash: s.hash, at: s.at, error: s.error }])); + const phones = await this.o.phones.links(); + const acts = this.o.docs.recentActs(); + const encoded = (carried: typeof sections) => { + const message: SyncRequest & { acts: unknown } = { + v: 1, + at, + ...(this.o.version ? { version: this.o.version } : {}), + ...(apk ? { apk } : {}), + config, + sections: carried, + have, + acks, + phones, + acts, + }; + return new TextEncoder().encode(JSON.stringify(message)); + }; + let body = encoded(sections); + // The build and large sections together could pass what the edge + // takes in one report. Measured on the report as it would be sent, + // in bytes: when it is past the room there is, the build goes + // alone; the sections are not marked sent and follow at once. + if (apk?.data && sections.length > 0 && body.byteLength > REPORT_ROOM) { + sections = []; + body = encoded(sections); + this.more = true; } - const message: SyncRequest & { acts: unknown } = { - v: 1, - at, - ...(this.o.version ? { version: this.o.version } : {}), - ...(apk ? { apk } : {}), - config: await this.o.config(), - sections, - have: Object.fromEntries(snapshot.map((s) => [s.name, { hash: s.hash, at: s.at, error: s.error }])), - acks, - phones: await this.o.phones.links(), - acts: this.o.docs.recentActs(), + // A report that carries the build is large and slow to send. If it + // does not get through, the same report again would not either, and + // while that went on the edge would hear nothing at all from this + // host. So the reports after it go without the build, the first of + // them at once. + const lost = () => { + if (!apk?.data) return; + this.holdBuild("a report carrying the Android build did not get through"); + this.more = true; }; - const body = new TextEncoder().encode(JSON.stringify(message)); let res: Response; try { res = await this.fetchImpl(`${this.o.url}/console/edge/sync`, { @@ -233,6 +276,7 @@ export class EdgeLink { }); } catch (error) { if (this.last) this.log(`cannot reach the edge: ${(error as Error).message}`); + lost(); this.last = null; return null; } @@ -243,6 +287,7 @@ export class EdgeLink { // gives (it ran backwards): step past it. if (res.status === 409 && typeof answer?.last === "number") this.lastAt = Math.max(this.lastAt, answer.last); if (this.last) this.log(`the edge refused the report: http ${res.status} ${answer?.error ?? ""}`); + lost(); this.last = null; return null; } @@ -271,10 +316,11 @@ export class EdgeLink { void this.o.docs.current(WATCHED, 0); } const answer = await this.once(); - // Something was done or is wanted: say so at once. + // Something was done, is wanted, or was left out of that report: + // say so at once. // (The Android build is not such a thing: it waits for the next // ordinary report, and half a megabyte is never sent in a hurry.) - if (this.acks.length > 0 || [...this.want].some((name) => name !== "apk")) return 500; + if (this.acks.length > 0 || this.more || [...this.want].some((name) => name !== "apk")) return 500; return answer?.watching || this.o.docs.watched() ? FAST_MS : IDLE_MS; } diff --git a/pm-stack/console/test/edge.test.ts b/pm-stack/console/test/edge.test.ts index b3ea25c41e..35555f294b 100644 --- a/pm-stack/console/test/edge.test.ts +++ b/pm-stack/console/test/edge.test.ts @@ -415,9 +415,12 @@ async function setup(options: { direct?: boolean } = {}) { const stored = new Map(); /** Every key written to the edge's storage, in order. */ const puts: string[] = []; + /** Keys the edge's storage refuses to write, as a store in trouble would. */ + const storeFails = new Set(); const kv: KV = { get: async (key) => structuredClone(stored.get(key)), put: async (key, value) => { + if (storeFails.has(key)) throw new Error(`storage: could not write ${key}`); puts.push(key); stored.set(key, structuredClone(value)); }, @@ -550,13 +553,25 @@ async function setup(options: { direct?: boolean } = {}) { audited.push(entry); }, }; - const net = { hostUp: true, edgeUp: true, loseAnswer: false, giveUpEarly: false }; + const net: { + hostUp: boolean; + edgeUp: boolean; + loseAnswer: boolean; + giveUpEarly: boolean; + /** A report of more than this many bytes does not get through: it + * is cut off on the way ("lost", a slow connection running out of + * time) or turned away by something in front of the edge ("refused"). */ + large: { over: number; fate: "lost" | "refused" } | null; + } = { hostUp: true, edgeUp: true, loseAnswer: false, giveUpEarly: false, large: null }; + /** The size of each report the host sent, whether or not it arrived. */ + const reportSizes: number[] = []; /** The signed Android build on the host, if any, and how often it was read to be sent. */ - const build: { bytes: Uint8Array | null; at: number; reads: number; corrupt: boolean } = { + const build: { bytes: Uint8Array | null; at: number; reads: number; corrupt: boolean; unreadable: boolean } = { bytes: null, at: 0, reads: 0, corrupt: false, + unreadable: false, }; /** Requests to the host still running after the edge stopped waiting. */ const stillRunning: Promise[] = []; @@ -623,6 +638,7 @@ async function setup(options: { direct?: boolean } = {}) { at: build.at, read: async () => { build.reads++; + if (build.unreadable) throw new Error("EACCES: permission denied"); return build.corrupt ? bytes.map((b) => b ^ 1) : bytes; }, }; @@ -636,6 +652,12 @@ async function setup(options: { direct?: boolean } = {}) { run: heldRunner(hostDeps), fetchImpl: (async (url: string, init: RequestInit) => { if (!net.edgeUp) throw new Error("no route to the edge"); + const size = (init.body as Uint8Array).byteLength; + reportSizes.push(size); + if (net.large && size > net.large.over) { + if (net.large.fate === "lost") throw new Error("The operation timed out."); + return new Response("bad gateway", { status: 502 }); + } return route( new Request(url, { ...init, headers: { ...(init.headers as Record), "cf-ray": "1" } }), io, @@ -699,6 +721,7 @@ async function setup(options: { direct?: boolean } = {}) { edge, makeEdge, stored, + storeFails, puts, keys, done, @@ -722,6 +745,7 @@ async function setup(options: { direct?: boolean } = {}) { core, hostReads, build, + reportSizes, failing, gate, stillRunning, @@ -1319,6 +1343,13 @@ describe("the Android build", () => { const res = await w.browse("/console/pm-console.apk"); return { res, bytes: new Uint8Array(await res.arrayBuffer()) }; }; + /** The questions as the edge holds them, put back together. */ + const questionsAtEdge = (w: Awaited>) => { + const pieces = (w.stored.get("m:questions") as { chunks: number } | undefined)?.chunks ?? 0; + let text = ""; + for (let i = 0; i < pieces; i++) text += String(w.stored.get(`m:questions:${i}`)); + return text === "" ? null : (JSON.parse(text) as Record); + }; test("a copy is kept at the edge, sent once, and served when the laptop is away", async () => { const w = await setup(); @@ -1421,16 +1452,157 @@ describe("the Android build", () => { w.data.questions = { sets: [{ id: "big", text: "q".repeat(3_000_000) }] }; w.now.t += 11_000; await w.hostReads(); - // Every report from here is accepted: none is refused as too large. - const answers = [await report(w), await report(w), await report(w)]; + // The build goes alone, and the host does not wait to send what it displaced. + w.now.t += 1_000; + expect(await w.link.now.turn()).toBe(500); + expect(w.link.now.last?.ok).toBe(true); + expect((w.stored.get("apk") as { size: number }).size).toBe(4_900_000); + expect(questionsAtEdge(w)).toEqual({ open: [] }); + // The questions arrive whole in the report after it, and then there is no hurry. + w.now.t += 1_000; + expect(await w.link.now.turn()).toBeGreaterThan(500); + expect(w.link.now.last?.ok).toBe(true); + expect((w.stored.get("m:questions") as { chunks: number }).chunks).toBeGreaterThan(1); + expect(questionsAtEdge(w)?.sets[0].text.length).toBe(3_000_000); + // No report was as large as the edge refuses (8 MiB), and the build's kept the room it is given. + expect(Math.max(...w.reportSizes)).toBeLessThanOrEqual(7.5 * 1024 * 1024); + }); + + test("room in a report is counted in bytes, so text outside ASCII cannot push it past the limit", async () => { + const w = await setup(); + await w.hostReads(); + await report(w); + w.build.bytes = apk(5, 4_900_000); + w.build.at = w.now.t; + await report(w); // described; the edge asks for it + // 700,000 characters, each three bytes as sent. Counted as characters + // they fit beside the build; as bytes the two are past what the edge takes. + const text = "\u65e5".repeat(700_000); + expect(new TextEncoder().encode(text).byteLength).toBe(2_100_000); + w.data.questions = { sets: [{ id: "wide", text }] }; + w.now.t += 11_000; + await w.hostReads(); + const answers = [await report(w), await report(w)]; expect(answers.every((answer) => answer?.ok === true)).toBe(true); + expect(Math.max(...w.reportSizes)).toBeLessThanOrEqual(7.5 * 1024 * 1024); expect((w.stored.get("apk") as { size: number }).size).toBe(4_900_000); - // And the questions arrived whole, in the report after the build's. - const pieces = (w.stored.get("m:questions") as { chunks: number } | undefined)?.chunks ?? 0; - expect(pieces).toBeGreaterThan(1); - let text = ""; - for (let i = 0; i < pieces; i++) text += String(w.stored.get(`m:questions:${i}`)); - expect(JSON.parse(text).sets[0].text.length).toBe(3_000_000); + expect(questionsAtEdge(w)?.sets[0].text).toBe(text); + }); + + test("a build that does not get through does not hold up the reports after it", async () => { + for (const fate of ["lost", "refused"] as const) { + const w = await setup(); + await w.hostReads(); + await report(w); + w.build.bytes = apk(1); + w.build.at = w.now.t; + expect((await report(w))?.want).toContain("apk"); // described; the edge asks for it + // A connection too slow for a report that large, or something in + // front of the edge that will not pass one. + w.net.large = { over: 500_000, fate }; + w.data.questions = { sets: [{ id: "new", text: "what next?" }] }; + w.now.t += 11_000; + await w.hostReads(); + // The report with the build in it fails. The host does not wait to + // send the next, and that one goes without the build... + w.now.t += 1_000; + expect(await w.link.now.turn()).toBe(500); + expect(w.link.now.last).toBeNull(); + expect(w.reportSizes.at(-1)).toBeGreaterThan(500_000); + w.now.t += 1_000; + expect(await w.link.now.turn()).toBeGreaterThan(500); + expect(w.link.now.last?.ok).toBe(true); + expect(w.reportSizes.at(-1)).toBeLessThan(500_000); + // ...and brings what had changed. + expect(questionsAtEdge(w)).toEqual({ sets: [{ id: "new", text: "what next?" }] }); + // An edge that cannot be reached at all is another matter: a report + // without the build that fails is not hurried after. + w.net.edgeUp = false; + w.now.t += 1_000; + expect(await w.link.now.turn()).toBeGreaterThan(500); + expect(w.link.now.last).toBeNull(); + w.net.edgeUp = true; + // The edge still asks for the build. For ten minutes it is not sent again. + for (let i = 0; i < 20; i++) expect((await report(w))?.want).toContain("apk"); + expect(w.build.reads).toBe(1); + // Then it is tried once more. If that fails too, again only that one report is lost. + w.now.t += 10 * 60_000; + expect(await report(w)).toBeNull(); + expect(w.build.reads).toBe(2); + expect((await report(w))?.ok).toBe(true); + expect(w.build.reads).toBe(2); + // On a connection that can carry it, it arrives at the next try. + w.net.large = null; + w.now.t += 10 * 60_000; + expect((await report(w))?.want).not.toContain("apk"); + expect(w.build.reads).toBe(3); + expect((w.stored.get("apk") as { size: number }).size).toBe(700_000); + } + }); + + test("a copy whose replacement stops half-way is not handed out as either build", async () => { + const w = await setup(); + await w.hostReads(); + w.build.bytes = apk(1, 1_500_000); + w.build.at = w.now.t; + await report(w); + await report(w); + expect((w.stored.get("apk") as { chunks: number }).chunks).toBe(3); + // A newer build arrives, and the edge's storage fails on its second piece. + w.build.bytes = apk(2, 1_500_000); + w.build.at = w.now.t + 500; + await report(w); // described; the edge asks for it + w.storeFails.add("apk:1"); + expect((await report(w))?.ok).toBe(true); // the report itself is taken + // The first piece is now the new build's and the rest are the old one's. + // There is no record over them: the edge has no copy, and says so. + expect(w.stored.has("apk")).toBe(false); + const health = (await (await w.browse("/console/health", { token: null })).json()) as Record; + expect(health.androidBuild).toBeNull(); + // The laptop goes away. Nothing is handed out from those pieces. + w.net.hostUp = false; + w.now.t += 2 * 60_000; + expect((await download(w)).res.status).not.toBe(200); + // It comes back with a smaller build. That one is kept whole, and the + // pieces of the larger ones before it are gone, record or no record. + w.net.hostUp = true; + w.storeFails.clear(); + w.build.bytes = apk(3, 400_000); + w.build.at = w.now.t + 500; + expect((await report(w))?.want).toContain("apk"); + expect((await report(w))?.want).not.toContain("apk"); + expect([...w.stored.keys()].filter((k) => /^apk:\d+$/.test(k))).toEqual(["apk:0"]); + w.net.hostUp = false; + w.now.t += 2 * 60_000; + const got = await download(w); + expect(got.res.status).toBe(200); + expect(got.bytes).toEqual(apk(3, 400_000)); + }); + + test("a build that cannot be read is left out, and the report goes anyway", async () => { + const w = await setup(); + await w.hostReads(); + await report(w); + w.build.bytes = apk(4); + w.build.at = w.now.t; + expect((await report(w))?.want).toContain("apk"); + w.build.unreadable = true; + w.data.questions = { sets: [{ id: "new", text: "what next?" }] }; + w.now.t += 11_000; + await w.hostReads(); + // The report is not given up for the build's sake. + expect((await report(w))?.ok).toBe(true); + expect(questionsAtEdge(w)).toEqual({ sets: [{ id: "new", text: "what next?" }] }); + expect(w.build.reads).toBe(1); + // Nor is the file tried again with every report. + for (let i = 0; i < 20; i++) expect((await report(w))?.ok).toBe(true); + expect(w.build.reads).toBe(1); + // Ten minutes on it can be read, and is sent. + w.build.unreadable = false; + w.now.t += 10 * 60_000; + expect((await report(w))?.want).not.toContain("apk"); + expect(w.build.reads).toBe(2); + expect((w.stored.get("apk") as { size: number }).size).toBe(700_000); }); test("a build that is not the one described is not kept, and one too large is not sent", async () => {