Skip to content

Keep test-only source out of the published build - #218

Merged
wpak-ai merged 2 commits into
cppalliance:mainfrom
timon0305:fix/tsconfig-exclude-test-code-217
Jul 15, 2026
Merged

Keep test-only source out of the published build#218
wpak-ai merged 2 commits into
cppalliance:mainfrom
timon0305:fix/tsconfig-exclude-test-code-217

Conversation

@timon0305

@timon0305 timon0305 commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator

Closes #217

The tsconfig exclude pointed at a stale path (src/server/tools/test-helpers.ts), but the file lives at src/core/server/tools/test-helpers.ts. Because the glob never matched, tsc compiled it into dist/. Scoping that out surfaced a second leak: config-branding.compile-test.ts also shipped, since its -test.ts name is not caught by **/*.test.ts.

What changed

Split the build config from the typecheck config. tsconfig.build.json excludes all test code by pattern (**/*.test.ts, **/*.compile-test.ts, **/test-helpers.ts, **/__tests__/**), so it stays correct if files move. The base tsconfig.json still type-checks the .compile-test.ts brand guards, which is their whole purpose. build and build:watch now run -p tsconfig.build.json.

Added a regression test that asks tsc which files the build config compiles (--listFilesOnly) and fails if any test module survives. It also asserts a real source file is present so it cannot pass on an empty program.

Verification

  • Clean build: 50 source JS files, zero test artifacts in dist/.
  • Typecheck still covers the compile-test guards.
  • Lint, format:check, and the full suite (367 tests) pass.

Summary by CodeRabbit

  • Build Improvements

    • Updated production builds to use a dedicated TypeScript build configuration and clean dist before compiling.
    • Ensured test-only files and development helpers are excluded from production build output.
    • Updated build watch mode to track the production build TypeScript configuration.
  • Tests

    • Added an automated check that verifies test-only modules are not compiled into the production build, while confirming the main app entry point is included.

The tsconfig exclude pointed at a stale path (src/server/tools/test-helpers.ts),
so the real file (src/core/server/tools/test-helpers.ts) and the *.compile-test.ts
brand guards were compiled into dist/ and shipped in the package.

Split the build config from the typecheck config: tsconfig.build.json excludes all
test code by pattern (won't rot if files move), while the base tsconfig still
type-checks the compile-test guards. build/build:watch now use -p tsconfig.build.json.

Adds a regression test that asks tsc which files the build config compiles and
fails if any test module survives.
@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 176001ac-3894-43b6-8cbe-9ee0afc43e86

📥 Commits

Reviewing files that changed from the base of the PR and between 56dda47 and 7c653f9.

📒 Files selected for processing (2)
  • src/__tests__/build-excludes-test-code.test.ts
  • tsconfig.build.json
🚧 Files skipped from review as they are similar to previous changes (1)
  • tsconfig.build.json

📝 Walkthrough

Walkthrough

The PR adds tsconfig.build.json with test-source exclusions, updates build scripts to use it, removes an incorrect base-config exclusion, and adds a Vitest check for test-file leakage.

Changes

Build configuration and validation

Layer / File(s) Summary
Dedicated build configuration and scripts
tsconfig.json, tsconfig.build.json, package.json
Build and watch commands now use tsconfig.build.json, which excludes test-only sources and build artifacts.
Test-source exclusion verification
src/__tests__/build-excludes-test-code.test.ts
The test lists compiled files, confirms src/index.ts is included, and rejects test-only modules from the build input set.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: wpak-ai

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: keeping test-only source out of the published build.
Linked Issues check ✅ Passed The changes address #217 by adding build-specific exclusions and a regression test that prevents test-only files from entering dist.
Out of Scope Changes check ✅ Passed The diff stays focused on build exclusion fixes and verification, with no obvious unrelated code changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Jul 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (main@02014e0). Learn more about missing BASE report.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #218   +/-   ##
=======================================
  Coverage        ?   85.07%           
=======================================
  Files           ?       46           
  Lines           ?     2399           
  Branches        ?      826           
=======================================
  Hits            ?     2041           
  Misses          ?      357           
  Partials        ?        1           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread src/__tests__/build-excludes-test-code.test.ts
…in sync

Cross-reference tsconfig.build.json's exclude and the TEST_CODE regexes in
build-excludes-test-code.test.ts so a new test-only suffix gets added in both.
@wpak-ai
wpak-ai merged commit 9ef2938 into cppalliance:main Jul 15, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tsconfig exclude ships test-helpers into the published dist

3 participants