simulate

package
v0.5.0-rc.4 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewCommand

func NewCommand() *cobra.Command

NewCommand builds the simulate parent command and its subcommands.

Types

type Action

type Action interface {
	// Name is a short identifier for the action (for example "promote").
	Name() string

	// Describe returns a one-line human-readable summary of the action.
	Describe() string

	// Apply replays the action against the clone manifest and returns the
	// effects plus the after-state path.
	Apply(ctx ActionContext) (*ActionOutcome, error)
}

Action is a hypothetical operation the what-if engine can replay against a cloned manifest. Implementations drive the real orchestration logic in record-only mode and report the effects it would produce.

type ActionContext

type ActionContext struct {
	// ClonePath is the path to the temp clone of the manifest the action may
	// mutate. The real promoter writes its transitions here.
	ClonePath string

	// Actor is the identity that performs the hypothetical action.
	Actor string
}

ActionContext carries the inputs an Action needs to replay orchestration against the cloned manifest. ClonePath points at the temp copy of the user's manifest; the real file is never handed to an action.

type ActionOutcome

type ActionOutcome struct {
	// Effects is the ordered list of steps the orchestration would take.
	Effects []Effect

	// AfterStatePath is the manifest path holding the after-state.
	AfterStatePath string
}

ActionOutcome is what an Action returns after replaying orchestration. It carries the ordered effects plus the path holding the resolved after-state (the clone path, since the real promoter writes there).

type DeployDiff

type DeployDiff struct {
	Name    string      `json:"name"`
	SHA     FieldChange `json:"sha"`
	Version FieldChange `json:"version"`
}

DeployDiff captures the field changes for a single named deploy within an environment.

type Disposition

type Disposition string

Disposition classifies how the orchestration treats a single effect when the hypothetical action is replayed in record-only mode.

const (
	// DispositionRun marks an effect the orchestration would carry out.
	DispositionRun Disposition = "run"

	// DispositionSkip marks an effect the orchestration would skip as a no-op.
	DispositionSkip Disposition = "skip"

	// DispositionGate marks an effect held back behind a gate or guard.
	DispositionGate Disposition = "gate"
)

type Effect

type Effect struct {
	Disposition Disposition `json:"disposition"`
	Action      string      `json:"action"`
	Target      string      `json:"target"`
	Detail      string      `json:"detail"`
}

Effect is one ordered step the orchestration would take for the simulated action. It carries the disposition (run, skip, or gate), the kind of action, the target it acts on, and a human-readable detail string.

type Engine

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

Engine runs hypothetical actions against a clone of the user's manifest and reports the resulting state diff and effect sequence. It never mutates the user's real manifest and never touches git or the network.

func NewEngine

func NewEngine(manifestPath string, opts ...Option) (*Engine, error)

NewEngine builds an Engine bound to the manifest at manifestPath. The path is validated by reading it; the file is never modified.

func (*Engine) Simulate

func (e *Engine) Simulate(a Action) (*Result, error)

Simulate replays the action against a temp clone of the manifest and returns the before and after diff plus the ordered effects. The clone is created in a temp directory and removed when Simulate returns.

type EnvDiff

type EnvDiff struct {
	Environment  string       `json:"environment"`
	Version      FieldChange  `json:"version"`
	SHA          FieldChange  `json:"sha"`
	Divergence   FieldChange  `json:"divergence"`
	PreviousRing FieldChange  `json:"previous_ring"`
	Deploys      []DeployDiff `json:"deploys,omitempty"`
}

EnvDiff captures the field-by-field changes for a single environment. The run-stamped CommittedAt and CommittedBy fields are deliberately excluded: timestamps are run-stamped and not part of the what-if outcome.

type FieldChange

type FieldChange struct {
	Field   string `json:"field"`
	From    string `json:"from"`
	To      string `json:"to"`
	Changed bool   `json:"changed"`
}

FieldChange records a single field transitioning from one value to another. Changed is true only when From and To differ.

type Option

type Option func(*Engine)

Option configures an Engine.

func WithActor

func WithActor(actor string) Option

WithActor sets the actor identity used when replaying an action.

type PromoteAction

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

PromoteAction replays the real promotion orchestration against a cloned manifest. It drives promote.NewPromoter in non-dry-run mode so the genuine state-machine computes transitions and writes them to the clone only.

func NewPromoteAction

func NewPromoteAction(mode promote.PromotionMode, target string) *PromoteAction

NewPromoteAction builds a PromoteAction for the given promotion mode and target. The target is only consulted for cascade mode.

func (*PromoteAction) Apply

func (a *PromoteAction) Apply(ctx ActionContext) (*ActionOutcome, error)

Apply runs the real promoter against the clone manifest in non-dry-run mode and maps the returned PromotionResult into an ordered effect sequence. The promoter writes its transitions to the clone path via os.WriteFile only; no git or network call is made.

func (*PromoteAction) Describe

func (a *PromoteAction) Describe() string

Describe returns a one-line summary of the promotion being simulated.

func (*PromoteAction) Name

func (a *PromoteAction) Name() string

Name returns the action identifier.

type Result

type Result struct {
	// ActionName is the short identifier of the simulated action.
	ActionName string `json:"action"`

	// ActionDescribe is the one-line human-readable summary of the action.
	ActionDescribe string `json:"describe"`

	// Diff is the before and after state difference.
	Diff StateDiff `json:"diff"`

	// Effects is the ordered list of orchestration steps.
	Effects []Effect `json:"effects"`
}

Result is the outcome of one simulation: the action identity, the before and after state diff, and the ordered effect sequence.

func (*Result) RenderHuman

func (r *Result) RenderHuman(w io.Writer) error

RenderHuman writes a human-readable report of the simulation to w. The output is deterministic: environment keys are sorted and run-stamped timestamps are excluded from the diff.

func (*Result) RenderJSON

func (r *Result) RenderJSON(w io.Writer) error

RenderJSON writes the simulation result as deterministic, 2-space-indented JSON to w.

type StateDiff

type StateDiff struct {
	// Envs holds the per-environment diffs in sorted-key order.
	Envs []EnvDiff `json:"envs"`
}

StateDiff is the difference between a before and after manifest state, keyed by environment name in deterministic (sorted) order.

func DiffState

func DiffState(before, after map[string]*config.EnvState) StateDiff

DiffState computes the StateDiff between before and after environment states. Environment keys are sorted for deterministic output. Run-stamped timestamps (CommittedAt, CommittedBy) are ignored so output stays stable across runs.

func (StateDiff) Changed

func (s StateDiff) Changed() bool

Changed reports whether any environment in the diff changed.

func (StateDiff) Env

func (s StateDiff) Env(name string) (EnvDiff, bool)

Env returns the diff for a single environment by name.

Jump to

Keyboard shortcuts

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