testutil

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2026 License: MIT Imports: 29 Imported by: 0

Documentation

Overview

Package testutil provides test helpers and utilities for the agent-factory.

Package testutil provides test helpers and harnesses.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendFactoryInferenceThrottleGuard

func AppendFactoryInferenceThrottleGuard(
	t *testing.T,
	dir string,
	provider interfaces.ModelProvider,
	model string,
	refreshWindow time.Duration,
)

AppendFactoryInferenceThrottleGuard authors a root-level inference throttle guard into a copied fixture so tests exercise the supported config path instead of retired runtime-only wiring.

func AssertGuardedLoopBreakerTransition added in v0.0.5

func AssertGuardedLoopBreakerTransition(
	t *testing.T,
	transition *petri.Transition,
	inputPlace string,
	outputPlace string,
	watchedTransitionID string,
	maxVisits int,
)

AssertGuardedLoopBreakerTransition asserts a normal loop-breaker transition with a single VisitCountGuard input arc and a single output arc to the expected places.

func AssertNoTransitionExhaustion added in v0.0.5

func AssertNoTransitionExhaustion(t *testing.T, transitions map[string]*petri.Transition, opts PetriTransitionAssertOptions)

AssertNoTransitionExhaustion fails when any non-nil transition has type TransitionExhaustion.

func CanonicalPath added in v0.0.5

func CanonicalPath(value string) string

CanonicalPath normalizes a path for comparisons in tests that may observe platform-specific symlinked temp roots such as /var versus /private/var on macOS.

func CopyFixtureDir

func CopyFixtureDir(t *testing.T, srcDir string) string

CopyFixtureDir copies the entire directory tree at srcDir into a new temporary directory and returns the path to the copy. The temporary directory is automatically removed when t finishes (via t.Cleanup).

Each call produces an independent copy, so parallel subtests can safely use the same source fixture without interfering with each other.

func LoadReplayArtifact

func LoadReplayArtifact(t *testing.T, artifactPath string) *interfaces.ReplayArtifact

LoadReplayArtifact loads and validates a replay artifact fixture for tests.

func MustRepoPath

func MustRepoPath(t testing.TB, rel string) string

func MustRepoRoot

func MustRepoRoot(t testing.TB) string

func PipelineConfig

func PipelineConfig(stages int, workerName string) *interfaces.FactoryConfig

PipelineConfig returns a FactoryConfig for a linear N-stage pipeline: task:init → stage1 → stage2 → ... → stageN → complete, with a failed state. All transitions use the specified worker name.

func ScaffoldFactoryDir

func ScaffoldFactoryDir(t *testing.T, cfg *interfaces.FactoryConfig) string

ScaffoldFactoryDir writes a FactoryConfig as factory.json to a new temporary directory and returns the directory path. The temp directory is cleaned up via t.Cleanup. This allows tests to construct configs programmatically while still exercising the full service path (config loading → ConfigMapper.Map()).

func UpdateFactoryJSON

func UpdateFactoryJSON(t *testing.T, dir string, mutate func(map[string]any))

UpdateFactoryJSON applies an in-place mutation to a copied fixture's factory.json so tests can author focused topology or guard changes without bypassing the normal config loader.

func WriteSeedBatchFile

func WriteSeedBatchFile(t *testing.T, dir string, request interfaces.WorkRequest)

WriteSeedBatchFile writes a canonical FACTORY_REQUEST_BATCH watched-file input into inputs/BATCH/default so functional tests exercise the public mixed-work- type file-watcher boundary instead of direct API or runtime helpers.

func WriteSeedFile

func WriteSeedFile(t *testing.T, dir, workType string, payload []byte)

WriteSeedFile writes a JSON payload as a seed file in the fixture directory's inputs/<workType>/default/ directory. The file watcher picks up these files during preseed on startup. Call this BEFORE constructing the harness so the files are present when BuildFactoryService runs.

func WriteSeedMarkdownFile

func WriteSeedMarkdownFile(t *testing.T, dir, workType, name string, content []byte)

WriteSeedMarkdownFile writes raw content as a .md seed file with the given filename (without extension). The file watcher derives the SubmitRequest Name from the filename, so this exercises the non-JSON submission path.

func WriteSeedRequest

func WriteSeedRequest(t *testing.T, dir string, req interfaces.SubmitRequest)

WriteSeedRequest marshals a one-item FACTORY_REQUEST_BATCH as a seed file. Use this instead of WriteSeedFile when the test needs to preserve TraceID, Tags, state placement, or internal execution fields through the file watcher pipeline.

Types

type MarkingAssert

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

MarkingAssert provides fluent assertions on a MarkingSnapshot.

func AssertMarking

func AssertMarking(t *testing.T, marking *petri.MarkingSnapshot) *MarkingAssert

AssertMarking creates a new MarkingAssert for fluent assertion chaining.

