Skip to content

Commit e0ebab3

Browse files
committed
test(coverage): fix what the deletion pins claimed
Two review threads survived #3486 and #3492 because both were merged while the checks were still queued. The second deletion case was named for a function whose own lines did not change, and its own fixture deletes a line inside that function. Renamed to the scenario it covers: additions below the span, alongside a removal inside it. The third case pinned its fixture rather than any scoping rule, since a function absent from the map is unscored in either scope. Measured that first: a stale map which still records the deleted function yields nothing from `--all` either, so no scoping keeps it uncharged — the removal takes the score with it. The test now asserts that in both scopes and says which of the two mechanisms it is evidence for. CONTRIBUTING said removing code retires debt. It does not always: dropping lines that used to be covered lowers the coverage side of the ratio and can raise the score, and that debt lands in the `--all` backlog rather than the PR. The sentence now says deletions are uncharged, which is the accurate claim, and names where the debt it can create goes. Part of #3414.
1 parent 4b58dd0 commit e0ebab3

2 files changed

Lines changed: 23 additions & 16 deletions

File tree

‎CONTRIBUTING.md‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -252,12 +252,13 @@ fails when it cannot score them. It prints `no trustworthy verdict` and names th
252252
or when a touched function postdates the map and would be scored from complexity alone. Every one of
253253
those is a stale coverage run, not a debt you owe: re-run `pnpm test:coverage` on the commit and
254254
re-check. What does count as debt is editing a function that already scores 30 or more — the score
255-
does not have to be new. Moving a file without editing its lines touches none of its functions, and
256-
neither does deleting lines from one: removing code retires debt instead of adding it, which is also
257-
why deleting a whole function passes. A deletion that leaves an untested complex function standing is
258-
not charged, and that function keeps showing in the `--all` backlog. Unlike the changed-line gate,
259-
this one has no `coverage-waiver` label: the only way past a score is to test or simplify the
260-
function, or to exempt the file in `fallow-crap.json`.
255+
does not have to be new. Only lines you add are charged, so removing them is not: deleting a whole
256+
function takes its score with it, and deleting lines from one is not charged however it moves the
257+
score — a deletion that drops lines which used to be covered can raise what the function scores, and
258+
that debt reaches the `--all` backlog rather than your PR. Moving a file without editing its lines
259+
touches none of its functions. Unlike the changed-line gate, this one has no `coverage-waiver` label:
260+
the only way past a score is to test or simplify the function, or to exempt the file in
261+
`fallow-crap.json`.
261262

262263
Two things are listed rather than blocked, so a green run does not mean they were checked. A touched
263264
function in a file coverage never instrumented — one `coverage.exclude` drops, or one a stale local

‎scripts/coverage-crap/run.test.ts‎

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -291,10 +291,10 @@ test('a rename that also edits the body owes the edited lines', () => {
291291
test('deleting lines from a debt function does not charge the function that survives them', () => {
292292
// Measured, not assumed: fallow's `--diff-file` index holds added lines only, so a hunk that is
293293
// nothing but removals contributes no line to intersect a function's span with, and this run
294-
// agrees rather than overriding it. Removing code retires debt instead of adding it, which is the
295-
// rule the whole-file and pure-rename exemptions already follow — the residual is deliberate: a
296-
// deletion that leaves an untested complex function standing is not charged here, and `--all`
297-
// still lists it on main. Pinned so a change to either layer's scoping has to say so.
294+
// agrees rather than overriding it — the same reason the whole-file and pure-rename exemptions
295+
// exist. The residual is deliberate and not free: a deletion can even raise a surviving
296+
// function's CRAP by removing lines that used to be covered, and that new debt shows up only in
297+
// `--all`. Pinned so a change to either layer's scoping has to say so.
298298
writeCoverage({ 'src/debt.ts': { span: [1, 13] }, 'src/clean.ts': { hits: 4 } });
299299
write('src/debt.ts', DEBT.replace(' total += 1;\n', ''));
300300
commit('delete a line inside the debt function');
@@ -309,11 +309,10 @@ test('deleting lines from a debt function does not charge the function that surv
309309
assert.match(backlog.out, /\| `src\/debt\.ts:1` score \| 42\.0 \| 6 \| 0% \|/);
310310
});
311311

312-
test('lines added elsewhere in a file do not charge a function whose own lines did not change', () => {
313-
// Scoping is per function span, not per file, so a one-line edit in a large module does not
314-
// inherit every debt score inside it. Here the file has added lines — `helper` is rewritten and
315-
// another export appears below the function — and the function lost one line, yet none of the
316-
// added lines fall in its span, so it is not this change's verdict.
312+
test('lines added below a debt function do not charge it, though the diff also deleted one inside', () => {
313+
// The per-span half of the boundary: scoping is per function span, not per file, so a module is
314+
// not charged for the debt it merely contains. `score` loses one line here and the file gains two
315+
// below it, and because none of the added lines land inside the span, none of them charge it.
317316
writeCoverage({ 'src/debt.ts': { span: [1, 13] }, 'src/clean.ts': { hits: 4 } });
318317
write(
319318
'src/debt.ts',
@@ -329,7 +328,11 @@ test('lines added elsewhere in a file do not charge a function whose own lines d
329328
assert.match(backlog.out, /\| `src\/debt\.ts:1` score \| 42\.0 \| 6 \| 0% \|/);
330329
});
331330

332-
test('deleting the debt function altogether is retiring it, not a change to it', () => {
331+
test('a deleted function takes its score with it, out of both scopes', () => {
332+
// The exemption here is structural, not the diff filter: the head file no longer contains the
333+
// function, so no report of that run scores it — measured, `--all` finds nothing either. So this
334+
// pins that a removal leaves no residue behind in either scope, which is the opposite of what the
335+
// two cases above pin, where the debt is in the map and only the scoping keeps it uncharged.
333336
writeCoverage({ 'src/debt.ts': { noFunctions: true }, 'src/clean.ts': { hits: 4 } });
334337
write('src/debt.ts', TRIVIAL);
335338
commit('replace the debt function with a constant');
@@ -338,6 +341,9 @@ test('deleting the debt function altogether is retiring it, not a change to it',
338341

339342
assert.equal(code, 0);
340343
assert.match(out, /no touched function\(s\) at or above 30/);
344+
const backlog = check(['--all']);
345+
assert.equal(backlog.code, 0);
346+
assert.match(backlog.out, /no function\(s\) at or above 30/);
341347
});
342348

343349
test('a touched file the sanitizer dropped as corrupt yields no verdict', () => {

0 commit comments

Comments
 (0)