Skip to content

ci(gate): the changed-lines coverage classifier measures type lines and skips executable ones #1313

Backlog

Description

@HugoXK

Written-by: Fledge Platform Product
Found by: post-merge verification of #1302/#1281 (Test's trap record, T7). That record is a local .verify/ note that is not in the repository, so every input it names is reproduced inline below.

Pin: 14d835abcda38fcb9f90ebfc82ef6d241551835c, live main read at Date: Wed, 25 Nov 2026 04:52:16 GMT. Every citation below was read at that sha unless it names another commit.

Rev 2 — folds in the Lead's four T3 conditions: the tightening clause is now written (condition 2), the ADR is required with its rejected alternative (condition 3), and a Verification section names the Security review and Test's independent negative case (condition 4). Corrections against v1: the pin is 14d835ab, not 15cc6db; the classifier test is test/coverageDiff.test.ts:127-140 (v1 said 78-83, which is a fixture); isMeasuredLine(" key: 'instance',") already returns true and is a new pin, not an existing one; the total floor is package.json:19, not :18.

Risk surface

This is an internal gate gap, not an exploitable production vulnerability. It does not touch production data, it does not touch secrets and it does not touch user repositories. The exposure is our own merge gate: the false negative lets a pull request merge while its own coverage report shows that no test executed the lines it added, and nothing outside this repository is reachable through it.

The two labels name two different things and are not double-labelling. area:deploy is where the code lives — scripts/lib/coverage-diff.mjs and scripts/coverage-diff.mjs, the repository-level gate scripts — while area:security is the surface it touches: the merge gate's own judgement. Security reviews that surface, and the label is what keeps the review visible to triage.

What happens

The changed-lines coverage gate decides what counts as a measurable line with one regex list, isMeasuredLine at scripts/lib/coverage-diff.mjs:38-47, and it is wrong in both directions at once.

False positive — it blocks an honest PR. A TypeScript interface member standing alone on a line is measured, because the list only exempts a line that opens a declaration (:43), never a member inside one. That is what failed #1302. At 7ed4c76e11bbe4ee27c4a4245af3757ba5cd3c53 the added line was instancesUsed: boolean in src/views/checklist.ts, and the coverage job 138428712059 (failure, 2026-11-24T12:00:27Z→12:04:36Z) ended with, verbatim from its log at 12:04:32Z:

coverage-diff: src/views/checklist.ts:35 — added line is not covered
coverage-diff: below the floor — 3/4 changed lines covered (75%, floor 80%)

