From 34d86be274bdc04f0c62a805152427cdf597b78a Mon Sep 17 00:00:00 2001 From: Dylan Conway Date: Sat, 25 Apr 2026 21:04:56 -0700 Subject: [PATCH 1/2] test: avoid TLA self-cycle in bun-main dynamic-import test bun:main statically imports the entry, so awaiting import("bun:main") at the entry's top level is a TLA self-cycle that never resolves under the new JSC module loader (#29393). Prior to that rewrite the loader broke the cycle early, which is why this passed when #29719 landed. Switch the entry from `await import("bun:main")` to `import("bun:main").then(...)` so the entry finishes synchronously, bun:main finishes, and the import promise resolves on the next tick. The preload and --hot tests are unaffected. --- .../bun/resolve/bun-main-entry-point.test.ts | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/test/js/bun/resolve/bun-main-entry-point.test.ts b/test/js/bun/resolve/bun-main-entry-point.test.ts index 9cfea1c7e17..2e1cc75e308 100644 --- a/test/js/bun/resolve/bun-main-entry-point.test.ts +++ b/test/js/bun/resolve/bun-main-entry-point.test.ts @@ -21,14 +21,25 @@ test.concurrent("dynamic import('bun:main') returns the wrapper module", async ( // package.json disables auto-install so a regression in the bun:main alias // cannot silently fall through to fetching the npm `main` package. "package.json": "{}", + // bun:main statically imports entry.mjs, so awaiting import("bun:main") + // at the top level of entry.mjs is a TLA self-cycle that never resolves. + // Defer the import to a .then() so entry.mjs (and therefore bun:main) + // can finish evaluating first. "entry.mjs": ` - const m = await import("bun:main"); - if (m[Symbol.toStringTag] !== "Module") throw new Error("expected module namespace, got " + Object.prototype.toString.call(m)); - // The wrapper has no named exports. The npm \`main\` package (what this - // resolved to before the alias fix) exports {default,length,name,prototype}. - const keys = Object.keys(m); - if (keys.length !== 0) throw new Error("expected empty wrapper namespace, got keys: " + keys.join(",")); - console.log("OK"); + import("bun:main").then( + m => { + if (m[Symbol.toStringTag] !== "Module") throw new Error("expected module namespace, got " + Object.prototype.toString.call(m)); + // The wrapper has no named exports. The npm \`main\` package (what this + // resolved to before the alias fix) exports {default,length,name,prototype}. + const keys = Object.keys(m); + if (keys.length !== 0) throw new Error("expected empty wrapper namespace, got keys: " + keys.join(",")); + console.log("OK"); + }, + e => { + console.error(String(e)); + process.exit(1); + }, + ); `, }); await using proc = Bun.spawn({ From ca81de45b8a3e1e20339aa8799599532d3934795 Mon Sep 17 00:00:00 2001 From: Dylan Conway Date: Sat, 25 Apr 2026 22:02:27 -0700 Subject: [PATCH 2/2] test: chain .catch so assertion throws in fulfillment handler are reported --- .../bun/resolve/bun-main-entry-point.test.ts | 25 ++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/test/js/bun/resolve/bun-main-entry-point.test.ts b/test/js/bun/resolve/bun-main-entry-point.test.ts index 2e1cc75e308..c3ba614e0e9 100644 --- a/test/js/bun/resolve/bun-main-entry-point.test.ts +++ b/test/js/bun/resolve/bun-main-entry-point.test.ts @@ -26,20 +26,17 @@ test.concurrent("dynamic import('bun:main') returns the wrapper module", async ( // Defer the import to a .then() so entry.mjs (and therefore bun:main) // can finish evaluating first. "entry.mjs": ` - import("bun:main").then( - m => { - if (m[Symbol.toStringTag] !== "Module") throw new Error("expected module namespace, got " + Object.prototype.toString.call(m)); - // The wrapper has no named exports. The npm \`main\` package (what this - // resolved to before the alias fix) exports {default,length,name,prototype}. - const keys = Object.keys(m); - if (keys.length !== 0) throw new Error("expected empty wrapper namespace, got keys: " + keys.join(",")); - console.log("OK"); - }, - e => { - console.error(String(e)); - process.exit(1); - }, - ); + import("bun:main").then(m => { + if (m[Symbol.toStringTag] !== "Module") throw new Error("expected module namespace, got " + Object.prototype.toString.call(m)); + // The wrapper has no named exports. The npm \`main\` package (what this + // resolved to before the alias fix) exports {default,length,name,prototype}. + const keys = Object.keys(m); + if (keys.length !== 0) throw new Error("expected empty wrapper namespace, got keys: " + keys.join(",")); + console.log("OK"); + }).catch(e => { + console.error(String(e)); + process.exit(1); + }); `, }); await using proc = Bun.spawn({