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_into60. - 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
- Take the API snapshot before creating the resource, then start an episode from that snapshot.
- Create the resource inside the episode with the episode, run and action headers. Save the returned ID; it differs from the recorded fixture ID.
- Read that ID inside the episode. The initial read should return
200withX-Ghost-Resource: true. - 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.
| Step | API time since creation | Application control | Expected observation |
|---|---|---|---|
| Before expiry | 59 seconds | Hold the scheduler at zero | Read the returned ID. The API reports valid; the refresh callback remains pending. |
| At expiry | 60 seconds | Keep the scheduler held | Read the same ID. The API reports expired; the client handles the response without claiming its timer fired. |
| After expiry | 61 seconds | Keep the scheduler held | The old resource remains expired. Moving API time alone produces no refresh request. |
| Run the refresh | Hold at 61 seconds | Advance to the 30-second callback | The 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.