Using Gostly
Episodes
An episode is a named, temporary run of a mocked API environment. Requests assigned to the same episode share its modeled resource state, virtual clock and configured chaos sequence.
Use an episode when a test needs several related calls, a clean starting point and a record of the API outcomes. An order can be paid in one run while a separate run explores what happens after its payment deadline.
When to use an episode
- Keep a create, update and later read in the same modeled customer workflow.
- Give separate test runs their own resource changes instead of sharing the default resource namespace.
- Restore a prepared starting state before comparing a client change, fault condition or action sequence.
- Associate requests with named runs and actions to inspect the dependency's responses alongside your application's result.
A single fixed response may need only an ordinary mock. Episodes are useful when the relationship between calls or the state left by an earlier call matters.
What an episode isolates
Each episode has its own supported resource state, clock, seeded random-stream position and rate-limit window state. A named snapshot supplies the baseline used to create or reset it. Changes in that episode's modeled resources do not become the default namespace's resource changes.
Service routes, mock libraries, operating modes, chaos configuration and statechart definitions remain shared configuration. Reset restores episode state against that configuration; it does not restore an older copy of the installation. Prepare those inputs before the snapshot and take a new snapshot when they change.
Your application, its database, other tools and separate network connections remain under your test harness's control.
Assign requests to an episode
Configure the selected HTTP client to use Gostly, then include the episode identifier on every request that belongs to the run. A request without it uses the default namespace. An instruction to an agent does not add the header to its HTTP tools automatically.
X-Gostly-Episode: checkout-run X-Gostly-Run-Id: attempt-1 X-Gostly-Action-Id: read-order
X-Gostly-Episodeselects the episode state.X-Gostly-Run-Ididentifies the attempt.X-Gostly-Action-Ididentifies a step. Give each step a distinct value and reuse those step identifiers when repeating the procedure.
The proxy removes these correlation headers before upstream forwarding. They label actions; they do not assert that the response or application behavior was correct. See Proxy Setup for client routing.
Create and reset from a baseline
Prepare the mocked services and take a snapshot of the default namespace. Reset a named episode from that snapshot before the test. A later reset restores its captured resource state, virtual clock, seeded chaos position and rate-limit windows.
Snapshot and episode names are separate. One snapshot can supply several episodes. Each reset starts a new journal generation, identified by a reset correlation ID. Keep that generation with the run and action identifiers when comparing results.
Repeat requests in the same order with the same clock advances and compatible configuration when comparing seeded decisions. Concurrent calls can reach the proxy in a different order. An opted-in resource create can return a new identifier after reset; compare its meaning and relationships rather than assuming identical response text.
Time Chamber describes preparation, virtual time and dashboard inspection.
Compare an order workflow
For an illustrative case, configure an order lifecycle with an unpaid state, a payment event and an expiry timer. Prepare a baseline before payment. In one run, send payment before the deadline. In another, restore the baseline and advance API time past the deadline before payment.
Check the application decision in both cases: does it confirm only a paid order, explain an expired attempt and preserve a useful recovery path? The episode supplies modeled API state. Your application or evaluation harness checks the decision shown to the customer.
Inspect and finish the run
An owner or administrator can open Time Chamber in the local dashboard to snapshot, fork, reset and inspect live episodes and journals. Keep the selected agent instance, boot and reset generation with the run record. A journal records operations and outcomes; it does not expose model reasoning or establish that an application assertion passed.
Close episodes and remove snapshots when they are no longer needed. Control operations require authentication. The standard installation enables proxy episodes with GOSTLY_EPISODES=1. Shared API and MCP snapshot, fork and reset operations have their own setting, GOSTLY_SHARED_EPISODE_MUTATIONS_ENABLED, which is on by default; set it to 0 to refuse them. Direct proxy controls do not depend on it.
Lifetime and recovery
- Proxy restart: live episodes and usable in-memory snapshots end. Create a baseline for the new boot. Retained journal or snapshot files are not a restartable episode.
- Configuration change: a snapshot can be refused because its environment no longer matches. Take a new snapshot after preparing the intended configuration.
- Idle expiry: defaults close an episode after one hour without activity and remove a snapshot after 24 hours without a reset using it. Operators can configure these limits.
- Capacity: live episode and snapshot quotas are bounded. Finish unused runs before starting more.
Related documentation
- API time & episodes reference: request contracts, authentication, errors and expiring-resource configuration.
- Stateful Flows & Statecharts: model the lifecycle an episode exercises.
- Chaos & Fault Injection: configure failure conditions before taking a baseline.
- Stateful API testing guide: choose resource changes and application assertions for a multi-call test.