sprite

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2026 License: MIT Imports: 7 Imported by: 0 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 sprite is a thread-safe, in-memory model of Sprites and their checkpoint/restore semantics. It owns the canonical state; callers receive copies so that concurrent reads and writes never share mutable memory.

A sprite's filesystem is modeled as a path -> contents map. exec runs a small scripted interpreter (see exec.go) that can write or modify an fs key, so a checkpoint (a deep copy of the fs under a label) and a later restore (replace the fs with that copy) are observable. This mirrors the behavior of chant's in-process Sprites fake rather than real code execution.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound is returned for a sprite that was never created or has been
	// destroyed. A destroyed sprite is treated as absent, matching the fake.
	ErrNotFound = errors.New("sprite not found")
	// ErrCheckpointNotFound is returned by Restore for an unknown label.
	ErrCheckpointNotFound = errors.New("checkpoint not found")
)

Sentinel errors returned by the store.

Functions

This section is empty.

Types

type ExecResult

type ExecResult struct {
	Stdout   string `json:"stdout"`
	Stderr   string `json:"stderr"`
	ExitCode int    `json:"exitCode"`
}

ExecResult is the outcome of running a command in a sprite. The JSON tags match the Sprites exec response (note the camelCase exitCode).

type Sprite

type Sprite struct {
	ID          string
	Status      Status
	URL         string
	FS          map[string]string
	Checkpoints map[string]map[string]string
	Policy      any
	// CreatedAt is stamped from the injected clock at creation. It is internal
	// bookkeeping and is not part of the wire contract.
	CreatedAt string
}

Sprite is a single sprite: its lifecycle status, its addressable URL, its filesystem, and its checkpoints (each a full copy of the fs at checkpoint time, keyed by label).

type Status

type Status string

Status is the lifecycle state of a sprite.

const (
	StatusStarting  Status = "starting"
	StatusRunning   Status = "running"
	StatusPaused    Status = "paused"
	StatusDestroyed Status = "destroyed"
)

The sprite lifecycle states. A sprite is created running; destroy moves it to destroyed, after which every operation on it reports ErrNotFound.

type Store

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

Store holds sprites keyed by id.

func New

func New(clk clock.Clock) *Store

New returns an empty store. A nil clock is replaced with a real one.

func (*Store) Checkpoint

func (s *Store) Checkpoint(id, label string) (string, error)

Checkpoint deep-copies the sprite's current filesystem under a label and returns the checkpoint id. An empty label defaults to "cp-<n>", where n is one past the current checkpoint count. It returns ErrNotFound for a missing or destroyed sprite.

func (*Store) Create

func (s *Store) Create(id, url string, policy any) Sprite

Create records a new running sprite under id, with an empty filesystem and no checkpoints. Like the fake, it overwrites any existing sprite with the same id. It returns a copy of the created sprite.

func (*Store) Destroy

func (s *Store) Destroy(id string) error

Destroy marks the sprite destroyed. It returns ErrNotFound if the sprite is missing or already destroyed.

func (*Store) Exec

func (s *Store) Exec(id, cmd string) (ExecResult, error)

Exec runs cmd against the sprite's filesystem and returns the result. It returns ErrNotFound for a missing or destroyed sprite.

func (*Store) Get

func (s *Store) Get(id string) (View, error)

Get returns a read-only view of the sprite. It returns ErrNotFound for a missing or destroyed sprite.

func (*Store) Restore

func (s *Store) Restore(id, checkpoint string) error

Restore replaces the sprite's filesystem with the labeled checkpoint's copy and sets its status back to running. It returns ErrNotFound for a missing or destroyed sprite, and ErrCheckpointNotFound for an unknown label.

type View

type View struct {
	ID          string            `json:"id"`
	Status      Status            `json:"status"`
	URL         string            `json:"url"`
	FS          map[string]string `json:"fs"`
	Checkpoints []string          `json:"checkpoints"`
}

View is the read-only projection returned by GET /v1/sprites/{id}: the checkpoints are exposed as a sorted list of labels, not their fs copies.

Jump to

Keyboard shortcuts

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