func (*MarkingAssert) AllTokensTerminal

func (ma *MarkingAssert) AllTokensTerminal() *MarkingAssert

AllTokensTerminal asserts all tokens are in places whose state suffix indicates TERMINAL or FAILED status. It checks that no tokens remain in non-terminal places by verifying every token's PlaceID ends with a terminal or failed state.

func (*MarkingAssert) HasNoTokenInPlace

func (ma *MarkingAssert) HasNoTokenInPlace(placeID string) *MarkingAssert

HasNoTokenInPlace asserts that no tokens exist in the given place.

func (*MarkingAssert) HasTokenInPlace

func (ma *MarkingAssert) HasTokenInPlace(placeID string) *MarkingAssert

HasTokenInPlace asserts that at least one token exists in the given place.

func (*MarkingAssert) PlaceTokenCount

func (ma *MarkingAssert) PlaceTokenCount(placeID string, expected int) *MarkingAssert

PlaceTokenCount asserts the number of tokens in a specific place.

func (*MarkingAssert) TokenCount

func (ma *MarkingAssert) TokenCount(expected int) *MarkingAssert

TokenCount asserts the total number of tokens across all places.

func (*MarkingAssert) TokenHasTag

func (ma *MarkingAssert) TokenHasTag(placeID string, tagKey string, tagValue string) *MarkingAssert

TokenHasTag asserts that a token in the given place has the expected tag value.

func (*MarkingAssert) TokenHasTraceID

func (ma *MarkingAssert) TokenHasTraceID(placeID string, traceID string) *MarkingAssert

TokenHasTraceID asserts that a token in the given place has the expected trace ID.

func (*MarkingAssert) TokenHasWorkTypeID

func (ma *MarkingAssert) TokenHasWorkTypeID(placeID string, workTypeID string) *MarkingAssert

TokenHasWorkTypeID asserts that a token in the given place has the expected work type ID.

type MockExecutor

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

MockExecutor returns predetermined WorkResults in sequence. When the sequence is exhausted, returns a default result.

func NewMockExecutor

func NewMockExecutor(results ...interfaces.WorkResult) *MockExecutor

NewMockExecutor creates a MockExecutor that returns the given results in order. When the sequence is exhausted, it returns a default WorkResult with OutcomeAccepted.

func (*MockExecutor) CallCount

func (m *MockExecutor) CallCount() int

CallCount returns how many times Execute was called.

func (*MockExecutor) Calls

func (m *MockExecutor) Calls() []interfaces.WorkDispatch

Calls returns all WorkDispatches received by this executor, in order.

func (*MockExecutor) Execute

Execute records the dispatch and returns the next predetermined result.

func (*MockExecutor) LastCall

func (m *MockExecutor) LastCall() interfaces.WorkDispatch

LastCall returns the most recent WorkDispatch, or panics if none.

type MockFactory

type MockFactory struct {
	Submitted                   []interfaces.SubmitRequest
	SubmitErr                   error
	WorkRequests                []interfaces.WorkRequest
	SubmitWorkRequestErr        error
	WorkRequestResults          map[string]interfaces.WorkRequestSubmitResult
	Marking                     *petri.MarkingSnapshot
	State                       interfaces.FactoryState
	Net                         *state.Net
	EngineState                 *interfaces.EngineStateSnapshot[petri.MarkingSnapshot, *state.Net]
	EngineStateSnapshotErr      error
	Uptime                      time.Duration
	FactoryEvents               []factoryapi.FactoryEvent
	FactoryEventStream          *interfaces.FactoryEventStream
	FactoryEventStreamCtx       context.Context
	EngineStateSnapshotCalls    int
	CreatedFactories            []factoryapi.Factory
	SaveFactoryForSessionErr    error
	CurrentFactory              *factoryapi.Factory
	CurrentFactoryErr           error
	FactoryVersion              factoryapi.HybridLogicalTimestamp
	CurrentFactoryReadErr       error
	SavedCurrentFactories       []factoryapi.Factory
	Models                      factoryapi.ListModelsResponse
	ListModelsErr               error
	ModelDetails                map[string]factoryapi.ModelDetail
	GetModelErr                 error
	InvokedModels               []factoryapi.ModelInvocationRequest
	InvokedModelNames           []string
	InvokeModelResult           apisurface.ModelInvocationResult
	InvokeModelErr              error
	PulledModelNames            []string
	PullModelResult             apisurface.ModelPullResult
	PullModelErr                error
	SessionFactories            map[string]*MockFactory
	FactorySessions             factoryapi.ListFactorySessionsResponse
	ListFactorySessionsErr      error
	OpenFactorySessionResult    factoryapi.OpenFactorySessionResponse
	OpenFactorySessionErr       error
	OpenedFactorySessions       []factoryapi.OpenFactorySessionRequest
	ClosedFactorySessions       []string
	CloseFactorySessionErr      error
	MoveWorkErr                 error
	AppliedOperatorMoveRequests map[string]interfaces.OperatorMoveResult
}

