From 63dd62870c148480ca8afea5fc07ddac3bae04b0 Mon Sep 17 00:00:00 2001 From: Amit Kumar Date: Sat, 25 Apr 2026 02:06:02 +0000 Subject: [PATCH] fix(ui): pin NODE_ENV=test in vitest config so prod env shells pass (RAN-40) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit React 19 ships separate CJS builds and selects between them via process.env.NODE_ENV at require-time; the production build omits `act`, which @testing-library/react needs. Any developer whose shell exports NODE_ENV=production (CI-adjacent shells, the Paperclip agent harness, etc.) would see 78/97 tests fail with `TypeError: React.act is not a function`, even though CI runners (NODE_ENV unset) pass. Vitest already does `process.env.NODE_ENV ||= 'test'`, but only when unset; when it's already `production` it's preserved, hence the bug. `--mode test` also doesn't override an already-set NODE_ENV in vitest 4. Force NODE_ENV=test at the top of vitest.config.ts before any worker forks so the test suite is deterministic regardless of caller env. Verified locally: - NODE_ENV=production npm --prefix ui run test → 97/97 pass - NODE_ENV=production npm --prefix ui run test:coverage → coverage generated - NODE_ENV unset npm --prefix ui run test → 97/97 pass (CI parity) Co-Authored-By: Paperclip --- ui/vitest.config.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ui/vitest.config.ts b/ui/vitest.config.ts index 370ad40..dfc9ffa 100644 --- a/ui/vitest.config.ts +++ b/ui/vitest.config.ts @@ -2,6 +2,12 @@ import { defineConfig } from "vitest/config"; import react from "@vitejs/plugin-react"; import { resolve } from "path"; +// React 19's CJS entry picks production vs development at require-time off +// NODE_ENV; the production build omits `act`. Force the test build before any +// worker forks so callers with NODE_ENV=production (CI-adjacent shells, the +// Paperclip agent harness) get the same result as bare `npm test`. +process.env.NODE_ENV = "test"; + export default defineConfig({ plugins: [react()], resolve: {