Repository navigation
fix(sonar): count tests as tests, fix open issues, raise coverage - #515
Conversation
There was a problem hiding this comment.
Changes requested: one blocking config issue in sonar-project.properties.
The refactors (ReDoS-safe trimTrailing and tag stripping, createTransport extraction in the HTTP transport, tightened extractBearer) and the new tests look correct, and Test & Build passes. The SonarQube check was skipped on this PR, so nothing has verified the Sonar config yet.
Blocking
- blocking
sonar-project.properties:1: Main and test source sets overlap.sonar.sources=packages,scriptsandsonar.tests=packages, andsonar.test.inclusionsnarrows only the test set. Every**/__tests__/**file is indexed as both main and test, so the scanner aborts with "File ... can't be indexed twice. Please check that inclusion/exclusion patterns produce disjoint sets for main and test files". Even without the abort, tests would still count as source, which is what this PR is meant to fix. Fix: addsonar.exclusions=**/__tests__/**,**/dist/**so the main set leaves out the tests and any built output underpackages/*/dist.
Suggestions
- suggestion
packages/mcp-core/src/__tests__/trim.test.ts:19: the< 500mscheck here and the< 1000mscheck inpackages/mcp/src/tools/__tests__/docs-html-strip.test.ts:29depend on runner speed, and coverage instrumentation slows them further. The inputs are large enough that a quadratic regression would take seconds, so the margin is wide. Optional: keep them, or use a much larger input where only quadratic behaviour would time out the test.
Formal verification
Nothing to prove. The diff touches no Rust (no *.rs, Cargo.toml or Cargo.lock), so Kani has nothing in scope and no harnesses were written. trimTrailing, the new extractBearer regex and the docs-html tag stripping are candidates for fast-check property tests in a separate effort.
|
Timing assertions removed; the large inputs stay, so a quadratic regression would hit the test timeout. On sonar-project.properties: the scan action passes -Dsonar.exclusions on the command line (the shared workflow's default, which already covers dist), and command-line properties override the file, so adding sonar.exclusions there would be dead config. Overlapping sources and tests with sonar.test.inclusions is the documented pattern for colocated tests. The scan is skipped on PRs, so I can't verify it here; I'll check the first analysis on main and follow up if the scanner reports the files twice. |
There was a problem hiding this comment.
Blocking (still stands, fix revised): You're right that -Dsonar.exclusions on the command line overrides the file, so my suggested line would be dead config. But that default list (reusable-sonarqube-scan.yml, exclusions input) has no **/__tests__/**, so the main set still contains every test file. sonar.test.inclusions only filters the test side. The documented colocated-tests pattern pairs it with a main-side exclusion of the same glob, and without one the scanner aborts with "can't be indexed twice".
Waiting for the first analysis on main is costly here. The sonarqube job is part of the test reusable call, and release requires needs.test.result == 'success', so a scanner abort blocks the release on main.
Suggested fix: since the file can't carry exclusions, add a sonar-exclusions input to FerrLabs/.github reusable-ci-node.yml that is forwarded as exclusions: to the scan workflow. Then pass the default list plus **/__tests__/** from ci.yml. That's a cross-repo change, but it is the only place the setting takes effect.
There was a problem hiding this comment.
Changes requested. The code changes are sound, but sonar-project.properties will make the Sonar scanner fail once this lands on main.
Blocking
sonar-project.properties:1(blocking):sonar.sources=packages,scriptsandsonar.tests=packagesboth indexpackages/.sonar.test.inclusionsonly narrows the test set, so every**/__tests__/**file also stays in the main set. The scanner then aborts with "File ... can't be indexed twice. Please check that inclusion/exclusion patterns produce disjoint sets for main and test files". The SonarQube job is skipped onpull_request(reusable-ci-node.yml:github.event_name != 'pull_request'), so this PR's CI cannot catch it and it will fail after the merge to main. Fix: addsonar.exclusions=**/__tests__/**so the two sets are disjoint.
Suggestions
packages/mcp-core/src/auth/__tests__/oauth-flow.test.ts:200(suggestion): the spawn mock assignsstubbedUrlbefore thelet stubbedUrlline. It works because the closure runs later, but it reads like a TDZ bug. Move the declaration above thespawnMock.mockImplementationcall.
Review summary
The code changes (trimTrailing, the linear tag stripping in docs-html.ts, the createTransport extraction in transports/http.ts, the tightened bearer regex) are correct, and CI tests pass.
Formal verification
Nothing to prove. The PR touches no Rust source, so no Kani harness was built or run (0 harnesses). The new TypeScript logic is covered by example-based vitest tests added in this PR; nothing was formally proved.
|
Dropped sonar.tests. With only sonar.sources plus sonar.test.inclusions, each file is indexed once and typed as test when it matches the pattern, so the main and test sets can no longer overlap and no main-side exclusion is needed. Also moved the stubbedUrl declaration above its use. |
There was a problem hiding this comment.
Blocking (still stands, in a new form): sonar-project.properties. Dropping sonar.tests stops the "indexed twice" abort, but it also stops tests from being counted as tests. sonar.test.inclusions does not decide whether a file is a test. It only narrows the set that sonar.tests defines. With sonar.tests unset that set is empty, and the scan workflow doesn't pass -Dsonar.tests either. So every **/__tests__/** file is still indexed as main source with 0% coverage, which is the bug #502 asks to fix.
Fix: put sonar.tests=packages back and add a main-side exclusion for the same glob. The file can't hold that exclusion, because -Dsonar.exclusions on the command line overrides it. The same problem applies to sonar.test.exclusions, so that's no way around it. The exclusion has to come from CI: add an input to reusable-ci-node.yml that forwards to the scan's exclusions, and have ci.yml pass the default list plus **/__tests__/**.
The stubbedUrl declaration now comes before its use in oauth-flow.test.ts (3fc5da4). Fixed.
|
Agreed: sonar.tests is back. Without a main-side exclusion of /tests/ the scan would abort on main, and the file cannot carry it because the CLI -Dsonar.exclusions wins. The shared workflow needs a sonar-exclusions input (proposed for FerrLabs/.github). Auto-merge is off until that lands; then this PR repins the workflow and passes the default list plus /tests/ from ci.yml. |
There was a problem hiding this comment.
Changes requested. One blocking issue in the new Sonar config; the code changes themselves look correct.
Blocking
-
sonar-project.properties:3Test files are indexed as both main sources and tests.sonar.sources=packages,scriptsandsonar.tests=packagesoverlap, andsonar.test.inclusionsonly narrows the test set. Every**/__tests__/**file therefore stays in the main set too, and the scanner stops withFile ... can't be indexed twice. Sonar needs disjoint sets, so the main side needs a matching exclusion. TheTest / SonarQubejob was skipped on this PR, so CI has not exercised this config and the quality gate this PR targets would not run on main. Fix:sonar.test.inclusions=**/__tests__/** sonar.exclusions=**/__tests__/**
Suggestions
packages/mcp-core/src/trim.ts:1(suggestion)trimTrailingsilently returns its input unchanged whencharis longer than one character, because it compares one character at a time. All current callers pass a single character, so nothing is broken today. Consider a guard such asif (char.length !== 1) throw new RangeError('trimTrailing expects a single character');.
Review summary
The stripTags, trimTrailing, bearer regex and http.ts refactor changes are correct, and the new tests pass in CI.
Formal verification
Nothing to prove. The diff touches no Rust source (it changes TypeScript, tests, Sonar and vitest config), so no Kani harness was built or run. No harnesses, properties or counterexamples.
|
Blocking item is already tracked: sonar.exclusions in the file is overridden by the CLI default, so the main-side exclusion comes from the new sonar-exclusions input in FerrLabs/.github#441 (FerrLabs/.github#441). Once it merges this PR repins and passes the list from ci.yml; auto-merge stays off until then. trimTrailing keeps its single-character contract, all callers pass one char and a runtime guard would be unused code. |
|
FerrLabs/.github#441 merged (0e16caa). ci.yml is repinned to it and passes sonar-exclusions with the default list plus /tests/, so the main and test sets are disjoint. Auto-merge is back on. |
| packages: read | ||
| name: Test | ||
| uses: FerrLabs/.github/.github/workflows/reusable-ci-node.yml@0a075f35954063ac01310b4e01543fd7009916e4 # main | ||
| uses: FerrLabs/.github/.github/workflows/reusable-ci-node.yml@0e16caae3fc74c1a9683f085b69dc31ab8161cd0 # main |
| contents: write | ||
| id-token: write | ||
| uses: FerrLabs/.github/.github/workflows/reusable-ferrflow-release.yml@0a075f35954063ac01310b4e01543fd7009916e4 # main | ||
| uses: FerrLabs/.github/.github/workflows/reusable-ferrflow-release.yml@0e16caae3fc74c1a9683f085b69dc31ab8161cd0 # main |
There was a problem hiding this comment.
The Sonar blocking finding is fixed in 3648af4. ci.yml now pins reusable-ci-node.yml at 0e16caa, which is the merge commit of FerrLabs/.github#441 and matches current main. It passes sonar-exclusions as the default list plus **/__tests__/**, and that value is forwarded as -Dsonar.exclusions. The main and test sets are now disjoint, and sonar.tests=packages still classifies the tests. My last review's suggestion to put sonar.exclusions in the properties file was wrong, because the CLI flag overrides it.
Dropping the trimTrailing guard is fine.
There was a problem hiding this comment.
Blocking finding on sonar-project.properties fixed in 3648af4. ci.yml pins reusable-ci-node.yml@0e16caa, which forwards sonar-exclusions to the scan's exclusions. With **/__tests__/** there, the main set is packages,scripts minus __tests__ and the test set is packages limited to __tests__. The two sets are now disjoint, and tests are classified as tests.
The Sonar job still doesn't run on PRs, so the first scan on main is what will confirm this. Test & Build was still running when I reviewed.
## [10.17.2] - 2026-11-27 ### Bug Fixes - fix(sonar): count tests as tests, fix open issues, raise coverage (#515)
There was a problem hiding this comment.
Not approved: failed step(s): verify.
Approve. The code review found only nits and Test & Build is green. The ReDoS-prone regexes are replaced with linear equivalents that behave the same, the http.ts refactor preserves session behaviour, and the Sonar and coverage config separates tests from sources correctly.
Findings
- Suggestion
packages/mcp-core/src/trim.ts:1:trimTrailingcompares one code unit (value[end - 1] === char), so acharlonger than one character never matches and the call silently does nothing. It is now public API exported from mcp-core. Rename the parameter to make the single-character contract explicit, or throw whenchar.length !== 1. - Suggestion
.github/workflows/ci.yml:34:sonar-exclusionsreplaces the reusable workflow's default list, so the defaults were copied here just to add**/__tests__/**. If the shared default changes, this copy drifts. Acceptable for now. Longer term, add anextra-exclusionsinput toreusable-ci-node.ymlthat is appended to the default list.
Formal verification: that step failed and returned no result, so nothing is reported from it.
Closes #502
Coverage locally: 94% lines (was 75% reported, 36% in Sonar).