func (*MockFactory) CloseFactorySession added in v0.0.5

func (m *MockFactory) CloseFactorySession(_ context.Context, sessionID string) error

func (*MockFactory) GetCurrentFactory added in v0.0.5

func (m *MockFactory) GetCurrentFactory(_ context.Context) (factoryapi.Factory, error)

func (*MockFactory) GetCurrentFactoryForSession added in v0.0.5

func (m *MockFactory) GetCurrentFactoryForSession(ctx context.Context, sessionID string) (factoryapi.Factory, error)

func (*MockFactory) GetEngineStateSnapshot

func (*MockFactory) GetEngineStateSnapshotForSession added in v0.0.5

func (m *MockFactory) GetEngineStateSnapshotForSession(ctx context.Context, sessionID string) (*interfaces.EngineStateSnapshot[petri.MarkingSnapshot, *state.Net], error)

func (*MockFactory) GetFactoryEvents

func (m *MockFactory) GetFactoryEvents(_ context.Context) ([]factoryapi.FactoryEvent, error)

func (*MockFactory) GetModel added in v0.0.5

func (m *MockFactory) GetModel(_ context.Context, modelName string) (factoryapi.ModelDetail, error)

func (*MockFactory) InvokeModel added in v0.0.5

func (*MockFactory) ListFactorySessions added in v0.0.5

func (*MockFactory) ListModels added in v0.0.5

func (*MockFactory) MoveWork added in v0.0.5

func (m *MockFactory) MoveWork(_ context.Context, workID, stateName string, _ interfaces.WorkStateChangeSource, requestID string) (interfaces.OperatorMoveResult, error)

func (*MockFactory) MoveWorkForSession added in v0.0.5

func (m *MockFactory) MoveWorkForSession(ctx context.Context, sessionID, workID, stateName, requestID string) (interfaces.OperatorMoveResult, error)

func (*MockFactory) OpenFactorySession added in v0.0.5

func (*MockFactory) Pause

func (m *MockFactory) Pause(_ context.Context) error

func (*MockFactory) PullModel added in v0.0.5

func (m *MockFactory) PullModel(_ context.Context, modelName string) (apisurface.ModelPullResult, error)

func (*MockFactory) Run

func (m *MockFactory) Run(_ context.Context) error

func (*MockFactory) SaveCurrentFactoryForSession added in v0.0.5

func (m *MockFactory) SaveCurrentFactoryForSession(
	ctx context.Context,
	sessionID string,
	request factoryapi.Factory,
) (factoryapi.Factory, error)

func (*MockFactory) SaveFactoryForSession added in v0.0.5

func (m *MockFactory) SaveFactoryForSession(
	_ context.Context,
	sessionID string,
	mode factoryapi.FactorySaveMode,
	request factoryapi.Factory,
) (factoryapi.Factory, error)

func (*MockFactory) SubmitWorkRequest

func (*MockFactory) SubmitWorkRequestForSession added in v0.0.5

func (m *MockFactory) SubmitWorkRequestForSession(ctx context.Context, sessionID string, request interfaces.WorkRequest) (interfaces.WorkRequestSubmitResult, error)

func (*MockFactory) SubscribeFactoryEvents

func (m *MockFactory) SubscribeFactoryEvents(ctx context.Context) (*interfaces.FactoryEventStream, error)

func (*MockFactory) SubscribeFactoryEventsForSession added in v0.0.5

func (m *MockFactory) SubscribeFactoryEventsForSession(ctx context.Context, sessionID string) (*interfaces.FactoryEventStream, error)

func (*MockFactory) WaitToComplete

func (m *MockFactory) WaitToComplete() <-chan struct{}

type MockProvider

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

MockProvider implements workers.Provider for testing. It returns predetermined InferenceResponses in sequence. When the sequence is exhausted, it returns a default response.

func NewMockProvider

func NewMockProvider(responses ...interfaces.InferenceResponse) *MockProvider

NewMockProvider creates a MockProvider that returns the given responses in order. Each response can optionally have a paired error at the same index in the errors slice. When the sequence is exhausted, returns a default InferenceResponse with StopTokenFound=true (so MODEL_WORKER with stop tokens will ACCEPT by default).

func NewMockProviderWithErrors

func NewMockProviderWithErrors(responses []interfaces.InferenceResponse, errors []error) *MockProvider

NewMockProviderWithErrors creates a MockProvider with paired responses and errors. The responses and errors slices must be the same length; a nil error means success.

func (*MockProvider) CallCount

func (m *MockProvider) CallCount() int

CallCount returns how many times Infer was called.

func (*MockProvider) Calls

Calls returns all InferenceRequests received by this provider, in order.

func (*MockProvider) Infer

