Guides · failures & time

Test expiring resources

The API expires a temporary resource while the app still has its ID cached. Check what the app shows at the expiry boundary, then watch what changes when its refresh callback runs.

Temporary access

An export grant expires before the app refreshes

Step through the same grant at 59, 60 and 61 seconds. Then run the application’s separate refresh callback.

LedgerlineNorthstar Co.JL
OverviewExportsSettings

Finance workspace

Monthly ledger

ledger-june.csvJune 1–30 · CSV · 24 KB
Private
Created by
Jordan Lee
Access scope
Read export
Grant lifetime
60 seconds
Export preview3 of 186 rows
DateAccountAmount
Jun 03Freight revenue$4,280.00
Jun 04Warehouse rent−$1,450.00
Jun 04Carrier services−$680.00
Export access ready

Your temporary grant is still valid.

Active grant
grant_q7w2b49m

Request evidence

Probe 1 / 4
API elapsed
00:59
App scheduler
00:00 · held

Read the current grant

GET /export-grants/grant_q7w2b49m200

Response headers
X-Ghost-Resource: true
App cache
{
  "activeGrantId": "grant_q7w2b49m",
  "access": "ready"
}

This is an explicit probe. No refresh callback ran.

This model uses the documented episode resource contract and runs in the page without calling an API.

Before expiry. API elapsed 59 seconds. Read returned 200 valid. App scheduler still held.

Use this case when the API owns expiry

The resource read is authoritative in this case. The app reacts to the API’s answer; it does not decode a JWT or compare a local expiry timestamp.

Prepare an isolated test

  • Use a licensed Gostly installation with MOCK responses and the documented episode-create contract. Configure paired create/read fixtures and set the disposable resource’s expires_in to 60.
  • Use a harness that holds the client scheduler, observes outgoing requests and can explicitly probe the read through the client.
  • Use synthetic data. This exercise needs no real authentication token or live account.

API times below are elapsed from the resource’s creation. Moving episode time changes the supported resource’s API response. Your harness controls when the application’s callback runs.

Prepare the API and client starting states

  1. Take the API snapshot before creating the resource, then start an episode from that snapshot.
  2. Create the resource inside the episode with the episode, run and action headers. Save the returned ID; it differs from the recorded fixture ID.
  3. Read that ID inside the episode. The initial read should return 200 with X-Ghost-Resource: true.
  4. Start the application’s controlled scheduler at zero with one refresh callback pending at 30 seconds.

Keep both starting states. Restoring the API does not clear the client’s cached ID or pending work.

Probe before, at and after expiry

Advance API time explicitly. Hold the client scheduler while sending each read probe, then move that scheduler as a separate operation.

Authored test plan · expected observations, not a recorded run
StepAPI time since creationApplication controlExpected observation
Before expiry59 secondsHold the scheduler at zeroRead the returned ID. The API reports valid; the refresh callback remains pending.
At expiry60 secondsKeep the scheduler heldRead the same ID. The API reports expired; the client handles the response without claiming its timer fired.
After expiry61 secondsKeep the scheduler heldThe old resource remains expired. Moving API time alone produces no refresh request.
Run the refreshHold at 61 secondsAdvance to the 30-second callbackThe callback makes the configured create, saves its new ID and reads a valid new resource.

At and after expiry, the documented read returns 401 with X-Ghost-Resource: expired. Expiry begins when the episode clock reaches expired_at. Keep each resource ID with its observation so the expired and refreshed resources cannot be confused.

Check what the app actually did

  • The same old resource is valid before its API lifetime ends and expired at and after the boundary.
  • API-time advances alone cause no refresh callback or extra client request. Explicit probes still reach the client’s response handler.
  • Advancing the client scheduler runs the selected callback. The create’s new returned ID becomes the active resource.

Save request and response observations alongside the app’s active resource ID. An API response alone does not show whether the application replaced its expired state.

Reset both baselines before repeating

Reset the API episode, then clear the app’s cached ID, pending timers and observable state separately. Create again and use its returned ID. Created IDs change on every reset, even with the same run and action IDs.

If your application owns expiry through a timestamp or JWT claim, keep the API response fixed and move the app’s time source instead. The episode contract does not validate arbitrary bearer tokens or reproduce a provider’s authentication policy. Requests that merely carry the token in an Authorization header are served as usual.

The API time and application timers guide explains how to choose that control.

Configure the supported API case

The API reference contains enablement, create/read requirements, clock commands, reset behavior and operational limits.

Read API time & episodes