lifecycleharness

package
v1.17.0 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: MIT Imports: 12 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 lifecycleharness provides a reusable fake provider and hook harness for agent lifecycle work.

It exists so that lifecycle tests can exercise the awkward cases — events arriving out of order, the same event twice, a rotated provider session, a child agent, a cancelled turn, a dead process, and a hook that simply fails — against real tmux pane identity, without needing a real provider and without going anywhere near the developer's own tmux server or Sidecar state.

Isolation

Both axes are isolated, because they are independent and isolating only one is how a proof run has previously destroyed real user state:

  • tmux: the harness creates its own socket under the test's temporary directory and passes -S explicitly on every single tmux invocation. It never runs a bare tmux command, so no environment variable, and no mistake in one, can route a call to the machine's default server. The server is killed by socket path on cleanup.
  • Sidecar state: the harness points config at a temporary state directory and asserts, before returning, that nothing resolved inside the real user tree.

Reusability

The harness writes into a Sink. Phase A ships Recorder, an in-memory sink that applies the sequence and identity rules the persistent store will later own, so the scenarios below are meaningful before any store exists. Phase B implements the JSONL store against the same interface and reuses every scenario unchanged.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Harness

type Harness struct {
	// Socket is the private tmux socket path. Every tmux call the harness
	// makes passes this with -S.
	Socket string
	// StateDir is the private Sidecar state tree.
	StateDir string
	// Session is the tmux session name the harness created.
	Session string
	// PaneID is the live pane, e.g. "%0".
	PaneID string
	// PanePID is the pane's process.
	PanePID int
	// ServerIncarnation identifies this tmux server's lifetime.
	ServerIncarnation string
	// Host is the identity reports are bound to.
	Host string
	// Recorder is the default in-memory sink.
	Recorder *Recorder
	// contains filtered or unexported fields
}

Harness owns one isolated tmux server, one live pane, and one private Sidecar state tree.

func Start

func Start(t *testing.T) *Harness

Start brings up the isolated environment and returns a harness bound to a live pane. Cleanup is registered on t.

func (*Harness) Identity

func (h *Harness) Identity(provider, runID string) agentlifecycle.Identity

Identity returns the live identity for a run in this harness's pane.

func (*Harness) KillPaneProcess

func (h *Harness) KillPaneProcess(t *testing.T)

KillPaneProcess ends the pane's process, which is the process-exit scenario. It returns once the pane is gone.

func (*Harness) PaneAlive

func (h *Harness) PaneAlive() bool

PaneAlive reports whether the harness pane still exists.

func (*Harness) Provider

func (h *Harness) Provider(providerName, source, runID string) *Provider

Provider returns a fake provider integration bound to this pane.

type Provider

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

Provider emits scripted lifecycle reports as one integration source.

func (*Provider) Advance

func (p *Provider) Advance(d time.Duration)

Advance moves the provider's clock, so freshness can be exercised without sleeping.

func (*Provider) Blocked

func (*Provider) Cancel

func (p *Provider) Cancel() agentlifecycle.Report

func (*Provider) Child

func (p *Provider) Child(runID string) *Provider

Child returns a provider representing a subagent: same pane and same source, a distinct run. Keeping the run distinct is what lets a test prove a child cannot block or complete its parent.

func (*Provider) EmitOutOfOrder

func (p *Provider) EmitOutOfOrder(state agentactivity.State, reason agentlifecycle.ReasonCode, seq uint64) (agentlifecycle.Acceptance, error)

EmitOutOfOrder delivers a report carrying an explicit stale sequence, which is what a provider with no ordering guarantee produces under load.

func (*Provider) End

End finishes the run with an outcome. Cancel is the cancellation scenario.

func (*Provider) FailNextHook

func (p *Provider) FailNextHook()

FailNextHook makes the next emission fail the way a broken hook does: the report is never delivered, and the provider carries on. Nothing about the agent's own operation changes, which is the property the plan requires.

func (*Provider) HookFailures

func (p *Provider) HookFailures() int

HookFailures counts emissions dropped by FailNextHook.

func (*Provider) Identity

func (p *Provider) Identity() agentlifecycle.Identity

Identity is the identity this provider stamps on its reports.

func (*Provider) Idle

func (*Provider) Latest

func (p *Provider) Latest() (agentlifecycle.Report, bool)

Latest returns the sink's current record for this provider's run.

func (*Provider) Now

func (p *Provider) Now() time.Time

Now is the provider's current clock reading.

func (*Provider) Release

Release surrenders authority without claiming an outcome.

func (*Provider) Replay

Replay re-delivers an already-emitted report verbatim. A correct sink treats it as a duplicate and does not advance anything.

func (*Provider) RotateSession

func (p *Provider) RotateSession(fingerprint string)

RotateSession changes the provider's session fingerprint, as a provider does when it starts or resumes a different session.

func (*Provider) RunID

func (p *Provider) RunID() string

RunID is the run this provider reports for.

func (*Provider) SessionReport

func (p *Provider) SessionReport(fingerprint string) agentlifecycle.Report

SessionReport announces session identity without asserting a lane.

func (*Provider) Source

func (p *Provider) Source() string

Source is this integration's identifier.

func (*Provider) WithSink

func (p *Provider) WithSink(s Sink) *Provider

WithSink redirects this provider at another sink, which is how Phase B points the same scenarios at the JSONL store.

func (*Provider) Working

Working, Blocked, and Idle emit ordinary lane reports.

type Recorder

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

Recorder is an in-memory Sink that applies the ordering and identity rules the persistent store will own.

It is deliberately not a stand-in for that store: it has no locking, no file format, no compaction, and no crash behavior. What it does have is the exact acceptance semantics the harness scenarios need to be meaningful before the store exists, so Phase B can swap in the real implementation and expect every scenario to keep passing.

func NewRecorder

func NewRecorder() *Recorder

func (*Recorder) All

func (r *Recorder) All() []agentlifecycle.Report

All returns every accepted report in arrival order.

func (*Recorder) Append

Append records a report if it is valid and advances its sequence key.

func (*Recorder) Latest

Latest returns the current record for a key.

func (*Recorder) Rejected

func (r *Recorder) Rejected() []error

Rejected returns the errors from reports that were not accepted.

type Sink

type Sink interface {
	// Append validates and records a report. It returns how the report was
	// accepted, or an error describing why it was not.
	Append(agentlifecycle.Report) (agentlifecycle.Acceptance, error)
	// Latest returns the most recent accepted report for a sequence key.
	Latest(agentlifecycle.Key) (agentlifecycle.Report, bool)
}

Sink receives reports. The persistent store implements this in Phase B.

Jump to

Keyboard shortcuts

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