Skip to content

fix(merge-coverage): eliminate Windows path-separator duplication#203

Merged
nev21 merged 11 commits into
mainfrom
copilot/fix-merge-coverage-path-duplication
May 10, 2026
Merged

fix(merge-coverage): eliminate Windows path-separator duplication#203
nev21 merged 11 commits into
mainfrom
copilot/fix-merge-coverage-path-duplication

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 9, 2026

  • Fix exclusion filter in merge-coverage.ts: normalize glob paths to forward slashes
  • Fix path key duplication: add normalizeCoverageKeys() helper
  • Add tests for normalizeCoverageKeys in merge-coverage.test.ts
  • Fix CI failure (Node 24): replace istanbul merge with simple overwrite
  • Fix CI failure (Node 18): move normalizeCoverageKeys to utils.ts to avoid ESM loader issue — merge-coverage.ts imports globby v13 (ESM-only), which caused Node 18 to switch to ESM loader mode and fail to load .ts test files
  • Code review and CodeQL scan: no issues found

Copilot AI and others added 3 commits May 9, 2026 15:39
- Add normalizeCoverageKeys() to convert backslash path keys and `path`
  properties to forward slashes in coverage JSON blobs before merging.
  This prevents nyc (backslash) vs karma-typescript (forward-slash) key
  duplication on Windows.
- Normalize globby paths to forward slashes before the exclusion filter
  so that `coverage/coverage-final.json` is correctly excluded even when
  globby returns backslash-separated paths on Windows.
- Add tests for normalizeCoverageKeys in merge-coverage.test.ts

Agent-Logs-Url: https://github.com/nevware21/ts-build-tools/sessions/fe9562c3-39c4-4338-9207-223a423590cb

Co-authored-by: nev21 <82737406+nev21@users.noreply.github.com>
Co-authored-by: nev21 <82737406+nev21@users.noreply.github.com>
Address code review feedback: use string type annotations instead of any
in lambda parameters, and use const instead of var for jsonBlobs.

Agent-Logs-Url: https://github.com/nevware21/ts-build-tools/sessions/fe9562c3-39c4-4338-9207-223a423590cb

Co-authored-by: nev21 <82737406+nev21@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix path key duplication issue in merge coverage on Windows fix(merge-coverage): eliminate Windows path-separator duplication May 9, 2026
Copilot finished work on behalf of nev21 May 9, 2026 15:41
Copilot AI requested a review from nev21 May 9, 2026 15:41
@nev21 nev21 marked this pull request as ready for review May 9, 2026 15:46
@nev21 nev21 requested a review from a team as a code owner May 9, 2026 15:46
Copilot AI review requested due to automatic review settings May 9, 2026 15:46
@nev21 nev21 requested a review from a team as a code owner May 9, 2026 15:46
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses Windows-specific coverage merging issues in merge-coverage by normalizing path separators so that Istanbul treats coverage entries for the same file as identical, and by ensuring the tool doesn’t re-merge its own previously generated output.

Changes:

  • Added normalizeCoverageKeys() to rewrite coverage JSON keys (and path fields) to forward slashes before creating Istanbul coverage maps.
  • Normalized globby results to forward slashes prior to filtering so coverage/coverage-final.json is reliably excluded on Windows.
  • Added unit tests covering key/path normalization behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
lib/coverage-tools/src/merge-coverage.ts Adds coverage key/path normalization and normalizes globbed file paths before filtering.
lib/coverage-tools/test/src/merge-coverage.test.ts Adds tests for normalizeCoverageKeys() behavior across empty, forward-slash, backslash, and missing-path cases.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/coverage-tools/src/merge-coverage.ts Outdated
Comment thread lib/coverage-tools/src/merge-coverage.ts Outdated
Comment thread lib/coverage-tools/test/src/merge-coverage.test.ts Outdated
nev21 and others added 2 commits May 9, 2026 08:54
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

Comment thread lib/coverage-tools/src/merge-coverage.ts Outdated
Comment thread lib/coverage-tools/src/merge-coverage.ts Outdated
nevware21-bot and others added 2 commits May 9, 2026 12:00
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

@nev21
Copy link
Copy Markdown
Contributor

nev21 commented May 10, 2026

@copilot review your changes as the tests are failing

Copilot AI and others added 2 commits May 10, 2026 00:24
… in normalizeCoverageKeys

The istanbul FileCoverage.merge() call requires complete statementMap
location data (start/end), which may not be present. Use simple
last-write-wins overwrite instead — cross-blob merging is handled by
istanbul in the main mergeCoverage loop. All 23 tests pass.

Agent-Logs-Url: https://github.com/nevware21/ts-build-tools/sessions/148514cb-94a7-4094-a057-e3cb05720107

Co-authored-by: nev21 <82737406+nev21@users.noreply.github.com>
Co-authored-by: nev21 <82737406+nev21@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 10, 2026

@copilot review your changes as the tests are failing

Fixed in b9afbfd. The test failure was caused by the istanbul FileCoverage.merge() call introduced in the previous "potential fix" commits — it requires full statementMap location data (start/end per entry) which our test data doesn't have. Replaced it with a simple last-write-wins overwrite: the forward-slash-keyed entry overwrites the backslash-keyed one (matching what the test already expected). Cross-blob merging continues to be handled by istanbul in the main mergeCoverage loop. All 23 tests now pass.

Copilot finished work on behalf of nev21 May 10, 2026 00:26
Copilot AI requested a review from nev21 May 10, 2026 00:26
@nev21
Copy link
Copy Markdown
Contributor

nev21 commented May 10, 2026

@copilot node 18 is still failing with this fix

… issue

merge-coverage.ts imports globby v13 (ESM-only). On Node 18, loading
any test that imports from merge-coverage.ts triggers the ESM loader,
which can't handle .ts file extensions (ERR_UNKNOWN_FILE_EXTENSION).

Moving normalizeCoverageKeys to utils.ts (only CJS deps: fs, path,
@nevware21/ts-utils) and updating the test to import from utils.ts
avoids this ESM cascade. merge-coverage.ts re-exports the function
for API compatibility. utils.ts also gets stronger types
(Record<string, any> instead of any).

Agent-Logs-Url: https://github.com/nevware21/ts-build-tools/sessions/4303ce38-8fd4-4261-a66a-f982cd20395a

Co-authored-by: nev21 <82737406+nev21@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 10, 2026

@copilot node 18 is still failing with this fix

Fixed in 4919ceb. The Node 18 failure was caused by merge-coverage.ts importing globby v13, which is ESM-only. On Node 18, loading any test that imports from merge-coverage.ts triggers the ESM loader chain, which then can't handle .ts file extensions (ERR_UNKNOWN_FILE_EXTENSION). The fix moves normalizeCoverageKeys to utils.ts (which only has CJS-compatible deps: fs, path, @nevware21/ts-utils) and updates the test to import from there. merge-coverage.ts still re-exports the function for API compatibility.

Copilot finished work on behalf of nev21 May 10, 2026 02:35
@nev21 nev21 enabled auto-merge (squash) May 10, 2026 02:45
Copy link
Copy Markdown
Contributor

@nevware21-bot nevware21-bot left a comment

Choose a reason for hiding this comment

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

Approved by nevware21-bot

@nev21 nev21 merged commit 61a0cb5 into main May 10, 2026
8 checks passed
@nev21 nev21 deleted the copilot/fix-merge-coverage-path-duplication branch May 10, 2026 03:30
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.

[Bug] merge-coverage: path key duplication on Windows due to backslash vs forward-slash mismatch

4 participants