oracle

package
v19.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package oracle verifies invariants over the observation channels a flowtest run leaves behind. The invariant registry is the single source of truth for the verifiable properties: the verifier evaluates it and the documentation catalog is rendered from it.

Index

Constants

View Source
const DefaultRetentionWindow = 89 * 24 * time.Hour

DefaultRetentionWindow is the reconciliation lookback floor: the engine retires workflow partitions after its 90-day retention window (see doc/autocore.md, "Partition Management & Retention"), and one safety day less keeps a bucket retired mid-verify out of the reconciled population.

Variables

This section is empty.

Functions

func RenderCatalog

func RenderCatalog() []byte

RenderCatalog renders the invariant catalog as a Markdown document from the registry, deterministically: one table per class, invariants in evaluation order. The output is written to doc/flowtest-invariants.md by `make regenerate-flowtest-docs`; the registry stays the single source of truth and CI fails when the generated file drifts from it.

Types

type CheckContext

type CheckContext struct {
	Ledger *ledger.Store
	// History carries the system-under-test's own databases. Nil skips
	// history-kind checks.
	History *HistoryChannel
	// Metrics carries the run's Prometheus. Nil skips metrics-kind checks.
	Metrics   *MetricsChannel
	PostDrain bool      // the run has quiesced: liveness checks may assert emptiness
	Now       time.Time // evaluation instant (deadline comparisons)
	// Window bounds verification to the sessions and workflows created in
	// [Since, Until). A zero bound leaves that side unbounded.
	// Metrics checks diverge one-sidedly: their ranges cover [Since, Now]
	// rather than [Since, Until), because terminals recorded during the
	// drain tail must stay in range.
	Window Window
	// RetentionWindow floors the directory reconciliation's lookback so
	// engine retention is not mistaken for corruption; zero means
	// DefaultRetentionWindow.
	RetentionWindow time.Duration
	// contains filtered or unexported fields
}

CheckContext carries the observation channels a check may use. Fields are nil when the corresponding channel is not configured; checks requiring a nil channel are skipped and reported as such.

type CheckFunc

type CheckFunc func(ctx context.Context, cc *CheckContext) (*Result, error)

type CheckKind

type CheckKind int

CheckKind names the observation channel an invariant's check consumes.

const (
	CheckLedger CheckKind = iota + 1
	CheckHistory
	CheckMetrics
)

func (CheckKind) MarshalJSON

func (k CheckKind) MarshalJSON() ([]byte, error)

func (CheckKind) String

func (k CheckKind) String() string

func (*CheckKind) UnmarshalJSON

func (k *CheckKind) UnmarshalJSON(data []byte) error

type Class

type Class int

Class groups invariants by the kind of guarantee they verify.

const (
	ClassSafety Class = iota + 1
	ClassLiveness
	ClassCoverage
)

func (Class) MarshalJSON

func (c Class) MarshalJSON() ([]byte, error)

func (Class) String

func (c Class) String() string

func (*Class) UnmarshalJSON

func (c *Class) UnmarshalJSON(data []byte) error

type HistoryChannel

type HistoryChannel struct {
	Central  *pgxpool.Pool
	Workflow []WorkflowDB // every workflow DB in the deployment
}

HistoryChannel is the observation channel for history-kind checks: direct read access to the system-under-test's own databases.

type Invariant

type Invariant struct {
	Name        string // kebab-case, unique
	Class       Class
	Kind        CheckKind
	Severity    Severity
	Description string // one or two sentences, rendered into the catalog
	DocAnchor   string // optional doc/autocore.md anchor for background
	Check       CheckFunc
}

Invariant is one verifiable property of the system under test. The registry is the single source of truth: the verifier evaluates it and the documentation catalog is rendered from it.

func All

func All() []Invariant

All returns the registered invariants in evaluation order.

type InvariantResult

type InvariantResult struct {
	Name       string      `json:"name"`
	Class      Class       `json:"class"`
	Kind       CheckKind   `json:"kind"`
	Severity   Severity    `json:"severity"`
	Checked    int64       `json:"checked"`
	Violations []Violation `json:"violations,omitempty"`
	Skipped    bool        `json:"skipped,omitempty"`
	SkipReason string      `json:"skip_reason,omitempty"`
}

InvariantResult pairs an invariant's identity with its evaluation result.

type MetricsChannel

type MetricsChannel struct {
	// Query evaluates one instant PromQL query at the given instant and sums
	// the resulting vector to a single value. An empty vector sums to 0.
	Query func(ctx context.Context, promql string, at time.Time) (float64, error)
}

MetricsChannel is the observation channel for metrics-kind checks.

func NewPrometheusMetricsChannel

func NewPrometheusMetricsChannel(baseURL string) *MetricsChannel

NewPrometheusMetricsChannel returns a MetricsChannel backed by the Prometheus HTTP API at baseURL (e.g. http://prometheus:9090): each Query runs one instant query against /api/v1/query and sums the resulting vector to a single value.

type Report

type Report struct {
	Results []InvariantResult `json:"results"`
}

Report is the outcome of evaluating a set of invariants.

func Evaluate

func Evaluate(ctx context.Context, cc *CheckContext, invs []Invariant) (*Report, error)

Evaluate runs the given invariants against the configured observation channels. A check error aborts the evaluation: it means the check could not run, not that the invariant is violated.

func (*Report) Pass

func (r *Report) Pass() bool

Pass reports whether no evaluated invariant of SeverityViolation recorded a violation. Warnings and skipped invariants never fail a run.

func (*Report) RenderMarkdown

func (r *Report) RenderMarkdown() string

RenderMarkdown renders the report as a compact human-readable summary: one status line per invariant with sample violations underneath.

type Result

type Result struct {
	Checked    int64       // population size examined
	Violations []Violation // empty = pass
	Skipped    bool        // channel not configured / not applicable in this mode
	SkipReason string
}

type Severity

type Severity int

Severity decides what a violation means for the run's verdict.

const (
	// SeverityViolation fails a run.
	SeverityViolation Severity = iota + 1
	// SeverityWarning is reported but never fails a run.
	SeverityWarning
)

func (Severity) MarshalJSON

func (s Severity) MarshalJSON() ([]byte, error)

func (Severity) String

func (s Severity) String() string

func (*Severity) UnmarshalJSON

func (s *Severity) UnmarshalJSON(data []byte) error

type Violation

type Violation struct {
	Detail  string `json:"detail"`            // human-readable, self-contained
	Subject string `json:"subject,omitempty"` // session id / workflow key the violation anchors to, if any
}

type Window

type Window struct {
	Since time.Time
	Until time.Time
}

Window is a half-open creation-time interval [Since, Until). A zero bound leaves that side unbounded.

type WorkflowDB

type WorkflowDB struct {
	Name string           // identifies the DB in violation details
	DBID persistence.DBID // identity in the central registry, for shard routing checks
	Pool *pgxpool.Pool
}

WorkflowDB is one workflow database of the deployment under test.

Directories

Path Synopsis
cmd
docgen command
Command docgen writes the flowtest invariant catalog rendered from the oracle registry.
Command docgen writes the flowtest invariant catalog rendered from the oracle registry.

Jump to

Keyboard shortcuts

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