@devries-cameron20 / t3code-1 / commits / 8f66e67de3
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

test: local test runs use package configs and a clean env (#22714)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Theo Browne committed Oct 21, 2026 at 00:42 UTC 8f66e67de35ee42bc26d081d894f8c5eee6edf17
8 files changed +114 -13
apps/desktop/vite.config.ts
+4 -1
@@ -150,6 +150,9 @@ export default defineConfig({
150 // The Windows lane runs workspace suites concurrently; filesystem-heavy
151 // desktop integration tests can exceed Vitest's 5 second default there.
152 testTimeout: 15_000,
153 - setupFiles: ["../../packages/shared/src/testing/longTempDir.ts"],
153 + setupFiles: [
154 + "../../packages/shared/src/testing/longTempDir.ts",
155 + "../../packages/shared/src/testing/providerEnv.ts",
156 + ],
157 },
158 });
apps/mobile/vite.config.ts
+5 -1
@@ -20,7 +20,10 @@ export default defineConfig({
20 name: "unit",
21 include: ["**/*.test.{ts,tsx,mjs}"],
22 exclude: ["**/node_modules/**", ...reactTests],
23 - setupFiles: ["../../packages/shared/src/testing/longTempDir.ts"],
23 + setupFiles: [
24 + "../../packages/shared/src/testing/longTempDir.ts",
25 + "../../packages/shared/src/testing/providerEnv.ts",
26 + ],
27 },
28 },
29 {
@@ -30,6 +33,7 @@ export default defineConfig({
33 include: reactTests,
34 // Native components mock React Native and render through react-dom in these tests.
35 environment: "jsdom",
36 + setupFiles: ["../../packages/shared/src/testing/providerEnv.ts"],
37 },
38 },
39 ],
apps/server/src/testUtils/gitConfig.setup.ts
+27
@@ -1,3 +1,9 @@
1 +// @effect-diagnostics nodeBuiltinImport:off - runs once at test setup, outside any Effect runtime.
2 +import * as NodeChildProcess from "node:child_process";
3 +import * as NodeFS from "node:fs";
4 +import * as NodePath from "node:path";
5 +import * as HostProcess from "@t3tools/shared/HostProcess";
6 +
7 // Git for Windows installs with core.autocrlf=true, which checks committed LF
8 // files out as CRLF and breaks every byte-exact content assertion; a signing
9 // key or a non-default init branch on the developer's machine breaks fixtures
@@ -18,3 +24,24 @@ entries.forEach(([key, value], index) => {
24 process.env[`GIT_CONFIG_KEY_${existing + index}`] = key;
25 process.env[`GIT_CONFIG_VALUE_${existing + index}`] = value;
26 });
27 +
28 +// Without Homebrew git, macOS resolves `git` to /usr/bin/git, an xcrun shim that costs
29 +// about 8 ms per spawn against 3 ms for the real binary. Git-heavy files such as
30 +// GitVcsDriverCore.test.ts and GitManager.test.ts run twice as fast with the real one.
31 +if (HostProcess.Platform.defaultValue() === "darwin") {
32 + const gitOnPath = (process.env.PATH ?? "")
33 + .split(NodePath.delimiter)
34 + .map((dir) => NodePath.join(dir, "git"))
35 + .find((candidate) => NodeFS.existsSync(candidate));
36 + if (gitOnPath === "/usr/bin/git") {
37 + try {
38 + const realGit = NodeChildProcess.execFileSync("xcrun", ["-f", "git"], {
39 + encoding: "utf8",
40 + stdio: ["ignore", "pipe", "ignore"],
41 + }).trim();
42 + if (NodePath.isAbsolute(realGit)) {
43 + process.env.PATH = `${NodePath.dirname(realGit)}${NodePath.delimiter}${process.env.PATH}`;
44 + }
45 + } catch {}
46 + }
47 +}
apps/server/vite.config.ts
+5 -1
@@ -58,8 +58,12 @@ const packExecutableTargets = packExecutableTarget
58 ]
59 : undefined;
60
61 +// The root config's `projects` route repo-root runs to package configs,
62 +// including this one. Inheriting them would make this config a container.
63 +const { projects: _rootTestProjects, ...baseTestConfig } = baseConfig.test ?? {};
64 +
65 export default mergeConfig(
62 - baseConfig,
66 + { ...baseConfig, test: baseTestConfig },
67 defineConfig({
68 run: {
69 tasks: {
apps/web/vite.config.ts
+4 -1
@@ -80,7 +80,10 @@ const unitTestProject = {
80 exclude: ["src/**/*.browser.test.{ts,tsx}"],
81 hookTimeout: 15_000,
82 testTimeout: 15_000,
83 - setupFiles: ["../../packages/shared/src/testing/longTempDir.ts"],
83 + setupFiles: [
84 + "../../packages/shared/src/testing/longTempDir.ts",
85 + "../../packages/shared/src/testing/providerEnv.ts",
86 + ],
87 },
88 } satisfies TestProjectInlineConfiguration;
89
packages/client-runtime/vite.config.ts
+1 -1
@@ -5,6 +5,6 @@ export default defineConfig({
5 test: {
6 environment: "node",
7 include: ["src/**/*.test.ts"],
8 - setupFiles: ["../shared/src/testing/longTempDir.ts"],
8 + setupFiles: ["../shared/src/testing/longTempDir.ts", "../shared/src/testing/providerEnv.ts"],
9 },
10 });
packages/shared/src/testing/providerEnv.ts new
+22
@@ -0,0 +1,22 @@
1 +// Agent shells carry real provider credentials (CLIProxy sets ANTHROPIC_AUTH_TOKEN and
2 +// ANTHROPIC_BASE_URL) and the agent's own T3 state. Tests that read the ambient environment
3 +// then pass or fail by who runs them. Tests that need one of these variables set it
4 +// themselves. Set T3CODE_TEST_KEEP_PROVIDER_ENV=1 to keep them, for example for a live run.
5 +const PROVIDER_ENV_PREFIXES = ["ANTHROPIC_", "CLAUDE_", "CODEX_", "OPENAI_", "T3CODE_"];
6 +
7 +const KEPT_ENV = new Set([
8 + // CI sets these so the transfer budget integration test writes its report for the job summary.
9 + "T3CODE_TRANSFER_BUDGET_REPORT_PATH",
10 + "T3CODE_TRANSFER_BUDGET_RESULT_PATH",
11 + // Opt-in: points the HtmlRender tests at a headless browser, which they skip without.
12 + "T3CODE_TEST_HEADLESS_SHELL",
13 +]);
14 +
15 +if (process.env.T3CODE_TEST_KEEP_PROVIDER_ENV !== "1") {
16 + for (const key of Object.keys(process.env)) {
17 + if (KEPT_ENV.has(key)) continue;
18 + if (PROVIDER_ENV_PREFIXES.some((prefix) => key.startsWith(prefix))) {
19 + delete process.env[key];
20 + }
21 + }
22 +}
vite.config.ts
+46 -8
@@ -4,6 +4,30 @@ import * as NodeURL from "node:url";
4
5 const DOM_TEST_ENVIRONMENT_ALLOWLIST: Array<string> = [];
6
7 +const TEST_EXCLUDE = [
8 + "**/.repos/**",
9 + "**/.t3/**",
10 + "**/node_modules/**",
11 + "**/dist/**",
12 + "**/dist-electron/**",
13 + "**/.{idea,git,cache,output,temp}/**",
14 +];
15 +
16 +// Directories whose tests belong to a package's own test config. desktop also
17 +// owns the kde-snap-shot tests through its `include`.
18 +const TEST_CONFIG_PACKAGES = [
19 + "apps/desktop",
20 + "apps/mobile",
21 + "apps/server",
22 + "apps/web",
23 + "packages/client-runtime",
24 +];
25 +
26 +// `vp test run <file>` from the repo root hands each file to its package's
27 +// config. Packages that borrow this config (`--config ../../vite.config.ts`) run
28 +// from their own directory, as CI does, so they keep one plain project.
29 +const isRepoRootTestRun = process.cwd() === import.meta.dirname;
30 +
31 const RESTRICTED_IMPORT_PATHS = [
32 {
33 name: "@t3tools/client-runtime",
@@ -56,14 +80,7 @@ export default defineConfig({
80 },
81 test: {
82 environment: "node",
59 - exclude: [
60 - "**/.repos/**",
61 - "**/.t3/**",
62 - "**/node_modules/**",
63 - "**/dist/**",
64 - "**/dist-electron/**",
65 - "**/.{idea,git,cache,output,temp}/**",
66 - ],
83 + exclude: TEST_EXCLUDE,
84 hookTimeout: 60_000,
85 testTimeout: 60_000,
86 allowOnly: !process.env.CI,
@@ -89,7 +106,28 @@ export default defineConfig({
106 NodeURL.fileURLToPath(
107 new URL("./packages/shared/src/testing/longTempDir.ts", import.meta.url),
108 ),
109 + NodeURL.fileURLToPath(
110 + new URL("./packages/shared/src/testing/providerEnv.ts", import.meta.url),
111 + ),
112 ],
113 + ...(isRepoRootTestRun
114 + ? {
115 + projects: [
116 + ...TEST_CONFIG_PACKAGES,
117 + {
118 + extends: true,
119 + test: {
120 + name: "root",
121 + exclude: [
122 + ...TEST_EXCLUDE,
123 + ...TEST_CONFIG_PACKAGES.map((dir) => `${dir}/**`),
124 + "native/kde-snap-shot/**",
125 + ],
126 + },
127 + },
128 + ],
129 + }
130 + : {}),
131 },
132 staged: {
133 "*": "vp fmt --no-error-on-unmatched-pattern",