invariant

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package invariant registers invariant checks, matching runtime-diagnostics/invariants. Development checks enforce event ordering, turn/step pairing, tool pairing, and goal CAS revisions before invalid state reaches persistence. Violations identify the owning package. Production can disable checks with SetEnabled(false).

Initialize a Registry and register checks per package; Run collects all failures. Errors use the prefix INVARIANT [pkgName] for diagnosis.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsEnabled

func IsEnabled() bool

IsEnabled returns the global invariant-checking state.

func SetEnabled

func SetEnabled(on bool)

SetEnabled globally enables or disables checks; production can disable them at startup.

Types

type Checker

type Checker func() error

Checker returns nil on success or an error for a violation.

type InvariantError

type InvariantError struct {
	// Pkg is the registered owner, such as pkg/session.
	Pkg string
	// Msg describes the violation.
	Msg string
}

InvariantError describes a violation and its owning package.

func (*InvariantError) Error

func (e *InvariantError) Error() string

Error includes the owning package for diagnosis.

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry groups invariant checkers by package.

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates an empty invariant registry.

func (*Registry) Ledger

func (r *Registry) Ledger() []string

Ledger returns violations in registration order for auditing and assertions.

func (*Registry) MustSatisfy

func (r *Registry) MustSatisfy()

MustSatisfy panics on any violation as a development assertion. It becomes a no-op when checks are disabled.

func (*Registry) Register

func (r *Registry) Register(pkgName string, checker Checker) error

Register adds a checker to a package. Empty package names are rejected and nil checkers are ignored. Packages register during initialization; the harness runs checks before critical writes such as Session.Append.

func (*Registry) Run

func (r *Registry) Run() []error

Run returns all violations in deterministic package order. Disabled checks return nil immediately. Checker panics become errors so other checks still run.

Jump to

Keyboard shortcuts

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