Simulating Stripe Identity Verification in Test Pipelines
Stateful simulators catch the webhook and ordering bugs mocks miss.

Integration testing against stateful APIs requires a simulator that preserves resource state across calls, enforces operation order, and connects webhook events to the actions that caused them. For Stripe Identity, that means testing session creation, document submission, status transitions, and downstream decisions as one lifecycle. Stateless mocks work for single requests, but they cannot show whether the full verification flow works without hitting production.
Why Stripe Identity verification resists simple mocking
A Stripe Identity verification is not a single request-response exchange. Creating a VerificationSession returns a hosted URL for a document-and-selfie flow, but the applicant submits those materials asynchronously. Document checks and biometric comparison belong to the verification lifecycle, while webhook events communicate its progress to the application. The initial response is only the beginning. A successful creation request says nothing about whether the application will handle the eventual decision correctly.
Stripe Identity emits identity.verification_session.processing, .verified, .requires_input, and .canceled events when the corresponding status changes occur. Those events can trigger Slack notifications, grants of discounts or exemptions, and session redaction. Their order also affects what the application sees. Testing an individual response therefore leaves the connections between submission, status, notification, and access decisions unexamined.
Test mode changes how checks run while preserving the structure of that lifecycle. Identity verification checks are simulated, so they do not use real documents or databases. The environment is safe, but still has state. Test-mode objects do not exist in live mode, and signing secrets differ between environments. A checkout can pass its test-mode checks and still fail on its first real transaction, illustrating why environment isolation and integration correctness are separate properties.
How do integration tests fail when API operation order matters?
Stateless mocks are fast and appropriate for many tests. They can validate request shapes or supply a known response so that an isolated application branch can run. They fall short when the expected response depends on what happened earlier. A stateless mock has no memory of those actions, so it cannot derive the current session status from the lifecycle that the test has exercised.
For example, a POST that creates a session may succeed against a mock, while the subsequent GET returns an independently canned body. That body does not reflect the creation request. A webhook handler then gets whichever event the test supplies, even if that event does not fit the session’s history.
Recorded-response replay preserves a captured sequence without modeling a resource lifecycle. A deviation from the recorded call order can produce a miss or a stale response, and replay alone cannot force a new requires_input path or inject a failure. Better recordings do not remove that structural constraint. A stateful simulator models creation, processing, and what happens next, so each response follows from the state left by earlier actions.
The webhook loop is where stateless testing actually breaks in CI
The integration described here verifies signatures against the raw request body with a 300-second timestamp tolerance, including rejection of timestamps more than 300 seconds in the future. The test must check that delivery is accepted when the signature and timestamp are valid and rejected when either is invalid. Returning 200 from a stub exercises none of that boundary. The same integration enforces a 1 MB body cap before signature verification, so the order of validation also needs testing.
Repeated events must be handled idempotently, including concurrent deliveries of the same event. An out-of-order sequence, such as verified arriving before processing, must not be treated as an ordinary progression through statuses. The test needs both session state and delivery history to distinguish these cases systematically. One successful webhook request cannot stand in for all three.
Downstream failure further complicates that history. If the handler propagates a Slack notification failure as a non-2xx response rather than catching it, Stripe retries delivery. The application must then handle the repeated event without repeating an approval or denial. This makes notification failure part of the verification test surface.
Credential isolation adds another boundary in the described integration. TRIBAL_STRIPE_TEST_MODE_ONLY, enabled by default, accepts only sk_test_ or rk_test_ keys, returns 503 for live or malformed keys, and rejects live-mode webhook events with 400. Those protections need their own negative tests. Preview environments make local simulation structurally necessary because their URLs change with each deployment and sit behind authentication. In that setup, a CI preview run has no reachable live webhook endpoint, so preview testing must use simulated delivery.
What a stateful simulator actually tracks across an Identity session
A simulator must keep track of the session’s identity and current status through creation, verification, and redaction after the decision. A later read must reflect earlier operations. That includes the distinction between processing, verified, requires_input, and canceled, rather than a generic successful response for every request. The simulator must also track which events it dispatched and to which endpoint, allowing retry behavior to be exercised without calling Stripe.
Idempotency belongs to the same model, but requires separate bookkeeping. The simulator needs idempotency keys and stored responses so that repeated requests can return the appropriate prior result and avoid creating duplicate records. Delivery history supports testing repeated webhook handling. After an approve or deny decision, the lifecycle continues through verificationSessions.redact and its retry behavior. A simulator that stops at the verification decision leaves that final operation outside the test.
Slack messages, exemption conditions, and masked-last-4 displays depend on the session object’s status and other field values. Skeletal responses cannot exercise those dependencies faithfully. The schema also needs to be checked against the real API over time, because a simulator can be consistent with itself while following an outdated contract.
The Kalshi SDK illustrates the operational cost of that drift. Its nightly strict contract tests failed repeatedly through October–November 2026 as upstream changes introduced properties and endpoints and removed WebSocket channels that the SDK did not reflect. Those failures exposed a mismatch. A simulator with an equivalent gap could keep application tests green while concealing it. Fidelity must be checked before every release, starting after initial setup.
Fault injection as a first-class requirement for Identity pipelines
Fault injection tests the failure side of the webhook contract. A delivery timeout must expose whether recovery works or the session remains stalled in processing. A signature mismatch must result in rejection of the forged payload. These are not separate concerns from lifecycle testing. The application depends on recovery and rejection of untrusted deliveries to preserve the intended verification outcome when delivery fails or cannot be trusted.
When another request with the same idempotency key is still executing, the duplicate receives 409. Once the original request completes, a replay returns its stored response. Testing both conditions reveals whether the caller surfaces the existing session or creates a second one. A fixed duplicate-request response would miss the change between in-flight and completed work.
Slack unavailability connects fault injection directly to repeated webhook delivery. Where the handler returns non-2xx for that failure, the test must establish that retries do not produce duplicate approvals or denials. Rate-limit responses of 429 on post-decision redaction exercise backoff behavior. Latency spikes during session creation test whether the UI provides usable error feedback on a timeout. Each fault targets a distinct point where the flow can lose progress or make an incorrect downstream decision.
These scenarios belong in CI on every pull request. They do not require a production chaos exercise. Local fault injection avoids live API calls and per-verification fees while keeping real PII out of the test. That separation is especially important for Identity because the underlying flow handles government documents and selfie biometrics.
How stateful Identity simulators serve AI agent testing
An AI agent that calls Stripe Identity as a tool faces the same sequencing constraints as a conventional application. It may verify identity before it grants access, completes a transaction, or updates account state. Its evaluation therefore needs an environment that changes as the agent acts. A canned successful response can test one decision, but cannot validate the agent’s behavior across the full verification lifecycle.
An agent may create a session, poll its status, receive a simulated webhook event, and act on the result across four or more distinct API calls. Those calls must remain causally consistent. If a stateless mock returns processing no matter what happened before, the evaluation cannot show whether the agent handles changes in verification state correctly. A simulator must preserve the session, dispatch events on demand, and expose the same failure paths used in conventional integration tests.
Repeatability and isolation become particularly important when evaluations run in parallel. An RL environment using Identity verification calls needs many containers, each with isolated but deterministic state. A live sandbox introduces rate-limit and credential collisions that interfere with that requirement. Local simulation lets the environment change without live credentials. Realistic seeded fields remain essential because training or evaluating against skeletal responses does not establish that behavior will generalize to the real API’s field structure.
Running a Stripe Identity simulator in a CI pipeline — the practical workflow
The practical approach is to replace live API calls and webhook deliveries with a locally hosted stateful simulator, then run lifecycle and fault scenarios as standard CI jobs. Session creation tests POST to that simulator and assert that the returned VerificationSession matches Stripe’s schema. In the described integration, they also verify that the hosted URL appears only when both feature flags are set. Schema correctness alone is not the completion criterion.
Status tests then drive processing to verified, requires_input, and canceled. For each path, assertions check the final status along with the right Slack message, exemption grant, and redaction call. Local webhook delivery tests exercise signature validation, repeated and concurrent delivery, out-of-order events, and the body cap. The simulator’s dispatch history gives those assertions context. It connects the handler’s response to a specific event and session history.
Fault jobs inject Slack 5xx responses, signature mismatches, 429 responses on redaction, and delivery timeouts, then assert that recovery does not silently lose data. Separate guard tests check that live and malformed keys get 503 responses and live-mode webhook events get 400 responses. These jobs produce a deterministic pass or fail without network access to Stripe. They also avoid per-verification fees and live credentials.
Each CI container gets its own isolated session state. This keeps changes made in one scenario from affecting another. Stripe’s documentation notes a related isolation problem in its test mode, where card-level state persists between tests and requires a different card for each independent scenario. That example applies specifically to payments.
Keeping the simulator current as Stripe's Identity API changes
Offline application tests do not remove the need for an external fidelity check. Stripe can change schemas, webhook event fields, or status transition rules while a simulator keeps returning the same responses. Application tests may then remain green because both their assumptions and their simulated environment are stale. Without contract verification, drift can remain hidden until production exposes it.
Continuous verification compares simulator behavior with the real Stripe test-mode API on a schedule, before every release at minimum. This is distinct from the ordinary offline CI run. The comparison must fail the build when differences in responses would change how the integration works, even if every application test is green. New webhook fields and changed transition rules need to become visible discrepancies.
Simulator fidelity must be treated as a versioned, auditable artifact. Its accuracy requires maintenance just as the integration does. A stateful model provides the memory needed to test ordered operations, but continuous verification keeps that model tied to the API it represents.


