
Illustrative test design

Test what the agent did to the world, not what it said: the rows it wrote, the messages it posted and how many times. Run the same scenario on every pull request, and fail the build when the final state changes.
Five steps
- Unit-test the tools. Test
save_recordandpost_slackfor validation, retries and idempotency. Use a real throwaway database (Postgres in a container, rolled back per test), because a mock can't catch bad SQL or a constraint violation. - Assert on final state. After the workflow runs, check how many rows exist and with which values, and how many Slack messages were posted and to which channel.
- Replay failures, not just success. A timeout after a write, a duplicate webhook, a 500 on the second call. These are where double writes and double messages come from.
- Keep each failure as a regression. A scenario that found a bug becomes a permanent test, so the bug can't return unnoticed.
- Run it in CI on every pull request.
With AgentTwin
npx agenttwin runs your real code against twins of the services it calls, including real Postgres and Redis inside the sandbox, then compares every service's final state with a clean run. npx agenttwin check install writes a GitHub workflow so each pull request gets a check showing what the branch does to Stripe, Slack and your database.
Related: Write better workflow assertions and How to reset a multi-service test environment between runs.