Infer records the request and returns the next predetermined response.

func (*MockProvider) LastCall

LastCall returns the most recent InferenceRequest, or panics if none.

type MockWorkerMapProvider

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

MockProvider implements workers.Provider for testing. It returns predetermined InferenceResponses in sequence. When the sequence is exhausted, it returns a default response.

func NewMockWorkerMapProvider

func NewMockWorkerMapProvider(responses map[string][]interfaces.InferenceResponse) *MockWorkerMapProvider

NewMockProvider creates a MockProvider that returns the given responses in order. Each response can optionally have a paired error at the same index in the errors slice. When the sequence is exhausted, returns a default InferenceResponse with StopTokenFound=true (so MODEL_WORKER with stop tokens will ACCEPT by default).

func NewMockWorkerMapProviderWithDefault

func NewMockWorkerMapProviderWithDefault(responses map[string][]WorkResponse) *MockWorkerMapProvider

func (*MockWorkerMapProvider) CallCount

func (m *MockWorkerMapProvider) CallCount(workerType string) int

CallCount returns how many times Infer was called.

func (*MockWorkerMapProvider) Calls

Calls returns all InferenceRequests received by this provider, in order.

func (*MockWorkerMapProvider) Infer

Infer records the request and returns the next predetermined response.

func (*MockWorkerMapProvider) LastCall

LastCall returns the most recent InferenceRequest, or panics if none.

type MockWorkerMapProviderOption

type MockWorkerMapProviderOption func(*MockWorkerMapProvider)

MockWorkerMapProviderOption configures a MockWorkerMapProvider.

type PetriTransitionAssertOptions added in v0.0.5

type PetriTransitionAssertOptions struct {
	// ExhaustionContext is embedded in AssertNoTransitionExhaustion fatals
	// (for example "customer-authored mapping" or "replay-mapped customer config").
	ExhaustionContext string
}

PetriTransitionAssertOptions configures Petri transition assertion failure messages.

type ProviderCommandRunner

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

ProviderCommandRunner is a test double for ScriptWrapProvider's shared command seam. It records every request and returns queued results in order.

func NewProviderCommandRunner

func NewProviderCommandRunner(results ...workers.CommandResult) *ProviderCommandRunner

NewProviderCommandRunner creates a runner that returns the supplied results in order.

func (*ProviderCommandRunner) CallCount

func (r *ProviderCommandRunner) CallCount() int

CallCount returns how many commands were executed.

func (*ProviderCommandRunner) LastRequest

func (r *ProviderCommandRunner) LastRequest() workers.CommandRequest

LastRequest returns the latest recorded command request.

func (*ProviderCommandRunner) Queue

func (r *ProviderCommandRunner) Queue(results ...workers.CommandResult)

Queue appends ordered subprocess results for subsequent Run calls.

func (*ProviderCommandRunner) Requests

Requests returns the recorded command requests in order.

func (*ProviderCommandRunner) Run

Run records the request and returns the next queued result.

type ProviderErrorPauseIsolationOutcome

type ProviderErrorPauseIsolationOutcome struct {
	ThrottledLane  ProviderErrorSmokeOutcome
	UnaffectedLane ProviderErrorSmokeOutcome
	EngineState    *interfaces.EngineStateSnapshot[petri.MarkingSnapshot, *state.Net]
}

ProviderErrorPauseIsolationOutcome captures the observable state proving that one throttled provider/model lane requeued without blocking another lane.

func WaitForProviderErrorPauseIsolation

func WaitForProviderErrorPauseIsolation(
	t *testing.T,
	serviceHarness *ServiceTestHarness,
	throttledWork ProviderErrorSmokeWork,
	unaffectedWork ProviderErrorSmokeWork,
	timeout time.Duration,
) ProviderErrorPauseIsolationOutcome

WaitForProviderErrorPauseIsolation waits until the throttled lane requeues to init while the unaffected lane reaches complete.

type ProviderErrorSmokeHarness

type ProviderErrorSmokeHarness struct {
	Dir        string
	Provider   interfaces.ModelProvider
	Model      string
	WorkerName string
	// contains filtered or unexported fields
}

ProviderErrorSmokeHarness owns a copied script-wrap fixture configured for a requested provider/model pair plus the corresponding service harness.

func NewProviderErrorSmokeHarness

func NewProviderErrorSmokeHarness(
	t *testing.T,
	fixtureDir string,
	provider interfaces.ModelProvider,
	model string,
	opts ...ProviderErrorSmokeHarnessOption,
) *ProviderErrorSmokeHarness

NewProviderErrorSmokeHarness copies a real script-wrap fixture, rewrites the requested worker AGENTS.md with the provider/model pair under test, and returns a configured fixture helper. Build the service harness after writing any seed work so preseed sees the intended inputs.

func (*ProviderErrorSmokeHarness) BuildRunningServiceHarness

