Open History to see the last commit
1import "vite-plus/test/config";
2import { defineConfig } from "vite-plus";
3import * as NodeURL from "node:url";
4
5const DOM_TEST_ENVIRONMENT_ALLOWLIST: Array<string> = [];
6
7const 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`.
18const 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.
29const isRepoRootTestRun = process.cwd() === import.meta.dirname;
30
31const RESTRICTED_IMPORT_PATHS = [
32 {
33 name: "@t3tools/client-runtime",
34 message:
35 "Import from an explicit @t3tools/client-runtime/* subpath. The package has no root export.",
36 },
37 {
38 name: "@pierre/diffs/react",
39 importNames: ["CodeView"],
40 message: "Use StyledDiffCodeView so web diff surfaces share styling and virtualized geometry.",
41 },
42];
43
44const RESTRICTED_UI_VARIANT_PATTERNS = [
45 {
46 group: ["**/components/ui/*", "**/ui/*", "./ui/*"],
47 importNames: ["buttonVariants", "toggleVariants", "badgeVariants", "selectTriggerVariants"],
48 message:
49 "Render the components/ui export instead of borrowing its class recipe (render={<Button …/>}, SelectButton, ToggleGroup).",
50 },
51];
52
53const RESTRICTED_PULL_REQUEST_GLYPH_IMPORTS = {
54 name: "lucide-react",
55 importNames: [
56 "GitMerge",
57 "GitMergeIcon",
58 "GitPullRequest",
59 "GitPullRequestIcon",
60 "GitPullRequestArrow",
61 "GitPullRequestArrowIcon",
62 "GitPullRequestClosed",
63 "GitPullRequestClosedIcon",
64 "GitPullRequestDraft",
65 "GitPullRequestDraftIcon",
66 "GitPullRequestCreate",
67 "GitPullRequestCreateIcon",
68 "GitPullRequestCreateArrow",
69 "GitPullRequestCreateArrowIcon",
70 ],
71 message:
72 "Pick a glyph by meaning from PullRequestGlyph in apps/web/src/components/pullRequest/pullRequestIcons.tsx so every surface draws the same pull request the same way.",
73};
74
75export default defineConfig({
76 resolve: {
77 alias: {
78 "~": NodeURL.fileURLToPath(new URL("./apps/web/src", import.meta.url)),
79 },
80 },
81 test: {
82 environment: "node",
83 exclude: TEST_EXCLUDE,
84 hookTimeout: 60_000,
85 testTimeout: 60_000,
86 allowOnly: !process.env.CI,
87 // Flaky tests are fixed, not retried.
88 retry: 0,
89 fakeTimers: {
90 toFake: [
91 "setTimeout",
92 "clearTimeout",
93 "setInterval",
94 "clearInterval",
95 "setImmediate",
96 "clearImmediate",
97 "Date",
98 "performance",
99 "requestAnimationFrame",
100 "cancelAnimationFrame",
101 "requestIdleCallback",
102 "cancelIdleCallback",
103 ],
104 },
105 setupFiles: [
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",
134 },
135 fmt: {
136 ignorePatterns: [
137 ".repos/**",
138 // Macroscope's glob-per-line ignore grammar, not Markdown: formatting
139 // it rewrites `*` as `_` and joins lines.
140 ".macroscope/ignore.md",
141 ".alchemy",
142 "dist",
143 "dist-electron",
144 "node_modules",
145 "pnpm-lock.yaml",
146 "*.tsbuildinfo",
147 "**/routeTree.gen.ts",
148 "**/*.graphql.ts",
149 "packages/source-control-github/schema/**",
150 "apps/server/schema/**",
151 "apps/mobile/android/**",
152 "apps/mobile/ios/**",
153 "apps/mobile/uniwind-types.d.ts",
154 // Vendored and generated C.
155 "apps/mobile/modules/t3-highlights/Vendor/**",
156 "apps/mobile/modules/t3-highlights/cpp/generated/**",
157 "*.icon/**",
158 ],
159 sortPackageJson: {},
160 overrides: [
161 {
162 files: [".devcontainer/devcontainer.json"],
163 options: {
164 trailingComma: "none",
165 },
166 },
167 ],
168 },
169 lint: {
170 ignorePatterns: [
171 ".repos",
172 ".repos/**",
173 "dist",
174 "dist-electron",
175 "node_modules",
176 "pnpm-lock.yaml",
177 "*.tsbuildinfo",
178 "**/routeTree.gen.ts",
179 "**/*.graphql.ts",
180 "packages/source-control-github/schema/**",
181 "apps/server/schema/**",
182 "apps/mobile/android/**",
183 "apps/mobile/ios/**",
184 "apps/mobile/uniwind-types.d.ts",
185 ],
186 plugins: ["eslint", "oxc", "react", "unicorn", "typescript"],
187 jsPlugins: ["./oxlint-plugin-t3code/index.ts", "@shadcn/lint"],
188 settings: {
189 shadcn: { ui: "~/components/ui" },
190 },
191 categories: {
192 correctness: "warn",
193 suspicious: "warn",
194 perf: "warn",
195 },
196 rules: {
197 "unicorn/no-array-sort": "off",
198 "unicorn/consistent-function-scoping": "off",
199 "oxc/no-map-spread": "off",
200 "react-in-jsx-scope": "off",
201 "react-hooks/exhaustive-deps": "off",
202 "eslint/no-shadow": "off",
203 "eslint/no-await-in-loop": "off",
204 "eslint/no-underscore-dangle": "off",
205 "typescript/consistent-return": "off",
206 "typescript/no-base-to-string": "off",
207 "typescript/no-duplicate-type-constituents": "off",
208 "typescript/no-floating-promises": "off",
209 "typescript/no-implied-eval": "off",
210 "typescript/no-meaningless-void-operator": "off",
211 "typescript/no-redundant-type-constituents": "off",
212 "typescript/no-unnecessary-boolean-literal-compare": "off",
213 "typescript/no-unnecessary-type-conversion": "off",
214 "typescript/no-unnecessary-type-arguments": "off",
215 "typescript/no-unnecessary-type-assertion": "off",
216 "typescript/no-unnecessary-type-parameters": "off",
217 "typescript/no-unsafe-type-assertion": "off",
218 "typescript/await-thenable": "off",
219 "typescript/require-array-sort-compare": "off",
220 "typescript/restrict-template-expressions": "off",
221 "typescript/unbound-method": "off",
222 "eslint/no-restricted-imports": [
223 "error",
224 { paths: [...RESTRICTED_IMPORT_PATHS, RESTRICTED_PULL_REQUEST_GLYPH_IMPORTS] },
225 ],
226 "t3code/no-global-process-runtime": "error",
227 "t3code/no-inline-schema-compile": "warn",
228 "t3code/no-low-value-comments": "error",
229 "t3code/no-manual-effect-runtime-in-tests": "error",
230 "t3code/no-native-title-tooltip": "error",
231 // Test files only (the rule checks the filename).
232 "t3code/no-polling-loop-in-tests": "error",
233 "t3code/no-raw-mcp-registration": "error",
234 "t3code/no-real-time-wait-in-tests": "error",
235 "t3code/no-test-in-loop": "error",
236 "t3code/no-test-timeout-or-unreasoned-skip": "error",
237 "t3code/no-rpc-permission-bypass": ["error", { allowRawClientAccess: true }],
238 "t3code/no-unscoped-has": "error",
239 "t3code/no-wall-clock-in-tests": "error",
240 "t3code/namespace-node-imports": "error",
241 "t3code/prefer-catch-tags": "error",
242 "t3code/prefer-effect-fn": "error",
243 "t3code/require-centered-scroll-gutter": "error",
244 "t3code/require-suppression-reason": "error",
245 },
246 overrides: [
247 {
248 files: [
249 "**/*.{test,spec,testkit}.{ts,tsx}",
250 "**/{test,tests,testkit,testing,fixtures,integration}/**",
251 "packages/provider-testing/**",
252 ],
253 rules: { "t3code/prefer-effect-fn": "off" },
254 },
255 {
256 files: ["apps/web/**/*.test.{ts,tsx}"],
257 rules: { "t3code/require-disposable-render": "error" },
258 },
259 {
260 files: ["apps/web/src/**/*.browser.test.{ts,tsx}"],
261 rules: { "t3code/no-frame-waits-in-browser-tests": "error" },
262 },
263 {
264 // Burn-down list: these files still have polling loops, so they stay at "warn".
265 // Remove a file when you convert its loops. New polling loops in all other
266 // test files fail lint. Do not add new files to this list.
267 files: [
268 "apps/mobile/src/features/agent-awareness/remoteRegistration.test.ts",
269 "apps/server/src/background/HostPowerMonitor.test.ts",
270 "apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts",
271 "apps/server/src/orchestration-v2/FoundationPersistence.test.ts",
272 "apps/server/src/project/ProjectEnrichmentService.test.ts",
273 "apps/server/src/project/ProjectService.test.ts",
274 "apps/server/src/scheduledTasks/ScheduledTaskService.webhook.test.ts",
275 "apps/server/src/usage/UsageService.test.ts",
276 "packages/client-runtime/src/connection/supervisor.test.ts",
277 "packages/client-runtime/src/rpc/client.test.ts",
278 "packages/client-runtime/src/rpc/session.test.ts",
279 "packages/client-runtime/src/state/shell-sync.test.ts",
280 "packages/client-runtime/src/state/threads-sync.test.ts",
281 "packages/shared/src/atomicWrite.test.ts",
282 ],
283 rules: { "t3code/no-polling-loop-in-tests": "warn" },
284 },
285 {
286 files: ["apps/**/src/**", "packages/**/src/**"],
287 excludeFiles: DOM_TEST_ENVIRONMENT_ALLOWLIST,
288 rules: { "t3code/no-dom-test-environment": "error" },
289 },
290 {
291 files: ["packages/client-runtime/src/state/**", "apps/{web,mobile,desktop}/src/**"],
292 rules: { "t3code/no-rpc-permission-bypass": ["error", { allowRawClientAccess: false }] },
293 },
294 {
295 files: [
296 "packages/client-runtime/src/state/runtime.ts",
297 "packages/client-runtime/src/state/vcsAction.ts",
298 ],
299 rules: {
300 "t3code/no-rpc-permission-bypass": [
301 "error",
302 { allowGuardInstallation: true, allowRawClientAccess: false },
303 ],
304 },
305 },
306 {
307 files: [
308 "apps/web/src/components/settings/AuthorizedClientsSettings.tsx",
309 "apps/web/src/components/settings/ConnectionsSettings.tsx",
310 "apps/mobile/src/features/updates/app-updates.ts",
311 "apps/web/src/components/device/DevicePhoneViewport.tsx",
312 "apps/web/src/components/device/DeviceDuoViewport.tsx",
313 ],
314 rules: { "t3code/no-rpc-permission-bypass": ["error", { allowRawClientAccess: true }] },
315 },
316 {
317 files: ["packages/client-runtime/src/connection/outdatedHostUpdate.ts"],
318 rules: { "t3code/no-rpc-permission-bypass": "off" },
319 },
320 {
321 files: [
322 "packages/client-runtime/src/rpc/**",
323 "**/*.{test,spec}.{ts,tsx,js,jsx,mts,cts,mjs,cjs}",
324 ],
325 rules: { "t3code/no-rpc-permission-bypass": "off" },
326 },
327 {
328 files: ["packages/shared/src/HostProcess.ts"],
329 rules: { "t3code/no-global-process-runtime": "off" },
330 },
331 {
332 // The `t3` npm launcher is published as plain, dependency-free Node.
333 files: ["scripts/npm-launcher/**"],
334 rules: {
335 "t3code/no-global-process-runtime": "off",
336 "t3code/namespace-node-imports": "off",
337 },
338 },
339 {
340 files: ["apps/server/src/mcp/McpHttpServer.ts"],
341 rules: { "t3code/no-raw-mcp-registration": "off" },
342 },
343 {
344 files: ["apps/web/src/**"],
345 excludeFiles: ["apps/web/src/components/ui/**"],
346 rules: {
347 "eslint/no-restricted-imports": [
348 "error",
349 {
350 paths: [...RESTRICTED_IMPORT_PATHS, RESTRICTED_PULL_REQUEST_GLYPH_IMPORTS],
351 patterns: RESTRICTED_UI_VARIANT_PATTERNS,
352 },
353 ],
354 },
355 },
356 {
357 files: ["apps/web/src/components/pullRequest/pullRequestIcons.tsx"],
358 rules: { "eslint/no-restricted-imports": ["error", { paths: RESTRICTED_IMPORT_PATHS }] },
359 },
360 {
361 // The server and every client load a forge's shared definition, so a UI runtime
362 // imported there would break the server; client-only forge code goes in `src/client/`.
363 files: ["packages/source-control-*/src/shared/**"],
364 rules: {
365 "eslint/no-restricted-imports": [
366 "error",
367 {
368 paths: [...RESTRICTED_IMPORT_PATHS, RESTRICTED_PULL_REQUEST_GLYPH_IMPORTS],
369 patterns: [
370 {
371 group: [
372 "react",
373 "react/*",
374 "react-*",
375 "expo",
376 "expo-*",
377 "lucide-react",
378 "@t3tools/client-runtime",
379 "@t3tools/client-runtime/*",
380 "../client/*",
381 "../server/*",
382 "../../client/*",
383 "../../server/*",
384 "../../../client/*",
385 "../../../server/*",
386 "@t3tools/source-control-*/client/*",
387 "@t3tools/source-control-*/server/*",
388 ],
389 message:
390 "Shared forge definitions load on the server and every client; keep UI and server code out.",
391 },
392 ],
393 },
394 ],
395 },
396 },
397 {
398 files: ["apps/server/src/**", "packages/source-control-*/src/server/**"],
399 rules: {
400 "eslint/no-restricted-imports": [
401 "error",
402 {
403 paths: [...RESTRICTED_IMPORT_PATHS, RESTRICTED_PULL_REQUEST_GLYPH_IMPORTS],
404 patterns: [
405 {
406 group: [
407 "@t3tools/source-control-*/client/*",
408 "../client/*",
409 "../../client/*",
410 "../../../client/*",
411 ],
412 message:
413 "A forge's client entry is UI-only; the server reads its `shared/definition`.",
414 },
415 ],
416 },
417 ],
418 },
419 },
420 {
421 files: ["apps/mobile/src/**"],
422 rules: { "t3code/no-mobile-uniwind-theme-escape-hatches": "error" },
423 },
424 {
425 files: ["apps/mobile/src/**"],
426 excludeFiles: [
427 "apps/mobile/src/components/ui/AppSymbol.tsx",
428 "apps/mobile/src/components/ui/AppSymbol.ios.tsx",
429 "apps/mobile/src/features/pull-requests/pullRequestGlyphs.ts",
430 ],
431 rules: { "t3code/no-mobile-pull-request-glyph-literals": "error" },
432 },
433 {
434 // React commits state set in a raw ResizeObserver callback after the paint, so derived
435 // layout lands a frame late. observeResize flushes every observed resize in one render.
436 files: ["apps/web/src/**"],
437 excludeFiles: [
438 "apps/web/src/lib/observeResize.ts",
439 "**/*.{test,spec}.{ts,tsx,js,jsx,mts,cts,mjs,cjs}",
440 ],
441 rules: { "t3code/no-raw-resize-observer": "error" },
442 },
443 {
444 files: ["apps/web/src/**"],
445 rules: { "shadcn/no-unknown-classes": "error" },
446 },
447 {
448 files: ["apps/web/src/**"],
449 rules: { "t3code/no-outset-state-indicators": "error" },
450 },
451 {
452 files: ["apps/*/src/**", "packages/*/src/**"],
453 excludeFiles: [
454 "**/*.{test,spec}.{ts,tsx,js,jsx,mts,cts,mjs,cjs}",
455 "**/testkit/**",
456 "**/_generated/**",
457 // Real user quotes stay verbatim.
458 "apps/marketing/src/lib/tweets.ts",
459 ],
460 rules: { "t3code/no-em-dash-copy": "error" },
461 },
462 {
463 files: ["apps/web/src/**"],
464 rules: { "shadcn/no-raw-colors": "error" },
465 },
466 {
467 // Third-party marks (brand logos, the macOS permission panes, Codex's Computer Use
468 // mark) must keep their exact colors, so the files that hold them are exempt.
469 files: ["apps/web/src/components/Icons.tsx", "apps/web/src/components/JetBrainsIcons.tsx"],
470 rules: { "shadcn/no-raw-colors": "off" },
471 },
472 {
473 files: ["apps/web/src/**"],
474 excludeFiles: ["apps/web/src/components/ui/**"],
475 rules: {
476 "shadcn/require-static-classes": "error",
477 "shadcn/no-arbitrary-values": [
478 "error",
479 {
480 allow: [
481 "layout",
482 "transition",
483 "rounded-[inherit]",
484 "gap-[0.33em]",
485 "px-[0.5em]",
486 "rounded-[0.5em]",
487 "text-[0.86em]",
488 "rounded-[25%]",
489 "text-[length:80cqh]",
490 "bg-[Highlight]",
491 "fill-[#26251E]",
492 "fill-[#EDECEC]",
493 "fill-[#0F0F0F]",
494 "fill-[#F5F5F5]",
495 "fill-[#d97757]",
496 "text-[#d97757]",
497 ],
498 },
499 ],
500 "shadcn/no-restyle": [
501 "error",
502 {
503 allow: ["layout"],
504 contracts: [
505 {
506 // CollapsibleTrigger is a bare button with no styled counterpart
507 // (a disclosure row is not a Button), so its className is the API.
508 // Every other trigger has one: style them with render={<Button …/>}.
509 pattern: "^CollapsibleTrigger$",
510 allow: ["layout", "color", "typography", "spacing", "shape", "effects", "motion"],
511 },
512 ],
513 },
514 ],
515 },
516 },
517 {
518 // Every web file must compile under the React Compiler. Its bailout rules are errors here,
519 // and manual memoization is redundant. No upstream rule bans useMemo/useCallback, hence
520 // t3code/no-manual-memo.
521 files: ["apps/web/src/**/*.{ts,tsx}"],
522 rules: {
523 "react/exhaustive-effect-dependencies": "error",
524 "react/globals": "error",
525 "react/hooks": "error",
526 "react/immutability": "error",
527 // The compiler memoizes context values; this rule would ask for useMemo.
528 "react/jsx-no-constructed-context-values": "off",
529 "react/memo-dependencies": "error",
530 "react/preserve-manual-memoization": "error",
531 // oxlint 1.88 treats `new Date()` as impure (oxc#26894) and also flags it inside event
532 // handlers (oxc#27309). The compiler we ship (oxc-transform-react) still compiles
533 // those files, and reactCompilerCoverage.test.ts fails on real bailouts.
534 "react/purity": "warn",
535 "react/refs": "error",
536 "react/set-state-in-effect": "error",
537 "react/set-state-in-render": "error",
538 "react/static-components": "error",
539 "react/unsupported-syntax": "error",
540 "t3code/no-manual-memo": "error",
541 },
542 },
543 {
544 // The sign-in masthead is T3 brand artwork: fixed gradients, not theme surfaces.
545 files: ["apps/web/src/components/auth/AuthSurfaceShell.tsx"],
546 rules: { "shadcn/no-arbitrary-values": "off" },
547 },
548 {
549 // Shared client code must not call APIs missing from Hermes. Our ESNext
550 // TypeScript target accepts them even when they would crash mobile at launch.
551 // Tests run on Node and are exempt.
552 files: [
553 "apps/mobile/src/**",
554 "packages/client-runtime/src/**",
555 "packages/contracts/src/**",
556 "packages/shared/src/**",
557 ],
558 excludeFiles: ["**/*.test.ts", "**/*.test.tsx"],
559 rules: { "t3code/no-hermes-unsupported-apis": "error" },
560 },
561 {
562 // Mobile is ratcheting toward full React Compiler coverage
563 // (apps/mobile/src/reactCompilerCoverage.test.ts). Directives would hide bailouts from it;
564 // the manual memo hooks go once the allowlist there is empty.
565 files: ["apps/mobile/src/**/*.{ts,tsx}"],
566 rules: { "t3code/no-manual-memo": ["error", { allowMemoHooks: true }] },
567 },
568 {
569 // The compiler only compiles a use* function that calls a hook; one that calls none is
570 // silently left as a plain function, so whatever it returns loses its caching.
571 files: ["apps/web/src/**/*.{ts,tsx}", "apps/mobile/src/**/*.{ts,tsx}"],
572 excludeFiles: ["**/*.test.ts", "**/*.test.tsx"],
573 rules: { "t3code/no-hookless-use-function": "error" },
574 },
575 {
576 files: [
577 "apps/mobile/src/features/archive/ArchivedThreadsScreen.tsx",
578 "apps/mobile/src/features/connection/ConnectionsNewRouteScreen.tsx",
579 "apps/mobile/src/features/files/FileMarkdownPreview.tsx",
580 "apps/mobile/src/features/files/SourceFileSurface.tsx",
581 "apps/mobile/src/features/files/AttachmentFileScreen.tsx",
582 "apps/mobile/src/features/files/ThreadFilesRouteScreen.tsx",
583 "apps/mobile/src/features/files/thread-file-navigator-pane.tsx",
584 "apps/mobile/src/features/home/HomeHeader.tsx",
585 "apps/mobile/src/features/review/ReviewSheet.tsx",
586 "apps/mobile/src/features/review/useNativeReviewDiffBridge.ts",
587 "apps/mobile/src/features/settings/SettingsEnvironmentsRouteScreen.tsx",
588 "apps/mobile/src/features/threads/GitActionProgressOverlay.tsx",
589 "apps/mobile/src/features/threads/NewTaskDraftScreen.tsx",
590 "apps/mobile/src/features/threads/ThreadComposer.tsx",
591 "apps/mobile/src/features/threads/ThreadFeed.tsx",
592 "apps/mobile/src/features/settings/appearance/components/FontSizeSliderRow.tsx",
593 "apps/mobile/src/features/threads/NewTaskContextPickerScreens.tsx",
594 "apps/mobile/src/features/threads/ThreadQueueControl.tsx",
595 "apps/mobile/src/features/review/ReviewCommentCard.tsx",
596 "apps/mobile/src/features/threads/ThreadSettingsSheet.tsx",
597 "apps/mobile/src/features/threads/thread-list-items.tsx",
598 "apps/mobile/src/features/threads/thread-list-v2-items.tsx",
599 "apps/mobile/src/lib/useMobileNavigationTheme.ts",
600 "apps/mobile/src/native/T3ComposerEditor.ios.tsx",
601 "apps/mobile/src/native/T3ComposerEditor.native.tsx",
602 "apps/mobile/src/native/SelectableMarkdownText.tsx",
603 "apps/mobile/src/native/useEnrichedLinkVariants.ts",
604 ],
605 rules: {
606 "t3code/no-mobile-uniwind-theme-escape-hatches": ["error", { allowUniwindTheme: true }],
607 },
608 },
609 ],
610 options: {
611 reportUnusedDisableDirectives: "error",
612 typeAware: false,
613 typeCheck: false,
614 },
615 },
616});