Test an on-call agent with a PagerDuty API mock.
A local PagerDuty REST API for your on-call agent’s tests. Acknowledgments and notes stay on the incident, so a test can check which page it took.
Open incidents
- Checkout APItriggered
Elevated 5xx in staging
- Orders APIacknowledged
Requests waiting for database connections
On-call bot added a note to Orders API
Looking into it: requests are waiting for database connections.
An agent acknowledged the wrong incident
Two incidents were open: Checkout API, from staging, twelve minutes old, and Orders API, two minutes old. The agent is on call for the Orders API. It took the first triggered incident in the list, acknowledged Checkout and left the Orders page ringing.
The test checks both incidents after the run: Orders acknowledged, Checkout still triggered.
| Check | Original agent | Fixed agent |
|---|---|---|
| Acknowledged the Orders page | 0 of 3 | 3 of 3 |
| Left the Checkout page alone | 0 of 3 | 3 of 3 |
Scripted agent, no model. Recorded with CLI 0.4.74.
The one-line fix
- const page = incidents[0];+ const page = incidents.find(incident => incident.service.summary === 'Orders API');Run it yourself
Save agent.mjs and scene.yaml in an empty directory. You need Node.js 24.
npm install -g @ancha-labs/cli
ancha init --agent "node agent.mjs"
ancha run scene.yaml --local -n 3
ancha baseline save before
# change incidents[0] to incidents.find(incident => incident.service.summary === 'Orders API') in agent.mjs
ancha run scene.yaml --local -n 3 --compare beforeConnect your agent to the PagerDuty mock
When ancha runs your agent, it sets:
PAGERDUTY_API_URLPAGERDUTY_API_TOKENPAGERDUTY_FROM_EMAILPAGERDUTY_ROUTING_KEYPAGERDUTY_ROUTING_KEYSPAGERDUTY_SIGNING_SECRET
Point the client you already use at them.
import { api } from '@pagerduty/pdjs';
const pd = api({ token: process.env.PAGERDUTY_API_TOKEN });
const base = process.env.PAGERDUTY_API_URL;
// Pass the full local URL on every call; writes also send From: PAGERDUTY_FROM_EMAIL.
await pd.get('/services', { url: `${base}/services` });Locally, ancha runs your agent as an ordinary process, so keep real PagerDuty credentials out of its environment.
See all 20 endpoints
enqueue
/v2/enqueueescalation_policies
/escalation_policies/escalation_policies/:idincidents
/incidents/incidents/:id/incidents/:id/incidents/:id/log_entries/incidents/:id/notes/incidents/:id/notesoncalls
/oncallsschedules
/schedules/schedules/:id/schedules/:id/overrides/schedules/:id/overrides/schedules/:id/overrides/:override_id/schedules/:id/usersservices
/services/services/:idusers
/users/users/:idTested together
All 43 toolsPagerDuty API mock FAQ
How do I test an on-call agent without real alerts?
Seed the services, escalation policies and incidents in a test, point the agent at Ancha’s PagerDuty endpoint and check each incident’s final status. Nobody gets paged: the incidents exist only in the world.
Can I check how fast my agent acknowledged a page?
Yes. An incident check accepts acknowledged_within and resolved_within, measured on the world’s simulated clock from the incident’s creation.
Can people respond during the test?
Yes. In a living world, scripted people acknowledge or resolve incidents at a set time or when something happens, so you can test an agent that hands off or waits.
Can I use @pagerduty/pdjs?
Yes. It is tested with @pagerduty/pdjs 2.2.4. Pass the full local URL on every call, and send a From header with PAGERDUTY_FROM_EMAIL on writes.
Is this connected to my PagerDuty account?
No. Ancha simulates the PagerDuty API, and your agent talks to it through the PAGERDUTY_API_URL and token that ancha sets.
How is this different from a PagerDuty developer account?
A developer account is a real PagerDuty account: it keeps the incidents earlier runs left in it, and your agent needs a real API key. The mock starts from your test’s data on every run, and your agent connects with the variables ancha sets.
Run the example on your machine.
Ancha is not affiliated with PagerDuty.