simulate

package
v1.0.310 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 24, 2026 License: MIT Imports: 3 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

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

type CaseResult struct {
	ID       string
	Decision policy.Decision
}

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
)

func (Relation) String

func (r Relation) String() string

String returns the relation label.

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 New

func New(lim policy.Limits) *Simulator

New returns a simulator bounded by lim, backed by the shared policy engine.

func (*Simulator) Compare

func (s *Simulator) Compare(oldSnap, newSnap *policy.Snapshot, cases []Case) (Comparison, error)

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

func (s *Simulator) Corpus(snap *policy.Snapshot, cases []Case) ([]CaseResult, error)

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.

func (*Simulator) Single

func (s *Simulator) Single(snap *policy.Snapshot, in *policy.DecisionInput) Result

Single evaluates one input against one snapshot (decision + explain trace).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL