assert

package
v0.194.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: Apache-2.0, MIT Imports: 4 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 assert is the fixed registry of named deterministic checks a `gate` node may name (yaah-0u0v.21).

An allowlist, not a namespace

A document names one of the checks below by name. A name this package does not hold makes the gate unrunnable — it does not fall back to an expression evaluator, a shell command, or a model. That is the deliberate half of the gate design ("named asserts only"): a deterministic scheduler can only promise a deterministic answer for code it ships, and a free-form expression language is a second language to specify, sandbox, and validate. The validator (validate's WF037) and the scheduler both read this ONE list, so a document that validates is a document the scheduler can evaluate, and there is no second copy of the vocabulary to drift.

The signature

func(Input) (bool, string)

Input carries the check's subject and its declared arguments; the answer is the verdict plus one short sentence saying why. Every check is pure: no clock, no I/O, no randomness, and no map iteration whose order could reach the answer. The scheduler evaluates a check inside a reducer cycle and records both values it returned; nothing re-runs it.

The subject

A check that reads a value (Spec.ReadsValue) is handed it in Input.Value. The subject is the recorded value of the step named by the reserved argument "from" — and, when the author names none, the recorded values of the gate's own needs, in declaration order. Input.Value is nil when the subject step produced nothing, so a check can tell "no value at all" from "an empty value" and both answers stay honest: an assert that cannot be proven is not a pass.

Arguments

Spec.Args declares the argument keys a check reads and the kind each must have; every declared argument is required, every undeclared one is refused. Problem answers "would this assert run at all" from the declarations alone, which is what makes the same sentence usable as a validation finding and as a run-time refusal.

Index

Constants

View Source
const SubjectKey = "from"

SubjectKey is the reserved argument that names the step whose recorded value is the check's subject. It is not passed to the check: it selects its input.

Variables

This section is empty.

Functions

func Names

func Names() []string

Names returns every registered assert name, sorted. The slice is a copy: the allowlist is a package invariant, not a caller's to edit.

func Problem

func Problem(name string, args map[string]any) string

Problem reports why one assert declaration cannot run, or "" when it can. It answers from the declaration alone — the name, the argument keys, the argument kinds, and the shape of the subject reference — so a validator can report it before a run and a scheduler can refuse it without ever calling the check. The message is a phrase, not a sentence with a leading code: the caller states which rule or which node found it.

Types

type ArgKind

type ArgKind string

ArgKind is the shape a declared argument must have. The set is deliberately small: an assert's arguments are literal document data, and a kind the vocabulary cannot express is a check that needs a different declaration rather than a looser one.

const (
	// ArgNumber is an integer or floating-point number.
	ArgNumber ArgKind = "number"
)

Argument kinds.

type Check

type Check func(Input) (bool, string)

Check is the one fixed signature every registry entry has.

type Input

type Input struct {
	// Value is the subject: the recorded value of the step named by "from", or
	// the gate's needs' values in declaration order. nil means no value was
	// produced.
	Value any
	// Args are the check's declared arguments, exactly as the document wrote
	// them. The reserved "from" key is not present.
	Args map[string]any
}

Input is what one check is evaluated against.

type Spec

type Spec struct {
	// Name is the allowlist key a document names.
	Name string
	// Doc states, in one line, what a pass means. It is the sentence a reader
	// of the registry needs; the checks themselves document the reasons.
	Doc string
	// ReadsValue reports that the check reads Input.Value. A check that does
	// not read one is a check over its arguments alone, and naming "from" for
	// it is refused rather than ignored.
	ReadsValue bool
	// Args declares the accepted argument keys and their required kinds. Every
	// declared argument is required; an empty map means the check takes none.
	Args map[string]ArgKind
	// Check is the evaluation.
	Check Check
}

Spec is one registry entry: what the check is called, what it means, what it reads, and the arguments it accepts.

func Lookup

func Lookup(name string) (Spec, bool)

Lookup returns the entry for one name.

Jump to

Keyboard shortcuts

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