Skip to content

Commit 92598a6

Browse files
committed
fix(console): keep the build-identity define out of the vitest projects' process.env
Vitest moves every import.meta.env.* / process.env.* define into the main process's process.env while it resolves a project's config, so the console project's VITE_APP_VERSION (the build's git sha) reached app-shell's getConsoleBuild() in other projects' workers. The console vitest config now drops those keys from the merged vite config; the build keeps them. Claude-Session: https://claude.ai/code/session_01KpXmBvpnCGgpgx8hNbqsso Co-authored-by: Claude <noreply@anthropic.com>
1 parent 601c773 commit 92598a6

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

‎ui/apps/console/vitest.config.ts‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,23 @@ import rootConfig from '../../vitest.config.mts';
77
// (objectui#3384).
88
import viteConfig from './vite.config.ts';
99

10+
// The console BUILD bakes its identity as a `define` on
11+
// `import.meta.env.VITE_APP_VERSION` (objectui#12970) — and vitest does not
12+
// scope such a define to the project that declares it. While it resolves a
13+
// project's config it moves every `import.meta.env.*` / `process.env.*` define
14+
// into the main process's `process.env` (`deleteDefineConfig` in vitest's
15+
// cli-api chunk), which the workers of EVERY project inherit. So the console's
16+
// git sha surfaced in app-shell's `getConsoleBuild()` and turned
17+
// `buildIdentity-12970`'s "reads null" case red in full runs, depending on
18+
// shard layout (#26126). Those defines stay in the build and stop here; no
19+
// console test reads them.
20+
const LEAKS_INTO_PROCESS_ENV = /^(import\.meta\.env|process\.env)\./;
21+
const testDefine = Object.fromEntries(
22+
Object.entries(viteConfig.define ?? {}).filter(([key]) => !LEAKS_INTO_PROCESS_ENV.test(key))
23+
);
24+
1025
export default mergeConfig(
11-
mergeConfig(rootConfig, viteConfig),
26+
mergeConfig(rootConfig, { ...viteConfig, define: testDefine }),
1227
defineConfig({
1328
test: {
1429
// The root config no longer sets global setupFiles (they moved into the

0 commit comments

Comments
 (0)