// SPDX-License-Identifier: LicenseRef-ConusAI-Template-1.0 import { afterEach, expect, it, vi } from "vitest" afterEach(() => { vi.unstubAllEnvs() vi.resetModules() }) /** The build's real configuration, evaluated with this environment. */ const viteConfig = async () => { vi.resetModules() const { default: config } = await import("../apps/web/vite.config") return config as { base?: string envPrefix?: unknown define?: unknown build?: { assetsDir?: string; outDir?: string } } } it("keeps compiled chunk URLs stable when the platform injects a deployment asset prefix", async () => { // Compose serves the image's assets itself. Vite writes its chunk URLs into the build, so a base read at // startup would leave the browser waiting for chunks under a name nothing serves: one image, every // environment, and no `base` in the build at all. vi.stubEnv("CONUSAI_ASSET_PREFIX", "/_conusai/assets/app-42") const config = await viteConfig() expect(config.base ?? "").toBe("") }) it("writes the build where server.mjs serves it from, under the folder RESERVED_SLUGS keeps from organizations", async () => { const config = await viteConfig() expect(config.build?.outDir).toBe("dist") // Vite's default; test/reserved-routes.test.ts reserves `assets` because of it. expect(config.build?.assetsDir ?? "assets").toBe("assets") }) it("hands the browser's bundle no variable: Vite's `VITE_` prefix stays the only way in, and nothing uses it", async () => { // A wider `envPrefix` or a `define` is how a server variable would reach a chunk (spec ยง6.4: the server // writes what the browser needs into the page, and there is no build-time public value). const config = await viteConfig() expect(config.envPrefix).toBeUndefined() expect(config.define).toBeUndefined() })