fixture

package
v0.1.0 Latest Latest
Warning

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

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

Documentation

Overview

Package fixture provides read/write support for .loopfix fixture files.

A .loopfix file is a gzipped JSONL file:

  • Line 1: header JSON {version, loopName, configHash, recordedAt, loopkitVersion}
  • Lines 2..n: event envelopes in canonical JSON (sorted keys)

Usage:

traj := []event.Envelope{...}
if err := fixture.Save("run.loopfix", "my-loop", "", traj); err != nil { ... }

header, envelopes, err := fixture.Load("run.loopfix")

Index

Constants

View Source
const LoopkitVersion = "0.1.0-sp4"

LoopkitVersion is the version of this loopkit build.

View Source
const Version = "1"

Version is the current .loopfix format version.

Variables

This section is empty.

Functions

func Record

func Record(ctx context.Context, store EventStoreLoader, loopID event.LoopID, path, loopName, configHash string) error

Record exports the event log for loopID from store into a .loopfix file at path. loopName and configHash are stored in the header. Pass "" for configHash if unknown.

func Save

func Save(path, loopName, configHash string, envelopes []event.Envelope) error

Save writes envelopes to path as a gzipped JSONL .loopfix file. loopName and configHash are stored in the header. Pass "" for configHash if unknown.

Types

type ErrCorrupt

type ErrCorrupt struct {
	Cause error
}

ErrCorrupt is returned when the gzip or JSONL structure is invalid.

func (*ErrCorrupt) Error

func (e *ErrCorrupt) Error() string

func (*ErrCorrupt) Unwrap

func (e *ErrCorrupt) Unwrap() error

type ErrVersionMismatch

type ErrVersionMismatch struct {
	Got  string
	Want string
}

ErrVersionMismatch is returned when the file version does not match Version.

func (*ErrVersionMismatch) Error

func (e *ErrVersionMismatch) Error() string

type EventStoreLoader

type EventStoreLoader interface {
	Load(ctx context.Context, id event.LoopID, fromSeq uint64) iter.Seq2[event.Envelope, error]
}

EventStore is satisfied by any runtime EventStore implementation. Declared here to avoid importing the runtime package (which would create an import cycle).

type Header struct {
	Version        string    `json:"version"`
	LoopName       string    `json:"loopName"`
	ConfigHash     string    `json:"configHash"`
	RecordedAt     time.Time `json:"recordedAt"`
	LoopkitVersion string    `json:"loopkitVersion"`
}

Header is the first line of a .loopfix file.

func Load

func Load(path string) (Header, []event.Envelope, error)

Load reads a .loopfix file and returns the header and all event envelopes. Returns ErrVersionMismatch if the version field doesn't match Version. Returns ErrCorrupt if the gzip or JSONL structure is invalid.

Jump to

Keyboard shortcuts

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