Testability Boundaries
External-system boundaries and deterministic testing guidance.
Inject external systems so workflow tests can control failures, ordering, and time without live providers or host-dependent results. Use real adapter tests to verify the boundaries themselves.
Testability and Boundaries🔗
Unit tests live in sibling *_test.rs modules. Shared fixtures remain test-only; public integration tests exercise supported APIs without exposing private implementation.
| Boundary | Contract |
|---|---|
| Git and worktrees | GitClient |
| Commit hooks | CommitHookRunner |
| Sandboxed host commands | SessionCommandClient |
| Harness session transcripts | SessionTranscriptClient |
| Filesystem and path probes | FsClient |
| Session turns | AgentChannel |
| Isolated model calls | OneShotClient |
| Provider setup | AgentBackend |
| Provider runtime lifecycle | AppServerClient |
| Provider availability, keys | AgentAvailabilityProbe |
| Forge reviews, threads, stacks | ReviewRequestClient |
| Programmatic session lifecycle | SessionBackend |
| Terminal events | EventSource |
| Wall and monotonic time | Clock |
| Worktree launch commands | TmuxClient |
| Clipboard capture | ClipboardImageClient |
| Terminal clipboard copies | TerminalClipboard |
| Browser pages and links | BrowserClient |
| Workspace agents | AgentCatalogClient |
| Process sampling | ResourceClient |
| Trusted Cargo cache fetches | CargoCacheClient |
| Remote-control relay link | RemoteControlLauncher |
| Paired remote devices | DeviceStore |
| Relay host resolution, dials | NetworkClient |
| Agentty Platform API and Sync | PlatformClient |
| Persistence | Repository traits in ag-store |
| Storage timestamps | TimestampSource |
Use mockall mocks at the narrowest useful boundary. Smaller command-runner traits isolate subprocess sequencing when a public client is too broad. Runtime rendering can use an injected terminal backend. Module Map identifies the owning crates and layers.
What Each Boundary Proves🔗
- Pure contracts such as execution-graph validation, proposal resolution, and status policies are tested without I/O.
- Storage tests use real SQLite adapters with injected timestamps. They prove atomic admission, rollback, ownership, idempotent redelivery, and that reopening the database restores state without replaying or dispatching work.
- History rewrites run against real Git repositories, since a mock cannot show what Git leaves behind. They prove that only the intended commits move, that a conflict stops with its metadata until an abort restores the head, and that invalid input is refused before any change.
- Workers are tested through injected queues, hosts, persistence, and runtime contracts; scripted providers stand in for models. Real process tests verify descendant cleanup and inherited pipes.
- Application workflows receive scripted clients through
SessionRunFactoryorMockRunClient, so ordering, cancellation, retries, and stale-result rejection are deterministic. - Providers and transports are tested against local HTTP servers or injected provider events. Live provider behavior, event availability, and native sandbox enforcement need separate qualification; mocks cannot prove them, and missing native infrastructure is a failed qualification, not a skipped check.
- Forge adapters run against mocked command runners. They prove the exact
ghandglabarguments, that an invalid display id or option-like branch is refused before any command, that a GitLab merge request still a draft after being marked ready is an error, and how forge check states, including GitLab pipeline statuses, map to the check facts a review request reports. - PTY scenarios cover user journeys end to end with pinned time and scripted providers.
Typed Errors Across Layers🔗
External clients expose typed errors. Adapters translate transport details into shared execution error categories so workers and hosts remain independent of provider implementations.
Application workflows propagate SessionError and AppError. Convert them to display strings only at event and UI boundaries; preserve causes until then.
Testing Guidance🔗
- Inject process, filesystem, and clock access in application and runtime workflows.
- Test ordering, failure, cancellation, and retries through controllable boundaries.
- Use isolated real-system tests for behavior mocks cannot establish.
- Keep executable selection, canonical path validation, bounded output, and inherited process configuration handling inside command adapters.
- Keep production defaults intact; tests select offline clients through composition.
- Keep explicit expectations in model catalog, default, and retirement tests; other workflows use the pinned selections from the
ag-sessiontest-utilsfeature.
TUI E2E Testing Framework (testty)🔗
PTY tests provide semantic assertions over terminal text, style, and position. VHS recordings provide visual review artifacts. Pin time, provider executables, and version labels so recordings do not depend on the host. PTY scenarios can advance monotonic time through the pinned Clock adapter; wall time stays fixed for captures.
Follow crates/agentty/tests/e2e/AGENTS.md for PTY scenarios and skills/refresh-feature-recordings/SKILL.md for published recordings.
Headless worker boundaries🔗
Inject WorkQueue, WorkerHost, persistence, runtime contracts, and the worker clock. Cover shared ordering, heartbeats, cancellation, shutdown, and terminal settlement without a frontend.
OperationLivenessRepository judges an overdue heartbeat against the store's injected TimestampSource, the clock that wrote it. Test a stalled or reporting operation by moving that source; no test waits on real time.
Session composition boundary🔗
Application tests receive scripted worker clients and provider workspace setup through SessionRunFactory. The default test factory is offline, skips provider CLI setup, and fails unexpected model calls, including detached ones.
Worker submission boundary🔗
Utility workflows inject MockRunClient; session workflows use scripted SessionRunClient instances. Worker tests own raw runtime and storage injection. Cancellation tests must observe adapter cleanup before terminal persistence, including nested calls, caller drop, and provider panics. See Execution for the mandatory worker path.
Prompt Behavior🔗
Contract tests cover schemas, native policy delivery, evidence encoding, and continuation invalidation. Behavioral fixtures run through the production worker and runtime with an injected provider. Opt-in live evaluations use the same path and record responses, settings, usage, latency, and bounded grades. Grades are regression signals, not a proof of correctness.
See skills/evaluate-prompts/SKILL.md for the evaluation workflow and root AGENTS.md for required gates.
Trace Export🔗
Hosts compose OTLP export from the ag-telemetry otlp feature and choose the destination; execution crates use its span guards with default features disabled. Local HTTP receivers verify protobuf payloads and exporter failure, while in-memory exporters verify span ownership and asynchronous context. git.command spans are verified against real isolated git processes; forge.command spans use mocked forge command runners. Trace boundaries report observable backend activity without inferring hidden model or tool timings.