Skip to content
Source
Sign inSign up
TanStack/router

test(start-plugin-core): cover whitespace-tolerant server fn filter #7281

Opencyphercodes(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/7281/headopened

Summary

  • add regression coverage for the Start Vite server-fn transform code filter
  • verify the filter still matches AST-roundtripped chains where . and handler are split across lines
  • intentionally avoid matching the literal createServerFn identifier in the fixture so the .handler regex 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.ts
  • CI=1 NX_DAEMON=false pnpm nx run @tanstack/start-plugin-core:test:unit --outputStyle=stream --skipRemoteCache
  • CI=1 NX_DAEMON=false pnpm nx run @tanstack/start-plugin-core:test:types --outputStyle=stream --skipRemoteCache
  • CI=1 NX_DAEMON=false pnpm nx run @tanstack/start-plugin-core:test:eslint --outputStyle=stream --skipRemoteCache
  • pnpm prettier --check packages/start-plugin-core/tests/vite-start-compiler-plugin.test.ts
  • git 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

    2. 📝 Walkthrough

      Walkthrough

      Adds test utilities to instantiate startCompilerPlugin for specific client vs ssr environments and introspect the Vite transform filter's regex include list. Introduces a new test validating the filter's behavior with whitespace-sensitive server function code.

      Changes

      Cohort / File(s)Summary
      Test Utilities & Filter Validation
      packages/start-plugin-core/tests/vite-start-compiler-plugin.test.ts
      Added helper functions to instantiate the compiler plugin for different environments and inspect filter regexes. Introduced test case asserting the transform filter correctly matches server function code containing whitespace between dot and method names (e.g., .\nhandler(, .\nserver().

      Estimated code review effort

      🎯 1 (Trivial) | ⏱️ ~5 minutes

      Poem

      🐰 With whiskers twitching, I spy the test, Whitespace between dots? My regex knows best! No more shall filters silently fail, When .server() wraps a newline tale! ✨

      🚥 Pre-merge checks | ✅ 4 | ❌ 1

      ❌ Failed checks (1 warning)

      Check nameStatusExplanationResolution
      Docstring Coverage⚠️ WarningDocstring coverage is 0.00% which is insufficient. The required threshold is 80.00%.Write docstrings for the functions missing them to satisfy the coverage threshold.
      ✅ Passed checks (4 passed)
      Check nameStatusExplanation
      Description Check✅ PassedCheck skipped - CodeRabbit’s high-level summary is enabled.
      Title check✅ PassedThe title accurately describes the main change: adding test coverage for the whitespace-tolerant server function filter in the start-plugin-core package.
      Linked Issues check✅ PassedThe PR adds regression tests for the whitespace-tolerant server function filter described in issue #7280, verifying the filter accepts AST-roundtripped code with whitespace between dot and method names.
      Out of Scope Changes check✅ PassedAll changes are scoped to test-file-local helper functions and test cases in the test file, directly addressing the whitespace-filter regression test objective from issue #7280.
      ✏️ Tip: You can configure your own custom pre-merge checks in the settings.
      ✨ Finishing Touches
      🧪 Generate unit tests (beta)
      • Create PR with unit tests

      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
      Comment `@coderabbitai help` to get the list of available commands and usage tips.
    3. Bundle Size Benchmarks

      • Commit: b0024d6310f1
      • Measured at: 2026-04-28T14:14:12.443Z
      • Baseline source: history:b0024d6310f1
      • Dashboard: bundle-size history
      ScenarioCurrent (gzip)Delta vs baselineRawBrotliTrend
      react-router.minimal87.30 KiB0 B (0.00%)274.68 KiB75.83 KiB█████████▁▁
      react-router.full90.80 KiB0 B (0.00%)286.19 KiB79.00 KiB▁▁▁▁▁▁▁▁▁██
      solid-router.minimal35.55 KiB0 B (0.00%)106.95 KiB31.97 KiB▁▁▁▁▁████▁▁
      solid-router.full40.28 KiB0 B (0.00%)121.16 KiB36.16 KiB▁▄▄▄▄▆███▆▆
      vue-router.minimal53.30 KiB0 B (0.00%)152.09 KiB47.88 KiB█████████▁▁
      vue-router.full58.44 KiB0 B (0.00%)168.27 KiB52.33 KiB▁▁▁▁▁▁▁▁▁██
      react-start.minimal101.92 KiB0 B (0.00%)322.84 KiB88.06 KiB▁▁▁▁▁▁▁▁▁██
      react-start.full105.34 KiB0 B (0.00%)333.17 KiB90.98 KiB█████████▁▁
      react-start.rsbuild.minimal101.45 KiB0 B (0.00%)325.78 KiB87.12 KiB▁▁▁▁▁▁▁▁▁██
      react-start.rsbuild.full104.76 KiB0 B (0.00%)336.47 KiB89.88 KiB▁▁▁▁▁▁▁▁▁██
      solid-start.minimal49.55 KiB0 B (0.00%)152.77 KiB43.68 KiB▁▁▁▁▁████▂▂
      solid-start.full55.33 KiB0 B (0.00%)169.68 KiB48.71 KiB▁▄▄▄▄▅███▆▆

      Trend sparkline is historical gzip bytes ending with this PR measurement; lower is better.

    4. 🧹 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 to as any and 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 matchesTransformCodeFilter helper:

      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, the as Array<Plugin> cast is reasonable given PluginOption is 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

Sign in to join this conversation.