func (h *ProviderErrorSmokeHarness) BuildRunningServiceHarness(
	t *testing.T,
	timeout time.Duration,
) *ServiceTestHarness

BuildRunningServiceHarness constructs the ServiceTestHarness, starts the real async run loop, and registers cleanup so provider-error smoke tests can focus on lane behavior rather than run-loop lifecycle plumbing.

func (*ProviderErrorSmokeHarness) BuildServiceHarness

func (h *ProviderErrorSmokeHarness) BuildServiceHarness(t *testing.T) *ServiceTestHarness

BuildServiceHarness constructs the ServiceTestHarness for the rewritten fixture. Call this after any seed requests have been written into Dir.

func (*ProviderErrorSmokeHarness) ProviderRunner

func (h *ProviderErrorSmokeHarness) ProviderRunner() *ProviderCommandRunner

ProviderRunner exposes the recorded provider subprocess seam for assertions.

func (*ProviderErrorSmokeHarness) QueueProviderResults

func (h *ProviderErrorSmokeHarness) QueueProviderResults(results ...workers.CommandResult)

QueueProviderResults appends ordered provider subprocess outcomes to the smoke harness.

func (*ProviderErrorSmokeHarness) SeedWork

SeedWork writes a stable named smoke-test submission into the copied fixture so startup preseed preserves deterministic WorkID and TraceID values.

func (*ProviderErrorSmokeHarness) WaitForFailedAfterBoundedRetries

func (h *ProviderErrorSmokeHarness) WaitForFailedAfterBoundedRetries(
	t *testing.T,
	serviceHarness *ServiceTestHarness,
	work ProviderErrorSmokeWork,
	timeout time.Duration,
) ProviderErrorSmokeOutcome

WaitForFailedAfterBoundedRetries waits until the seeded work reaches its failed place after exhausting the expected number of provider attempts.

func (*ProviderErrorSmokeHarness) WaitForRetryableRequeue

func (h *ProviderErrorSmokeHarness) WaitForRetryableRequeue(
	t *testing.T,
	serviceHarness *ServiceTestHarness,
	work ProviderErrorSmokeWork,
	timeout time.Duration,
) ProviderErrorSmokeOutcome

WaitForRetryableRequeue waits until the seeded work has a completed failed dispatch whose output mutations recreated the work in its initial place.

func (*ProviderErrorSmokeHarness) WaitForThrottleRequeue

func (h *ProviderErrorSmokeHarness) WaitForThrottleRequeue(
	t *testing.T,
	serviceHarness *ServiceTestHarness,
	work ProviderErrorSmokeWork,
	timeout time.Duration,
) ProviderErrorSmokeOutcome

WaitForThrottleRequeue waits until the seeded work requeues to its init lane after a throttled provider result pauses that provider/model lane.

type ProviderErrorSmokeHarnessOption

type ProviderErrorSmokeHarnessOption func(*providerErrorSmokeHarnessConfig)

ProviderErrorSmokeHarnessOption customizes NewProviderErrorSmokeHarness.

func WithProviderErrorSmokeServiceOptions

func WithProviderErrorSmokeServiceOptions(opts ...ServiceTestHarnessOption) ProviderErrorSmokeHarnessOption

WithProviderErrorSmokeServiceOptions forwards service harness options to the constructed ServiceTestHarness.

type ProviderErrorSmokeLane

type ProviderErrorSmokeLane struct {
	WorkTypeID      string
	WorkerName      string
	WorkstationName string
	Provider        interfaces.ModelProvider
	Model           string
	PromptBody      string
}

ProviderErrorSmokeLane declares one provider/model lane in a generated provider-error smoke fixture.

type ProviderErrorSmokeOutcome

type ProviderErrorSmokeOutcome struct {
	Work         ProviderErrorSmokeWork
	FinalPlaceID string
	Token        interfaces.Token
	Dispatches   []interfaces.CompletedDispatch
	EngineState  *interfaces.EngineStateSnapshot[petri.MarkingSnapshot, *state.Net]
}

ProviderErrorSmokeOutcome captures the normalized observable state that provider-error smoke tests assert after a lane fails or requeues.

func WaitForProviderErrorFailedAfterBoundedRetries

func WaitForProviderErrorFailedAfterBoundedRetries(
	t *testing.T,
	serviceHarness *ServiceTestHarness,
	work ProviderErrorSmokeWork,
	timeout time.Duration,
) ProviderErrorSmokeOutcome

WaitForProviderErrorFailedAfterBoundedRetries waits until the seeded work reaches its failed place after exhausting provider retries.

func WaitForProviderErrorRetryableRequeue

func WaitForProviderErrorRetryableRequeue(
	t *testing.T,
	serviceHarness *ServiceTestHarness,
	work ProviderErrorSmokeWork,
	timeout time.Duration,
) ProviderErrorSmokeOutcome

WaitForProviderErrorRetryableRequeue observes the durable dispatch-history requeue signal for retryable provider failures. Unlike throttled failures, non-throttled retryable failures may be redispatched immediately, so the live marking is not guaranteed to pause in the initial place long enough to poll.

func WaitForProviderErrorThrottleRequeue

func WaitForProviderErrorThrottleRequeue(
	t *testing.T,
	serviceHarness *ServiceTestHarness,
	work ProviderErrorSmokeWork,
	timeout time.Duration,
) ProviderErrorSmokeOutcome

WaitForProviderErrorThrottleRequeue waits until the seeded work requeues to its init lane after a throttled provider result pauses that provider/model lane.

type ProviderErrorSmokePauseIsolationHarness

type ProviderErrorSmokePauseIsolationHarness struct {
	Dir            string
	ThrottledLane  ProviderErrorSmokeLane
	UnaffectedLane ProviderErrorSmokeLane
	// contains filtered or unexported fields
}

ProviderErrorSmokePauseIsolationHarness owns a generated two-lane fixture for proving that a throttled provider/model lane pauses without blocking an unrelated lane.

func NewProviderErrorSmokePauseIsolationHarness

func NewProviderErrorSmokePauseIsolationHarness(
	t *testing.T,
	throttledLane ProviderErrorSmokeLane,
	unaffectedLane ProviderErrorSmokeLane,
	opts ...ProviderErrorSmokePauseIsolationHarnessOption,
) *ProviderErrorSmokePauseIsolationHarness

NewProviderErrorSmokePauseIsolationHarness builds a two-lane smoke fixture without requiring committed factory JSON or hand-written lane AGENTS files.

func (*ProviderErrorSmokePauseIsolationHarness) BuildRunningServiceHarness

func (h *ProviderErrorSmokePauseIsolationHarness) BuildRunningServiceHarness(
	t *testing.T,
	timeout time.Duration,
) *ServiceTestHarness

BuildRunningServiceHarness constructs the generated pause-isolation service harness, starts the real async run loop, and registers cleanup for the test.

func (*ProviderErrorSmokePauseIsolationHarness) BuildServiceHarness

BuildServiceHarness constructs the ServiceTestHarness for the generated pause-isolation fixture. Call this after seeding any startup work.

func (*ProviderErrorSmokePauseIsolationHarness) ProviderRunner

ProviderRunner exposes the recorded provider subprocess seam for assertions.

func (*ProviderErrorSmokePauseIsolationHarness) QueueProviderResults

func (h *ProviderErrorSmokePauseIsolationHarness) QueueProviderResults(results ...workers.CommandResult)

QueueProviderResults appends ordered provider subprocess outcomes to the shared script-wrap runner for both pause-isolation lanes.

func (*ProviderErrorSmokePauseIsolationHarness) SeedWork

SeedWork writes a stable named submission into the generated fixture so startup preseed preserves deterministic work identity.

func (*ProviderErrorSmokePauseIsolationHarness) WaitForPauseIsolation

func (h *ProviderErrorSmokePauseIsolationHarness) WaitForPauseIsolation(
	t *testing.T,
	serviceHarness *ServiceTestHarness,
	throttledWork ProviderErrorSmokeWork,
	unaffectedWork ProviderErrorSmokeWork,
	timeout time.Duration,
) ProviderErrorPauseIsolationOutcome

WaitForPauseIsolation waits until the throttled lane requeues to init while the unaffected lane reaches complete in the same running factory.

func (*ProviderErrorSmokePauseIsolationHarness) WaitForThrottleRequeue

WaitForThrottleRequeue waits until the throttled lane requeues to init after exhausting bounded provider retries.

type ProviderErrorSmokePauseIsolationHarnessOption

type ProviderErrorSmokePauseIsolationHarnessOption func(*providerErrorSmokePauseIsolationHarnessConfig)

ProviderErrorSmokePauseIsolationHarnessOption customizes the generated two-lane pause-isolation smoke fixture.

func WithProviderErrorSmokePauseIsolationServiceOptions

func WithProviderErrorSmokePauseIsolationServiceOptions(
	opts ...ServiceTestHarnessOption,
) ProviderErrorSmokePauseIsolationHarnessOption

WithProviderErrorSmokePauseIsolationServiceOptions forwards service harness options to the generated pause-isolation fixture.

type ProviderErrorSmokeWork

type ProviderErrorSmokeWork struct {
	Name       string
	WorkTypeID string
	WorkID     string
	TraceID    string
	Payload    []byte
}

ProviderErrorSmokeWork captures the stable submission fields that provider-error smoke tests assert against.

type ReplayHarness

type ReplayHarness struct {
	ArtifactPath string
	Artifact     *interfaces.ReplayArtifact
	Service      *ServiceTestHarness
	// contains filtered or unexported fields
}

