27: named sources, adapters, and normalized outcomes - #42
Conversation
- Enrich SourceResolver.resolve() context with ResolveContext (required principalId, evaluation now timestamp, optional CancellationSignal) - Add registerPlan() to Mizan instance for named source plans - Add plan-scoped evaluation via forPrincipal(principalId, planName) — resolves only sources referenced by the plan - Keep default forPrincipal() resolving all sources (backward compatible) - Add CancellationSignal interface (runtime-neutral AbortSignal mirror) - Update MemoryAdapter to accept the new ResolveContext - Tests: plan registration, plan-scoped resolution, custom source replacement, context enrichment, adapter-as-fact-provider contract Refs #27
|
@coderabbitai review |
✅ Action performedReview finished.
|
📝 WalkthroughWalkthroughChangesCore plan-scoped evaluation
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant Caller
participant Mizan
participant PrincipalEvaluator
participant SourceResolver
Caller->>Mizan: registerPlan(name, plan)
Caller->>Mizan: forPrincipal(principalId, planName)
Mizan->>PrincipalEvaluator: create evaluator with planName
PrincipalEvaluator->>SourceResolver: resolve({ principalId, now })
SourceResolver-->>PrincipalEvaluator: SourceOutcome facts
PrincipalEvaluator-->>Caller: authorization result
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@coderabbitai review |
✅ Action performedReview finished.
|
|
@coderabbitai review |
✅ Action performedReview finished.
|
|
@coderabbitai review |
✅ Action performedReview finished.
|
|
@coderabbitai review |
✅ Action performedReview finished.
|
|
@coderabbitai review |
✅ Action performedReview finished.
|
|
@coderabbitai review |
✅ Action performedReview finished.
|
|
@coderabbitai review |
✅ Action performedReview finished.
|
|
@coderabbitai review |
✅ Action performedReview finished.
|
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/core/src/index.ts`:
- Around line 33-57: The declared CancellationSignal and ResolveContext.signal
are not wired into the evaluation pipeline. Either add an end-to-end signal
parameter through decide(), can(), forPrincipal(), and collectFacts() so it is
populated when constructing ResolveContext, or update the documentation to
explicitly state cancellation is not yet supported; do not expose the signal as
an active capability while callers cannot provide it.
- Around line 300-328: Update collectFacts plan-source resolution to inspect
each SourcePlanEntry.required value; skip missing resolvers for optional
entries, while continuing to throw the existing error for missing required
sources and retaining normal registration for found sources.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 5c2a6c06-d8ba-47b3-911c-4215b10e0fbe
📒 Files selected for processing (5)
packages/core/__tests__/decision.test.tspackages/core/src/index.tspackages/memory/__tests__/decision.test.tspackages/memory/__tests__/smoke.test.tspackages/memory/src/index.ts
…urcePlanEntry.required
|
@coderabbitai review |
✅ Action performedReview finished.
|
|
@coderabbitai review |
✅ Action performedReview finished.
|
|
@coderabbitai review |
✅ Action performedReview finished.
|
Summary
Introduce the adapter and named-source boundary that lets Mizan consume facts from any host data source. Add the normalized source outcomes needed by later source plans.
Changes
Core (@mizan/core)
principalId, evaluationnowtimestamp, and optionalCancellationSignalforPrincipal(principalId, planName?)— with plan, only referenced sources are resolved; without plan, all sources (backward compatible)get()andhas()for plan validationMemory Adapter (@mizan/memory)
resolve()to acceptResolveContext(requiresprincipalId+now)Tests
Acceptance criteria coverage
Refs #27
Verification
bun run typecheck)bun run test— 58 pass, 0 fail)bun run build)Summary by CodeRabbit
New Features
principalId, annowtimestamp, and optional cancellation signaling.Bug Fixes
principalIdand a validnow).Tests