runner

package
v0.14.0 Latest Latest
Warning

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

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

Documentation

Overview

Plik: flow/runner/config.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatDuration added in v0.10.0

func FormatDuration(d time.Duration) string

FormatDuration handles Windows clock resolution limits cleanly without misleading '0ns' outputs.

func JSONMapView added in v0.10.0

func JSONMapView(value any) any

JSONMapView applies JSON tags to struct outputs before expr evaluation.

func PrintInfo added in v0.10.0

func PrintInfo(w io.Writer, path, _ string, meta map[string]any, ast core.Expr) int

PrintInfo describes a .nflow file without executing it. It shows directives from meta, the sequence of atoms from the AST, and expected input.

func PrintInfoJSON added in v0.14.0

func PrintInfoJSON(w io.Writer, path string, meta map[string]any, ast core.Expr) error

func Run added in v0.10.0

func Run(ctx context.Context, cfg Config, path string, payload map[string]any, opts Opts) int

Run executes a .nflow file from disk.

func RunAssertions

func RunAssertions(w io.Writer, result any, durationMS int64, actions, asserts []string, verbosity int) int

RunAssertions ewaluuje @assert: z meta plus CLI --assert.

Env dostępny dla asercji:

result       — output ostatniej akcji w pipeline
duration_ms  — całkowity czas wykonania
actions      — lista nazw wykonanych akcji

Verbosity < 1 → cisza przy sukcesie.

func RunSource added in v0.10.0

func RunSource(ctx context.Context, cfg Config, src, name string, payload map[string]any, opts Opts) int

RunSource executes workflow DSL directly from in-memory text.

It is a thin wrapper over Execute: it handles --info, installs the observer, prints the result, and evaluates @assert: directives. Every other piece of orchestration lives in Execute so the same pipeline runs across cli, selftest, and embedded binaries.

func SplitPipelineModifiers added in v0.14.0

func SplitPipelineModifiers(table *core.ModifierTable, mods []string) (wrapper, body []string)

SplitPipelineModifiers separates a pipeline header's modifiers into those that belong on the wrapper action and those that propagate to the pipeline body. Inheritable policy modifiers (:timeout, :retry, …) propagate; metadata modifiers (:tag, :status, :route, …) stay on the wrapper.

It is shared by compile-time pipeline materialization and callers that need the same wrapper-versus-body modifier split.

Types

type Compilation added in v0.14.0

type Compilation struct {
	Program  action.AnyAction
	Meta     map[string]any
	Resolver core.CapabilityResolver
}

Compilation is the result of compiling one source without invoking its workflow actions. Program is nil for declaration-only sources such as a file containing only @pipeline definitions.

func Compile added in v0.14.0

func Compile(ctx context.Context, cfg Config, src, name string) (Compilation, error)

Compile preprocesses source, materializes declarations, and compiles its top-level program without invoking workflow actions.

type Config added in v0.10.0

type Config struct {
	Resolver      core.CapabilityResolver
	Directives    *core.DirectiveTable
	Modifiers     *core.ModifierTable
	Operators     *core.OperatorTable
	Primaries     *core.PrimaryExtensionTable
	Materializers []core.Materializer
	CompileOpts   []core.CompileOption

	// Hooks are applied to every resolver action and to the top-level
	// program before execution. Callers that only want to see the
	// result set this to nil.
	Hooks []action.AnyHook

	// EventSink, when non-nil, is wrapped by observe.Hook and appended
	// to Hooks. Both paths end up on the execution-local resolver's
	// actions; use either, or both.
	EventSink observe.Sink

	// MeasureAllocs wraps the compile and run phases of Execute with
	// MemStats deltas so callers can attribute allocations to the
	// compiler versus the runtime. ReadMemStats triggers a brief
	// stop-the-world pause; leave false on production hot paths. This
	// mirrors the same precedent as CompileDuration and RunDuration:
	// Execute already reports per-phase diagnostics, and this is the
	// allocation counterpart.
	MeasureAllocs bool

	// ArgSchemas is the merged per-action argument schema published by
	// every mounted bundle. It is exposed so diagnostics (nflow lint
	// today) can validate @{...} capability references without building
	// the action tree. Build-time advisors are the runtime counterpart;
	// this field makes the same checks reachable from a pure parse.
	ArgSchemas map[string][]core.ArgFieldSpec
}

