From 71dc2fdc01baf061ab0484e467e94f8bd4c27a30 Mon Sep 17 00:00:00 2001 From: "developing-today[bot]" <5454422+developing-today[bot]@users.noreply.github.com> Date: Tue, 3 Nov 2026 20:32:54 -0600 Subject: [PATCH] fix(id): format biome drift and replace production expect() with propagation (#5123) --- pkgs/id/src/web/markdown.rs | 16 ++++++++------ pkgs/id/src/world_net.rs | 7 ++++-- pkgs/id/web/src/collab.test.ts | 34 ++++++++++-------------------- pkgs/id/web/src/world.ts | 7 +++++- pkgs/id/worker-poc/package.json | 20 +++++++++++++++++- pkgs/id/worker-poc/src/guest.ts | 14 ++++++++++-- pkgs/id/worker-poc/src/manifest.ts | 9 ++------ pkgs/id/worker-poc/src/worker.ts | 17 ++++++++------- pkgs/id/worker-poc/tsconfig.json | 15 ++++++++++++- 9 files changed, 87 insertions(+), 52 deletions(-) diff --git a/pkgs/id/src/web/markdown.rs b/pkgs/id/src/web/markdown.rs index a212e729c0..10b544ff84 100644 --- a/pkgs/id/src/web/markdown.rs +++ b/pkgs/id/src/web/markdown.rs @@ -1955,11 +1955,12 @@ fn collect_link_reference_definitions(markdown: &str) -> Vec<(usize, String)> { found } }; - let single_start = is_link_reference_definition_start(def_stripped).then(|| { - let close = - link_reference_definition_label_close(def_stripped).expect("start shape checked"); - (vec![line], def_stripped[close + 2..].to_string(), i + 1) - }); + let single_start = if is_link_reference_definition_start(def_stripped) { + link_reference_definition_label_close(def_stripped) + .map(|close| (vec![line], def_stripped[close + 2..].to_string(), i + 1)) + } else { + None + }; // A line carrying a list marker starts a NEW list item // and so a fresh block: `- [url]: ...` after `- Body` is a // definition in its own item, not a continuation of the @@ -1973,8 +1974,9 @@ fn collect_link_reference_definitions(markdown: &str) -> Vec<(usize, String)> { && (!in_footnote_block || new_list_item) && (single_start.is_some() || multiline_start.is_some()) { - let (mut block, mut after, mut j) = - single_start.or(multiline_start).expect("start checked"); + let Some((mut block, mut after, mut j)) = single_start.or(multiline_start) else { + continue; + }; // Rollback point for a title attempted on a FOLLOWING // line (twenty-first cut): (block length, `after`, j) // before the first such line is appended. A title that diff --git a/pkgs/id/src/world_net.rs b/pkgs/id/src/world_net.rs index 17a8ddfda6..4417844b48 100644 --- a/pkgs/id/src/world_net.rs +++ b/pkgs/id/src/world_net.rs @@ -1879,12 +1879,15 @@ impl WorldSessions { let session = self .roots .get(&key.0) - .expect("root inserted above") + .context("root inserted above")? .open_session(world) .await?; self.sessions.insert(key.clone(), session); } - Ok(self.sessions.get_mut(&key).expect("session inserted above")) + Ok(self + .sessions + .get_mut(&key) + .context("session inserted above")?) } /// The live session for (`addr`, `world`), if one is open. diff --git a/pkgs/id/web/src/collab.test.ts b/pkgs/id/web/src/collab.test.ts index ee58a89b0e..aedb4fab44 100644 --- a/pkgs/id/web/src/collab.test.ts +++ b/pkgs/id/web/src/collab.test.ts @@ -178,15 +178,11 @@ describe("initCollab protocol handling (#1463, #2824)", () => { it("caps repeated open-then-drop failures until Init succeeds", () => { const statuses: string[] = []; - const conn = track(initCollab( - "ws://example.test/collab", - makeContainer(), - "doc-1", - "notes.md", - null, - undefined, - (status) => statuses.push(status), - )); + const conn = track( + initCollab("ws://example.test/collab", makeContainer(), "doc-1", "notes.md", null, undefined, (status) => + statuses.push(status), + ), + ); let socket = FakeWebSocket.instances[0]; // The initial connection plus ten reconnects all reach OPEN, but the @@ -207,15 +203,11 @@ describe("initCollab protocol handling (#1463, #2824)", () => { it("starts a fresh retry budget after receiving Init", () => { const statuses: string[] = []; - const conn = track(initCollab( - "ws://example.test/collab", - makeContainer(), - "doc-1", - "notes.md", - null, - undefined, - (status) => statuses.push(status), - )); + const conn = track( + initCollab("ws://example.test/collab", makeContainer(), "doc-1", "notes.md", null, undefined, (status) => + statuses.push(status), + ), + ); let socket = FakeWebSocket.instances[0]; for (let i = 0; i < 10; i++) { @@ -252,11 +244,7 @@ describe("initCollab protocol handling (#1463, #2824)", () => { }); it("does not reconnect after an intentional disconnect", () => { - const conn = track(initCollab( - "ws://example.test/collab", - makeContainer(), - "doc-1", - )); + const conn = track(initCollab("ws://example.test/collab", makeContainer(), "doc-1")); const socket = FakeWebSocket.instances[0]; socket.open(); diff --git a/pkgs/id/web/src/world.ts b/pkgs/id/web/src/world.ts index 696fc8bf39..74ecd9f3ef 100644 --- a/pkgs/id/web/src/world.ts +++ b/pkgs/id/web/src/world.ts @@ -635,7 +635,12 @@ function initWorld(): void { if (frame.type === "upload_ready" && !uploadStarted) { uploadStarted = true; const chunkBytes = frame.chunk_bytes; - if (typeof chunkBytes !== "number" || !Number.isInteger(chunkBytes) || chunkBytes < 1 || chunkBytes > 6 * 1024) { + if ( + typeof chunkBytes !== "number" || + !Number.isInteger(chunkBytes) || + chunkBytes < 1 || + chunkBytes > 6 * 1024 + ) { setStatus("Host returned an invalid module chunk size", "error"); upload.close(); return; diff --git a/pkgs/id/worker-poc/package.json b/pkgs/id/worker-poc/package.json index 58a0fb6ba1..7f110b2b77 100644 --- a/pkgs/id/worker-poc/package.json +++ b/pkgs/id/worker-poc/package.json @@ -1 +1,19 @@ -{"description":"PoC (#2271): plaza_* example worlds running unmodified in a Worker isolate, journal equality vs the native wasmtime host.","devDependencies":{"typescript":"^5.6.0","wrangler":"^3.90.0"},"name":"id-worker-poc","private":true,"scripts":{"dev":"wrangler dev","smoke":"node smoke/counter-smoke.mjs && node smoke/post-update-failure.mjs","typecheck":"tsc --noEmit","compare":"node compare/compare.mjs","do-cold-start":"node compare/do-cold-start.mjs","participant-clamp":"node smoke/participant-clamp.mjs","post-update-failure":"node smoke/post-update-failure.mjs"},"type":"module"} +{ + "description": "PoC (#2271): plaza_* example worlds running unmodified in a Worker isolate, journal equality vs the native wasmtime host.", + "devDependencies": { + "typescript": "^5.6.0", + "wrangler": "^3.90.0" + }, + "name": "id-worker-poc", + "private": true, + "scripts": { + "dev": "wrangler dev", + "smoke": "node smoke/counter-smoke.mjs && node smoke/post-update-failure.mjs", + "typecheck": "tsc --noEmit", + "compare": "node compare/compare.mjs", + "do-cold-start": "node compare/do-cold-start.mjs", + "participant-clamp": "node smoke/participant-clamp.mjs", + "post-update-failure": "node smoke/post-update-failure.mjs" + }, + "type": "module" +} diff --git a/pkgs/id/worker-poc/src/guest.ts b/pkgs/id/worker-poc/src/guest.ts index 7693ae96b6..16b0d6f7d9 100644 --- a/pkgs/id/worker-poc/src/guest.ts +++ b/pkgs/id/worker-poc/src/guest.ts @@ -61,7 +61,15 @@ export class PlazaGuest { ): Promise { const instance = await WebAssembly.instantiate(module, {}); const ex = instance.exports as unknown as PlazaExports; - for (const name of ["memory", "plaza_alloc", "plaza_free", "plaza_init", "plaza_update", "plaza_view", "plaza_out_len"] as const) { + for (const name of [ + "memory", + "plaza_alloc", + "plaza_free", + "plaza_init", + "plaza_update", + "plaza_view", + "plaza_out_len", + ] as const) { if (ex[name] === undefined) throw new Error(`guest must export \`${name}\``); } if ((ex.plaza_snapshot === undefined) !== (ex.plaza_restore === undefined)) { @@ -110,7 +118,9 @@ export class PlazaGuest { // ID above i32::MAX); -Infinity is a negative non-finite and is // rejected. if (typeof participant !== "number" || Number.isNaN(participant)) { - throw new Error(`guest participant must be a non-negative integer, got ${String(participant)} (NaN or non-number)`); + throw new Error( + `guest participant must be a non-negative integer, got ${String(participant)} (NaN or non-number)`, + ); } if (participant === -Infinity) { throw new Error("guest participant must be a non-negative integer, got -Infinity"); diff --git a/pkgs/id/worker-poc/src/manifest.ts b/pkgs/id/worker-poc/src/manifest.ts index 4f2e4ad4e0..cecb7d0b4a 100644 --- a/pkgs/id/worker-poc/src/manifest.ts +++ b/pkgs/id/worker-poc/src/manifest.ts @@ -13,14 +13,9 @@ export interface HostedManifest { export function assertHostable(manifest: HostedManifest): void { if (manifest.portability === "native") { - throw new Error( - `manifest ${manifest.name}: portability=native is not hostable in a Worker isolate`, - ); + throw new Error(`manifest ${manifest.name}: portability=native is not hostable in a Worker isolate`); } - if ( - manifest.wasm_memory_bytes !== undefined && - manifest.wasm_memory_bytes > HOSTED_MEMORY_CEILING_BYTES - ) { + if (manifest.wasm_memory_bytes !== undefined && manifest.wasm_memory_bytes > HOSTED_MEMORY_CEILING_BYTES) { throw new Error( `manifest ${manifest.name}: declared memory ${manifest.wasm_memory_bytes} exceeds hosted ceiling ${HOSTED_MEMORY_CEILING_BYTES} (64MB)`, ); diff --git a/pkgs/id/worker-poc/src/worker.ts b/pkgs/id/worker-poc/src/worker.ts index ac96713da1..40a3674532 100644 --- a/pkgs/id/worker-poc/src/worker.ts +++ b/pkgs/id/worker-poc/src/worker.ts @@ -95,9 +95,7 @@ export class WorldObject { if (this.guest) return Promise.resolve(this.guest); if (!this.guestPromise) { this.guestPromise = (async () => { - const rows = this.sql - .exec(`SELECT step, snapshot FROM journal ORDER BY step DESC LIMIT 1`) - .toArray(); + const rows = this.sql.exec(`SELECT step, snapshot FROM journal ORDER BY step DESC LIMIT 1`).toArray(); const guest = await loadHostedModule(MANIFEST, COUNTER_WASM as WebAssembly.Module, SEED); if (rows.length > 0) { guest.restore(asBytes(rows[0].snapshot)); @@ -134,9 +132,7 @@ export class WorldObject { if (req.method === "POST" && url.pathname === "/step") { // Validate before touching the guest: a malformed request must never // mutate state it cannot journal. - const body = (await req.json().catch(() => null)) as - | { participant?: unknown; event?: unknown } - | null; + const body = (await req.json().catch(() => null)) as { participant?: unknown; event?: unknown } | null; const participant = body?.participant; const event = body?.event; if ( @@ -165,8 +161,13 @@ export class WorldObject { snapshotHash = await sha256Hex(snapshot); this.sql.exec( `INSERT INTO journal (step, participant, event, snapshot, view, records, snapshot_hash) VALUES (?, ?, ?, ?, ?, ?, ?)`, - nextStep, participant, event, snapshot, dec.decode(view), - records ? dec.decode(records) : null, snapshotHash, + nextStep, + participant, + event, + snapshot, + dec.decode(view), + records ? dec.decode(records) : null, + snapshotHash, ); } catch (err) { // Any failure before the journal commit may leave the guest advanced diff --git a/pkgs/id/worker-poc/tsconfig.json b/pkgs/id/worker-poc/tsconfig.json index 242a9589ce..de9a317483 100644 --- a/pkgs/id/worker-poc/tsconfig.json +++ b/pkgs/id/worker-poc/tsconfig.json @@ -1 +1,14 @@ -{"compilerOptions":{"allowImportingTsExtensions":true,"lib":["ES2022","DOM"],"module":"ESNext","moduleResolution":"bundler","noEmit":true,"skipLibCheck":true,"strict":true,"target":"ES2022","types":[]},"include":["src/**/*.ts"]} \ No newline at end of file +{ + "compilerOptions": { + "allowImportingTsExtensions": true, + "lib": ["ES2022", "DOM"], + "module": "ESNext", + "moduleResolution": "bundler", + "noEmit": true, + "skipLibCheck": true, + "strict": true, + "target": "ES2022", + "types": [] + }, + "include": ["src/**/*.ts"] +}