Commit graph

20 commits

Author SHA1 Message Date
trvon
fb055c9978
merge: bring main into the audit and state-map work
Some checks failed
Lint Commits / commitlint (pull_request) Successful in 19s
Tests / Static Analysis (pull_request) Has been cancelled
Tests / Tests (pull_request) Has been cancelled
main gained six PRs (#1-#6) while the audit fixes and the state-map seam
were in progress. Four of main's commits fixed the same bugs this branch
did, independently; where they overlap, the more complete version wins:

- Fingerprints: main's (a0844bb) - catchSite (`member#index` among all
  catches), union/owner as identity, a legacy fingerprint so version-1
  baselines still match, baseline "version": 2. This branch's `catch`
  ordinal is dropped; its fingerprint_test still guards the result.
- verify --rule: main's verifyAnalysis (cf9e0b7), which also reports
  findings in skipped files as NOT SCANNED.
- Unreadable SDK: both kept - this branch's up-front probe gives the
  early, specific error; main's catch around the analyzer (d6b6bcb) is
  the backstop.
- Riverpod: main's "a ref.listen is not a render" (f6411dc) and this
  branch's AsyncError patterns / stored-value tracking compose; the
  fixture keeps both sets of cases.

Ported onto the model-only rules (the seam), since main edited code this
branch had moved into front-end facts:
- excerpt.dart's literal-free, bounded quoting (a prompt-injection
  guard) now also covers front-end facts: SwallowedFailure.handler and
  NonSubscribingRead.excerpt, and the C++ front end elides string
  literals in handler evidence the same way.
- ScanCoverage: runChecks stays source-free; the model carries coverage
  (`scanCoverage` in the state JSON, written by both front ends), so
  `check --model` states coverage like a source check.
- main's softened wording (rendered-not-emitted "probably unreachable",
  the remove-policy dead-handler text, notifier-field-unread) and the
  backticked flag message.

Docs: main's README grew the Firestore query inventory and the output
contract; the README stays short, the inventory moves to
docs/queries.md, and the contract, exit codes, verify and baseline
details join docs/usage.md.

Checked against origin/main on resolved mirrors of the dogfood apps:
nuwayze (102), dex (0) and word_alive (0) identical; tick differs only
by the intended riverpod stored-value fix. On the fixture every
difference is one of this branch's fixes. 214 tests pass.
2026-09-24 07:33:53 -06:00
trvon
1f60197a15
feat(queries): inventory firestore query surfaces as typed records
Add `pipe queries`, which lists every Firestore query a project can issue:
scope, collection, path pattern, filters with operators and value types,
composites, orderBy, limit, cursors, realtime, aggregation, in-loop, plus a
confidence and the reasons it is not exact. Receivers are matched by static
type and cloud_firestore library URI, never by name.

Queries are followed through chains, local variables (flow-insensitive with
two cuts), fields, getters and one level of helper methods with arguments
bound. An --adapter-config (YAML or JSON) maps declarative query APIs such as
a server-side gateway onto the same schema.

Inventory only: no rules, findings or baseline changes. Every emitted name is
validated against a safe character set so no source text reaches the output.
2026-09-23 18:03:09 -06:00
trvon
4b499c1e21
feat(cpp): experimental C++ front end for scoped-enum state
tool/cpp_front.py is a second front end written against the state model,
not the rules: it reads a compile database with libclang (Homebrew LLVM)
and writes the JSON that `pipe check --model` takes. Every rule,
baseline and gate works on it unchanged.

Mapping, per project `enum class` (identity from clang's resolved AST,
so two enums both named QueryIntent are never confused):
- a reference that produces a value (assignment, atomic store, argument,
  return, initialiser) is an emission; a cast from an int is an indirect
  one;
- a `case`, `==` or `!=` is an observation;
- a busy enumerator written to the method's OWN state, followed by a
  top-level try whose catch neither writes state nor rethrows, is a
  swallowed failure;
