flowgen

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: 12 Imported by: 0

Documentation

Overview

Package flowgen generates flowtest Units outcome-first: a typed plan is drawn from a seeded, weighted block grammar, and the Starlark script, the drive ops and the expectation all derive from that one plan, so every generated flow is self-validating by construction. Grammar v2 adds the nondeterministic surface without giving up that property: a select block races a timer against a driver-fed channel but consumes the value either way, a cancel unit races the driver's cancel against completion under a two-state expectation, and a fail unit ends its blocks with a deliberate failure. Grammar v3 reaches the child and poll surfaces: a child block spawns an awaitable or detached child running a record-free mini-plan, and a poll block drives the ledger-backed testkit counter through a CEL predicate that forces a known number of not-ready re-polls. Grammar v4 adds the real built-in modules to the mix: a gitlab_call block calls the GitLab REST API, where every status is data rather than an error, and an emit block publishes a CloudEvent through the event module's inlineable emit.

Index

Constants

View Source
const GeneratorVersion = "flowgen/v4"

GeneratorVersion identifies the grammar; recorded in each unit's provenance so any session is re-renderable from (seed, version, config).

Variables

This section is empty.

Functions

func Generate

func Generate(rng *rand.Rand, cfg Config) (*flowtest.Unit, error)

Generate draws one unit from rng: it mints a seed, then derives everything else from a unit-local RNG so the unit is a pure function of (seed, GeneratorVersion, cfg).

func GenerateFromSeed

func GenerateFromSeed(seed int64, cfg Config) (*flowtest.Unit, error)

GenerateFromSeed renders the unit seed draws under cfg. Re-rendering a recorded session is this call: its ledger row carries both arguments.

Types

type BlockKind

type BlockKind int

BlockKind identifies one grammar production.

const (
	BlockSleep BlockKind = iota
	BlockTimerGather
	BlockEcho
	BlockDelay
	BlockRecord
	BlockRecv
	BlockLoop
	BlockSelectRace
	BlockChildAwait
	BlockChildStart
	BlockPoll
	BlockGitLabCall
	BlockEmit
)

func (BlockKind) String

func (k BlockKind) String() string

type Config

type Config struct {
	// MaxBlocks caps the sequential blocks per unit; default 8, min 1.
	MaxBlocks int
	// MaxChannels caps the channel kwargs per unit; default 2.
	MaxChannels int
	// DurationScale scales every generated duration; default 1.0, must not
	// be negative. Large scales stretch sleeps, timers, and jitter alike, and
	// a unit's cumulative duration must stay well below the driver's
	// SessionDeadline, or the session-not-lost check fires for pacing, not
	// correctness reasons.
	DurationScale float64
	// Weights biases the block-kind draw. A kind absent from the map keeps its
	// default weight of 1; weight 0 disables a kind.
	Weights map[BlockKind]int
	// CancelProbability is the chance in [0, 1] that a unit gets a cancel op
	// racing its completion; default 0. Such a unit expects either terminal and
	// draws no record block.
	CancelProbability float64
	// FailProbability is the chance in [0, 1] that a unit ends its blocks with a
	// deliberate fail(); default 0. Such a unit expects Failed. Canceling and
	// failing are arms of one draw, so the two probabilities must sum to at most
	// 1.
	FailProbability float64
}

Config bounds and biases the grammar. The zero value uses all defaults.

func ParseCanonicalConfig

func ParseCanonicalConfig(s string) (Config, error)

ParseCanonicalConfig reads back a config rendered by CanonicalConfig.

func (Config) CanonicalConfig

func (c Config) CanonicalConfig() string

CanonicalConfig renders the effective config: defaults resolved and the weight table materialized for every kind, so it pins the exact grammar a seed was drawn against without depending on today's defaults. Idempotent under ParseCanonicalConfig.

func (Config) Swarm

func (c Config) Swarm(seed uint64) Config

Swarm returns c with a weight in [0, maxSwarmWeight] drawn for every block kind from seed. Replicas swarming under different seeds explore different statistical mixes of the grammar, while each unit's provenance still pins the table it was drawn from.

Jump to

Keyboard shortcuts

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