Files
oh-my-opencode/src/plugin/ultrawork-db-model-override.bun-sqlite-unavailable.test.ts
T
herjarsa 3a93a40e68 fix(desktop): hide bun:sqlite import from Node.js/Electron ESM loader
Uses new Function() to prevent the static ESM loader from seeing
the bun: protocol import at parse time. In Electron/Node.js, the
import() call is evaluated at runtime and gracefully returns null
when bun:sqlite is unavailable.

Fixes #3829, likely fixes #3762
2026-05-07 10:38:31 +02:00

23 lines
1002 B
TypeScript

import { describe, expect, test } from "bun:test"
describe("scheduleDeferredModelOverride bun:sqlite unavailable", () => {
test("#given source code #when inspected #then bun:sqlite is loaded dynamically with an unavailable-runtime fallback", async () => {
//#given
const source = await Bun.file(new URL("./ultrawork-db-model-override.ts", import.meta.url)).text()
//#when
const hasStaticBunSqliteImport = source.includes('from "bun:sqlite"')
|| source.includes("from 'bun:sqlite'")
|| source.includes('import "bun:sqlite"')
|| source.includes("import 'bun:sqlite'")
//#then
expect(hasStaticBunSqliteImport).toBe(false)
// new Function() hides the bun: import from Node.js/Electron static ESM loader
expect(source).toContain("new Function(\"return import('bun:sqlite')\")")
expect(source).toContain("typeof globalThis.Bun === \"undefined\"")
expect(source).toContain("bun:sqlite unavailable")
expect(source).toContain("return")
})
})