test(start-plugin-core): cover whitespace-tolerant server fn filter #7281
main fromrefs/pull/7281/head·opened Summary#
- add regression coverage for the Start Vite server-fn transform code filter
- verify the filter still matches AST-roundtripped chains where
.andhandlerare split across lines - intentionally avoid matching the literal
createServerFnidentifier in the fixture so the.handlerregex path is exercised
Fixes #7280
Test plan#
CI=1 NX_DAEMON=false pnpm nx run @tanstack/start-plugin-core:test:unit --outputStyle=stream --skipRemoteCache -- tests/vite-start-compiler-plugin.test.tsCI=1 NX_DAEMON=false pnpm nx run @tanstack/start-plugin-core:test:unit --outputStyle=stream --skipRemoteCacheCI=1 NX_DAEMON=false pnpm nx run @tanstack/start-plugin-core:test:types --outputStyle=stream --skipRemoteCacheCI=1 NX_DAEMON=false pnpm nx run @tanstack/start-plugin-core:test:eslint --outputStyle=stream --skipRemoteCachepnpm prettier --check packages/start-plugin-core/tests/vite-start-compiler-plugin.test.tsgit diff --check
Summary by CodeRabbit#
- Tests
- Added test utilities for plugin instantiation across different environments (client and server-side rendering).
- Added test case verifying plugin correctly identifies and transforms server function code in various formatting scenarios.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: start-plugin-core
Bundle Size Benchmarks#
- Commit:
b0024d6310f1 - Measured at:
2026-04-28T14:14:12.443Z - Baseline source:
history:b0024d6310f1 - Dashboard: bundle-size history
Scenario Current (gzip) Delta vs baseline Raw Brotli Trend react-router.minimal87.30 KiB 0 B (0.00%) 274.68 KiB 75.83 KiB █████████▁▁ react-router.full90.80 KiB 0 B (0.00%) 286.19 KiB 79.00 KiB ▁▁▁▁▁▁▁▁▁██ solid-router.minimal35.55 KiB 0 B (0.00%) 106.95 KiB 31.97 KiB ▁▁▁▁▁████▁▁ solid-router.full40.28 KiB 0 B (0.00%) 121.16 KiB 36.16 KiB ▁▄▄▄▄▆███▆▆ vue-router.minimal53.30 KiB 0 B (0.00%) 152.09 KiB 47.88 KiB █████████▁▁ vue-router.full58.44 KiB 0 B (0.00%) 168.27 KiB 52.33 KiB ▁▁▁▁▁▁▁▁▁██ react-start.minimal101.92 KiB 0 B (0.00%) 322.84 KiB 88.06 KiB ▁▁▁▁▁▁▁▁▁██ react-start.full105.34 KiB 0 B (0.00%) 333.17 KiB 90.98 KiB █████████▁▁ react-start.rsbuild.minimal101.45 KiB 0 B (0.00%) 325.78 KiB 87.12 KiB ▁▁▁▁▁▁▁▁▁██ react-start.rsbuild.full104.76 KiB 0 B (0.00%) 336.47 KiB 89.88 KiB ▁▁▁▁▁▁▁▁▁██ solid-start.minimal49.55 KiB 0 B (0.00%) 152.77 KiB 43.68 KiB ▁▁▁▁▁████▂▂ solid-start.full55.33 KiB 0 B (0.00%) 169.68 KiB 48.71 KiB ▁▄▄▄▄▅███▆▆ Trend sparkline is historical gzip bytes ending with this PR measurement; lower is better.
- Commit:
🧹 Nitpick comments (1)
packages/start-plugin-core/tests/vite-start-compiler-plugin.test.ts (1)
21-38: Test helpers bypass type safety; consider safer alternatives toas anyand assertions.Lines 27, 31, and 35 use type bypasses (
as Array<Plugin>,!,as any) to work with Vite plugin shapes. While common in test code across this repo, these mask potential API changes and could benefit from safer patterns.A pragmatic middle ground: instead of complex refactoring, use non-null coalescing and optional chaining for the
matchesTransformCodeFilterhelper:function matchesTransformCodeFilter(plugin: Plugin, code: string) { - const include = (plugin.transform as any).filter.code.include as Array<RegExp> - - return include.some((pattern) => pattern.test(code)) + if (typeof plugin.transform === 'function') return false + const include = (plugin.transform as any)?.filter?.code?.include + return Array.isArray(include) && include.some((p) => p instanceof RegExp && p.test(code)) }For
getPerEnvironmentServerFnPlugin, theas Array<Plugin>cast is reasonable givenPluginOptionis a union; the non-null assertion is acceptable if the plugin is guaranteed to exist at that point. If uncertain, add a guard:- return plugins.find( + const plugin = plugins.find( (candidate) => candidate.name === `tanstack-start-core::server-fn:${name}`, - )! + ) + if (!plugin) throw new Error(`Plugin not found for ${name}`) + return plugin🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/start-plugin-core/tests/vite-start-compiler-plugin.test.ts` around lines 21 - 38, Replace unsafe casts and the non-null assertion in getPerEnvironmentServerFnPlugin and matchesTransformCodeFilter with guarded, typed access: keep the cast of startCompilerPlugin's result to Plugin[] if needed, but remove the trailing "!" in getPerEnvironmentServerFnPlugin and return/check the found plugin with a guard (throw or test assertion) if it is undefined; in matchesTransformCodeFilter avoid "as any" by reading the include array via optional chaining and a fallback (e.g. const include = (plugin.transform as unknown as { filter?: { code?: { include?: RegExp[] } } }).filter?.code?.include ?? []) so you never rely on non-null casts and then call include.some(...). This keeps tests safe without heavy refactors while making failures explicit.🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed. Nitpick comments: In `@packages/start-plugin-core/tests/vite-start-compiler-plugin.test.ts`: - Around line 21-38: Replace unsafe casts and the non-null assertion in getPerEnvironmentServerFnPlugin and matchesTransformCodeFilter with guarded, typed access: keep the cast of startCompilerPlugin's result to Plugin[] if needed, but remove the trailing "!" in getPerEnvironmentServerFnPlugin and return/check the found plugin with a guard (throw or test assertion) if it is undefined; in matchesTransformCodeFilter avoid "as any" by reading the include array via optional chaining and a fallback (e.g. const include = (plugin.transform as unknown as { filter?: { code?: { include?: RegExp[] } } }).filter?.code?.include ?? []) so you never rely on non-null casts and then call include.some(...). This keeps tests safe without heavy refactors while making failures explicit.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID:
11ad4868-1938-430a-bb6f-2152e049fe3e📥 Commits
Reviewing files that changed from the base of the PR and between b0024d6310f123736ea18a7f8692b45265cdee74 and 2d0bbc4f45e73591c2f79b76dac0af039a796822.
📒 Files selected for processing (1)
packages/start-plugin-core/tests/vite-start-compiler-plugin.test.ts
cyphercodes(GitHub profile, opens in a new tab) linked this to fix #7280
Sign in to join this conversation.
📝 Walkthrough
Walkthrough#
Adds test utilities to instantiate
startCompilerPluginfor specificclientvsssrenvironments and introspect the Vite transform filter's regexincludelist. Introduces a new test validating the filter's behavior with whitespace-sensitive server function code.Changes#
packages/start-plugin-core/tests/vite-start-compiler-plugin.test.ts.\nhandler(,.\nserver().Estimated code review effort#
🎯 1 (Trivial) | ⏱️ ~5 minutes
Poem#
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)#
✅ Passed checks (4 passed)
#7280, verifying the filter accepts AST-roundtripped code with whitespace between dot and method names.#7280.✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share