Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

vite.config.ts

610 lines21.9 KB

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