diff --git a/web/hwlab-cloud-web/scripts/workbench-native-vite-config.test.ts b/web/hwlab-cloud-web/scripts/workbench-native-vite-config.test.ts index fce65748..31624c4f 100644 --- a/web/hwlab-cloud-web/scripts/workbench-native-vite-config.test.ts +++ b/web/hwlab-cloud-web/scripts/workbench-native-vite-config.test.ts @@ -1,6 +1,6 @@ import { describe, expect, test } from "bun:test"; -import { parseWorkbenchNativeRuntimeConfig } from "../vite.config"; +import { nativeViteCacheDir, parseWorkbenchNativeRuntimeConfig } from "../vite.config"; const validConfig = { displayTime: { timeZone: "Asia/Shanghai", locale: "zh-CN", label: "北京时间" }, @@ -19,4 +19,13 @@ describe("Workbench native Vite runtime config", () => { test("fails closed when required runtime capabilities are missing", () => { expect(() => parseWorkbenchNativeRuntimeConfig(JSON.stringify({ displayTime: validConfig.displayTime, workbench: {} }))).toThrow("workbench.realtimeFeatures"); }); + + test("isolates Vite optimizer caches by native runtime", () => { + const workbench = nativeViteCacheDir({ nativeApiUrl: "http://127.0.0.1:6677", nativeCaseRunEnabled: false }); + const caserun = nativeViteCacheDir({ nativeApiUrl: "", nativeCaseRunEnabled: true }); + const cloudWeb = nativeViteCacheDir({ nativeApiUrl: "", nativeCaseRunEnabled: false }); + + expect(new Set([workbench, caserun, cloudWeb]).size).toBe(3); + expect(workbench).toBe(".state/vite/workbench"); + }); }); diff --git a/web/hwlab-cloud-web/vite.config.ts b/web/hwlab-cloud-web/vite.config.ts index f7d261ce..6ad34196 100644 --- a/web/hwlab-cloud-web/vite.config.ts +++ b/web/hwlab-cloud-web/vite.config.ts @@ -31,6 +31,7 @@ export default defineConfig(({ mode }) => { : undefined; return { + cacheDir: nativeViteCacheDir({ nativeApiUrl, nativeCaseRunEnabled }), plugins: [ ...(nativeApiUrl ? [nativeRuntimeConfigPlugin(nativeRuntimeConfig)] : []), ...(nativeCaseRunEnabled ? [nativeCaseRunRuntimeConfigPlugin()] : []), @@ -65,6 +66,11 @@ export default defineConfig(({ mode }) => { }; }); +export function nativeViteCacheDir(input: { nativeApiUrl: string; nativeCaseRunEnabled: boolean }): string { + const runtime = input.nativeApiUrl ? "workbench" : input.nativeCaseRunEnabled ? "caserun" : "cloud-web"; + return `.state/vite/${runtime}`; +} + function nativeRuntimeConfigPlugin(serialized: string): Plugin { const config = parseWorkbenchNativeRuntimeConfig(serialized); const inlineJson = JSON.stringify(config).replace(/