Documentation
¶
Overview ¶
Package simulate is the PR-6 policy simulator. It evaluates decision inputs against immutable policy snapshots using the EXACT SAME compiled evaluator the runtime uses (policy.Engine.Evaluate) — there is no second "simulation evaluator" — and computes deterministic single-case results, bounded-corpus results, old-vs-new revision comparisons (blast radius) and side-by-side shadow comparisons. It is PURE: it publishes nothing, activates no policy, modifies no runtime, calls no provider, executes no tool, performs no I/O, and retains no raw arguments. It never mutates either snapshot.
Index ¶
- type Case
- type CaseResult
- type ChangedCase
- type Comparison
- type Relation
- type Result
- type ShadowResult
- type Simulator
- func (s *Simulator) Compare(oldSnap, newSnap *policy.Snapshot, cases []Case) (Comparison, error)
- func (s *Simulator) Corpus(snap *policy.Snapshot, cases []Case) ([]CaseResult, error)
- func (s *Simulator) Shadow(active, candidate *policy.Snapshot, in *policy.DecisionInput) ShadowResult
- func (s *Simulator) Single(snap *policy.Snapshot, in *policy.DecisionInput) Result
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Case ¶
type Case struct {
ID string
Input policy.DecisionInput
}
Case is one named decision input in a simulation corpus.
type CaseResult ¶
CaseResult is a corpus case's decision (bounded, no trace to keep it compact).
type ChangedCase ¶
type ChangedCase struct {
ID string
OldAction policy.Action
NewAction policy.Action
OldReason policy.ReasonCode
NewReason policy.ReasonCode
OldRule policy.RuleID
NewRule policy.RuleID
NewAllowClass bool // the candidate newly permits — a security-sensitive blast-radius class
}
ChangedCase is a bounded evidence sample of a decision that changed between snapshots. It carries only safe metadata.
type Comparison ¶
type Comparison struct {
Total int
Unchanged int
ActionChanges int
ReasonChanges int
RuleChanges int
ObligationChanges int // same action/reason/rule but a different obligation payload
NewAllow int // NEW ALLOW-class decisions (security-sensitive)
NewDeny int
NewQuarantine int
NewApprovalRequired int
AffectedRules []policy.RuleID // sorted, deduped
Samples []ChangedCase // bounded by MaxCompareSamples
ByTenant map[string]int // changed-case counts per tenant
ByServer map[string]int // changed-case counts per server
ByTool map[string]int // changed-case counts per tool
}
Comparison is the deterministic blast-radius summary of evaluating one corpus against an old and a proposed snapshot.
type Relation ¶
type Relation uint8
Relation is the permissiveness relation of a candidate decision to the active one.
const ( // RelEqual — same action. RelEqual Relation = iota // RelBroader — the candidate is more permissive than the active decision. RelBroader // RelNarrower — the candidate is more restrictive than the active decision. RelNarrower // RelIncomparable — same permissiveness rank but a different action/reason. RelIncomparable )
type Result ¶
type Result struct {
Decision policy.Decision
Trace policy.ExplainTrace
}
Result is a single-case simulation result: the runtime-safe decision plus the internal explain trace.
type ShadowResult ¶
type ShadowResult struct {
Active policy.Decision
Candidate policy.Decision
Relation Relation
Changed bool
}
ShadowResult is a side-by-side evaluation of the active and candidate snapshots for one input. It never changes the active decision.
type Simulator ¶
type Simulator struct {
// contains filtered or unexported fields
}
Simulator runs the shared evaluator over inputs/snapshots. It holds no mutable state beyond the bounds.
func (*Simulator) Compare ¶
Compare evaluates the same corpus against oldSnap and newSnap and returns a deterministic blast-radius summary. New ALLOW-class decisions are highlighted (NewAllow) as the security-sensitive class. It mutates neither snapshot and does no I/O.
func (*Simulator) Corpus ¶
Corpus evaluates a bounded set of cases against one snapshot. It rejects an over-limit corpus (deterministic, no silent truncation).
func (*Simulator) Shadow ¶
func (s *Simulator) Shadow(active, candidate *policy.Snapshot, in *policy.DecisionInput) ShadowResult
Shadow evaluates one input against BOTH the active and candidate snapshots and returns both decisions plus their permissiveness relation. It is a pure function and mutates neither snapshot — a foundation for later shadow/canary work, not a rollout mechanism.