selftest

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2026 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Overview

Package selftest runs the Nexss Flow self-test suite: a feature-by- feature check of every registered bundle, run in-process against the binary's own compiler and runtime.

It is designed to be embedded: `nflow self test` prints a live, category-colored checklist and exits 0 only when every feature passes. Both inline SelfTest() sections and *.nflow fixtures embedded by each bundle (Bundle.Fixtures) are discovered automatically and executed identically regardless of working directory or installed files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(ctx context.Context, opts Options) int

Run executes the suite and returns a process exit code: 0 when every selected feature passes, 1 when at least one fails, 2 on configuration error (bad filter matched nothing).

The runner configuration is built exactly once. It is shared across every feature; fixtures are expected to be self-contained (each one declares its own @pipeline / @pool names). A fixture that references a name declared only by another fixture would still compile here, because the resolver is shared — the same way production behaves when two .nflow files are loaded into one process.

func SaveBaseline

func SaveBaseline(s Score) error

SaveBaseline writes the current run's fingerprint to the working directory. Overwrites any existing baseline; the caller is expected to invoke this only when the new behavior is intended.

func Sections

func Sections() []core.SelfTestSection

Sections returns every feature contributed by every registered bundle. Inline self-tests come first (in declaration order); auto-discovered fixtures follow in lexical order.

Types

type FeatureStat

type FeatureStat struct {
	Name          string        `json:"name"`
	Section       string        `json:"section,omitempty"`
	Elapsed       time.Duration `json:"elapsed_ns"`
	Allocs        uint64        `json:"allocs"`
	CompileAllocs uint64        `json:"compile_allocs"`
	RunAllocs     uint64        `json:"run_allocs"`
}

FeatureStat is one row in the slowest/top-allocator rankings.

type HostInfo

type HostInfo struct {
	GOOS       string `json:"goos"`
	GOARCH     string `json:"goarch"`
	GoVersion  string `json:"go_version"`
	NumCPU     int    `json:"num_cpu"`
	CPUModel   string `json:"cpu_model,omitempty"`
	Goroutines int    `json:"goroutines"`
}

HostInfo captures the runtime environment at the moment `nflow self test` starts. Every field is populated without spawning a subprocess and without CGo, so detection costs microseconds and behaves identically on Windows, Linux, macOS, and inside containers.

func DetectHost

func DetectHost() HostInfo

func (HostInfo) FormatBanner

func (h HostInfo) FormatBanner() string

FormatBanner returns the one-line host summary shown above the report.

type Options

type Options struct {
	Out          io.Writer // terminal output (default os.Stdout)
	Filters      []string  // case-insensitive substrings; empty = all sections
	Verbose      bool      // print DSL and full failure details
	NoColor      bool      // disable ANSI color
	NoSpinner    bool      // disable live updates (for CI logs)
	JSON         bool      // emit machine-readable JSON summary instead of text
	SaveBaseline bool      // write .nflow_selftest_baseline.json after the run
}

Options configures a self-test run.

type Renderer

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

Renderer writes the live checklist. When its writer is a TTY it overwrites each feature line in place as the result arrives; when redirected, it prints plain lines suitable for CI logs.

func (*Renderer) Banner

func (r *Renderer) Banner(sections []core.SelfTestSection)

func (*Renderer) FeatureDone

func (r *Renderer) FeatureDone(res Result)

FeatureDone prints one feature line: elapsed time, allocation counts split by phase, and — when the feature lives in an embedded *.nflow fixture — the path of that file. The path is deliberately shown last so the aligned columns stay readable when only some features are file-backed.

func (*Renderer) FeatureStart

func (r *Renderer) FeatureStart(_ core.SelfTestFeature)

func (*Renderer) ScoreSummary

func (r *Renderer) ScoreSummary(s Score, host HostInfo)

func (*Renderer) SectionDone

func (r *Renderer) SectionDone(s core.SelfTestSection, all []Result, elapsed time.Duration)

func (*Renderer) SectionStart

func (r *Renderer) SectionStart(s core.SelfTestSection)

func (*Renderer) Summary

func (r *Renderer) Summary(results []Result, elapsed time.Duration)

func (*Renderer) TopMetrics

func (r *Renderer) TopMetrics(s Score)

TopMetrics prints the slowest features and the biggest allocators. The allocator list shows the compile and run split so a reader can tell which phase dominated for that feature.

func (*Renderer) UnmatchedFilters

func (r *Renderer) UnmatchedFilters(filters []string)

UnmatchedFilters prints a red block after the summary listing every filter argument that matched no section and no feature.

type Result

type Result struct {
	core.SelfTestFeature
	Section           string
	Status            Status
	Elapsed           time.Duration
	CompileAllocs     uint64
	CompileAllocBytes uint64
	RunAllocs         uint64
	RunAllocBytes     uint64
	Err               error
	AssertErrs        []error
	SkipReason        string
	Captured          []byte
}

Result is one feature's outcome.

Elapsed covers the whole runner.Execute call. CompileAllocs and RunAllocs split the allocation count by phase: the compile phase is the compiler's cost for parsing and building this DSL fragment, the run phase is the actual runtime cost of the pipeline. In a feature like `noop` all the work is in CompileAllocs and RunAllocs is zero.

func (Result) TotalAllocBytes

func (r Result) TotalAllocBytes() uint64

TotalAllocBytes is the per-feature sum of compile and run bytes.

func (Result) TotalAllocs

func (r Result) TotalAllocs() uint64

TotalAllocs is the per-feature sum of compile and run allocations.

type Score

type Score struct {
	Passed  int `json:"passed"`
	Failed  int `json:"failed"`
	Skipped int `json:"skipped"`
	Total   int `json:"total"`

	Fingerprint string `json:"fingerprint"`

	TotalAllocs        uint64 `json:"total_allocs"`
	TotalAllocBytes    uint64 `json:"total_alloc_bytes"`
	TotalCompileAllocs uint64 `json:"total_compile_allocs"`
	TotalRunAllocs     uint64 `json:"total_run_allocs"`

	Slowest       []FeatureStat `json:"slowest,omitempty"`
	TopAllocators []FeatureStat `json:"top_allocators,omitempty"`

	BaselineFingerprint string `json:"baseline_fingerprint,omitempty"`
	BaselineMatched     bool   `json:"baseline_matched,omitempty"`
	BaselinePresent     bool   `json:"baseline_present,omitempty"`
}

Score summarizes one self-test run in a form that is comparable across machines and stable across runs. The allocation totals split compile and run phases so a review can distinguish compiler cost from runtime cost at the run level, not just per feature.

func ComputeScore

func ComputeScore(results []Result) Score

ComputeScore builds a Score from a completed run's results and attaches baseline comparison when the baseline file exists.

func (Score) Grade

func (s Score) Grade() string

Grade maps the score to a letter. The thresholds are chosen so that a single failed feature in a 66-feature suite lands at A (98.5), which is what a reviewer expects to see: real, visible, not hidden behind an A+.

func (Score) Value

func (s Score) Value() float64

Value returns the numeric score in [0, 100]. It is purely the fraction of features that passed, formatted to one decimal. A run with 66/66 always scores 100.0 on any machine.

type Status

type Status uint8
const (
	StatusPass Status = iota
	StatusFail
	StatusSkip
)

Jump to

Keyboard shortcuts

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