- sources the build does not compile are recorded as unresolved, so
  findings naming them drop a confidence step.

One rule-side change, optional and Dart-neutral: an EmissionSite may name
its stateType. rendered-not-emitted attributed indirect emissions by owner
(a bloc owns one state type), so a cast to one enum made "never emitted"
unprovable for every other enum in the same C++ class. With stateType
set, the suppression is scoped to that enum. Dart output is still byte
identical on the fixture and all four dogfood apps.

Run on ~/work/tools/yams (375 translation units from build/debug, 0 clang
errors, about two minutes): 118 state enums, 82 findings. A grep-based
hand check of 13 found 12 factually correct - e.g. the IPC connection FSM
never enters ImplState::ReadingHeader, the downloader never reports
ProgressStage::Verifying though three CLI commands render it,
ExtractScopeType qualifiers are parsed but never acted on - and one false
positive (a nested JSON-parse fallback taken for a stuck busy state),
now excluded by requiring the method's own state and a top-level try.

Bugs found on the way and fixed: ccache/compiler wrappers passed as
inputs, relative -I paths resolved against the wrong directory (7 TUs
silently lost third_party headers), a symlinked path putting every TU
"outside" the project, and an empty compile database producing an empty
"clean" model with exit 0 - all now fail loudly or are handled.

test/cpp_front_test.dart runs the front end on test/fixtures/cpp_state
with positive and negative controls for each rule; skipped without LLVM.
138 tests pass.
2026-09-22 19:16:53 -06:00
trvon
f6411dc23b
fix(riverpod): a listener that reads the value is not a render
Some checks failed
Lint Commits / commitlint (pull_request) Successful in 15s
Tests / Static Analysis (pull_request) Has been cancelled
Tests / Tests (pull_request) Has been cancelled
riverpod-async-gap treated any site that read an AsyncValue as a UI read,
including ref.listen. A listener mirrors the value into a side effect and
draws nothing, so it cannot leave a blank or stale screen. Dogfooding on
word_alive flagged an analytics user-property listener this way.

A gap now needs a ref.watch that reads the value. Listeners still count as
places that handle error or loading.
2026-09-22 15:17:19 -06:00
trvon
939cdcb251
fix(riverpod): recognise AsyncError patterns and follow stored values
riverpod-async-gap judged handling from the text of the expression a
`ref.watch` flows into, which missed two common shapes:

- Pattern handling. A switch with `AsyncError()` / `AsyncLoading()` cases
  - the form pipe's own remediation recommends - did not count as
  handling, and a switch STATEMENT on the watched value was never looked
  at, because the parent climb stops at the first non-expression. A
  provider handled that way in one widget and read with `.value` in
  another was reported as unhandled.
- A value stored in a local. `final v = ref.watch(p); ... v.when(...)`
  stopped the climb at the declaration, so both the handling and the read
  were invisible: a handled provider could be reported, and an unhandled
  one read as `v.value` was missed (a recall gap, not only precision).

The consumer now widens to an enclosing switch statement, the uses of a
declared local are followed through the enclosing body, and
AsyncError/AsyncLoading patterns count as handling.

Fixture: patterned, switched and stored providers (each also read
directly elsewhere, so the controls are not vacuous) were all reported
before and are silent now; storedUnhandledProvider was missed and is now
reported.

Real repos: tick's categoriesStreamProvider is no longer reported; its
categories screen handles it with `catsAsync.when(...)` through a
variable, which the rule's any-site-handles definition counts as handled.
nuwayze and dex unchanged. word_alive's internalUserProvider finding comes
from a commit made to word_alive during this work, not from this change:
the old code reports it too.
2026-09-22 13:45:11 -06:00
trvon
6e2d47f7db
fix(state-flow): credit freezed factory calls to their redirect target
freezed declares variants as redirecting factories on the base
(`const factory DocState.loading() = DocLoading;`) and blocs emit through
them. `emit(const DocState.loading())` was recorded as emitting
`DocState`, which is never a variant, so no freezed emission matched and
every variant the UI renders was reported by rendered-not-emitted as a
dead branch.

