Skip to content

fix(sonar): count tests as tests, fix open issues, raise coverage - #515

Merged
BryanFRD merged 6 commits into
mainfrom
fix/502-sonar-quality-gate
Nov 27, 2026
Merged

BryanFRD merged 6 commits into
mainfrom
fix/502-sonar-quality-gate

Conversation

@BryanFRD

Copy link
Copy Markdown
Contributor

Closes #502

  • Add sonar-project.properties so test files are analysed as tests instead of 0%-covered sources.
  • Include every source file in the vitest coverage report so untested files count.
  • Fix the 9 open Sonar issues: super-linear regexes (validate.ts, http.ts, docs-html.ts), cognitive complexity (handleMcpRequest, smoke.ts), nested template literal (issues.ts).
  • Add tests for the mcp tools, resources, register/index, OAuth loopback flow, persistence, stdio, HTTP sessions and bearer parsing.

Coverage locally: 94% lines (was 75% reported, 36% in Sonar).

@BryanFRD
BryanFRD enabled auto-merge (squash) November 27, 2026 15:38

@ferrfleet-interne ferrfleet-interne Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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,scripts and sonar.tests=packages, and sonar.test.inclusions narrows 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: add sonar.exclusions=**/__tests__/**,**/dist/** so the main set leaves out the tests and any built output under packages/*/dist.

Suggestions

  • suggestion packages/mcp-core/src/__tests__/trim.test.ts:19: the < 500ms check here and the < 1000ms check in packages/mcp/src/tools/__tests__/docs-html-strip.test.ts:29 depend 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.

@BryanFRD

Copy link
Copy Markdown
Contributor Author

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.

@ferrfleet-interne ferrfleet-interne Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@ferrfleet-interne ferrfleet-interne Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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,scripts and sonar.tests=packages both index packages/. sonar.test.inclusions only 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 on pull_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: add sonar.exclusions=**/__tests__/** so the two sets are disjoint.

Suggestions

  • packages/mcp-core/src/auth/__tests__/oauth-flow.test.ts:200 (suggestion): the spawn mock assigns stubbedUrl before the let stubbedUrl line. It works because the closure runs later, but it reads like a TDZ bug. Move the declaration above the spawnMock.mockImplementation call.

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.

@BryanFRD

Copy link
Copy Markdown
Contributor Author

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.

@ferrfleet-interne ferrfleet-interne Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@BryanFRD
BryanFRD disabled auto-merge November 27, 2026 15:59
@BryanFRD

Copy link
Copy Markdown
Contributor Author

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.

@ferrfleet-interne ferrfleet-interne Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes requested. One blocking issue in the new Sonar config; the code changes themselves look correct.

Blocking

  • sonar-project.properties:3 Test files are indexed as both main sources and tests. sonar.sources=packages,scripts and sonar.tests=packages overlap, and sonar.test.inclusions only narrows the test set. Every **/__tests__/** file therefore stays in the main set too, and the scanner stops with File ... can't be indexed twice. Sonar needs disjoint sets, so the main side needs a matching exclusion. The Test / SonarQube job 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) trimTrailing silently returns its input unchanged when char is 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 as if (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.

@BryanFRD

Copy link
Copy Markdown
Contributor Author

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.

@BryanFRD
BryanFRD enabled auto-merge (squash) November 27, 2026 16:17
@BryanFRD

Copy link
Copy Markdown
Contributor Author

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.

Comment thread .github/workflows/ci.yml
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
Comment thread .github/workflows/ci.yml
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

@ferrfleet-interne ferrfleet-interne Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@ferrfleet-interne ferrfleet-interne Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@BryanFRD
BryanFRD merged commit 8f4ab01 into main Nov 27, 2026
15 checks passed
@BryanFRD
BryanFRD deleted the fix/502-sonar-quality-gate branch November 27, 2026 16:17
ferrflow Bot added a commit that referenced this pull request Nov 27, 2026
## [10.17.2] - 2026-11-27

### Bug Fixes

- fix(sonar): count tests as tests, fix open issues, raise coverage (#515)

@ferrfleet-interne ferrfleet-interne Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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: trimTrailing compares one code unit (value[end - 1] === char), so a char longer 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 when char.length !== 1.
  • Suggestion .github/workflows/ci.yml:34: sonar-exclusions replaces 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 an extra-exclusions input to reusable-ci-node.yml that is appended to the default list.

Formal verification: that step failed and returned no result, so nothing is reported from it.

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.

Sonar : quality gate en échec sur MCP (couverture nouveau code 37.6 % < 80 %, 2 nouvelles violations)

2 participants