Open History to see the last commit
1import "vite-plus/test/config";
2import { defineConfig, mergeConfig } from "vite-plus";
3
4import baseConfig from "../../vite.config.ts";
5import { loadRepoEnv } from "../../scripts/lib/public-config.ts";
6import rootPackageJson from "../../package.json" with { type: "json" };
7import packageJson from "./package.json" with { type: "json" };
8import { WeightedShardSequencer } from "./src/testUtils/weightedShardSequencer.ts";
9
10// NSIS install time tracks file count, not bytes.
11import {
12 isExternalCliDependency,
13 shouldBundleCliDependency,
14} from "../../scripts/lib/cli-external-packages.ts";
15
16export { shouldBundleCliDependency };
17
18const repoEnv = loadRepoEnv();
19const cliBuildChannel = /^[^-+]+-(?:nightly|preview)\./.test(packageJson.version)
20 ? "nightly"
21 : "latest";
22// Official release workflows set the telemetry channel; local builds and forks use "dev".
23const TELEMETRY_CHANNELS = ["stable", "nightly", "preview", "dev"];
24const telemetryChannel = process.env.T3CODE_TELEMETRY_CHANNEL?.trim() || "dev";
25if (!TELEMETRY_CHANNELS.includes(telemetryChannel)) {
26 throw new Error(
27 `T3CODE_TELEMETRY_CHANNEL must be one of ${TELEMETRY_CHANNELS.join(", ")}, got "${telemetryChannel}".`,
28 );
29}
30
31// tsdown SEA needs one chunk (sourcemaps count) and Node >=25.7, so package separately.
32const packExecutable = process.env.T3CODE_PACK_EXE === "1";
33const SEA_TARGETS = {
34 "darwin-arm64": { platform: "darwin", arch: "arm64" },
35 "darwin-x64": { platform: "darwin", arch: "x64" },
36 "linux-arm64": { platform: "linux", arch: "arm64" },
37 "linux-x64": { platform: "linux", arch: "x64" },
38 "win-arm64": { platform: "win", arch: "arm64" },
39 "win-x64": { platform: "win", arch: "x64" },
40} as const;
41const packExecutableTarget = process.env.T3CODE_PACK_EXE_TARGET?.trim();
42const cliNodeVersion = rootPackageJson.engines.node;
43if (packExecutable && !packExecutableTarget && process.versions.node !== cliNodeVersion) {
44 throw new Error(
45 `Native CLI executables must be built with Node ${cliNodeVersion}; running ${process.versions.node}.`,
46 );
47}
48if (packExecutableTarget && !Object.hasOwn(SEA_TARGETS, packExecutableTarget)) {
49 throw new Error(
50 `T3CODE_PACK_EXE_TARGET must be one of ${Object.keys(SEA_TARGETS).join(", ")}, got "${packExecutableTarget}".`,
51 );
52}
53const packExecutableTargets = packExecutableTarget
54 ? [
55 {
56 ...SEA_TARGETS[packExecutableTarget as keyof typeof SEA_TARGETS],
57 nodeVersion: cliNodeVersion,
58 },
59 ]
60 : undefined;
61
62// The root config's `projects` route repo-root runs to package configs,
63// including this one. Inheriting them would make this config a container.
64const { projects: _rootTestProjects, ...baseTestConfig } = baseConfig.test ?? {};
65
66export default mergeConfig(
67 { ...baseConfig, test: baseTestConfig },
68 defineConfig({
69 run: {
70 tasks: {
71 build: {
72 command: "node scripts/cli.ts build",
73 dependsOn: ["@t3tools/web#build"],
74 cache: false,
75 },
76 },
77 },
78 pack: {
79 // SEA embeds one entry; expose the history worker as a hidden subcommand.
80 entry: packExecutable ? ["src/bin.ts"] : ["src/bin.ts", "src/claude-history-worker.ts"],
81 outDir: packExecutable ? "dist-exe" : "dist",
82 sourcemap: !packExecutable,
83 clean: true,
84 ...(packExecutable
85 ? {
86 exe: {
87 fileName: "t3",
88 outDir: "dist-exe",
89 ...(packExecutableTargets ? { targets: packExecutableTargets } : {}),
90 // Node SEA useCodeCache breaks import(), which the server needs.
91 seaConfig: { useCodeCache: false },
92 },
93 }
94 : {}),
95 deps: {
96 // alwaysBundle=false has no opinion; neverBundle must retain transitive native acceleration.
97 alwaysBundle: shouldBundleCliDependency,
98 neverBundle: (id: string) => isExternalCliDependency(id),
99 onlyBundle: false,
100 },
101 banner: {
102 js: "#!/usr/bin/env node\n",
103 },
104 define: {
105 __T3CODE_BUILD_CHANNEL__: JSON.stringify(cliBuildChannel),
106 __T3CODE_TELEMETRY_CHANNEL__: JSON.stringify(telemetryChannel),
107 __T3CODE_BUILD_RELAY_URL__: JSON.stringify(repoEnv.T3CODE_RELAY_URL?.trim() ?? ""),
108 __T3CODE_BUILD_CLERK_PUBLISHABLE_KEY__: JSON.stringify(
109 repoEnv.T3CODE_CLERK_PUBLISHABLE_KEY?.trim() ?? "",
110 ),
111 __T3CODE_BUILD_CLERK_CLI_OAUTH_CLIENT_ID__: JSON.stringify(
112 repoEnv.T3CODE_CLERK_CLI_OAUTH_CLIENT_ID?.trim() ?? "",
113 ),
114 __T3CODE_BUILD_RELAY_CLIENT_OTLP_TRACES_URL__: JSON.stringify(
115 repoEnv.T3CODE_RELAY_CLIENT_OTLP_TRACES_URL?.trim() ?? "",
116 ),
117 __T3CODE_BUILD_RELAY_CLIENT_OTLP_TRACES_DATASET__: JSON.stringify(
118 repoEnv.T3CODE_RELAY_CLIENT_OTLP_TRACES_DATASET?.trim() ?? "",
119 ),
120 __T3CODE_BUILD_RELAY_CLIENT_OTLP_TRACES_TOKEN__: JSON.stringify(
121 repoEnv.T3CODE_RELAY_CLIENT_OTLP_TRACES_TOKEN?.trim() ?? "",
122 ),
123 },
124 },
125 test: {
126 // Parallel sqlite/git/worktree/orchestration tests introduce load-sensitive flakes.
127 fileParallelism: false,
128 sequence: { sequencer: WeightedShardSequencer },
129 setupFiles: ["./src/testUtils/gitConfig.setup.ts"],
130 hookTimeout: 120_000,
131 testTimeout: 120_000,
132 },
133 }),
134);