Skip to content

Commit 6758902

Browse files
Hannia Valerahanniavalera
authored andcommitted
Update coverage tooling to use c8 instead of nyc and adjust related configurations
1 parent 8e3f9c9 commit 6758902

6 files changed

Lines changed: 55 additions & 38 deletions

File tree

.github/PULL_REQUEST_TEMPLATE/coverage.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ about: PR opened by the Copilot coverage agent
2727
- [ ] `yarn lint` passes
2828
- [ ] `CHANGELOG.md` has an entry under `Improvements:`
2929

30-
### Coverage delta (paste `nyc` text report here)
30+
### Coverage delta (paste `c8` text report here)
3131
```
32-
(paste output of: npx nyc report --reporter=text)
32+
(paste output of: npx c8 report --reporter=text)
3333
```

.github/copilot-test-coverage.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ yarn backendTests
4040
yarn unitTests
4141

4242
# 5. Confirm coverage improved for the specific file
43-
npx nyc --reporter=text \
43+
npx c8 --reporter=text --src=src \
4444
node ./node_modules/mocha/bin/_mocha \
4545
-u tdd --timeout 999999 --colors \
4646
-r ts-node/register \

.github/scripts/check-coverage-and-open-issue.mjs

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// @ts-check
33
import { readFileSync } from 'fs';
44
import { execSync } from 'child_process';
5+
import { relative, resolve } from 'path';
56

