fix(tools): stop contractaudit crediting dead paths as live consumers
Renaming the dashboard's request helper from req( to request( broke the consumer extractor: it matched the call by name, so 16 live routes were reported unconsumed. The extractor now keys on the call argument instead, which survives a rename. The first attempt at that fix was worse than the bug, and is recorded here because the direction of the error is the whole point. Crediting any quoted /api/... literal meant a comment, a retired-route array, or a display label counted as proof a route was reachable -- so deleting every real request still reported the surface as healthy. A false "unconsumed" is a loud, fixable failure; a false "consumed" is a silent hole in the gate, which is worse than having no gate at all. A path now counts as a consumer only when it is the first argument of a call in code. That excludes bare constants, dead arrays, object properties, and commented-out calls, while still accepting any function name. Both halves are pinned by tests: TestScanFileCreditsAnyCallSignature and TestScanFileIgnoresNonCallLiterals, plus a surface-level TestNegativeCommentedOutCallIsStillReported that the vacuous version fails. Re-injecting either half of the bug fails the suite. Requiring a call lost no real consumer: internal/webui still reads 49/49. The remaining limits (path must be the first argument; template interpolations unseen; routes credited per path rather than per verb) are declared in docs/contract-declarations.json and the PRD rather than left implicit. Also corrects a measurement I had quoted inconsistently: proto/state/v1 declares 45 RPCs, not 43 or 46.
This commit is contained in:
4 files changed
+260
-81
No files matched your search
@@ -24,7 +24,7 @@
|
||||
"blindSpots": [
|
||||
{
|
||||
"surface": "internal/webui",
|
||||
"reason": "Consumer extraction is textual over ui/src. A path assembled by string concatenation rather than written as a literal is invisible; scanFile fails loudly when a call shape it cannot parse appears, but it cannot see a path that is never a literal. Routes whose consumer is outside the dashboard (the asset mount, the health probes, the capture-intake webhook) are excluded from this surface by design: they have different consumers and are not part of the dashboard API contract."
|
||||
"reason": "A path counts as a consumer only when it is the first argument of a call in code. The function need not be named -- naming it broke on rename, when matching `req|fetch` reported 16 live routes as unconsumed after the dashboard's helper became `request(` -- but a bare constant, a dead array, an object property, or a commented-out call must not count, because crediting any quoted literal makes the surface pass on a file that issues no requests at all. Limits: a path passed as any argument other than the first is not seen (accepting a comma would start crediting array elements); a request inside a template-literal interpolation is not seen; a path built from a bare /api fragment is reported as unparsable; and a route is credited to every HTTP verb, so a route whose specific verb has no caller reads as consumed. Routes whose consumer is outside the dashboard (the asset mount, the health probes, the capture-intake webhook) are excluded from this surface by design: they have different consumers and are not part of the dashboard API contract."
|
||||
},
|
||||
{
|
||||
"surface": "proto/state/v1/state.proto",
|
||||
|
||||
@@ -120,11 +120,30 @@ presented as dead":
|
||||
|
||||
- **Runtime-loaded code** (Yaegi, reflection) — a route or RPC reached only
|
||||
through dynamic dispatch reads as unconsumed. Labelled with the package list.
|
||||
- **JSX call-site extraction is textual.** It matches path literals in
|
||||
`ui/src/**`, so a path built by string concatenation is invisible. The
|
||||
extractor must **fail loudly on an unexpected call shape** rather than
|
||||
under-report — under-reporting is the failure mode that makes a gate worse than
|
||||
no gate.
|
||||
- **Dashboard call-site extraction is textual, and deliberately narrow.** A path
|
||||
counts as a consumer only when it is the *first argument of a call* in code:
|
||||
the function need not be named (so renaming `req(` to `request(` is fine), but
|
||||
a bare constant, a dead array, an object property, or a commented-out call
|
||||
must not count. Both halves are load-bearing, and they pull in opposite
|
||||
directions.
|
||||
|
||||
Naming the call broke on rename: matching `req|fetch` reported 16 live routes
|
||||
as unconsumed the moment the dashboard's helper was renamed. Dropping the
|
||||
call requirement was **worse**, and is recorded here because it is the more
|
||||
tempting mistake: crediting any quoted `/api/...` literal meant a comment, a
|
||||
retired-route array, or a display label proved a route was reachable, so
|
||||
deleting every real request still read as healthy. The two directions are not
|
||||
symmetric — a false "unconsumed" is a loud, fixable failure, while a false
|
||||
"consumed" is a silent hole, which is worse than having no gate.
|
||||
|
||||
Remaining limits: a path passed as any argument other than the first is not
|
||||
seen (accepting a comma would start crediting array elements and restore the
|
||||
vacuity above); a request written inside a template-literal interpolation is
|
||||
not seen; and a path built from a bare `/api` fragment is reported as
|
||||
unparsable rather than silently contributing nothing.
|
||||
- **Routes are credited per path, not per verb.** A literal does not say which
|
||||
HTTP verb carries it, so a route is credited to every verb and a route whose
|
||||
specific verb has no caller reads as consumed.
|
||||
- **An `EventSource` subscription is a consumer.** `/events` and
|
||||
`/api/logs/stream` are consumed via `EventSource`, not `fetch`; an extractor
|
||||
that only looks for `fetch` reports them unconsumed and is simply wrong.
|
||||
|
||||
Reference in new issue
Block a user