From 0016730500f18d19708fd75c634355b40c33a5e7 Mon Sep 17 00:00:00 2001 From: only21mil Date: Sat, 31 Oct 2026 19:01:00 +0000 Subject: [PATCH 1/4] fix(scripts): report:renders works on machines without ~/.cache mkdtempSync does not create parent directories, so report:renders run threw ENOENT before vitest started on any machine without ~/.cache. Use the OS temp directory as the base for the report handoff directory. Co-Authored-By: Claude Opus 5.5 --- scripts/render-metrics.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/render-metrics.ts b/scripts/render-metrics.ts index a49154ff5c788..eea950557ba2e 100644 --- a/scripts/render-metrics.ts +++ b/scripts/render-metrics.ts @@ -38,7 +38,7 @@ export type RenderMetrics = Readonly>; const root = NodePath.resolve(import.meta.dirname, ".."); function runOnce(): RenderMetrics { - const directory = NodeFS.mkdtempSync(NodePath.join(NodeOS.homedir(), ".cache", "t3-renders-")); + const directory = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "t3-renders-")); try { const result = NodeChildProcess.spawnSync("vp", ["test", "run", "--project", "renders"], { cwd: NodePath.join(root, "apps/web"), From 039ec341110e00e6e10fa6c7b547c8d1cc9f3af6 Mon Sep 17 00:00:00 2001 From: only21mil Date: Sat, 31 Oct 2026 19:16:36 +0000 Subject: [PATCH 2/4] test(scripts): cover report:renders runs without ~/.cache Export runOnce and add one case that points HOME and TMPDIR at an empty temp dir and stubs only the spawned vitest run. It fails with ENOENT at mkdtemp on the old ~/.cache base, and checks that runOnce returns the parsed report and removes its report dir. Co-Authored-By: Claude Opus 5.5 --- scripts/render-metrics.test.ts | 39 ++++++++++++++++++++++++++++++++-- scripts/render-metrics.ts | 2 +- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/scripts/render-metrics.test.ts b/scripts/render-metrics.test.ts index 919ba77e5c366..91e627a7454dc 100644 --- a/scripts/render-metrics.test.ts +++ b/scripts/render-metrics.test.ts @@ -1,6 +1,41 @@ -import { describe, expect, it } from "vite-plus/test"; +import * as NodeFS from "node:fs"; +import * as NodeOS from "node:os"; +import * as NodePath from "node:path"; -import { nondeterministic, renderComparison } from "./render-metrics.ts"; +import { describe, expect, it, vi } from "vite-plus/test"; + +import { nondeterministic, renderComparison, runOnce } from "./render-metrics.ts"; + +const mountReport = { commits: 2, renders: 10, components: { Row: 10 } }; + +vi.mock("node:child_process", () => ({ + spawnSync: ( + _command: string, + _args: string[], + options: { env: { T3CODE_RENDER_REPORT_DIR: string } }, + ) => { + NodeFS.writeFileSync( + NodePath.join(options.env.T3CODE_RENDER_REPORT_DIR, "mount.json"), + JSON.stringify(mountReport), + ); + return { status: 0 }; + }, +})); + +describe("runOnce", () => { + it("collects the scenario reports when HOME has no .cache, then removes its report dir", () => { + const home = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "t3-render-metrics-")); + vi.stubEnv("HOME", home); + vi.stubEnv("TMPDIR", home); + try { + expect(runOnce()).toEqual({ mount: mountReport }); + expect(NodeFS.readdirSync(home)).toEqual([]); + } finally { + vi.unstubAllEnvs(); + NodeFS.rmSync(home, { recursive: true, force: true }); + } + }); +}); describe("nondeterministic", () => { it("names only the scenarios whose counts differ between runs", () => { diff --git a/scripts/render-metrics.ts b/scripts/render-metrics.ts index eea950557ba2e..4c9a81c2d8994 100644 --- a/scripts/render-metrics.ts +++ b/scripts/render-metrics.ts @@ -37,7 +37,7 @@ export type RenderMetrics = Readonly>; const root = NodePath.resolve(import.meta.dirname, ".."); -function runOnce(): RenderMetrics { +export function runOnce(): RenderMetrics { const directory = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "t3-renders-")); try { const result = NodeChildProcess.spawnSync("vp", ["test", "run", "--project", "renders"], { From f50f23b1926664fc574b6d022e54b8e68718e31a Mon Sep 17 00:00:00 2001 From: only21mil Date: Sat, 31 Oct 2026 19:18:18 +0000 Subject: [PATCH 3/4] test(scripts): allow node builtins in the render-metrics test The runOnce case uses node:fs and node:path on a real temp dir, like the other script tests, so turn off the Effect nodeBuiltinImport diagnostic for the file. Co-Authored-By: Claude Opus 5.5 --- scripts/render-metrics.test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/render-metrics.test.ts b/scripts/render-metrics.test.ts index 91e627a7454dc..4f36a2381df79 100644 --- a/scripts/render-metrics.test.ts +++ b/scripts/render-metrics.test.ts @@ -1,3 +1,4 @@ +// @effect-diagnostics nodeBuiltinImport:off - runOnce is a synchronous script, tested on a real temp dir. import * as NodeFS from "node:fs"; import * as NodeOS from "node:os"; import * as NodePath from "node:path"; From 9057866ec240bf84ddee8470d60f6cc4ce2ffc4f Mon Sep 17 00:00:00 2001 From: only21mil Date: Sat, 31 Oct 2026 19:37:35 +0000 Subject: [PATCH 4/4] test(scripts): isolate the render-metrics test home on Windows On Windows, os.homedir() reads USERPROFILE and os.tmpdir() reads TEMP then TMP, so stubbing only HOME and TMPDIR left the runOnce test on the real profile and temp dir there, and its cleanup check could pass without testing anything. Stub USERPROFILE, TEMP and TMP to the same empty dir too. Co-Authored-By: Claude Opus 5.5 --- scripts/render-metrics.test.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/render-metrics.test.ts b/scripts/render-metrics.test.ts index 4f36a2381df79..9ce66d27a9bde 100644 --- a/scripts/render-metrics.test.ts +++ b/scripts/render-metrics.test.ts @@ -28,6 +28,9 @@ describe("runOnce", () => { const home = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "t3-render-metrics-")); vi.stubEnv("HOME", home); vi.stubEnv("TMPDIR", home); + vi.stubEnv("USERPROFILE", home); + vi.stubEnv("TEMP", home); + vi.stubEnv("TMP", home); try { expect(runOnce()).toEqual({ mount: mountReport }); expect(NodeFS.readdirSync(home)).toEqual([]);