A GitHub API mock for testing agents.
Your agent reads the pull request’s check runs and decides whether to merge. The recorded test checks that failed CI leaves the pull request open and that the agent comments on it.
Revert the database pool cut #12
revert-pool-cutintomain
- lintpassed
- testfailed
release-bot commented
Not merging yet: test failed.
An agent merged a pull request with a failed check
Ben opened #12 to revert yesterday’s cut of the database pool. Lint passed and the test check failed. The agent was told to merge once CI is green, took one passing check as green, and merged.
The test checks two things after the run: the pull request is still open, and the agent commented on it.
| Check | Original agent | Fixed agent |
|---|---|---|
| Left the pull request open | 0 of 3 | 3 of 3 |
| Commented on the pull request | 0 of 3 | 3 of 3 |
Scripted agent, no model. Recorded with CLI 0.4.74.
The one-line fix
- const green = runs.some(run => run.conclusion === 'success');+ const green = runs.every(run => run.conclusion === 'success');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 runs.some( to runs.every( in agent.mjs
ancha run scene.yaml --local -n 3 --compare beforeConnect your agent to the GitHub mock
When ancha runs your agent, it sets:
GITHUB_API_URLGITHUB_TOKENGITHUB_WEBHOOK_SECRET
Point the client you already use at them.
import { Octokit } from '@octokit/rest';
const github = new Octokit({
auth: process.env.GITHUB_TOKEN,
baseUrl: process.env.GITHUB_API_URL,
});Locally, ancha runs your agent as an ordinary process, so keep real GitHub credentials out of its environment.
See all 86 endpoints
actions
/repos/:owner/:repo/actions/runs/repos/:owner/:repo/actions/runs/:id/repos/:owner/:repo/actions/runs/:id/rerun/repos/:owner/:repo/actions/workflows/:workflow/runsbranches
/repos/:owner/:repo/branches/repos/:owner/:repo/branches/:branchcheck-runs
/repos/:owner/:repo/check-runs/:idcollaborators
/repos/:owner/:repo/collaborators/repos/:owner/:repo/collaborators/:username/repos/:owner/:repo/collaborators/:username/repos/:owner/:repo/collaborators/:username/repos/:owner/:repo/collaborators/:username/permissioncommits
/repos/:owner/:repo/commits/repos/:owner/:repo/commits/:ref/repos/:owner/:repo/commits/:ref/check-runs/repos/:owner/:repo/commits/:ref/status/repos/:owner/:repo/commits/:ref/statusescompare
/repos/:owner/:repo/compare/:base...:headcontents
/repos/:owner/:repo/contents/:path/repos/:owner/:repo/contents/:path?deployments
/repos/:owner/:repo/deployments/repos/:owner/:repo/deployments/repos/:owner/:repo/deployments/:id/repos/:owner/:repo/deployments/:id/statuses/repos/:owner/:repo/deployments/:id/statuses/repos/:owner/:repo/deployments/:id/statuses/:statusIdgit
/repos/:owner/:repo/git/blobs/repos/:owner/:repo/git/blobs/:sha/repos/:owner/:repo/git/commits/repos/:owner/:repo/git/commits/:sha/repos/:owner/:repo/git/matching-refs/:ref?/repos/:owner/:repo/git/ref/:ref/repos/:owner/:repo/git/refs/repos/:owner/:repo/git/refs/:ref/repos/:owner/:repo/git/refs/:ref/repos/:owner/:repo/git/trees/repos/:owner/:repo/git/trees/:shagraphql
/graphqlissues
/repos/:owner/:repo/issues/repos/:owner/:repo/issues/repos/:owner/:repo/issues/:number/repos/:owner/:repo/issues/:number/repos/:owner/:repo/issues/:number/comments/repos/:owner/:repo/issues/:number/comments/repos/:owner/:repo/issues/:number/labels/repos/:owner/:repo/issues/:number/labels/repos/:owner/:repo/issues/:number/labels/repos/:owner/:repo/issues/:number/labels/repos/:owner/:repo/issues/:number/labels/:name/repos/:owner/:repo/issues/comments/repos/:owner/:repo/issues/comments/:id/repos/:owner/:repo/issues/comments/:id/repos/:owner/:repo/issues/comments/:idlabels
/repos/:owner/:repo/labels/repos/:owner/:repo/labels/repos/:owner/:repo/labels/:name/repos/:owner/:repo/labels/:name/repos/:owner/:repo/labels/:nameorgs
/orgs/:org/members/orgs/:org/members/:username/orgs/:org/members/:username/orgs/:org/memberships/:username/orgs/:org/memberships/:username/orgs/:org/repospulls
/repos/:owner/:repo/pulls/repos/:owner/:repo/pulls/repos/:owner/:repo/pulls/:number/repos/:owner/:repo/pulls/:number/repos/:owner/:repo/pulls/:number/comments/repos/:owner/:repo/pulls/:number/comments/repos/:owner/:repo/pulls/:number/commits/repos/:owner/:repo/pulls/:number/files/repos/:owner/:repo/pulls/:number/merge/repos/:owner/:repo/pulls/:number/merge/repos/:owner/:repo/pulls/:number/reviews/repos/:owner/:repo/pulls/:number/reviews/repos/:owner/:repo/pulls/:number/reviews/:id/repos/:owner/:repo/pulls/comments/repos/:owner/:repo/pulls/comments/:id/repos/:owner/:repo/pulls/comments/:id/repos/:owner/:repo/pulls/comments/:idrepos
/repos/:owner/:reposearch
/search/issuesstatuses
/repos/:owner/:repo/statuses/:refuser
/user/user/reposTested together
All 43 toolsGitHub API mock FAQ
What is a GitHub API mock server?
A GitHub API mock server answers the GitHub REST API on your machine. Ancha’s mock keeps state between calls: a merge moves the base branch, a comment shows up in later reads, and check runs come from the test’s starting data. A test can then check what your agent changed.
Can I test a GitHub bot without a real repository?
Yes. Seed the repository in a test: commits with file contents, branches, pull requests, issues and check runs. The downloadable example needs no GitHub account, token or model.
How is this different from mock-github or recorded fixtures?
mock-github stubs Octokit calls inside a test, and recorded fixtures replay the responses you captured. Ancha runs the API itself, with state: if your agent merges, the base branch moves and later reads see it. The test file also holds the checks, so the same checks run across trials and agent versions.
Can my agent merge pull requests in the mock?
Yes. A merge writes a merge commit and moves the base branch.
Will my agent change a real repository?
No, as long as it uses the GITHUB_API_URL and GITHUB_TOKEN that ancha sets: every change stays in the simulated GitHub.
How is this different from a GitHub test account?
A test account or organization is a real one on GitHub: it keeps what earlier runs left in it, and your agent needs a real token. 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 GitHub.