src/testing provides the in-memory process execution test harness for stackctl modules that depend
on the ProcessRunner interface. The harness replaces real external command execution with
configured ProcessResult responses, records every command invocation, supports dry-run
propagation, and exposes assertion helpers for command-oriented unit tests. mod.ts is the public
barrel export for these testing utilities.
- Interface substitution:
FakeProcessRunnerimplementsProcessRunner, allowing production modules to receive a deterministic test double through the same dependency boundary. - Builder pattern:
FakeProcessRunnerBuilderaccumulates command response fixtures and produces configured runner instances. - Fixture factory functions:
successResultandfailureResultconstruct canonicalProcessResultvalues for test setup. - Fail-fast verification: unknown command invocations throw immediately, which forces tests to declare the complete expected external command surface.
- Immutable observation: the
commandsgetter returns a copy of recorded invocations to preserve runner state integrity.
- A test creates
CommandResponsefixtures directly, throughFakeProcessRunnerBuilder, or with helper factories for result payloads. - The unit under test receives
FakeProcessRunneras aProcessRunnerdependency. - Calls to
run,stream, orwhichare recorded in order as command argument arrays. runandstreamresolve responses through prefix or exact command matching, then return aProcessResultwhosecommandfield reflects the actual invocation.whichrecords a syntheticwhich <name>command and resolves to the configured success state, defaulting tofalsewhen no response matches.- Assertion code inspects
recorded,commands, orcontainsCommandto verify command routing and argument construction. withDryRunreturns a new fake runner with the same response table and the requested dry-run flag.
../process/types.ts: suppliesProcessRunner,ProcessResult,RunOptions, andStreamOptions, which define the production contract implemented by the fake harness.- Command wrapper modules: docker, secrets, compose, env, and other modules can inject the fake runner to test external command orchestration without invoking Docker, sops, age, or shell tools.
- Public testing import path:
src/testing/mod.tsre-exportsfakes.tsso tests can import the harness through the testing module boundary.