The PR went green on 17bfc6dda1cb1662042d2b8717937764ae93ac5b, titled refactor(views): declare the workspace input as its own type (#1281) — one file, +8/−7, no test — which moved the same member onto export interface SetupWorkspaces { instancesUsed: boolean }, a line the list skips at :43. No test could ever have made that interface line "covered"; the gate refused an honest PR and the green came from formatting.

False negative — it waves uncovered code through. Two kinds of executable code are skipped, so a diff that adds only them measures nothing; the CLI then prints skip and exits 0 at scripts/coverage-diff.mjs:74-77:

  • a namespace body written on one line is skipped by the namespace term at scripts/lib/coverage-diff.mjs:44;
  • a top-level dynamic import call is skipped by ^import\b at scripts/lib/coverage-diff.mjs:42, which cannot tell a static import statement from a call expression.
added line isMeasuredLine at the pin correct
instancesUsed: boolean true false
namespace Hidden { const value = Math.random() } false true
import('./x.js').then((m) => m.run()) false true

Feeding a diff of those two code lines with a report that lists the same file and the same two lines as uncovered returns {"ok":true,"code":"NO_SOURCE_LINES","measured":0}, and the CLI turns that into a green skip: the coverage job passes on code its own report says no test executed.

The module comment at scripts/lib/coverage-diff.mjs:7-12 rests the classifier on "a line the report does not list has nothing for a test to execute". The #1302 log above shows the report can list a type-only line, so that assumption cannot carry the classifier either way.

Expected

  • A line that carries only a declaration, including an interface or type body member, is not measured.
  • A line that carries executable code is measured even when it also contains a declaration keyword or begins with import.
  • A line that carries a value, a call or an operator stays measured: key: 'instance', inside an object literal is code and must not become exempt.
  • A file the report never lists keeps failing closed, as it does today.

Two resolutions are acceptable and the card does not pick one:

  1. resolve the enclosing block — a declaration body versus a code block — from the file at head, which the CLI already has checked out;
  2. stay line-level, but treat name: Type as a declaration only when the right-hand side is a type expression, and never when the line carries a value, a call or an operator.

Whichever is chosen, the four red cases below flip, the green cases below stay green, and the rule must be checkable by reading the one line it is given.

Minimal reproduction

Save this as coverage-probe.mjs outside the repository and run node coverage-probe.mjs from a tree at the pin. Re-run for this revision: the five outputs are true, false, false, true, true, and the diff below prints {"ok":true,"code":"NO_SOURCE_LINES","measured":0,...}.

import { evaluateChangedLines, isMeasuredLine } from './scripts/lib/coverage-diff.mjs'
console.log('fp ', isMeasuredLine('  instancesUsed: boolean'))                        // true — should be false
console.log('fn1', isMeasuredLine('namespace Hidden { const value = Math.random() }')) // false — should be true
console.log('fn2', isMeasuredLine("import('./x.js').then((m) => m.run())"))            // false — should be true
console.log('g  ', isMeasuredLine("      key: 'instance',"))                           // true — must stay true
const diff = [
  'diff --git a/src/lib/hidden.ts b/src/lib/hidden.ts',
  '--- a/src/lib/hidden.ts',
  '+++ b/src/lib/hidden.ts',
  '@@ -0,0 +1,2 @@',
  '+namespace Hidden { const value = Math.random() }',
  "+import('./x.js').then((m) => m.run())",
].join('\n')
const report = [
  '# start of coverage report',
  '# src                 |        |         |         |',
  '#  lib                |        |         |         |',
  '#   hidden.ts         |  50.00 |   50.00 |   50.00 | 1-2',
  '# end of coverage report',
].join('\n')
console.log(evaluateChangedLines({ diff, report, floor: 80 })) // ok:true, NO_SOURCE_LINES, measured 0

Proposed red test

All of it belongs in test/coverageDiff.test.ts, the helper's own suite; no new file. The existing classifier test lives at :127-140 and is extended, not replaced.

  1. Interface member (red at the pin): assert.equal(isMeasuredLine(' instancesUsed: boolean'), false).
  2. Namespace body on one line (red at the pin): assert.equal(isMeasuredLine('namespace Hidden { const value = Math.random() }'), true).
  3. Dynamic import call (red at the pin): assert.equal(isMeasuredLine("import('./x.js').then((m) => m.run())"), true).
  4. End to end (red at the pin, one unique expected value): evaluateChangedLines on the minimal-reproduction diff returns code: 'BELOW_FLOOR' with measured: 2 and both added lines in violations; at the pin it returns code: 'NO_SOURCE_LINES' with measured: 0.

Three cases must stay green, because they are what a careless fix breaks:

  • assert.equal(isMeasuredLine(" key: 'instance',"), true) — a new assertion; the pin does not carry it today, and it is the value/type boundary the rule must respect;
  • assert.equal(isMeasuredLine(' const x = 1'), true) and ' return compute(x)' — test/coverageDiff.test.ts:128-129, unchanged;
  • the rest of the existing classifier test at :127-140 (comments, import { … } from, interface Shape {, type Id = string, punctuation) is unchanged and still green.

Tightening, not loosening

Removing a false positive necessarily stops measuring some lines, so the slice must not buy that by making the skip easier to reach. The rule:

  • NO_SOURCE_LINES and its exit 0 at scripts/coverage-diff.mjs:74-77 must not become reachable on a diff of executable lines. The end-to-end case above is the guard: the two-line hidden.ts diff must go from skip to a refusal with measured: 2, never stay a skip.
  • A file the report does not list keeps failing closed. :209 and :217 (if (!listed) missing.push(path) / ... || !listed) stay exactly as they are, so every line the new classifier still calls measurable in such a file remains a violation; no rule may exempt a file because its row is missing, and no exemption may be added beside the single admission point at :215.
  • The waiver path is untouched, not one byte. No-test: is read at scripts/coverage-diff.mjs:84 and nothing in this card changes that function, the report parser, or the floor (--floor 80 at .github/workflows/ci.yml:231, the 84 total at package.json:19).
  • No line the old classifier measured may stop being measured unless it is a declaration-only line. The review check is the pair instancesUsed: boolean (flips to unmeasured) versus key: 'instance', (stays measured); a rule that cannot separate them is the wrong rule.

Smallest mergeable slice

scripts/lib/coverage-diff.mjs plus test/coverageDiff.test.ts; if resolution 1 is chosen, scripts/coverage-diff.mjs gains the file text it needs and still ships in the same PR. Half a day at most.

With it, a short ADR (scripts/** is a T3 path and this changes a measurement contract that binds every future PR): docs/decisions/NNNN-coverage-measurement-semantics.md. The number is read from the live docs/decisions/ at the PR tip, not copied from here — at this read the highest is 0028-db-maintenance-window.md, and #1309's ratchet record may take the next one first. The ADR records: a measured line is defined by executable code, not by a keyword list; the classifier is gate contract and needs Lead sign-off; and the rejected alternative "keep the classifier, document the trap only", rejected because a documented trap does not bind the gate — scripts/coverage-diff.mjs:74-77 still lets a PR merge while its own report shows nothing executed, and the false positive still turns a formatting change into a coverage failure.

Tier T3. Because this changes the gate's own judgement, the Lead's sign-off on the chosen rule is part of the review even though the tier already demands a PASS; any change to a floor or to a policy value needs the Lead's explicit yes and is not part of this card.

No UI face: this changes a CI gate, so no before/after screenshot applies.

Verification

  • Security reviews the gate-hole surface before merge. The question is whether a future change can restore the skip on executable lines, and whether the declaration exemption can be widened into a value exemption; the tightening clause above is the checklist.
  • Test independently reproduces the false negative at a fixed sha it names in its verdict — the namespace one-liner plus the dynamic-import call through evaluateChangedLines returning NO_SOURCE_LINES with measured: 0 at the PR head, without reusing the card's probe file — and reproduces the false positive from 7ed4c76e's own log line above.

Non-goals

  • No change to the floor: --floor 80 at .github/workflows/ci.yml:231 and the 84 total at package.json:19 stay as they are.
  • No change to the waiver line (No-test: at scripts/coverage-diff.mjs:84) or to how the report is parsed.
  • No change to which paths are in scope (src/** only, scripts/lib/coverage-diff.mjs:19) or to when the step runs (pull requests only, .github/workflows/ci.yml:227).
  • No new gate, no second coverage tool, no per-file threshold.
  • Not the whole-suite coverage mask: that a red suite can still report a green coverage check is bug(ci): a red suite is reported as a green coverage check because the piped step drops the exit code #1312, a different defect in the same job.

Dedupe

No open issue covers the classifier. #641 is closed and is the card that created this gate; it is the origin, not a duplicate. Adjacent live cards are different mechanisms: #1309 is the arch grandfather gate (scripts/lib/arch-grandfather.json), #1312 is the piped coverage step losing the suite's exit code, #1303 is a pr-lint fence, #1304 is the ci-ok aggregate's own keys, #1273 is a required context reported missing, #1276 is a required job's steps compared against the base tree, #1228 is the import-boundary and file-size gate. None touches scripts/lib/coverage-diff.mjs. The five open PRs — #1280, #1278, #1276, #1250, #1249 — do not either, and the module has not changed since 46e686047bc0 (2026-11-15T08:01:24Z).

Acceptance

  • The four red cases fail at the pin and pass with the fix, in test/coverageDiff.test.ts.
  • isMeasuredLine(" key: 'instance',") is true with a new assertion, and the existing classifier test at :127-140 is unchanged and green.
  • The end-to-end case goes from NO_SOURCE_LINES/measured: 0 to BELOW_FLOOR/measured: 2, i.e. the skip is not easier to reach.
  • The ADR exists under docs/decisions/ with the next free number read at the tip, and records the rejected "document only" alternative.
  • Security's review of the gate-hole surface and Test's independent reproduction at a named sha are both on the PR.
  • npm run check and the coverage job pass on the PR, and the PR body names the 7ed4c76e failure line as the case the rule now classifies correctly.

Priority

priority:normal: the false negative is a real gate hole but needs an attacker-shaped diff to exploit, and the false positive costs an honest PR one formatting round-trip. It is a contract fix, not an incident.

Activity

  1. added
    bug
    area:security
    area:deploy
    needs-review
    on Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:deployarea:securitybugneeds-reviewpriority:normal

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions