diff --git a/.changeset/26126-console-version-define-test-leak.md b/.changeset/26126-console-version-define-test-leak.md new file mode 100644 index 00000000000..e8c9e6d12f5 --- /dev/null +++ b/.changeset/26126-console-version-define-test-leak.md @@ -0,0 +1,10 @@ +--- +'@object-ui/console': patch +--- + +fix(console): the console's build-identity define no longer leaks into the other ui test projects + +Clause-②: no (build/test configuration only; no exported type or runtime contract change; the console production build keeps its version stamp) +Metadata-protocol: none + +The console's Vite config bakes `import.meta.env.VITE_APP_VERSION` (the build's version, else the git short sha) as a `define`. The console's vitest project merges that config, and vitest moves every `import.meta.env.*` / `process.env.*` define into the main process's `process.env` while it resolves a project's config, so every other ui test project's workers inherited the console's git sha. App-shell's `getConsoleBuild()` then read that sha instead of `null`, and `buildIdentity-12970`'s "reads null" case went red in full ui runs. The console's vitest config now drops those keys from the merged Vite config. `vite build` still bakes the version exactly as before. diff --git a/ui/apps/console/vitest.config.ts b/ui/apps/console/vitest.config.ts index b8da0e6e4b3..1617fef5a71 100644 --- a/ui/apps/console/vitest.config.ts +++ b/ui/apps/console/vitest.config.ts @@ -7,8 +7,23 @@ import rootConfig from '../../vitest.config.mts'; // (objectui#3384). import viteConfig from './vite.config.ts'; +// The console BUILD bakes its identity as a `define` on +// `import.meta.env.VITE_APP_VERSION` (objectui#12970) — and vitest does not +// scope such a define to the project that declares it. While it resolves a +// project's config it moves every `import.meta.env.*` / `process.env.*` define +// into the main process's `process.env` (`deleteDefineConfig` in vitest's +// cli-api chunk), which the workers of EVERY project inherit. So the console's +// git sha surfaced in app-shell's `getConsoleBuild()` and turned +// `buildIdentity-12970`'s "reads null" case red in full runs, depending on +// shard layout (#26126). Those defines stay in the build and stop here; no +// console test reads them. +const LEAKS_INTO_PROCESS_ENV = /^(import\.meta\.env|process\.env)\./; +const testDefine = Object.fromEntries( + Object.entries(viteConfig.define ?? {}).filter(([key]) => !LEAKS_INTO_PROCESS_ENV.test(key)) +); + export default mergeConfig( - mergeConfig(rootConfig, viteConfig), + mergeConfig(rootConfig, { ...viteConfig, define: testDefine }), defineConfig({ test: { // The root config no longer sets global setupFiles (they moved into the