ReplayHarness runs a replay artifact through the production-style service path. It loads embedded config from the artifact, installs replay side effects through service replay mode, and uses the worker-pool dispatch path by default.

func AssertReplaySucceeds

func AssertReplaySucceeds(t *testing.T, artifactPath string, timeout time.Duration) *ReplayHarness

AssertReplaySucceeds runs a replay artifact and fails the test if replay diverges, times out, or returns another runtime error.

func BuildReplayHarness

func BuildReplayHarness(t *testing.T, artifactPath string) (*ReplayHarness, error)

BuildReplayHarness is the error-returning form used by assertion helpers.

func NewReplayHarness

func NewReplayHarness(t *testing.T, artifactPath string) *ReplayHarness

NewReplayHarness builds a replay service harness from an artifact path. To promote a customer recording into a regression fixture, commit the replay JSON under the relevant testdata directory and pass its path here.

func (*ReplayHarness) RunUntilComplete

func (h *ReplayHarness) RunUntilComplete(timeout time.Duration) error

RunUntilComplete runs replay until terminal state, divergence, or timeout.

type ServiceTestHarness

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

ServiceTestHarness wraps a FactoryService built via BuildFactoryService() with test-friendly convenience methods. It exercises the full service layer: BuildFactoryService → loadWorkersFromConfig → WorkstationExecutor → AgentExecutor → mock Provider. This ensures prompt rendering, stop-token evaluation, and output parsing are tested.

The harness does not expose the underlying factory or service — all operations are available through harness methods.

func NewServiceTestHarness

func NewServiceTestHarness(t *testing.T, dir string, opts ...ServiceTestHarnessOption) *ServiceTestHarness

NewServiceTestHarness builds a FactoryService from the given directory (which must contain factory.json and workers/{name}/AGENTS.md files) and returns a test harness that drives the engine step-by-step.

By default, the harness enables inline dispatch so that worker executors (built by BuildFactoryService from AGENTS.md configs) run during each Tick — no goroutines or channels required in tests.

Pass WithRunAsync() for tests that use RunUntilComplete or RunInBackground, which require the real async worker pool.

func (*ServiceTestHarness) Assert

func (h *ServiceTestHarness) Assert() *MarkingAssert

Assert returns a MarkingAssert for the current marking.

func (*ServiceTestHarness) GetEngineStateSnapshot

GetEngineStateSnapshot returns a unified EngineStateSnapshot combining runtime state, factory lifecycle, session metrics, and uptime.

func (*ServiceTestHarness) GetFactoryEvents

func (h *ServiceTestHarness) GetFactoryEvents(ctx context.Context) ([]factoryapi.FactoryEvent, error)

GetFactoryEvents returns the canonical factory event history recorded by the service.

func (*ServiceTestHarness) Marking

Marking returns the current marking snapshot.

func (*ServiceTestHarness) MockWorker

func (h *ServiceTestHarness) MockWorker(workerType string, results ...interfaces.WorkResult) *MockExecutor

MockWorker registers a MockExecutor for the given worker type and returns it. If the worker type was already registered, returns the existing mock. In inline mode, mocks execute during Tick. In async mode (WithRunAsync), mocks execute in the worker pool via the delegating executor.

func (*ServiceTestHarness) RunInBackground

func (h *ServiceTestHarness) RunInBackground(ctx context.Context) <-chan error

RunInBackground starts the factory's Run loop in a background goroutine and returns the error channel. Unlike RunUntilComplete, this does NOT block — the caller controls when to stop (via context cancel) and can submit work or query state while the engine runs.

Delegates to FactoryService.Run().

func (*ServiceTestHarness) RunUntilComplete

func (h *ServiceTestHarness) RunUntilComplete(t *testing.T, timeout time.Duration)

RunUntilComplete starts the factory's Run loop in a background goroutine and blocks until all tokens reach terminal/failed places or timeout elapses. It fails the test on timeout or factory error.

Works with both inline dispatch (default) and async dispatch (WithRunAsync). Delegates to FactoryService.Run().

func (*ServiceTestHarness) RunUntilCompleteError

func (h *ServiceTestHarness) RunUntilCompleteError(timeout time.Duration) error

RunUntilCompleteError is the error-returning form of RunUntilComplete. Tests that intentionally exercise timeout behavior can assert on the returned diagnostic message.

func (*ServiceTestHarness) SetCustomExecutor

func (h *ServiceTestHarness) SetCustomExecutor(workerType string, executor workers.WorkerExecutor)