Factory redirects are now also kept by constructor name, and an instance
creation of `Type.ctor` (or an unnamed redirecting factory) is credited to
the class it redirects to, for emissions, `state =` assignments and
dispatches alike.

Reproduced on freezed_style.dart before the fix: DocLoading, DocReady
and DocStale all reported as never emitted; after, only DocStale, which
really is never emitted and stays as the positive control. No change on
nuwayze, tick, dex or word_alive.
2026-09-22 13:39:31 -06:00
trvon
8d64718977
fix(loading-flag-not-reset): analyse closures once, and name handlers
The method-level check read the whole body text, closures included, for
both the `loading: true` probe and the await probe, while the try
collector skips closures. So a method whose closure set the flag and
guarded its own await was reported at high confidence as unguarded, and a
method that only registers `on<E>` closures was reported alongside each
closure. Every probe now stops at nested functions, which are analysed on
their own; the flag probe is a `field: true` named-argument visitor
instead of a regex over source.

`on<E>` handler closures were all named `<closure>`, so two handlers in one
class shared a fingerprint and encodeBaseline kept only one of them. They
are now named `on<E>`. Existing baselines that accepted a handler as
`<closure>` will see it once as new.

Fixture: scheduleGuarded (guarded closure) and registerHandlers are now
negative controls; two unguarded handlers must yield two findings with
distinct fingerprints. Before: scheduleGuarded, registerHandlers and two
colliding `<closure>` findings; after: on<FlagRefresh>, on<FlagReload>.
2026-09-22 13:30:31 -06:00
trvon
cb30269f64
fix(event-rules): follow the event hierarchy and every owning bloc
Two ways the event rules reported handled events as unhandled (error
severity, high confidence):

1. A handler on the event base or an intermediate group. `on<SyncEvent>`
   with a switch inside handles every subclass, but handlers were matched
   to dispatches by exact name, so every dispatched subclass was reported
   by event-without-handler and the base handler itself by dead-handler.
   Variants now record the supertype they were enumerated through, and
   coverage follows it: an event is handled when it or an ancestor is
   registered, and a handler is live when anything at or below it is
   dispatched or constructed. A group handler still does not cover a
   sibling outside the group (UploadAbandoned stays reported).

2. Blocs sharing an event type. Only the first owner of an event type was
   kept, so a second bloc's handlers were ignored: an event only it handles
   was reported unhandled, and its dead handlers were never examined. There
   is now one event union per owning bloc. A dispatch does not record which
   bloc it targets, so an event any sharing bloc handles counts as handled,
   and an unhandled event is reported once per shared union rather than
   once per bloc. Dead handlers are still judged per bloc.

Reproduced first on base_event.dart: 4 false findings before
(SyncStarted, UploadRetryNow unhandled; SyncEvent, UploadRetry dead) and
the shared case (ShareDismissed falsely unhandled, ShareBetaBloc's dead
ShareExpired missed). Each is now a contract control.

No change on nuwayze (102 findings) or tick (2): byte-identical before
and after, since neither uses these patterns.
2026-09-22 13:30:21 -06:00
trvon
f1c0e56a1a
docs(fixtures): record why the UI fixture must stay dependency-free
Some checks failed
Tests / Static Analysis (push) Has been cancelled
Tests / Tests (push) Has been cancelled
The fixture resolves with no pub get and no network, which is why
.dart_tool/package_config.json is committed by hand. Adding a package: import
would silently break every rule test that depends on it, so the constraint is
now stated where someone would violate it.
2026-09-20 21:30:56 -06:00
trvon
3c91db2946
fix: act on the external audit - 5 defects, 5 vacuous tests, a real fixture exclusion bug
Some checks failed
Tests / Static Analysis (push) Has been cancelled
Tests / Tests (push) Has been cancelled
An independent Gemini 3.8 Flash audit of this repo found real problems. Each was
reproduced before being fixed.

