/* Copyright 2026 Marimo. All rights reserved. */ import { afterEach, assert, describe, expect, it, vi } from "vitest"; import { getWasmRuntimeConfig } from "../runtime-config"; vi.mock("@/core/meta/globals", () => ({ getMarimoVersion: () => "0.0.0-test", })); afterEach(() => { document.head.innerHTML = ""; }); describe("getWasmRuntimeConfig", () => { it("uses runtime defaults when no URLs are configured", () => { expect(getWasmRuntimeConfig()).toEqual({ version: "0.0.0-test", pyodideIndexUrl: undefined, pyodideLockfileUrl: undefined, pypiIndexUrl: undefined, }); }); it("resolves URLs against the page base and preserves micropip placeholders", () => { document.head.innerHTML = ` `; expect(getWasmRuntimeConfig()).toEqual({ version: "0.0.0-test", pyodideIndexUrl: "https://example.com/blog/runtime/", pyodideLockfileUrl: "https://example.com/locks/pyodide.json?v=1&x=2", pypiIndexUrl: "https://packages.example.com/{package_name}/json", }); }); it.each(["pyodideIndexUrl", "pyodideLockfileUrl", "pypiIndexUrl"])( "ignores malformed %s while preserving valid overrides", (key) => { document.head.innerHTML = ` `; const element = document.querySelector("marimo-wasm"); assert(element); element.dataset[key] = "https://invalid host/"; expect(getWasmRuntimeConfig()).toEqual({ version: "0.0.0-test", pyodideIndexUrl: "https://example.com/notebook/pyodide/", pyodideLockfileUrl: "https://example.com/notebook/lockfile/pyodide.json", pypiIndexUrl: "https://example.com/notebook/packages/{package_name}.json", [key]: undefined, }); }, ); });