From 8cd1019478686e04e2c116aeb8c88899b9d19d24 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 21 Jul 2026 04:13:37 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=9A=94=E7=A6=BB=20Workbench=20Vite=20?= =?UTF-8?q?=E4=BE=9D=E8=B5=96=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../scripts/workbench-native-vite-config.test.ts | 11 ++++++++++- web/hwlab-cloud-web/vite.config.ts | 6 ++++++ 2 files changed, 16 insertions(+), 1 deletion(-) 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(/