Confirmed defects:
- tool/adjudicate.py crashed with KeyError once R001 started grouping variants
  under 'variants' instead of 'variant'. Fixing that exposed a second bug of my
  own: it then divided verified VARIANTS by FINDINGS and reported 216% precision.
  Counts are now coherent (findings vs variant-level checks) and a clean repo
  reports 0/0 rather than a fake 100%.
- GuideCommand called _readPolicy but never registered --policy, so
   exited 64 despite the README documenting it.
- loading-flag-not-reset treated a constructor-invoked method as inheriting the
  loading flag without checking flag.defaultsTrue, so a default-FALSE flag was
  reported as in flight.
- Finding.fingerprint embedded the line number for rules whose only identity was
  , so moving code broke baseline entries.  is now a
  discriminating key; only loading-not-reset, which can emit two findings from one
  method, carries an explicit catchLine.
- suggest grouped unrelated provider-read-in-build findings by file; the group key,
  label and target list now use valueType/call.

Recall defect found while checking the auditor's own claim: UI variant mentions
were collected project-wide by unqualified name, so ExportSuccess - which appears
in FOUR unions on nuwayze - was cross-credited. Mentions are now scoped per union
to files that also name the state type or its owner, which surfaced
ArtistStoreManagementState[ExportSuccess] as a real finding.

Five negative controls could not fail (an event that is never handled can never be
reported as unhandled; a union with no render sites can never be reported as
rendered-not-emitted). Added fixture cases that make each one bite: HandledTap
(handled AND dispatched), PatternState render sites, GuardedCubit (guarded loading
path), QuietCubit._warmUp (constructor-invoked await on a default-false flag).

