koura-testing
v0.1.0
Published
Test harness utilities for the koura framework. Makes it easy to test rules, engine runs, and trace output in isolation. All utilities are generic over `D extends ProjectionDomain`.
Readme
koura-testing
Test harness utilities for the koura framework. Makes it easy to test rules, engine runs, and trace output in isolation. All utilities are generic over D extends ProjectionDomain.
Key Exports
| Export | Description |
|--------|-------------|
| createRuleHarness(rule) | Wraps a rule for isolated effect testing |
| createRuleContext(overrides) | Builds a RuleContext with sensible defaults |
| runFixture(fixture) | Runs a complete engine fixture and returns the result |
| assertNoViolations(result) | Throws if any violations exist |
| assertViolationExists(result, kind) | Throws if no violation of given kind found |
| assertDerivedFact(result, key, expected) | Checks derived store |
| assertTraceContainsRule(result, ruleId) | Checks trace for a rule |
| assertPhaseExecuted(result, phaseId) | Checks trace for phase entries |
| assertDiagnosticExists(result, kind) | Checks diagnostics |
| serializeResult(result, options?) | Deterministic JSON snapshot of a result |
Usage
import { createRuleHarness, createRuleContext } from 'koura-testing';
import { sameKindSizeSyncRule } from 'koura-graph';
const harness = createRuleHarness(sameKindSizeSyncRule);
const ctx = createRuleContext({ phase: 'derive', source: mySource, facts: myFacts });
const effects = harness.runDerive(ctx);
expect(effects).toHaveLength(1);Rules emit declarative effect descriptors — test the kind, operation, target, and params fields rather than calling apply().