Config bundles all compiler tables, capability resolvers, and materializers for a run. It is passed explicitly to prevent mutable package-level state.

func BuildConfig added in v0.10.0

func BuildConfig(bundles []core.Bundle) (Config, error)

BuildConfig compiles bundles into execution configuration. It has ZERO knowledge of @require, URLs or module paths.

func (Config) PrimariesFor added in v0.14.0

func (c Config) PrimariesFor(
	meta map[string]any,
	parent ...core.PrimaryExtension,
) *core.PrimaryExtensionTable

PrimariesFor returns the parser primary table the compiler installs for a source that produced meta. Parent primaries, when supplied, are inserted between the base table and the source's own contributions, mirroring CompileReq.InheritedPrimaries.

Every call site that parses a source outside of CompileAction — nflow lint, nflow expand, and any future diagnostic tool — must go through this function. Reading cfg.Primaries directly is only correct for the base table, and doing so silently drops per-source primaries such as the macro engine. A linter that does this rejects a file the runtime accepts, which is exactly the class of "test and production disagree" bug the runner package exists to prevent.

Order of contribution:

  1. c.Primaries — the base table built at BuildConfig
  2. parent... — inherited from an outer source
  3. meta's OnPreprocess output — this source's own contributions

A MergeablePrimary in step 2 or 3 collapses with the same token in step 1 or 2. A plain primary collides and panics, which is the "duplicates fail loudly" rule.

type Execution added in v0.10.0

type Execution struct {
	Output          any
	Meta            map[string]any
	Resolver        core.CapabilityResolver
	CompileDuration time.Duration
	RunDuration     time.Duration

	CompileAllocs     uint64
	CompileAllocBytes uint64
	RunAllocs         uint64
	RunAllocBytes     uint64
}

Execution is the outcome of one Execute call.

func Execute added in v0.10.0

func Execute(ctx context.Context, cfg Config, src, name string, payload map[string]any) (Execution, error)

Execute compiles and runs a .nflow source under the given configuration.

type InfoShape added in v0.14.0

type InfoShape struct {
	Path        string   `json:"path"`
	Description string   `json:"description,omitempty"`
	Asserts     []string `json:"asserts,omitempty"`
	Atoms       []string `json:"atoms"`
}

type Observer added in v0.10.0

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

Observer tracks every action that passes through the runtime.

func NewObserver added in v0.10.0

func NewObserver(out io.Writer, verbosity int) *Observer

func (*Observer) ActionNames added in v0.10.0

func (o *Observer) ActionNames() []string

func (*Observer) Hook added in v0.10.0

func (o *Observer) Hook() action.AnyHook

func (*Observer) PrintSummary added in v0.10.0

func (o *Observer) PrintSummary(w io.Writer)

func (*Observer) Records added in v0.10.0

func (o *Observer) Records() []Record

type Opts added in v0.10.0

type Opts struct {
	Verbosity int
	Info      bool
	Asserts   []string
	Stdout    io.Writer
	Stderr    io.Writer
}

Opts controls execution options for a single runner invocation.

type Record added in v0.10.0

type Record struct {
	Action   string
	Duration time.Duration
	Err      error
	Start    time.Time
}

type SourcedModifier added in v0.14.0

type SourcedModifier struct {
	Raw    string
	Source core.ModifierSource
}

SourcedModifier is a modifier together with the origin that produced it. SplitPipelineModifiersWithSources returns these so `nflow explain` can attribute modifiers to a pipeline or a profile.

func SplitPipelineModifiersWithSources added in v0.14.0

func SplitPipelineModifiersWithSources(
	table *core.ModifierTable,
	mods []string,
	sources []core.ModifierSource,
) (wrapper, body []SourcedModifier)

SplitPipelineModifiersWithSources is SplitPipelineModifiers with the per-modifier origin preserved. Sources must be parallel to mods; missing entries default to Kind "pipeline" with no label.

Jump to

Keyboard shortcuts

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