Root cause of a recurring mystery: this repo EXCLUDED test/fixtures/** from
analysis, which made any analyzer running in the repo context parse the fixture
without resolving its imports and report phantom undefined-class errors. I had
dismissed these as stale cache several times; they were my own exclusion. The
exclude is gone and the fixture governs itself. A new test asserts the fixture has
zero analyzer errors, not merely that it resolves, so IR distortion cannot hide.

84 tests (was 81).
2026-09-20 20:45:58 -06:00
trvon
c391171e6a
fix: attribute typed variable patterns, and stop treating base-field reads as unrendered
Some checks failed
Tests / Static Analysis (push) Has been cancelled
Tests / Tests (push) Has been cancelled
Two real defects found by an audit of nuwayze, both confirmed against the code.

1. Recall: the switch 'case ChatListLoaded value => value' binds the type on a
   DeclaredVariablePattern, not the object pattern ChatListLoaded() this matcher
   looked for. An exhaustive switch was therefore invisible and two variants were
   wrongly reported as never rendered. Both the mention collector and the branch
   collector now handle declared variable patterns.

2. Precision: the UI often reads a union's payload off the BASE class
   (state.currentBooking, state.isRefreshing), so the data reaches the user even
   though the variant is never matched. StateUnion now records uiReadsBaseFields
   and those findings drop to info with an explanation instead of warning. That
   removed 5 false-positive warnings on nuwayze.

3. recall/manifest.json gains status=open|fixed. A fixed case that is reported
   again is a REGRESSION, so repaired bugs become permanent guards against the
   real code instead of deleted expectations. The three bugs fixed earlier today
   (dex x2, word_alive) are now fixed-status guards:
   recall --strict -> 5/5 accounted for, 0 regressions.

nuwayze: 111 findings, 11 warnings (was 16). 75 tests, fixture regression guard
patternView covers the typed-pattern case.
2026-09-20 18:10:56 -06:00
trvon
8244959773
docs: label the provider-created-in-build negative controls in the fixture
Some checks failed
Tests / Static Analysis (push) Has been cancelled
Tests / Tests (push) Has been cancelled
The two Provider<AppConfig>.value uses are the negative controls for
provider-created-in-build: the type is provided, but only through .value, which
passes an instance created once. Saying so in the fixture makes the control
readable instead of implicit.
2026-09-20 18:00:46 -06:00
trvon
88ed85b43a
feat: add notifier-field-unread and provider-created-in-build, bound the brief header
Some checks failed
Tests / Static Analysis (push) Has been cancelled
Tests / Tests (push) Has been cancelled
Completes the provider/ChangeNotifier rule set:

- notifier-field-unread: a public getter on a notifier the UI consumes that
  nothing reads, so the state it exposes cannot reach the user. Once per
  notifier. nuwayze: 3 (UserProvider.isInitializing,
  AppLocaleProvider.preferredLocale, and _AgentHubController with 8 members).

- provider-created-in-build: a provider constructed in build without .value, so
  create reruns on every rebuild. Reported once per build method, not once per
  provider: nuwayze's AppProviders.build constructs 45 of them and that is one
  decision, not 45 bugs. Deliberately info, not warning, because a root
  StatelessWidget rarely rebuilds and static analysis cannot tell rebuild
  frequency apart.

Also fixes a real defect the budget test caught: the brief's 'by rule:' line
grew with the rule count and crowded out the findings it summarises. It is now
capped at the top 6 with a '+N more' suffix, the omission note is reserved for
up front so the artifact stays inside its budget, and the overflow message is
shorter.

75 tests. Verified the fixture with pipe's own resolver (0 errors) and validated
that check by injecting a type error into a copy (errors=1).
2026-09-20 17:59:54 -06:00
trvon
2c7bea9ef0
feat: provider package support - model all provider declaration types, add provider-read-in-build
Some checks failed
Tests / Static Analysis (push) Has been cancelled
Tests / Tests (push) Has been cancelled
Adds the provider half of the state-management surface:
- collects every provider-package declaration type (Provider,
  ChangeNotifierProvider, ListenableProvider, ValueListenableProvider,
  FutureProvider, StreamProvider, StateProvider, ProxyProvider family) and
  reports the counts by type in the coverage note
- new rule provider-read-in-build: a Listenable read with context.read or
  Provider.of(listen: false) directly in a build body, so the widget never
  subscribes and can render stale state

447 raw context.read calls in nuwayze reduce to 1 finding. The first four were
hand-checked and every one was a read inside a closure (a BlobListener-style
listener callback or a Selector builder), so the collector now refuses to
descend into nested functions; that costs recall on reads inside Builder and is
recorded in the README rather than hidden.

Also fixes a third fingerprint collision: valueType/call were missing from the
finding identity, so two provider-read-in-build findings in one file shared a
baseline fingerprint. Identity now requires a discriminating key and falls back
to the line only when there is none.
2026-09-20 17:46:30 -06:00
trvon
4df7cc12b7 fix: track the rule fixture package_config so a fresh clone can run the tests
The fixtures are standalone packages with a hand-written
.dart_tool/package_config.json, and the blanket .dart_tool/ ignore rule
excluded it. Everything passed locally only because the file happened to
exist on disk, so a clone would have failed the rule-contract and recall
tests. Re-include that one path and give the fixture its own
analysis_options so it does not inherit the repository include.
2026-09-20 17:03:35 -06:00
pipe-loop
3cdb32f89d feat: provider rules (notifier-never-notifies, notifier-inert-consumer) with observable-field gate and coverage notes 2026-09-20 16:19:02 -06:00
pipe-loop
f2949dfbfd feat: rule contracts + recall measurement (5/5 real bugs) + real --fail-on gate 2026-09-20 16:00:10 -06:00
pipe-loop
73fdcfeb95 feat: Riverpod support - provider model, riverpod-async-gap rule, tiered by value type 2026-09-20 14:35:40 -06:00
pipe-loop
6859d7e78c feat: phase 5 dogfood - model flag-based state, add loading-flag-not-reset, fixture tests 2026-09-20 14:29:21 -06:00
pipe-loop
80daa12ff8 feat: phase 3 ranked breakage detectors, rules engine, fixture tests 2026-09-20 13:56:52 -06:00