Skip to content

@usine/durable/testing

The children the stub backend launched, in launch order.

  • Context.ServiceClass

readonly Service: object

The service’s operations: what yield* StubChildren returns.

readonly next: Effect.Effect<StubChild>

Waits for the next child the parent launches.


The durable storage behind stub runtimes: tasks and their sequence counters survive a runtime being closed and built again, as pi-durable storage survives an orchestrator restart.

new StubStorage(): StubStorage

StubStorage

readonly tasks: Map<string & Brand<"AttemptId">, StubTask>

What the testing layer runs on.

readonly database: string

The SQLite file; build another layer on the same file to simulate an orchestrator restart.

readonly parent: readonly FauxResponseStep[]

The parent model’s answers, one per model request, in order.


One child the stub backend launched; the test decides when and how it finishes.

readonly block: (message) => Effect<void>

Finishes with a blocked report, which fails the Attempt unless the parent relays it.

Parameter Type
message string

Effect<void>

readonly emit: (event) => Effect<void>

Adds one event to the child’s stream.

Parameter Type
event SessionStarted | TextOutput | ToolStarted | ToolFinished | PoolRateLimitsUpdated | SessionFinished | SessionIdle | SessionResumed | SessionTokensUpdated

Effect<void>

readonly interrupted: Effect<void>

Completes once the parent’s tool call interrupted the child (abort, cancel, or shutdown).

readonly interventions: Effect<readonly (Steer | Interrupt | OperatorMessage | Release)[]>

The operator actions delivered to this child so far.

readonly reply: (message) => Effect<void>

Finishes with message as the child’s report; under a Hold the report waits for the release.

Parameter Type
message string

Effect<void>

readonly request: ChildRequest


What a scripted stub parent can do while execute runs it.

readonly emit: (payload) => Effect<void, InfraFailure | DefectFailure | AgentFailure | RunawayFailure | ChildSessionBudgetFailure>

Records one outbound envelope with the task’s next sequence.

Parameter Type
payload Started | SessionEvent | Final | Failed | Interrupted | InterventionApplied | InterventionRejected

Effect<void, InfraFailure | DefectFailure | AgentFailure | RunawayFailure | ChildSessionBudgetFailure>

readonly reattached: boolean

Whether this execute call reattached a task a previous runtime started.

readonly request: AttemptRequest

readonly session: ParentSession

The parent session the stub reports events for.

ParentStep = FauxResponseStep

One scripted answer of the parent’s model, or a function of the request that returns one.


StubParent = (context) => Effect.Effect<string, AttemptFailure>

A stub parent’s work after Started; its result is the parent’s final message.

Parameter Type
context StubParentContext

Effect.Effect<string, AttemptFailure>

const answer: (text) => AssistantMessage

The parent gives its final answer.

Parameter Type
text string

AssistantMessage


const completes: StubParent

Completes at once with Completed: <task>.


const delegate: (task) => AssistantMessage

The parent delegates task to one child through the subagent tool.

Parameter Type
task string

AssistantMessage


const fauxParent: (steps) => Pick<DurableHarnessOptions, "models" | "defaultModel">

pi-ai model access that answers the parent’s requests with steps, in order; it accepts every reasoning effort up to high.

Parameter Type
steps ReadonlyArray<ParentStep>

Pick<DurableHarnessOptions, "models" | "defaultModel">


const layer: (options) => Layer.Layer<AttemptRuntime | ChildBackend | DurableHarness | StubChildren, DurableHarnessError, never>

The durable Attempt runtime on a SQLite file with a scripted parent model and stub children, for driving whole Attempts in tests without a model or a harness binary.

Parameter Type
options DurableTestingOptions

Layer.Layer<AttemptRuntime | ChildBackend | DurableHarness | StubChildren, DurableHarnessError, never>


const PARENT_MODEL: string & Brand

The parent model the testing layer serves; name it in RunSpec.parentModel or leave that empty.


const stubAttemptRuntime: (storage, parent?) => Layer.Layer<AttemptRuntime, never, never>

An in-memory AttemptRuntime over storage, for executor and engine tests that need no parent model. It records Started, the parent’s session events, intervention receipts, and a Final without facts (the executor harvests those) through the Attempt’s sink, numbering them per task so a reattached execute continues the sequence. Only a completed parent leaves the live state: interrupting execute (a stopped process) or a failing parent leaves the task live until someone cancels it, so tests see whether the executor stopped it. A completed task keeps its report, which a later execute returns and finished reports until recordResult replaces it.

Parameter Type
storage StubStorage
parent? StubParent

Layer.Layer<AttemptRuntime, never, never>


const stubChildBackendLayer: Layer.Layer<ChildBackend | StubChildren>

A ChildBackend whose children run only as the test scripts them through StubChildren.


const worksFor: (millis) => StubParent

Works for millis before completing.

Parameter Type
millis number

StubParent