Conversation
…ntext state (#46) Eliminates module-level Sets and manual reset functions in component rules by introducing `analysisState` on RuleContext. Each analysis run gets a fresh Map, so dedup state is automatically scoped and garbage-collected — no more fragile reset contracts between rule-engine and individual rules. https://claude.ai/code/session_01JYHYR7hwuZ7cLwrJadAcVz
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughRule execution state was moved from module-level globals to a per-analysis Map injected on Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant RuleEngine
participant Traverser
participant Rule as Rule/RuleContext
Client->>RuleEngine: analyze(AnalysisFile)
Note right of RuleEngine: creates analysisState = Map()
RuleEngine->>Traverser: traverseAndCheck(rootNode, analysisState)
Traverser->>Rule: build RuleContext (includes analysisState)
Note right of Rule: rule.check(context)
Rule->>Rule: getAnalysisState(context, key, init) — create/read per-analysis Set
Rule->>Traverser: (recursive) traverse children with same analysisState
Traverser->>RuleEngine: return collected issues
RuleEngine->>Client: analysis results
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/core/engine/rule-engine.ts (1)
147-179: 🧹 Nitpick | 🔵 TrivialAdd a regression that goes through
RuleEngine.analyze()twice.This is the code path that guarantees a fresh
analysisStateper run. A small integration test that callsanalyze()twice on the sameRuleEngineinstance and expects the same component-dedup violation both times would lock in the production bugfix.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/core/engine/rule-engine.ts` around lines 147 - 179, Add an integration test that exercises RuleEngine.analyze() twice on the same RuleEngine instance to ensure analysisState is fresh per run: instantiate a RuleEngine with the same test document, call analyze(file) once and capture issues, call analyze(file) a second time and assert the same component-dedup violation (or identical issues) is produced; target the RuleEngine.analyze method and the traversal path through traverseAndCheck/analysisState to reproduce any state-leak regression.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/core/contracts/rule.ts`:
- Around line 53-58: getAnalysisState currently treats a cached undefined the
same as a missing key because it checks the retrieved value (`existing !==
undefined`) instead of whether the Map contains the key; update getAnalysisState
to call context.analysisState.has(key) to detect presence, and only call
context.analysisState.get(key) when has(...) is true, otherwise run init(), set
the result with context.analysisState.set(key, value) and return it so an
initializer that returns undefined is preserved in the cache; references:
function getAnalysisState, property analysisState on RuleContext, parameter key
and init.
---
Outside diff comments:
In `@src/core/engine/rule-engine.ts`:
- Around line 147-179: Add an integration test that exercises
RuleEngine.analyze() twice on the same RuleEngine instance to ensure
analysisState is fresh per run: instantiate a RuleEngine with the same test
document, call analyze(file) once and capture issues, call analyze(file) a
second time and assert the same component-dedup violation (or identical issues)
is produced; target the RuleEngine.analyze method and the traversal path through
traverseAndCheck/analysisState to reproduce any state-leak regression.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: a826e6bc-a1b3-4392-b232-261a8cbe8f08
📒 Files selected for processing (7)
src/core/contracts/rule.tssrc/core/engine/rule-engine.tssrc/core/rules/ai-readability/invisible-layer.test.tssrc/core/rules/component/index.test.tssrc/core/rules/component/index.tssrc/core/rules/component/missing-component.test.tssrc/core/rules/custom/custom-rule-loader.test.ts
- Fix: Map.has() instead of !== undefined to correctly cache undefined values - Add: RuleEngine.analyze() regression test verifying fresh state per run https://claude.ai/code/session_01JYHYR7hwuZ7cLwrJadAcVz
Summary
analysisState: Map<string, unknown>toRuleContextand a typedgetAnalysisState<T>()helper for lazy-init per-analysis stateSets and 2reset*()functions fromcomponent/index.tsrule-engine.tscreates a freshMapperanalyze()call — no more manual reset contractsanalysisStateper test instead of calling reset functionsCloses #46
Why this is the top priority for v1
See comment on #46 for the full rationale.
Test plan
pnpm lint)analysisState= fresh dedup state (tested explicitly)https://claude.ai/code/session_01JYHYR7hwuZ7cLwrJadAcVz
Summary by CodeRabbit
Bug Fixes
Refactor
Tests