Managing Test Identity Fixtures and Pre-Seeded User Data in CI

Deterministic, isolated fixtures keep parallel CI tests reliable.

· 9 min read
Cover illustration for “Managing Test Identity Fixtures and Pre-Seeded User Data in CI”
Auth Flow Testing · November 17, 2026 · 9 min read · 1,968 words

Integration testing against stateful APIs requires a deterministic fixture world and a simulator that preserves resource state across calls. Each parallel test needs its own identities, a time it can control, and starting conditions it can check with assertions. This approach lets CI test workflows in order without hitting production, while checks against the live API keep the simulator’s behavior in line with it.

Why test fixture strategies fail in CI before a single assertion runs

Most CI fixture failures begin with data before assertions run. A user the test expects does not exist, workers mutate the same account, or seeded rows no longer satisfy the application’s schema. These failures appear intermittent because their symptoms depend on execution order or the path a test takes. The underlying defect is architectural. The fixture was treated as a static snapshot rather than a world whose relationships and state must remain consistent.

A SQL dump, JSON file, or hardcoded factory default can load successfully while describing an invalid starting point. For example, a migration can leave a new required column without a value, with the failure surfacing only when application code checks it. Parallel workers run into another problem when they read and change shared rows. Sequential API calls expose another when a stub returns the same body after creation, modification, and deletion.

What stateful fixture data actually means in practice

A stateful fixture world has consistently derived identities and relationships, supports the expected changes across operations, and exposes state that tests can assert before execution. Identity is its first anchor. CandleViewer’s admin-fixtures-A PR derives IDs from stable handles through uuid5, so the same handle produces the same identity across runs and machines. This avoids a collection of unrelated magic strings whose relationships exist only in the author’s assumptions.

The same implementation makes seeding idempotent through ON CONFLICT on derived IDs or composite keys. Running it again resets values in existing records. Its companion check_admin_world assertion verifies the post-conditions that tests depend on, turning the intended starting state into an executable contract. The seed establishes the world. The assertion checks it.

That world includes more than an active user. CandleViewer covers invited, active, disabled, and locked users across roles, accounts of different ages with time-sensitive restrictions, and trade grants with different permission combinations. Feature flags appear in both on and off states. These distinctions define which operations should succeed and which should fail. A fixture that preserves the user row but loses its permission or age constraints no longer represents the same scenario.

Deterministic seeding as the foundation of reproducible CI runs

Reproducing that world requires controlling every input to generation. Given the same seed and generator version, generated output should be identical across machines and CI runners. Otherwise, a failing test cannot reliably be reconstructed after the run ends. Determinism is therefore part of the fixture’s contract. The seed serves as a compact description of the generated data.

Time must be an input as well. A generator that reads new Date() or datetime.now() can change account ages or restrictions even when its random seed stays fixed. Passing a known time to the generator keeps those values from changing with the clock. For example, a fixture can use seed 42 with now set to "2026-10-05T12:00:00Z". Both the generated values and the time-sensitive conditions then have a reproducible basis.

A seed can produce different output after the generator adds name data, so failure output needs the generator version as well as the seed. Recording version v3 with seed 42 shows which generator version and seed were used. Scenario names also improve diagnosis. A readable seed such as checkout-eu-user communicates intent more directly than a bare integer.

Isolating fixture state so parallel workers cannot corrupt each other

Workers can still share an identity even when generation is deterministic. If two tests generate the same user and both modify it, their results still depend on execution order. Each test needs its own fixture data, must operate only on that data, and must clean up regardless of outcome. Reproducible shared mutation is still shared mutation.

Factory-created fixtures make this separation part of setup. The TypeScript pattern of seeding Faker from a hash of the test ID ties generation to the individual test. The identity is reproducible for its owning test, while workers must not resolve to the same mutable records.

CandleViewer distinguishes per-test data from baseline world state. Accounts and flags that must exist before execution use ON CONFLICT to make concurrent seeds safe, while isolated factories create per-test data. Upsert safety does not grant permission to mutate shared records concurrently. The fixture lifecycle remains setup, provide, and teardown, with cleanup failures logged. Cleanup that runs only after a pass leaves orphaned records precisely when a failing run most needs containment.

Keeping fixture identity safe: what credentials and sensitive data must never enter CI

The fixture world must also be kept free of real credentials, password hashes, and identity-sensitive data. Deterministic generation does not make copied production data safe. The design constraint is that prohibited material causes a build failure before tests run. This protects the fixture boundary even when a production extract is introduced to reproduce a bug.

CandleViewer provides a concrete model for derived identity without depending on production identities. A scan before tests run should reject records that look like real data, including phone number patterns, email domains outside reserved ranges, and social security or payment card patterns. Repository fixtures should use only @example.com, @example.net, and @example.org. A must_not_match assertion on the files makes that restriction executable and catches contributions that introduce real-looking addresses.

How do integration tests handle APIs where order of operations matters?

A seeded user that creates an account through Stripe or PayPal needs the resulting external state to remain available to the next step. A stateless response fixture cannot provide that continuity because it has no memory of the operation that preceded the request. Matching the response shape is not enough. The response must also be valid for the resource’s current lifecycle.

