materialise

package
v0.1.0-alpha.3 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: AGPL-3.0 Imports: 19 Imported by: ? 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 materialise executes a spec's materialise block against a provisioned workspace, in the one fixed order the handoff specifies:

ports -> files -> commands -> services -> health -> escape

The order is not configurable: a file that needs a port must be able to read it, and a command that needs a file must run after it.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ManagedSpec

func ManagedSpec(path string) (*fleet.Spec, string, string, error)

ManagedSpec reads one bounded exact source. The hash binds shell authority to the bytes reviewed by the operator, not merely a path or parsed shape.

func RenderPlan

func RenderPlan(spec *fleet.Spec, res *Result) string

RenderPlan prints a run's steps as a stable, ordered plan — the dry run's output and the golden file's shape.

func TCPDial

func TCPDial(addr string, timeout time.Duration) error

TCPDial is the real dialer.

Types

type Dialer

type Dialer func(addr string, timeout time.Duration) error

Dialer answers whether something is listening. Supervision uses it, and a test can substitute one rather than binding real ports.

type Engine

type Engine struct {
	Prov *workspace.Provisioner
	FS   FileSystem
	Exec Executor
	Prob Prober
	// Dial reports whether something is listening; supervision uses it.
	Dial Dialer
	// Settle is how long a freshly started service gets to bind its port before
	// supervision calls it dead. Zero means the package default.
	Settle time.Duration
	// DryRun records what would happen without starting services or running the
	// escape hatch. Commands and probes are recorded, never executed.
	DryRun bool
}

Engine materialises workspaces for one relay home.

func New

func New(prov *workspace.Provisioner) *Engine

New returns an Engine backed by the real filesystem, shell and network.

func (*Engine) DestroyManaged

func (e *Engine) DestroyManaged(name string, retryUncertain bool) error

DestroyManaged is explicitly requested, clean-worktree-only teardown. Each completed command is checkpointed; an uncertain command is never implicit.

func (*Engine) PlanManaged

func (e *Engine) PlanManaged(specPath, name string) (*fleet.Spec, *Result, string, error)

func (*Engine) Run

func (e *Engine) Run(spec *fleet.Spec, repoRoot, name string) (*Result, error)

Run executes the materialise block in its fixed order. It is idempotent (D3): allocated ports are reused, commands whose cache_key is unchanged are skipped, and services already up are left alone.

func (*Engine) RunManaged

func (e *Engine) RunManaged(specPath, name, trust string) (*Result, error)

RunManaged is the only entrypoint that executes a newly managed spec. It atomically provisions and binds exact-hash trust, then runs the engine.

func (*Engine) StopManaged

func (e *Engine) StopManaged(name string, retryUncertain bool) error

StopManaged never guesses whether a hook ran after a crash. An unresolved intent requires an explicit retry-uncertain operator decision.

func (*Engine) Supervise

func (e *Engine) Supervise(spec *fleet.Spec, name string) (string, error)

Supervise re-checks every supervised service in the spec and records the resulting state.

The managed-workspace cadence uses the same check and may restart within a persisted budget; this one-shot method remains useful to explicit callers. A workspace that was ready and whose service has since died must stop reading ready — and one that was marked unhealthy by this very check must be able to read ready again once the service answers, or the first blip would condemn it forever.

func (*Engine) TickManaged

func (e *Engine) TickManaged() error

TickManaged makes one bounded pass over every armed workspace. The daemon calls it on a fixed cadence; the per-workspace lock serializes shell effects against stop/destroy and other managers.

type Executor

type Executor interface {
	Run(dir string, env []string, cmdline string, timeout time.Duration) ([]byte, error)
}

Executor runs one shell command line in a directory with an environment.

type FileSystem

type FileSystem interface {
	ReadFile(path string) ([]byte, error)
	WriteFileWithin(root, relative string, b []byte, perm fs.FileMode) error
	// Resolve returns the path with every symlink followed, so a source policy
	// judges where a file really is rather than where a link says it is.
	Resolve(path string) (string, error)
}

FileSystem is the small surface the engine needs: read a source, write a file that must stay inside a workspace root. It is an interface so the test suite can substitute a recorder and assert "no filesystem writes occurred".

type HTTPProber

type HTTPProber struct{}

HTTPProber polls a URL until it answers below 500 or the timeout expires. A connection refused early in a service's startup is expected, not fatal — the probe's job is to decide when the workspace is usable, so it retries until the deadline rather than failing on the first attempt.

func (HTTPProber) HTTP

func (HTTPProber) HTTP(url string, timeout time.Duration) error

type OSFileSystem

type OSFileSystem struct{}

OSFileSystem is the real filesystem.

func (OSFileSystem) ReadFile

func (OSFileSystem) ReadFile(p string) ([]byte, error)

func (OSFileSystem) Resolve

func (OSFileSystem) Resolve(p string) (string, error)

func (OSFileSystem) WriteFileWithin

func (OSFileSystem) WriteFileWithin(root, relative string, b []byte, perm fs.FileMode) error

type Prober

type Prober interface {
	HTTP(url string, timeout time.Duration) error
}

Prober answers whether a health check passes.

type Result

type Result struct {
	Workspace *workspace.Record `json:"workspace"`
	Steps     []Step            `json:"steps"`
	State     string            `json:"state"`
	Failed    []string          `json:"failed_probes,omitempty"`
}

Result is one materialisation's outcome.

type ShellExecutor

type ShellExecutor struct{}

ShellExecutor runs command lines through `sh -c`, which is what a declared `run` string means. A timeout of 0 means no timeout.

func (ShellExecutor) Run

func (ShellExecutor) Run(dir string, env []string, cmdline string, timeout time.Duration) ([]byte, error)

type Step

type Step struct {
	Stage   string `json:"stage"`
	Action  string `json:"action"`
	Detail  string `json:"detail"`
	Skipped bool   `json:"skipped,omitempty"`
	Reason  string `json:"reason,omitempty"`
}

Step is one recorded action. A run returns its steps in execution order, which is what the dry run prints and what the tests assert against.

type StrictHTTPProber

type StrictHTTPProber struct{}

StrictHTTPProber is used by the opt-in managed path. An HTTP 404 is a responding server, but not a healthy declared endpoint. The one-shot legacy path retains its established below-500 behavior for compatibility.

func (StrictHTTPProber) HTTP

func (StrictHTTPProber) HTTP(url string, timeout time.Duration) error

Jump to

Keyboard shortcuts

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