SetCustomExecutor registers a custom WorkerExecutor for a worker type. Custom executors take precedence over mock executors. This is useful when a test needs dynamic behavior that depends on the dispatch inputs (e.g., setting ParentID on spawned tokens based on the input token's WorkID). Works in both inline and async (WithRunAsync) dispatch modes.

func (*ServiceTestHarness) SubmitError

func (h *ServiceTestHarness) SubmitError(workTypeID string, payload []byte) error

SubmitError is the nonfatal form of Submit. Use it for tests that assert validation failures at the submit boundary.

func (*ServiceTestHarness) SubmitFull

func (h *ServiceTestHarness) SubmitFull(ctx context.Context, reqs []interfaces.SubmitRequest) error

SubmitFull submits one or more work items with full control over WorkID, TraceID, Tags, Relations, and other SubmitRequest fields. It wraps those fields into a canonical WorkRequest before calling the service ingress.

func (*ServiceTestHarness) SubmitFullError

func (h *ServiceTestHarness) SubmitFullError(ctx context.Context, reqs []interfaces.SubmitRequest) error

SubmitFullError is the nonfatal form of SubmitFull for tests that need to assert validation errors without failing the test immediately.

func (*ServiceTestHarness) SubmitWork

func (h *ServiceTestHarness) SubmitWork(workTypeID string, payload []byte) error

SubmitWork injects a new work token into the factory's submission queue. The token is processed when the engine runs (via RunUntilComplete or RunInBackground). Returns an error if submission fails (also fatals the test). Callers that need token IDs should inspect the marking after the engine has run.

func (*ServiceTestHarness) SubmitWorkRequest

func (h *ServiceTestHarness) SubmitWorkRequest(ctx context.Context, request interfaces.WorkRequest) error

SubmitWorkRequest submits a canonical work request batch with full control over request IDs, work item names, payloads, tags, and relations.

func (*ServiceTestHarness) WaitToComplete

func (h *ServiceTestHarness) WaitToComplete() <-chan struct{}

WaitToComplete returns a channel that is closed when all tokens reach terminal or failed places and no dispatches are in flight.

type ServiceTestHarnessOption

type ServiceTestHarnessOption func(*harnessConfig)

ServiceTestHarnessOption configures a ServiceTestHarness.

func WithCommandRunner

func WithCommandRunner(runner workers.CommandRunner) ServiceTestHarnessOption

WithCommandRunner sets a CommandRunner override on the service config. SCRIPT_WORKER executors will use this runner instead of os/exec, allowing tests to mock command execution while exercising the full ScriptExecutor pipeline (arg templates, env merging, exit-code routing).

func WithExecutionBaseDir

func WithExecutionBaseDir(dir string) ServiceTestHarnessOption

WithExecutionBaseDir overrides the runtime base directory used to resolve relative workstation execution paths.

func WithExtraOptions

func WithExtraOptions(opts ...factory.FactoryOption) ServiceTestHarnessOption

WithExtraOptions appends additional factory options to the service config.

func WithFullWorkerPoolAndScriptWrap

func WithFullWorkerPoolAndScriptWrap() ServiceTestHarnessOption

func WithMockWorkersConfig

func WithMockWorkersConfig(mockCfg *factoryconfig.MockWorkersConfig) ServiceTestHarnessOption

WithMockWorkersConfig enables service-level mock-worker mode using the normalized runtime config supplied by pkg/config.

func WithProvider

WithProvider sets the ProviderOverride on the service config.

func WithProviderCommandRunner

func WithProviderCommandRunner(runner workers.CommandRunner) ServiceTestHarnessOption

WithProviderCommandRunner injects a fake subprocess runner into the real ScriptWrapProvider used by MODEL_WORKER executors. Use this for tests whose intent is to validate provider CLI construction rather than provider replacement at the higher-level Infer API.

func WithRecordPath

func WithRecordPath(path string) ServiceTestHarnessOption

WithRecordPath enables service record mode for harness runs.

func WithReplayPath

func WithReplayPath(path string) ServiceTestHarnessOption

WithReplayPath enables service replay mode for harness runs.

func WithRunAsync

func WithRunAsync() ServiceTestHarnessOption

WithRunAsync enables async dispatch mode for tests that use RunUntilComplete or RunInBackground. In async mode, the worker pool processes dispatches instead of inline execution during Tick. This is the production dispatch path.

func WithRuntimeInstanceID

func WithRuntimeInstanceID(id string) ServiceTestHarnessOption

WithRuntimeInstanceID sets a stable runtime log filename for assertions.

func WithRuntimeLogConfig

func WithRuntimeLogConfig(config logging.RuntimeLogConfig) ServiceTestHarnessOption

WithRuntimeLogConfig sets bounded rolling-file policy for service runtime logs.

func WithRuntimeLogDir

func WithRuntimeLogDir(dir string) ServiceTestHarnessOption

WithRuntimeLogDir writes service runtime logs under dir for assertions.

type WorkResponse

type WorkResponse struct {
	Content string
	Error   error
}

response from a provider can either be content or an error.

Directories

Path Synopsis
Package validationassert provides shared test helpers for factory validation target assertions.
Package validationassert provides shared test helpers for factory validation target assertions.

Jump to

Keyboard shortcuts

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