From 462f29812db2565383f8256253ae257330604b3b Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Tue, 3 Nov 2026 22:07:44 -0800 Subject: [PATCH 1/5] chore(quest): claim quest/m0/test-flakes-2/js-worklet-build.md Quest-Claim: 594ef6c443001c14 From 066f72932b3188556eed340ce761198bce4aaacd Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Tue, 3 Nov 2026 22:19:35 -0800 Subject: [PATCH 2/5] test(js): check worklet hooks without a full Vite build Co-Authored-By: GPT-6.1 Sol --- js/common/worklet.test.ts | 70 ++++++++++++---------- quest/m0/test-flakes-2/README.md | 1 - quest/m0/test-flakes-2/js-worklet-build.md | 37 ------------ test/worklet/matrix.ts | 28 ++++++++- 4 files changed, 65 insertions(+), 71 deletions(-) delete mode 100644 quest/m0/test-flakes-2/js-worklet-build.md diff --git a/js/common/worklet.test.ts b/js/common/worklet.test.ts index 574dfe20b5d..b1de4294d12 100644 --- a/js/common/worklet.test.ts +++ b/js/common/worklet.test.ts @@ -1,10 +1,11 @@ import { expect, test } from "bun:test"; import { spawnSync } from "node:child_process"; -import { mkdtempSync, readdirSync, readFileSync, rmSync, writeFileSync } from "node:fs"; +import { mkdtempSync, rmSync, writeFileSync } from "node:fs"; import { connect } from "node:net"; import { tmpdir } from "node:os"; import { join } from "node:path"; -import { build, createServer } from "vite"; +import type { EmittedAsset, EmittedFile, PluginContext } from "rolldown"; +import { createServer, type MinimalPluginContextWithoutEnvironment, type ResolvedConfig } from "vite"; import { worklet } from "./vite-plugin-worklet"; // A library build must never reference its worklets through import.meta.url: esbuild, Rollup, and Bun @@ -13,42 +14,49 @@ import { worklet } from "./vite-plugin-worklet"; // // A bundler child process would outlive `vite build` and be reaped by init, so its CPU escapes the // build's accounting and it lingers after the build. -// -// One build of a one-line worklet: the plugin's output doesn't depend on what the worklet imports, and -// bundling a real package graph costs over a CPU-second. The package builds bundle the real worklets. -test("library builds load worklets from a lazy blob or a hosted base, leaving no child process", async () => { +// Check the plugin's modules with its real compiler, without Vite's build setup. The full library +// build and its child-process check run in the nightly test/worklet/matrix.ts on the real worklets. +test("worklet modules load a lazy blob or a hosted script, leaving no child process", async () => { const dir = mkdtempSync(join(tmpdir(), "worklet-")); - const outDir = join(dir, "dist"); try { - writeFileSync(join(dir, "render.ts"), `registerProcessor("render", class extends AudioWorkletProcessor {});\n`); - writeFileSync(join(dir, "index.ts"), `export { default } from "./render.ts?worklet";\n`); - - await build({ - configFile: false, - logLevel: "silent", - plugins: [worklet()], - build: { outDir, minify: false, lib: { entry: join(dir, "index.ts"), formats: ["es"] } }, - }); - - expect(readdirSync(join(outDir, "assets"))).toEqual(["render.js"]); - - const chunks = readdirSync(outDir).filter((name) => name.endsWith(".js")); - const code = new Map(chunks.map((name) => [name, readFileSync(join(outDir, name), "utf8")])); - for (const text of code.values()) expect(text).not.toContain("import.meta.url"); + const path = join(dir, "render.ts"); + writeFileSync(path, `registerProcessor("render", class extends AudioWorkletProcessor {});\n`); + const plugin = worklet(); + if (typeof plugin.configResolved !== "function" || typeof plugin.load !== "function") + throw new Error("worklet hooks must be functions"); + await plugin.configResolved.call( + {} as MinimalPluginContextWithoutEnvironment, + { command: "build" } as ResolvedConfig, + ); + const assets: EmittedAsset[] = []; + const context = { + emitFile(file: EmittedFile) { + if (file.type !== "asset") throw new Error("worklet must emit an asset"); + assets.push(file); + return "hosted"; + }, + addWatchFile() {}, + } as PluginContext; + const entry = await plugin.load.call(context, `${path}?worklet`); + const blob = await plugin.load.call(context, `${path}?worklet-blob`); - const blob = chunks.filter((name) => code.get(name)?.includes("createObjectURL")); - expect(blob).toHaveLength(1); - const entry = chunks - .filter((name) => !blob.includes(name)) - .map((name) => code.get(name)) - .join("\n"); - expect(entry).toContain(`import("./${blob[0]}")`); - expect(entry).toContain(`new URL("render.js", `); + expect(assets).toHaveLength(1); + expect(assets[0].fileName).toBe("assets/render.js"); + expect(assets[0].source).toContain("registerProcessor"); + expect(entry).not.toContain("import.meta.url"); + expect(blob).not.toContain("import.meta.url"); + expect(entry).not.toContain("createObjectURL"); + expect(blob).toContain("URL.createObjectURL"); + expect(blob).toContain(JSON.stringify(assets[0].source)); + expect(entry).toContain(`import(${JSON.stringify(`${path}?worklet-blob`)})`); + expect(entry).toContain(`new URL("render.js", base)`); } finally { rmSync(dir, { recursive: true, force: true }); } - expect(spawnSync("pgrep", ["-l", "-P", String(process.pid)], { encoding: "utf8" }).stdout).toBe(""); + const children = spawnSync("pgrep", ["-l", "-P", String(process.pid)], { encoding: "utf8" }); + expect(children.stdout).toBe(""); + expect(children.status).toBe(1); }); // A page that calls assets() in dev fetches the same path a build emits, so the dev server serves it. diff --git a/quest/m0/test-flakes-2/README.md b/quest/m0/test-flakes-2/README.md index 875eb5e3ece..4c78c6577f7 100644 --- a/quest/m0/test-flakes-2/README.md +++ b/quest/m0/test-flakes-2/README.md @@ -92,7 +92,6 @@ Public API: none. Wire: none. - [moq-tokio's close-drain test survives load](/quest/m0/test-flakes-2/tokio-close-drain.md) - `quic_client_close_drains_finished_track` stops failing land batches with "Unroutable" - [moq-transcode's live multi-rung test survives load](/quest/m0/test-flakes-2/transcode-multi-rung.md) - `live_multi_rung` stops failing queue batches with a cancelled rung group - [moq-relay's embedded io_uring stop test survives load](/quest/m0/test-flakes-2/relay-embed-stop.md) - `uring_custom_route_and_quic` stops seeing HTTP accepted after its owner stopped -- [The JS worklet library-build test survives load](/quest/m0/test-flakes-2/js-worklet-build.md) - the lazy-blob worklet build test stops timing out at bun's 5 seconds - [moq-archive's cross-backend recording test survives load](/quest/m0/test-flakes-2/archive-backends-identical.md) - `recordings_are_byte_identical_on_every_backend` stops splitting S3's video objects differently - [moq-ffi's panicked-origin supervision test survives load](/quest/m0/test-flakes-2/ffi-origin-panic.md) - a read the origin driver's panic ends always reports `MoqError::Task` - [The scheduled macOS WebSocket version test completes reliably](/quest/m0/test-flakes-2/macos-websocket.md) - fix the scheduled timeout while preserving newest-version negotiation assertions diff --git a/quest/m0/test-flakes-2/js-worklet-build.md b/quest/m0/test-flakes-2/js-worklet-build.md deleted file mode 100644 index d34ea2fd5b8..00000000000 --- a/quest/m0/test-flakes-2/js-worklet-build.md +++ /dev/null @@ -1,37 +0,0 @@ -# [S] The JS worklet library-build test survives load - -## Goal - -"library builds load worklets from a lazy blob or a hosted base, leaving no -child process" (`js/common/worklet.test.ts`) passes reliably in a loaded -merge-queue `just ci`, fixed at its cause, never by raising a timeout or -adding a retry. Done when the test no longer fails the queue and a loaded -local repeat of it passes. - -## Plan - -Planned 2026-11-03 (maintainer, `/quest-plan`). It timed out in the -merge-queue batch for [moq-dev/moq#7536](https://github.com/moq-dev/moq/pull/7536) -([run 41700523666](https://github.com/moq-dev/moq/actions/runs/41700523666), -2026-11-03 19:13Z): - -```text -#[group]js/common/worklet.test.ts: -(fail) library builds load worklets from a lazy blob or a hosted base, leaving no child process [5004.51ms] - ^ this test timed out after 5000ms. -(pass) the dev server serves hosted worklets where builds emit them [803.45ms] -``` - -This test already failed the queue once and was counted fixed in the epic's -2026-10-26 entry. It runs a real `vite build` of a one-line worklet, so a -loaded host can push one build past bun's default 5-second test timeout. - -- Measure where the time goes under load: Vite's startup, the plugin's - in-process worklet bundle, or a wait on a child process. -- If the build is slow because the plugin does needless work, make it cheaper. - If it is a whole Vite build that no smaller unit can replace, move the check - to a cheaper level, for example by testing the plugin's transform without - a full build, and keep one build where it is cheap enough to stay reliable. -- A longer per-test timeout is not a fix under the epic's rules. - -Follow the rules in [More tests under load](/quest/m0/test-flakes-2/README.md). diff --git a/test/worklet/matrix.ts b/test/worklet/matrix.ts index 2cd5b24f936..6449eab830c 100644 --- a/test/worklet/matrix.ts +++ b/test/worklet/matrix.ts @@ -5,7 +5,9 @@ // uses blob: URLs with no CSP, and hosted mode serves the copied assets under a strict CSP. A control // run of blob: URLs under that CSP must fail, proving the CSP applies. The bundlers are pinned in this // package's manifest, so the lockfile decides their versions. -import { cpSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs"; +import assert from "node:assert/strict"; +import { spawnSync } from "node:child_process"; +import { cpSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, rmSync, writeFileSync } from "node:fs"; import { tmpdir } from "node:os"; import { join, resolve } from "node:path"; import { chromium } from "playwright"; @@ -42,8 +44,30 @@ try { root, logLevel: "silent", plugins: [worklet()], - build: { outDir: lib, lib: { entry: join(root, "lib.js"), formats: ["es"], fileName: "index" } }, + build: { outDir: lib, minify: false, lib: { entry: join(root, "lib.js"), formats: ["es"], fileName: "index" } }, }); + // Check the completed Vite build before consumer bundlers or Chromium can spawn children. + const children = spawnSync("pgrep", ["-l", "-P", String(process.pid)], { encoding: "utf8" }); + assert.equal(children.status, 1, children.error?.message ?? (children.stdout || children.stderr)); + assert.deepEqual(readdirSync(join(lib, "assets")).sort(), [ + "capture-worker.js", + "capture-worklet.js", + "render-worklet.js", + ]); + const chunks = readdirSync(lib) + .filter((name) => name.endsWith(".js")) + .map((name) => ({ name, code: readFileSync(join(lib, name), "utf8") })); + for (const { code } of chunks) assert.ok(!code.includes("import.meta.url")); + const blobs = chunks.filter(({ code }) => code.includes("createObjectURL")); + assert.equal(blobs.length, 3); + const entry = chunks + .filter((chunk) => !blobs.includes(chunk)) + .map(({ code }) => code) + .join("\n"); + for (const { name } of blobs) assert.ok(entry.includes(`import("./${name}")`)); + for (const name of ["render-worklet", "capture-worklet", "capture-worker"]) + assert.ok(entry.includes(`new URL("${name}.js", `)); + console.log("library build: lazy blobs, hosted assets, no child process"); writeFileSync( join(lib, "package.json"), JSON.stringify({ name: "worklet-lib", type: "module", exports: "./index.js" }), From 935df9bd29b3fa35daa09a1bcb634b243e827833 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Tue, 3 Nov 2026 22:29:36 -0800 Subject: [PATCH 3/5] test(js): exercise worklet hooks through native Rolldown Co-Authored-By: GPT-6.1 Sol --- js/common/worklet.test.ts | 49 ++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 26 deletions(-) diff --git a/js/common/worklet.test.ts b/js/common/worklet.test.ts index b1de4294d12..c5794febd2c 100644 --- a/js/common/worklet.test.ts +++ b/js/common/worklet.test.ts @@ -4,7 +4,7 @@ import { mkdtempSync, rmSync, writeFileSync } from "node:fs"; import { connect } from "node:net"; import { tmpdir } from "node:os"; import { join } from "node:path"; -import type { EmittedAsset, EmittedFile, PluginContext } from "rolldown"; +import { rolldown } from "rolldown"; import { createServer, type MinimalPluginContextWithoutEnvironment, type ResolvedConfig } from "vite"; import { worklet } from "./vite-plugin-worklet"; @@ -14,42 +14,39 @@ import { worklet } from "./vite-plugin-worklet"; // // A bundler child process would outlive `vite build` and be reaped by init, so its CPU escapes the // build's accounting and it lingers after the build. -// Check the plugin's modules with its real compiler, without Vite's build setup. The full library +// Bundle the plugin's modules without Vite's build setup. The full Vite library // build and its child-process check run in the nightly test/worklet/matrix.ts on the real worklets. test("worklet modules load a lazy blob or a hosted script, leaving no child process", async () => { const dir = mkdtempSync(join(tmpdir(), "worklet-")); try { const path = join(dir, "render.ts"); writeFileSync(path, `registerProcessor("render", class extends AudioWorkletProcessor {});\n`); + const index = join(dir, "index.ts"); + writeFileSync(index, `export { default } from "./render.ts?worklet";\n`); const plugin = worklet(); - if (typeof plugin.configResolved !== "function" || typeof plugin.load !== "function") - throw new Error("worklet hooks must be functions"); + if (typeof plugin.configResolved !== "function") throw new Error("worklet must configure its build mode"); await plugin.configResolved.call( {} as MinimalPluginContextWithoutEnvironment, { command: "build" } as ResolvedConfig, ); - const assets: EmittedAsset[] = []; - const context = { - emitFile(file: EmittedFile) { - if (file.type !== "asset") throw new Error("worklet must emit an asset"); - assets.push(file); - return "hosted"; - }, - addWatchFile() {}, - } as PluginContext; - const entry = await plugin.load.call(context, `${path}?worklet`); - const blob = await plugin.load.call(context, `${path}?worklet-blob`); - - expect(assets).toHaveLength(1); - expect(assets[0].fileName).toBe("assets/render.js"); - expect(assets[0].source).toContain("registerProcessor"); - expect(entry).not.toContain("import.meta.url"); - expect(blob).not.toContain("import.meta.url"); - expect(entry).not.toContain("createObjectURL"); - expect(blob).toContain("URL.createObjectURL"); - expect(blob).toContain(JSON.stringify(assets[0].source)); - expect(entry).toContain(`import(${JSON.stringify(`${path}?worklet-blob`)})`); - expect(entry).toContain(`new URL("render.js", base)`); + const bundle = await rolldown({ input: index, plugins: [plugin] }); + try { + const { output } = await bundle.generate({ format: "es" }); + const assets = output.filter((file) => file.type === "asset"); + expect(assets.map((file) => file.fileName)).toEqual(["assets/render.js"]); + expect(assets[0].source).toContain("registerProcessor"); + const chunks = output.filter((file) => file.type === "chunk"); + for (const { code } of chunks) expect(code).not.toContain("import.meta.url"); + const blobs = chunks.filter(({ code }) => code.includes("createObjectURL")); + expect(blobs).toHaveLength(1); + expect(blobs[0].code).toContain(JSON.stringify(assets[0].source)); + const entry = chunks.find((chunk) => chunk.isEntry); + expect(entry?.dynamicImports).toEqual([blobs[0].fileName]); + expect(entry?.code).not.toContain("createObjectURL"); + expect(entry?.code).toContain(`new URL("render.js", `); + } finally { + await bundle.close(); + } } finally { rmSync(dir, { recursive: true, force: true }); } From ee6a2f853e54fad454763c002f7ca6a2874a6586 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Tue, 3 Nov 2026 22:34:03 -0800 Subject: [PATCH 4/5] test(js): compile worklets through their load hooks Co-Authored-By: GPT-6.1 Sol --- js/common/worklet.test.ts | 49 +++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/js/common/worklet.test.ts b/js/common/worklet.test.ts index c5794febd2c..76a89dd6171 100644 --- a/js/common/worklet.test.ts +++ b/js/common/worklet.test.ts @@ -4,7 +4,7 @@ import { mkdtempSync, rmSync, writeFileSync } from "node:fs"; import { connect } from "node:net"; import { tmpdir } from "node:os"; import { join } from "node:path"; -import { rolldown } from "rolldown"; +import type { EmittedAsset, EmittedFile, PluginContext } from "rolldown"; import { createServer, type MinimalPluginContextWithoutEnvironment, type ResolvedConfig } from "vite"; import { worklet } from "./vite-plugin-worklet"; @@ -14,39 +14,42 @@ import { worklet } from "./vite-plugin-worklet"; // // A bundler child process would outlive `vite build` and be reaped by init, so its CPU escapes the // build's accounting and it lingers after the build. -// Bundle the plugin's modules without Vite's build setup. The full Vite library +// Check the plugin's modules with its real compiler, without Vite's build setup. The full library // build and its child-process check run in the nightly test/worklet/matrix.ts on the real worklets. test("worklet modules load a lazy blob or a hosted script, leaving no child process", async () => { const dir = mkdtempSync(join(tmpdir(), "worklet-")); try { const path = join(dir, "render.ts"); writeFileSync(path, `registerProcessor("render", class extends AudioWorkletProcessor {});\n`); - const index = join(dir, "index.ts"); - writeFileSync(index, `export { default } from "./render.ts?worklet";\n`); const plugin = worklet(); - if (typeof plugin.configResolved !== "function") throw new Error("worklet must configure its build mode"); + if (typeof plugin.configResolved !== "function" || typeof plugin.load !== "function") + throw new Error("worklet hooks must be functions"); await plugin.configResolved.call( {} as MinimalPluginContextWithoutEnvironment, { command: "build" } as ResolvedConfig, ); - const bundle = await rolldown({ input: index, plugins: [plugin] }); - try { - const { output } = await bundle.generate({ format: "es" }); - const assets = output.filter((file) => file.type === "asset"); - expect(assets.map((file) => file.fileName)).toEqual(["assets/render.js"]); - expect(assets[0].source).toContain("registerProcessor"); - const chunks = output.filter((file) => file.type === "chunk"); - for (const { code } of chunks) expect(code).not.toContain("import.meta.url"); - const blobs = chunks.filter(({ code }) => code.includes("createObjectURL")); - expect(blobs).toHaveLength(1); - expect(blobs[0].code).toContain(JSON.stringify(assets[0].source)); - const entry = chunks.find((chunk) => chunk.isEntry); - expect(entry?.dynamicImports).toEqual([blobs[0].fileName]); - expect(entry?.code).not.toContain("createObjectURL"); - expect(entry?.code).toContain(`new URL("render.js", `); - } finally { - await bundle.close(); - } + const assets: EmittedAsset[] = []; + const context = { + emitFile(file: EmittedFile) { + if (file.type !== "asset") throw new Error("worklet must emit an asset"); + assets.push(file); + return "hosted"; + }, + addWatchFile(_path: string) {}, + } as PluginContext; + const entry = await plugin.load.call(context, `${path}?worklet`); + const blob = await plugin.load.call(context, `${path}?worklet-blob`); + + expect(assets).toHaveLength(1); + expect(assets[0].fileName).toBe("assets/render.js"); + expect(assets[0].source).toContain("registerProcessor"); + expect(entry).not.toContain("import.meta.url"); + expect(blob).not.toContain("import.meta.url"); + expect(entry).not.toContain("createObjectURL"); + expect(blob).toContain("URL.createObjectURL"); + expect(blob).toContain(JSON.stringify(assets[0].source)); + expect(entry).toContain(`import(${JSON.stringify(`${path}?worklet-blob`)})`); + expect(entry).toContain(`new URL("render.js", base)`); } finally { rmSync(dir, { recursive: true, force: true }); } From a9122739938a3a55b1f26903e850fefde74a9b97 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Tue, 3 Nov 2026 22:43:47 -0800 Subject: [PATCH 5/5] test(js): retain production minification in the worklet matrix Co-Authored-By: GPT-6.1 Sol --- js/common/worklet.test.ts | 7 +++---- test/worklet/matrix.ts | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/js/common/worklet.test.ts b/js/common/worklet.test.ts index 76a89dd6171..c8ba6c5d094 100644 --- a/js/common/worklet.test.ts +++ b/js/common/worklet.test.ts @@ -12,10 +12,9 @@ import { worklet } from "./vite-plugin-worklet"; // consumers drop that asset (a 404), and an esbuild IIFE throws at load. The blob stays the default, // loaded lazily, with the hostable file emitted beside it. // -// A bundler child process would outlive `vite build` and be reaped by init, so its CPU escapes the -// build's accounting and it lingers after the build. -// Check the plugin's modules with its real compiler, without Vite's build setup. The full library -// build and its child-process check run in the nightly test/worklet/matrix.ts on the real worklets. +// No bundler child may outlive the plugin's compile and escape its CPU accounting. Check the load +// hooks with the real in-process compiler here; full Vite library output and build-lifecycle checks +// run nightly in test/worklet/matrix.ts on the real worklets. test("worklet modules load a lazy blob or a hosted script, leaving no child process", async () => { const dir = mkdtempSync(join(tmpdir(), "worklet-")); try { diff --git a/test/worklet/matrix.ts b/test/worklet/matrix.ts index 6449eab830c..65d10adcd98 100644 --- a/test/worklet/matrix.ts +++ b/test/worklet/matrix.ts @@ -44,7 +44,7 @@ try { root, logLevel: "silent", plugins: [worklet()], - build: { outDir: lib, minify: false, lib: { entry: join(root, "lib.js"), formats: ["es"], fileName: "index" } }, + build: { outDir: lib, lib: { entry: join(root, "lib.js"), formats: ["es"], fileName: "index" } }, }); // Check the completed Vite build before consumer bundlers or Chromium can spawn children. const children = spawnSync("pgrep", ["-l", "-P", String(process.pid)], { encoding: "utf8" });