67
const THRESHOLD = Number(process.env.THRESHOLD ?? 60);
78
const SUMMARY_PATH = 'coverage/coverage-summary.json';
@@ -19,17 +20,24 @@ try {
1920

2021
// ── 2. Find files below threshold ────────────────────────────────────────────
2122
const belowThreshold = [];
23+
const repoRoot = resolve('.');
2224

2325
for (const [file, metrics] of Object.entries(summary)) {
2426
if (file === 'total') continue;
25-
if (!file.startsWith('src/')) continue;
27+
28+
// Normalize: c8/Istanbul may emit absolute paths or repo-relative paths
29+
const relPath = file.startsWith('/') || /^[A-Za-z]:[/\\]/.test(file)
30+
? relative(repoRoot, file).replace(/\\/g, '/')
31+
: file;
32+
33+
if (!relPath.startsWith('src/')) continue;
2634

2735
const linePct = metrics.lines.pct ?? 0;
2836
const branchPct = metrics.branches.pct ?? 0;
2937
const fnPct = metrics.functions.pct ?? 0;
3038

3139
if (linePct < THRESHOLD || fnPct < THRESHOLD) {
32-
belowThreshold.push({ file, linePct, branchPct, fnPct });
40+
belowThreshold.push({ file: relPath, linePct, branchPct, fnPct });
3341
}
3442
}
3543

@@ -44,7 +52,21 @@ if (belowThreshold.length === 0 && totalLines >= THRESHOLD) {
4452
process.exit(0);
4553
}
4654

47-
// ── 3. Build the issue body (this is the Copilot agent's instruction set) ────
55+
// ── 3. Check for existing open coverage issue (avoid duplicates) ─────────────
56+
try {
57+
const existing = execSync(
58+
`gh issue list --repo ${REPO} --label test-coverage --state open --json number --jq '.[0].number'`,
59+
{ encoding: 'utf8' }
60+
).trim();
61+
if (existing) {
62+
console.log(`\n⏭️ Open coverage issue already exists: #${existing} — skipping.`);
63+
process.exit(0);
64+
}
65+
} catch {
66+
// gh CLI may fail if label doesn't exist yet — continue to create
67+
}
68+
69+
// ── 4. Build the issue body (this is the Copilot agent's instruction set) ────
4870
belowThreshold.sort((a, b) => a.linePct - b.linePct); // worst files first
4971

5072
const tableRows = belowThreshold
@@ -111,7 +133,17 @@ For each file:
111133
- Do **not** touch source files outside \`test/\`
112134
`;
113135

114-
// ── 4. Open the issue via gh CLI ──────────────────────────────────────────────
136+
// ── 5. Ensure the test-coverage label exists ─────────────────────────────────
137+
try {
138+
execSync(
139+
`gh label create test-coverage --repo ${REPO} --color 0075ca --description "Opened by the coverage agent" --force`,
140+
{ stdio: 'inherit' }
141+
);
142+
} catch {
143+
// --force handles existing labels; ignore unexpected errors
144+
}
145+
146+
// ── 6. Open the issue via gh CLI ──────────────────────────────────────────────
115147
const title = `chore: improve test coverage -- ${belowThreshold.length} files below ${THRESHOLD}% (run ${new Date().toISOString().slice(0, 10)})`;
116148

117149
const cmd = [

.github/workflows/coverage-agent.yml

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
name: Coverage Agent
22

33
on:
4-
push:
5-
branches: [ main, 'release/**' ]
6-
pull_request:
7-
branches: [ main, 'release/**' ]
84
schedule:
9-
- cron: '0 3 * * 1' # weekly Monday 03:00 UTC — keeps noise low
5+
- cron: '0 3 * * 1' # weekly Monday 03:00 UTC
106
workflow_dispatch:
117
inputs:
128
threshold:
@@ -25,9 +21,9 @@ jobs:
2521
issues: write
2622

2723
steps:
28-
- uses: actions/checkout@v3
24+
- uses: actions/checkout@v4
2925

30-
- uses: actions/setup-node@v3
26+
- uses: actions/setup-node@v4
3127
with:
3228
node-version: 20
3329

@@ -40,43 +36,29 @@ jobs:
4036
- name: Build (test config)
4137
run: yarn pretest # tsc -p test.tsconfig.json
4238

43-
# ── Coverage: backend tests (pure Mocha — nyc wraps directly) ──────────
39+
# ── Coverage: backend tests (c8 uses V8 native coverage) ───────────
4440
- name: Run backend tests with coverage
4541
run: |
46-
npx nyc \
47-
--reporter=json \
42+
npx c8 \
43+
--reporter=json-summary \
4844
--reporter=text \
45+
--src=src \
4946
--include='src/**/*.ts' \
5047
--exclude='src/**/*.d.ts' \
51-
--temp-dir=.nyc_output \
48+
-o coverage \
5249
node ./node_modules/mocha/bin/_mocha \
5350
-u tdd --timeout 999999 --colors \
5451
-r ts-node/register \
5552
-r tsconfig-paths/register \
5653
"./test/unit-tests/backend/**/*.test.ts"
5754
58-
# ── Coverage: unit tests (VS Code extension host — via xvfb) ──────────
59-
- name: Run unit tests with coverage
55+
# ── Unit tests (extension host — coverage not collected here) ──────
56+
# c8/nyc cannot instrument the VS Code extension-host child process.
57+
# This step validates tests pass; coverage comes from backend tests.
58+
- name: Run unit tests
6059
uses: GabrielBB/[email protected]
6160
with:
62-
run: |
63-
npx nyc \
64-
--reporter=json \
65-
--include='src/**/*.ts' \
66-
--exclude='src/**/*.d.ts' \
67-
--temp-dir=.nyc_output \
68-
node ./out/test/unit-tests/runTest.js
69-
continue-on-error: true # coverage report still matters even if some tests fail
70-
71-
# ── Merge all coverage runs and emit summary ──────────────────────────
72-
- name: Merge coverage and generate summary
73-
run: |
74-
npx nyc merge .nyc_output coverage/coverage-combined.json
75-
npx nyc report \
76-
--reporter=json-summary \
77-
--reporter=lcov \
78-
--temp-dir=coverage \
79-
-t .nyc_output
61+
run: node ./out/test/unit-tests/runTest.js
8062

8163
- name: Upload coverage artifacts
8264
uses: actions/upload-artifact@v4

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
.nyc_output/
12
.vscode-test/
23
build/
4+
coverage/
35
dist/
46
node_modules/
57
out/

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4428,6 +4428,7 @@
44284428
"chai": "^4.3.0",
44294429
"chai-as-promised": "^7.1.1",
44304430
"chai-string": "^1.5.0",
4431+
"c8": "^10.1.0",
44314432
"eslint": "^8.42.0",
44324433
"eslint-plugin-import": "^2.29.1",
44334434
"eslint-plugin-jsdoc": "^48.2.8",

0 commit comments

Comments
 (0)