Skip to content

The Testing Ledger

lpetronika edited this page Feb 16, 2026 · 3 revisions

The Testing Ledger

This page covers the test suite for react-state-basis. Every test validates a specific part of the v0.6.x engine, making sure the graph layer doesn't break performance or leak memory.

1. graph.test.ts - Spectral Ranking

Tests the Eigenvector Centrality algorithm that identifies "Prime Movers." The goal is to make sure the math picks the right root cause across different graph shapes.

  • Star Topology: A single node triggering multiple leaves ($Event \rightarrow \lbrace A, B, C \rbrace$) should rank highest.
  • Chain Topology: In a cascade ($A \rightarrow B \rightarrow C$), Node A should get the top score. The algorithm shouldn't be biased toward leaf nodes.
  • Convergence: The power iteration must stabilize within 20 iterations (tolerance < 0.001). Deterministic results, no runaway computation.
  • Loop Resistance: Circular dependencies ($A \leftrightarrow B$) must not crash or diverge the scoring.

2. ranker.test.ts - Ranking Logic

Tests the ranking engine that turns raw graph scores into human-readable priorities.

  • Event Aggregation: Multiple event ticks that hit the same set of targets get merged into a single "Global Event" issue.
  • Context Filtering: Context nodes naturally have high influence, but they shouldn't show up in the "Refactor Priority" list. That would be a false positive.
  • Label Borrowing: Anonymous event nodes pick up filenames from their target variables so the report shows a useful location.

3. engine.logic.test.ts - Causal Resolution

Tests the implicit event detection and graph cleanup.

  • Effect vs. Event: The engine must correctly tell the difference between Effects (explicit causal chains) and Events (implicit external triggers) when recording edges.
  • Graph Pruning: Event nodes older than the TTL window get deleted from the adjacency matrix. No memory leaks during long sessions.
  • Sibling Independence: If two variables are driven by the same event, the engine must not flag them as a causal leak. They're siblings, not a dependency chain.

4. math.test.ts - Correlation Math

Tests the cross-correlation math that powers redundancy detection.

  • Phase Sweep: An exhaustive $50 \times 50$ loop proving head-pointer independence. Two identical signals must return 1.0 similarity regardless of buffer rotation.
  • Negative Offsets: Pre-normalization must correctly handle negative temporal offsets without out-of-bounds access.
  • Jitter Tolerance: The 0.88 threshold must hold up against 10% signal noise from browser scheduling jitter.

5. reports.test.ts - Health Report Accuracy

Tests that the Health Report produces correct scores and suggestions.

  • Efficiency Score: The score gets penalized not just by redundancy, but by Causal Leaks (edges with path length > 1).
  • Suggestion Logic: The logger picks the right fix based on the data type:
    • Booleans $\rightarrow$ Suggests "Status Enum / Reducer".
    • Values $\rightarrow$ Suggests "useMemo".
    • Contexts $\rightarrow$ Suggests "Direct Consumption".

6. hooks.test.tsx - Hook Proxies

Tests that the instrumented hooks register correctly and track side effects.

  • Effect Tracking: useEffect must register as a source node when it triggers a state update inside its callback.
  • Role Assignment: useState registers as LOCAL, useContext registers as CONTEXT.
  • Anonymous Fallbacks: If the Babel plugin isn't present, the hooks fall back to anon_state_X labeling without crashing.

Clone this wiki locally