Consider an order created with a 201 response and an ID. The application polls that ID until the order is complete, then attempts cancellation and receives 409 because completion makes cancellation invalid. A fixed poll response shows an unchanging order state and may also return an ID unrelated to the created resource or leave the conflict path unreachable. A stateful simulator instead tracks creation, current state, and valid operations, allowing each call to depend on the calls before it.

What stateful simulation looks like across the APIs developers actually test against

Stripe makes webhook versioning and replay part of the fixture contract. Endpoints with a null api_version follow the account default, so an account upgrade can change payload shapes without an application deployment. Stripe retries undelivered events for up to three days, which makes replay idempotency essential. Local event triggering and version pinning are distinct operations. The Stripe CLI supports stripe trigger checkout.session.completed, while version pinning uses --stripe-version on supported commands such as stripe post or stripe get separately from stripe trigger.

PayPal’s webhook simulator sends demonstration events without the delivery state tied to an app. Those events do not appear in the dashboard event viewer, so their receipt cannot establish that a test has exercised real delivery behavior. PayPal retries failed deliveries up to 25 times over three days. A fixture must keep enough state to detect when those attempts cause duplicate mutations. A test that receives the same event again after an earlier attempt changed application state checks more than a test that receives a plausible event body once.

The vercel-labs/emulate project’s v0.12.3 example, dated November 2026 in the supplied material, covers stateful local emulators for GitHub, Slack, Resend, Stripe, and others. Its Slack emulator models the Web API, OAuth v2 flow, and Incoming Webhooks, preserving channels, messages, threads, and reactions across calls. Retry testing is explicit. POST /_slack/simulate/event-retry resends the latest recorded event delivery to its original subscription, or only the latest recipient when several subscribers received it. Preserving the payload and event ID allows deduplication testing without network access.

The drift problem: a simulator that isn't verified against the live API will lie to you

Preserving state internally does not establish fidelity to an external service. A simulator can keep its lifecycle fully consistent while returning payloads, status codes, or errors that the real API no longer returns. Its tests may remain green throughout that divergence. This is a different failure from corrupt fixture data. The model itself has become obsolete.

Kalshi’s versioned rate-limit change on 2026-04-23 illustrates the risk. It moved to a token-bucket model with five tiers, two independent buckets per tier, and no Retry-After header. A simulator retaining earlier behavior would not test the application against those constraints. Stripe’s account-default webhook versioning creates a related mismatch when simulated payloads remain pinned to an older shape after an account upgrade.

The simulator’s expected behaviors must be exercised against the real API before every release, with divergence failing the simulator’s own test suite. Published fidelity scores provide a numerical measure of agreement across a defined API surface. That defined surface is essential. A score is useful as evidence of agreement for the operations tested.

Fault injection as a first-class fixture concern, not an edge case

A faithful fixture world must include failures as controllable state. Timeouts, rate limits, and partial responses affect what later operations can safely do, so fixtures with only successful responses cannot test recovery. The position of the fault is decisive. A failure before creation poses a different recovery question from a failure after an earlier operation has already changed state.

Kalshi’s lack of a Retry-After header means the application needs its own backoff strategy. Validating that strategy requires a simulator to return 429 in the relevant sequence. Webhook recovery requires similar control. A fixture can inject a temporary 503, allow a retry, and assert that delivery does not cause a duplicate mutation. The assertion must cover retained application state.

AI agents that call external APIs need the same boundary tests. Correct parameter extraction and endpoint selection do not prevent an agent from mishandling a partial response or schema-drifted payload. The testing pattern is to inject the fault at a specific step, assert recovery, and check that retries have not corrupted prior successful state. This keeps agent testing focused on observable workflow behavior. A stateless mock cannot establish those cross-call guarantees.

A concrete fixture architecture that survives parallel runs, schema migrations, and API drift

The practical architecture combines four layers rather than treating fixture techniques as independent conveniences. Stable identity anchors relationships, deterministic generation reconstructs data, assertable post-conditions validate the starting world, and continuously verified simulation extends that world across API boundaries. Each layer has a separate responsibility. A schema migration, for example, must be checked against the post-conditions the application needs even when the seed script still completes.

The CI pipeline should begin with a provision stage that seeds the world and runs its post-condition assertion. Security checks gate the fixture contents before execution. Parallel workers then receive factory-created identities, while failure output records the scenario or commit-pinned seed, explicit time, and generator version. Unconditional teardown closes each test’s lifecycle. This arrangement separates baseline provisioning from the mutable data each worker owns.

External calls should run against a locally hosted stateful simulator with sequence-specific fault injection. For the services it supports, this lets ordinary CI runs work without live credentials, a network connection, or live-service rate limits, while keeping simulated rate-limit behavior for resilience tests. Live API access should be used to verify the simulator. A drift check can run after deployment or on a schedule where that access is available, complementing verification before each release. Its published fidelity score keeps the architecture accountable to real service behavior rather than merely to its own internally consistent model.

More in Auth Flow Testing