What the agent does
In an Express API laid out like hagopj13/node-express-boilerplate, package.json locks jest@^26.0.1 (26.6.3 in yarn.lock), the test script is jest -i --colors --verbose --detectOpenHandles, and jest.config.js sets testEnvironment: 'node', restoreMocks: true and a coveragePathIgnorePatterns list that leaves out src/config, src/app.js and tests. The suite is tests/unit (error.test.js, user.model.test.js, paginate.plugin.test.js, toJSON.plugin.test.js) and tests/integration (auth.test.js, user.test.js, docs.test.js), and every file that touches a model calls tests/utils/setupTestDB.js, which connects Mongoose to config.mongoose.url with -test appended. .travis.yml runs yarn lint and yarn test on Node 12 with a mongodb service, and engines allows any Node from 12 up. Coverage says which lines ran; nothing says whether the assertions would notice a wrong line.
The agent adds @stryker-mutator/core and @stryker-mutator/jest-runner as dev dependencies (the current release's package names Node 22 or later in engines, which the repository's own engines range admits) and writes stryker.config.json with testRunner: "jest", jest.configFile: "jest.config.js", and a mutate list of the files with logic worth mutating: src/utils/pick.js, src/validations/custom.validation.js, src/middlewares/validate.js, src/middlewares/error.js, src/models/plugins/*.js and src/services/token.service.js. It leaves out src/config, src/app.js, src/index.js, src/docs and the route files, the same shape as the coverage ignore list, because a mutant in wiring code only proves the server boots. Reporters are clear-text, progress and html, with reports/ and .stryker-tmp/ added to .gitignore, and thresholds.break is set to the score the first run reaches, so the score can only go up from here. A mutation script is added to package.json.
The integration tests need MongoDB, so in its sandbox the agent installs Docker (sudo apt-get install -y docker.io, then starts dockerd), starts a mongo container, and sets MONGODB_URL, JWT_SECRET and the other variables from .env.example. It runs yarn test once to confirm the suite is green, then yarn stryker run. Then it reads the survivors. On code like this the ones to expect sit at boundaries the tests never pin down: the < 8 in the password validator, parseInt(options.limit, 10) > 0 in paginate.plugin.js, where a limit of 0 must fall back to ten, the hasOwnProperty check in pick.js that keeps inherited keys out, and the nested path deletion in toJSON.plugin.js. For each survivor it can kill in a test of its own, it writes one: tests/unit/utils/pick.test.js and tests/unit/validations/custom.validation.test.js, which do not exist today, and new cases in the plugin tests.
A mutant that no test can distinguish from the original (an equivalent mutant) is marked with a // Stryker disable next-line comment naming the mutator, not hidden by lowering the threshold. The agent runs Stryker a second time to quote the new score, then yarn lint, since the Airbnb config and eslint-plugin-jest apply to the new test files. .travis.yml is left alone: it runs on Node 12, which cannot run the current Stryker, so the pull request says a mutation job needs a Node 22 runner and leaves adding one to the reviewer.
Start it with one API call
POST https://api.phoenix.so/o/{org}/sessions with this body:
{
"agent": "claude",
"input": "Add mutation testing with Stryker to this Express and Jest project. Read package.json, jest.config.js, .travis.yml, .env.example, tests/utils/setupTestDB.js and every file under tests/ and src/utils, src/validations, src/middlewares, src/models/plugins and src/services first. Install @stryker-mutator/core and @stryker-mutator/jest-runner, write stryker.config.json with the jest runner and a mutate list limited to the modules with logic (utils, validations, middlewares, model plugins, token.service), ignore reports/ and .stryker-tmp/, and add a mutation script. Start MongoDB in the sandbox with the variables from .env.example, run yarn test, then run Stryker and quote the score and every survivor with its file, line and mutator. Write tests that kill the survivors you can, mark equivalent mutants with a Stryker disable comment, run Stryker again and quote the new score, and set thresholds.break to it. Run yarn lint. Do not change .travis.yml; say what CI needs. Open a pull request.",
"resources": [
{
"url": "https://github.com/your-org/your-app"
}
]
}- Get an API key. In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
- Send the request. POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
- Read what came back. Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.
What comes back
What comes back is a pull request that adds stryker.config.json, two lines to .gitignore, the two dev dependencies in package.json and yarn.lock, a mutation script, and new or extended test files under tests/unit. No file under src/ changes except for a disable comment on an equivalent mutant. The description quotes the clear-text report from the first run, lists each survivor as file, line and mutator, says which got a test and which were marked equivalent and why, and quotes the score from the second run and the yarn lint result.
The run's record keeps both Stryker runs in full, the MongoDB container start and the test runs, so a reviewer can read the exact mutant a new test kills rather than trust the summary.
Before merging, a reviewer checks the equivalent-mutant comments, since each one is a judgment that a line cannot be tested, and decides where the mutation score runs in CI: a Node 22 job that starts MongoDB the way .travis.yml does, on a schedule or on pull requests that touch the mutated directories.
Run it on every nightly
Mutation runs are slow, so they belong on a schedule rather than on every push. An automation in the Project with a schedule trigger (a cron of 0 2 * * * and a timezone) runs this page's prompt each night with a smaller ask: run Stryker, write tests for the survivors it can kill, and open a pull request only when the score moved. A night with no survivors to kill ends with no pull request and a short answer saying so.
The thresholds.break in stryker.config.json is raised in the same pull request whenever a night's tests push the score up, so the floor follows the suite rather than waiting for someone to remember it. Each night's run is its own session with its own record, listed under the automation in the console.
The use case this job follows, with its automation and trigger: Write the missing tests.
Why run it on Rush?
Mutation testing is the kind of job that is easy to set up and expensive to act on: the first run on a suite like this produces a list of survivors, and the value is in reading each one and writing the assertion it exposes. In a Rush sandbox the agent starts the MongoDB the integration tests need, runs Stryker for as long as it takes, and reads every survivor with the source beside it.
Both Stryker runs stay in the run's record, and the pull request carries the before and after score with each new test tied to the mutant it kills, so review is checking that each assertion is right rather than re-running a long job to find out what it found. A team with several Jest services runs this on each at once, one sandbox and one pull request each.
Frequently asked questions
Will this slow down yarn test?
No. Stryker runs through its own mutation script and its own config; yarn test and jest.config.js are unchanged. The only changes to the existing suite are new test files and new cases, which make it longer by the tests they add and nothing more.
What happens to the integration tests that need MongoDB?
Stryker runs the same Jest suite, so they run against the MongoDB the sandbox starts, the same way .travis.yml gives them a mongodb service. A CI job for mutation needs that service too, which is one of the things the pull request says the reviewer has to add.
What is an equivalent mutant and why is it marked rather than fixed?
A change to the code that no input can tell apart from the original, such as swapping an operator on a branch whose both sides do the same thing. No test can kill it, so lowering the threshold to absorb it would hide real survivors; a Stryker disable comment naming the mutator records the judgment in the code, where a reviewer can disagree with it.
Does Stryker work with Jest 26?
The agent finds out by running it rather than assuming: the current Stryker release needs Node 22, which this repository's engines allows, and the Jest runner is pointed at the existing jest.config.js. If the installed pair refuses to drive this Jest, the pull request says so, with the error quoted, and pins the newest Stryker that does.