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 ¶
- Variables
- type ExecResult
- type Sprite
- type Status
- type Store
- func (s *Store) Checkpoint(id, label string) (string, error)
- func (s *Store) Create(id, url string, policy any) Sprite
- func (s *Store) Destroy(id string) error
- func (s *Store) Exec(id, cmd string) (ExecResult, error)
- func (s *Store) Get(id string) (View, error)
- func (s *Store) Restore(id, checkpoint string) error
- type View
Constants ¶
This section is empty.
Variables ¶
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 Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store holds sprites keyed by id.
func (*Store) Checkpoint ¶
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 ¶
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 ¶
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.
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.