Open History to see the last commit
1import "vite-plus/test/config";
2import { defineConfig } from "vite-plus";
3import * as NodeURL from "node:url";
4import { remoteCacheUrl } from "./infra/task-cache/src/remoteCache.ts";
5import { cachedTestTasks } from "./scripts/lib/cached-tests.ts";
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 name: "react-native-screens",
44 importNames: ["ScrollViewMarker"],
45 message:
46 "Use NativeScrollViewMarker or NativeScrollView (src/native/NativeScrollViewMarker.tsx): they carry the header's scroll-edge blur under the Duo's vertical bar.",
47 },
48];
49
50const RESTRICTED_UI_VARIANT_PATTERNS = [
51 {
52 group: ["**/components/ui/*", "**/ui/*", "./ui/*"],
53 importNames: ["buttonVariants", "toggleVariants", "badgeVariants", "selectTriggerVariants"],
54 message:
55 "Render the components/ui export instead of borrowing its class recipe (render={<Button …/>}, SelectButton, ToggleGroup).",
56 },
57];
58
59const RESTRICTED_PULL_REQUEST_GLYPH_IMPORTS = {
60 name: "lucide-react",
61 importNames: [
62 "GitMerge",
63 "GitMergeIcon",
64 "GitPullRequest",
65 "GitPullRequestIcon",
66 "GitPullRequestArrow",
67 "GitPullRequestArrowIcon",
68 "GitPullRequestClosed",
69 "GitPullRequestClosedIcon",
70 "GitPullRequestDraft",
71 "GitPullRequestDraftIcon",
72 "GitPullRequestCreate",
73 "GitPullRequestCreateIcon",
74 "GitPullRequestCreateArrow",
75 "GitPullRequestCreateArrowIcon",
76 ],
77 message:
78 "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.",
79};
80
81// Vite+ supports remote configuration before its published types include it.
82const cacheUrl = remoteCacheUrl(import.meta.dirname);
83const taskCacheConfig = {
84 scripts: false,
85 ...(cacheUrl ? { remote: { url: cacheUrl } } : {}),
86};
87
88export default defineConfig({
89 run: {
90 cache: taskCacheConfig,
91 tasks: cachedTestTasks(process.env.T3_CACHED_TESTS),
92 },
93 resolve: {
94 alias: {
95 "~": NodeURL.fileURLToPath(new URL("./apps/web/src", import.meta.url)),
96 },
97 },
98 test: {
99 environment: "node",
100 // Fixture subprocesses must not inherit the outer task runner’s cache policy.
101 env: { VP_REMOTE_CACHE: "off", VP_REMOTE_CACHE_URL: "" },
102 exclude: TEST_EXCLUDE,
103 hookTimeout: 60_000,
104 testTimeout: 60_000,
105 allowOnly: !process.env.CI,
106 // Flaky tests are fixed, not retried.
107 retry: 0,
108 fakeTimers: {
109 toFake: [
110 "setTimeout",
111 "clearTimeout",
112 "setInterval",
113 "clearInterval",
114 "setImmediate",
115 "clearImmediate",
116 "Date",
117 "performance",
118 "requestAnimationFrame",
119 "cancelAnimationFrame",
120 "requestIdleCallback",
121 "cancelIdleCallback",
122 ],
123 },
124 setupFiles: [
125 NodeURL.fileURLToPath(
126 new URL("./packages/shared/src/testing/longTempDir.ts", import.meta.url),
127 ),
128 NodeURL.fileURLToPath(
129 new URL("./packages/shared/src/testing/providerEnv.ts", import.meta.url),
130 ),
131 ],
132 ...(isRepoRootTestRun
133 ? {
134 projects: [
135 ...TEST_CONFIG_PACKAGES,
136 {
137 extends: true,
138 test: {
139 name: "root",
140 exclude: [
141 ...TEST_EXCLUDE,
142 ...TEST_CONFIG_PACKAGES.map((dir) => `${dir}/**`),
143 "native/kde-snap-shot/**",
144 ],
145 },
146 },
147 ],
148 }
149 : {}),
150 },
151 staged: {
152 "*": "vp fmt --no-error-on-unmatched-pattern",
153 },
154 fmt: {
155 ignorePatterns: [
156 ".repos/**",
157 "infra/task-cache/vendor/**",
158 // Macroscope requires one glob per line; Markdown formatting corrupts it.
159 ".macroscope/ignore.md",
160 ".alchemy",
161 "dist",
162 "dist-electron",
163 "node_modules",
164 "pnpm-lock.yaml",
165 "*.tsbuildinfo",
166 "**/routeTree.gen.ts",
167 "**/*.graphql.ts",
168 "packages/source-control-github/schema/**",
169 "apps/server/schema/**",
170 "apps/mobile/android/**",
171 "apps/mobile/ios/**",
172 "apps/mobile/uniwind-types.d.ts",
173 // Vendored and generated C.
174 "apps/mobile/modules/t3-highlights/Vendor/**",
175 "apps/mobile/modules/t3-highlights/cpp/generated/**",
176 "*.icon/**",
177 ],
178 sortPackageJson: {},
179 overrides: [
180 {
181 files: [".devcontainer/devcontainer.json"],
182 options: {
183 trailingComma: "none",
184 },
185 },
186 ],
187 },
188 lint: {
189 ignorePatterns: [
190 ".repos",
191 ".repos/**",
192 "infra/task-cache/vendor/**",
193 "dist",
194 "dist-electron",
195 "node_modules",
196 "pnpm-lock.yaml",
197 "*.tsbuildinfo",
198 "**/routeTree.gen.ts",
199 "**/*.graphql.ts",
200 "packages/source-control-github/schema/**",
201 "apps/server/schema/**",
202 "apps/mobile/android/**",
203 "apps/mobile/ios/**",
204 "apps/mobile/uniwind-types.d.ts",
205 ],
206 plugins: ["eslint", "oxc", "react", "unicorn", "typescript"],
207 jsPlugins: ["./oxlint-plugin-t3code/index.ts", "@shadcn/lint"],
208 settings: {
209 shadcn: { ui: "~/components/ui" },
210 },
211 categories: {
212 correctness: "warn",
213 suspicious: "warn",
214 perf: "warn",
215 },
216 rules: {
217 "oxc/no-accumulating-spread": "error",
218 "eslint/no-control-regex": "off",
219 "typescript/no-this-alias": "off",
220 "unicorn/prefer-add-event-listener": "off",
221 "unicorn/prefer-string-starts-ends-with": "off",
222 "unicorn/prefer-set-has": "off",
223 "unicorn/prefer-array-find": "off",
224 "unicorn/no-new-array": "off",
225 "unicorn/no-array-reverse": "off",
226 "react/no-object-type-as-default-prop": "off",
227 "react/jsx-no-constructed-context-values": "off",
228 "react/memo-dependencies": "error",
229 "react/purity": "error",
230 "react/refs": "error",
231 "react/exhaustive-effect-dependencies": "error",
232 "react/set-state-in-effect": "error",
233 "react/immutability": "error",
234 "react/no-array-index-key": "error",
235 "react/no-unstable-nested-components": "error",
236 "react/static-components": "error",
237 "react/capitalized-calls": "error",
238 "typescript/no-extraneous-class": "error",
239 "eslint/no-empty-pattern": "error",
240 "eslint/no-new": "error",
241 "unicorn/no-useless-spread": "error",
242 "eslint/no-unused-vars": [
243 "error",
244 { argsIgnorePattern: "^_", varsIgnorePattern: "^_", caughtErrorsIgnorePattern: "^_" },
245 ],
246 "eslint/no-unsafe-optional-chaining": "error",
247 "eslint/no-unneeded-ternary": "error",
248 "unicorn/no-useless-fallback-in-spread": "error",
249 "unicorn/require-module-specifiers": "error",
250 "unicorn/no-array-sort": "off",
251 "unicorn/consistent-function-scoping": "off",
252 "oxc/no-map-spread": "off",
253 "react-in-jsx-scope": "off",
254 "react-hooks/exhaustive-deps": "off",
255 "eslint/no-shadow": "off",
256 "eslint/no-await-in-loop": "off",
257 "eslint/no-underscore-dangle": "off",
258 "typescript/consistent-return": "off",
259 "typescript/no-base-to-string": "off",
260 "typescript/no-duplicate-type-constituents": "off",
261 "typescript/no-floating-promises": "off",
262 "typescript/no-implied-eval": "off",
263 "typescript/no-meaningless-void-operator": "off",
264 "typescript/no-redundant-type-constituents": "off",
265 "typescript/no-unnecessary-boolean-literal-compare": "off",
266 "typescript/no-unnecessary-type-conversion": "off",
267 "typescript/no-unnecessary-type-arguments": "off",
268 "typescript/no-unnecessary-type-assertion": "off",
269 "typescript/no-unnecessary-type-parameters": "off",
270 "typescript/no-unsafe-type-assertion": "off",
271 "typescript/await-thenable": "off",
272 "typescript/require-array-sort-compare": "off",
273 "typescript/restrict-template-expressions": "off",
274 "typescript/unbound-method": "off",
275 "eslint/no-restricted-imports": [
276 "error",
277 { paths: [...RESTRICTED_IMPORT_PATHS, RESTRICTED_PULL_REQUEST_GLYPH_IMPORTS] },
278 ],
279 "t3code/no-global-process-runtime": "error",
280 "t3code/no-inline-schema-compile": "error",
281 "t3code/no-low-value-comments": "error",
282 "t3code/no-manual-effect-runtime-in-tests": "error",
283 "t3code/no-native-title-tooltip": "error",
284 // Test files only (the rule checks the filename).
285 "t3code/no-polling-loop-in-tests": "error",
286 "t3code/no-raw-mcp-registration": "error",
287 "t3code/no-real-time-wait-in-tests": "error",
288 "t3code/no-test-in-loop": "error",
289 "t3code/no-test-timeout-or-unreasoned-skip": "error",
290 "t3code/no-rpc-permission-bypass": ["error", { allowRawClientAccess: true }],
291 "t3code/no-unscoped-has": "error",
292 "t3code/no-wall-clock-in-tests": "error",
293 "t3code/namespace-node-imports": "error",
294 "t3code/prefer-catch-tags": "error",
295 "t3code/prefer-effect-fn": "error",
296 "t3code/require-centered-scroll-gutter": "error",
297 "t3code/require-suppression-reason": "error",
298 },
299 overrides: [
300 {
301 files: [
302 "**/*.{test,spec,testkit}.{ts,tsx}",
303 "**/{test,tests,testkit,testing,fixtures,integration}/**",
304 "packages/provider-testing/**",
305 ],
306 rules: { "t3code/prefer-effect-fn": "off" },
307 },
308 {
309 files: ["apps/web/**/*.test.{ts,tsx}"],
310 rules: { "t3code/require-disposable-render": "error" },
311 },
312 {
313 files: ["apps/web/src/**/*.browser.test.{ts,tsx}"],
314 rules: { "t3code/no-frame-waits-in-browser-tests": "error" },
315 },
316 {
317 files: ["apps/**/src/**", "packages/**/src/**"],
318 rules: { "t3code/no-dom-test-environment": "error" },
319 },
320 {
321 files: ["packages/client-runtime/src/state/**", "apps/{web,mobile,desktop}/src/**"],
322 rules: { "t3code/no-rpc-permission-bypass": ["error", { allowRawClientAccess: false }] },
323 },
324 {
325 files: [
326 "packages/client-runtime/src/state/runtime.ts",
327 "packages/client-runtime/src/state/vcsAction.ts",
328 ],
329 rules: {
330 "t3code/no-rpc-permission-bypass": [
331 "error",
332 { allowGuardInstallation: true, allowRawClientAccess: false },
333 ],
334 },
335 },
336 {
337 files: [
338 "apps/web/src/components/settings/AuthorizedClientsSettings.tsx",
339 "apps/mobile/src/features/updates/app-updates.ts",
340 "apps/web/src/components/device/DevicePhoneViewport.tsx",
341 "apps/web/src/components/device/DeviceDuoViewport.tsx",
342 ],
343 rules: { "t3code/no-rpc-permission-bypass": ["error", { allowRawClientAccess: true }] },
344 },
345 {
346 files: ["packages/client-runtime/src/connection/outdatedHostUpdate.ts"],
347 rules: { "t3code/no-rpc-permission-bypass": "off" },
348 },
349 {
350 files: [
351 "packages/client-runtime/src/rpc/**",
352 "**/*.{test,spec}.{ts,tsx,js,jsx,mts,cts,mjs,cjs}",
353 ],
354 rules: { "t3code/no-rpc-permission-bypass": "off" },
355 },
356 {
357 files: ["packages/shared/src/HostProcess.ts"],
358 rules: { "t3code/no-global-process-runtime": "off" },
359 },
360 {
361 // The `t3` npm launcher is published as plain, dependency-free Node.
362 files: ["scripts/npm-launcher/**"],
363 rules: {
364 "t3code/no-global-process-runtime": "off",
365 "t3code/namespace-node-imports": "off",
366 },
367 },
368 {
369 files: ["apps/server/src/mcp/McpHttpServer.ts"],
370 rules: { "t3code/no-raw-mcp-registration": "off" },
371 },
372 {
373 files: ["apps/web/src/**"],
374 excludeFiles: ["apps/web/src/components/ui/**"],
375 rules: {
376 "eslint/no-restricted-imports": [
377 "error",
378 {
379 paths: [...RESTRICTED_IMPORT_PATHS, RESTRICTED_PULL_REQUEST_GLYPH_IMPORTS],
380 patterns: RESTRICTED_UI_VARIANT_PATTERNS,
381 },
382 ],
383 },
384 },
385 {
386 files: ["apps/web/src/components/pullRequest/pullRequestIcons.tsx"],
387 rules: { "eslint/no-restricted-imports": ["error", { paths: RESTRICTED_IMPORT_PATHS }] },
388 },
389 {
390 // The server and every client load a forge's shared definition, so a UI runtime
391 // imported there would break the server; client-only forge code goes in `src/client/`.
392 files: ["packages/source-control-*/src/shared/**"],
393 rules: {
394 "eslint/no-restricted-imports": [
395 "error",
396 {
397 paths: [...RESTRICTED_IMPORT_PATHS, RESTRICTED_PULL_REQUEST_GLYPH_IMPORTS],
398 patterns: [
399 {
400 group: [
401 "react",
402 "react/*",
403 "react-*",
404 "expo",
405 "expo-*",
406 "lucide-react",
407 "@t3tools/client-runtime",
408 "@t3tools/client-runtime/*",
409 "../client/*",
410 "../server/*",
411 "../../client/*",
412 "../../server/*",
413 "../../../client/*",
414 "../../../server/*",
415 "@t3tools/source-control-*/client/*",
416 "@t3tools/source-control-*/server/*",
417 ],
418 message:
419 "Shared forge definitions load on the server and every client; keep UI and server code out.",
420 },
421 ],
422 },
423 ],
424 },
425 },
426 {
427 files: ["apps/server/src/**", "packages/source-control-*/src/server/**"],
428 rules: {
429 "eslint/no-restricted-imports": [
430 "error",
431 {
432 paths: [...RESTRICTED_IMPORT_PATHS, RESTRICTED_PULL_REQUEST_GLYPH_IMPORTS],
433 patterns: [
434 {
435 group: [
436 "@t3tools/source-control-*/client/*",
437 "../client/*",
438 "../../client/*",
439 "../../../client/*",
440 ],
441 message:
442 "A forge's client entry is UI-only; the server reads its `shared/definition`.",
443 },
444 ],
445 },
446 ],
447 },
448 },
449 {
450 files: ["apps/mobile/src/**"],
451 rules: {
452 "t3code/no-mobile-uniwind-theme-escape-hatches": "error",
453 "t3code/require-registered-list-scroll": "error",
454 },
455 },
456 {
457 files: ["apps/mobile/src/**"],
458 excludeFiles: [
459 "apps/mobile/src/components/ui/AppSymbol.tsx",
460 "apps/mobile/src/components/ui/AppSymbol.ios.tsx",
461 "apps/mobile/src/features/pull-requests/pullRequestGlyphs.ts",
462 ],
463 rules: { "t3code/no-mobile-pull-request-glyph-literals": "error" },
464 },
465 {
466 files: ["apps/mobile/src/**"],
467 excludeFiles: ["**/*.test.{ts,tsx}"],
468 rules: { "t3code/no-ambiguous-detail-navigation": "error" },
469 },
470 {
471 // Raw ResizeObserver state commits miss the paint; observeResize flushes derived layout together.
472 files: ["apps/web/src/**"],
473 excludeFiles: [
474 "apps/web/src/lib/observeResize.ts",
475 "**/*.{test,spec}.{ts,tsx,js,jsx,mts,cts,mjs,cjs}",
476 ],
477 rules: { "t3code/no-raw-resize-observer": "error" },
478 },
479 {
480 files: ["apps/web/src/**"],
481 rules: { "shadcn/no-unknown-classes": "error" },
482 },
483 {
484 files: ["apps/web/src/**"],
485 rules: { "t3code/no-outset-state-indicators": "error" },
486 },
487 {
488 files: ["apps/*/src/**", "packages/*/src/**"],
489 excludeFiles: [
490 "**/*.{test,spec}.{ts,tsx,js,jsx,mts,cts,mjs,cjs}",
491 "**/testkit/**",
492 "**/_generated/**",
493 // Real user quotes stay verbatim.
494 "apps/marketing/src/lib/tweets.ts",
495 ],
496 rules: { "t3code/no-em-dash-copy": "error" },
497 },
498 {
499 files: ["apps/web/src/**"],
500 rules: { "shadcn/no-raw-colors": "error" },
501 },
502 {
503 // Third-party marks must retain their exact colors.
504 files: ["apps/web/src/components/Icons.tsx", "apps/web/src/components/JetBrainsIcons.tsx"],
505 rules: { "shadcn/no-raw-colors": "off" },
506 },
507 {
508 files: ["apps/web/src/**"],
509 excludeFiles: ["apps/web/src/components/ui/**"],
510 rules: {
511 "shadcn/require-static-classes": "error",
512 "shadcn/no-arbitrary-values": [
513 "error",
514 {
515 allow: [
516 "layout",
517 "transition",
518 "rounded-[inherit]",
519 "gap-[0.33em]",
520 "gap-[0.2em]",
521 "leading-[normal]",
522 "underline-offset-[0.2em]",
523 "rounded-[25%]",
524 "text-[length:80cqh]",
525 "bg-[Highlight]",
526 "fill-[#26251E]",
527 "fill-[#EDECEC]",
528 "fill-[#0F0F0F]",
529 "fill-[#F5F5F5]",
530 "fill-[#d97757]",
531 "text-[#d97757]",
532 ],
533 },
534 ],
535 "shadcn/no-restyle": [
536 "error",
537 {
538 allow: ["layout"],
539 contracts: [
540 {
541 // CollapsibleTrigger has no styled counterpart; other triggers use render={<Button …/>}.
542 pattern: "^CollapsibleTrigger$",
543 allow: ["layout", "color", "typography", "spacing", "shape", "effects", "motion"],
544 },
545 ],
546 },
547 ],
548 },
549 },
550 {
551 // React Compiler owns memoization; upstream rules do not ban redundant useMemo/useCallback.
552 files: ["apps/web/src/**/*.{ts,tsx}"],
553 rules: {
554 "react/exhaustive-effect-dependencies": "error",
555 "react/globals": "error",
556 "react/hooks": "error",
557 "react/immutability": "error",
558 // The compiler memoizes context values; this rule would ask for useMemo.
559 "react/jsx-no-constructed-context-values": "off",
560 "react/memo-dependencies": "error",
561 "react/preserve-manual-memoization": "error",
562 // Render-time clock reads use @t3tools/client-runtime/clock or state seeded with the
563 // time; any other read carries a suppression that says why. oxlint also flags time reads
564 // inside event handlers (oxc#27309); those suppressions cite it.
565 "react/purity": "error",
566 "react/refs": "error",
567 "react/set-state-in-effect": "error",
568 "react/set-state-in-render": "error",
569 "react/static-components": "error",
570 "react/unsupported-syntax": "error",
571 "t3code/no-manual-memo": "error",
572 },
573 },
574 {
575 // ESNext types allow APIs absent from Hermes; restrict shared client code, exempting Node tests.
576 files: [
577 "apps/mobile/src/**",
578 "packages/client-runtime/src/**",
579 "packages/contracts/src/**",
580 "packages/shared/src/**",
581 ],
582 excludeFiles: ["**/*.test.ts", "**/*.test.tsx"],
583 rules: { "t3code/no-hermes-unsupported-apis": "error" },
584 },
585 {
586 // Directives hide bailouts from mobile's compiler-coverage check; retain hooks until its allowlist is empty.
587 files: ["apps/mobile/src/**/*.{ts,tsx}"],
588 rules: { "t3code/no-manual-memo": ["error", { allowMemoHooks: true }] },
589 },
590 {
591 files: ["apps/web/src/**", "apps/mobile/src/**", "packages/*/src/**"],
592 rules: { "t3code/no-unreasoned-state-sync": "error" },
593 },
594 {
595 // React Compiler caches use* functions only if they call a hook.
596 files: ["apps/web/src/**/*.{ts,tsx}", "apps/mobile/src/**/*.{ts,tsx}"],
597 excludeFiles: ["**/*.test.ts", "**/*.test.tsx"],
598 rules: { "t3code/no-hookless-use-function": "error" },
599 },
600 {
601 files: [
602 "apps/mobile/src/features/archive/ArchivedThreadsScreen.tsx",
603 "apps/mobile/src/features/connection/ConnectionsNewRouteScreen.tsx",
604 "apps/mobile/src/features/files/FileMarkdownPreview.tsx",
605 "apps/mobile/src/features/files/SourceFileSurface.tsx",
606 "apps/mobile/src/features/files/AttachmentFileScreen.tsx",
607 "apps/mobile/src/features/files/ThreadFilesRouteScreen.tsx",
608 "apps/mobile/src/features/files/thread-file-navigator-pane.tsx",
609 "apps/mobile/src/features/review/ReviewSheet.tsx",
610 "apps/mobile/src/features/review/useNativeReviewDiffBridge.ts",
611 "apps/mobile/src/features/settings/SettingsEnvironmentsRouteScreen.tsx",
612 "apps/mobile/src/features/threads/ThreadComposer.tsx",
613 "apps/mobile/src/features/threads/ThreadFeed.tsx",
614 "apps/mobile/src/features/threads/ThreadQueueControl.tsx",
615 "apps/mobile/src/features/review/ReviewCommentCard.tsx",
616 "apps/mobile/src/features/threads/ThreadSettingsSheet.tsx",
617 "apps/mobile/src/features/threads/thread-list-v2-items.tsx",
618 "apps/mobile/src/lib/useMobileNavigationTheme.ts",
619 "apps/mobile/src/native/T3ComposerEditor.ios.tsx",
620 "apps/mobile/src/native/T3ComposerEditor.native.tsx",
621 "apps/mobile/src/native/SelectableMarkdownText.tsx",
622 "apps/mobile/src/native/useEnrichedLinkVariants.ts",
623 ],
624 rules: {
625 "t3code/no-mobile-uniwind-theme-escape-hatches": ["error", { allowUniwindTheme: true }],
626 },
627 },
628 ],
629 options: {
630 reportUnusedDisableDirectives: "error",
631 typeAware: false,
632 typeCheck: false,
633 },
634 },
635});