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 ¶
- type Harness
- type Provider
- func (p *Provider) Advance(d time.Duration)
- func (p *Provider) Blocked(reason agentlifecycle.ReasonCode) agentlifecycle.Report
- func (p *Provider) Cancel() agentlifecycle.Report
- func (p *Provider) Child(runID string) *Provider
- func (p *Provider) EmitOutOfOrder(state agentactivity.State, reason agentlifecycle.ReasonCode, seq uint64) (agentlifecycle.Acceptance, error)
- func (p *Provider) End(outcome agentlifecycle.Outcome, reason agentlifecycle.ReasonCode) agentlifecycle.Report
- func (p *Provider) FailNextHook()
- func (p *Provider) HookFailures() int
- func (p *Provider) Identity() agentlifecycle.Identity
- func (p *Provider) Idle(reason agentlifecycle.ReasonCode) agentlifecycle.Report
- func (p *Provider) Latest() (agentlifecycle.Report, bool)
- func (p *Provider) Now() time.Time
- func (p *Provider) Release(reason agentlifecycle.ReasonCode) agentlifecycle.Report
- func (p *Provider) Replay(r agentlifecycle.Report) (agentlifecycle.Acceptance, error)
- func (p *Provider) RotateSession(fingerprint string)
- func (p *Provider) RunID() string
- func (p *Provider) SessionReport(fingerprint string) agentlifecycle.Report
- func (p *Provider) Source() string
- func (p *Provider) WithSink(s Sink) *Provider
- func (p *Provider) Working(reason agentlifecycle.ReasonCode) agentlifecycle.Report
- type Recorder
- type Sink
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 ¶
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 ¶
KillPaneProcess ends the pane's process, which is the process-exit scenario. It returns once the pane is gone.
type Provider ¶
type Provider struct {
// contains filtered or unexported fields
}
Provider emits scripted lifecycle reports as one integration source.
func (*Provider) Advance ¶
Advance moves the provider's clock, so freshness can be exercised without sleeping.
func (*Provider) Blocked ¶
func (p *Provider) Blocked(reason agentlifecycle.ReasonCode) agentlifecycle.Report
func (*Provider) Cancel ¶
func (p *Provider) Cancel() agentlifecycle.Report
func (*Provider) Child ¶
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 ¶
func (p *Provider) End(outcome agentlifecycle.Outcome, reason agentlifecycle.ReasonCode) agentlifecycle.Report
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 ¶
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 (p *Provider) Idle(reason agentlifecycle.ReasonCode) agentlifecycle.Report
func (*Provider) Latest ¶
func (p *Provider) Latest() (agentlifecycle.Report, bool)
Latest returns the sink's current record for this provider's run.
func (*Provider) Release ¶
func (p *Provider) Release(reason agentlifecycle.ReasonCode) agentlifecycle.Report
Release surrenders authority without claiming an outcome.
func (*Provider) Replay ¶
func (p *Provider) Replay(r agentlifecycle.Report) (agentlifecycle.Acceptance, error)
Replay re-delivers an already-emitted report verbatim. A correct sink treats it as a duplicate and does not advance anything.
func (*Provider) RotateSession ¶
RotateSession changes the provider's session fingerprint, as a provider does when it starts or resumes a different session.
func (*Provider) SessionReport ¶
func (p *Provider) SessionReport(fingerprint string) agentlifecycle.Report
SessionReport announces session identity without asserting a lane.
func (*Provider) WithSink ¶
WithSink redirects this provider at another sink, which is how Phase B points the same scenarios at the JSONL store.
func (*Provider) Working ¶
func (p *Provider) Working(reason agentlifecycle.ReasonCode) agentlifecycle.Report
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 ¶
func (r *Recorder) Append(rep agentlifecycle.Report) (agentlifecycle.Acceptance, error)
Append records a report if it is valid and advances its sequence key.
func (*Recorder) Latest ¶
func (r *Recorder) Latest(key agentlifecycle.Key) (agentlifecycle.Report, bool)
Latest returns the current record for a key.
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.