What the agent does
The agent reads how the app is wired before writing a test against it, because the database connection decides whether tests can run at all. In sequelize/express-example, express-main-example/package.json depends on express ^4.17.1, sequelize ^6.3.3, sqlite3 ^5.0.0 and body-parser, has start and setup-example-db scripts and no test script, declares node >=10, and its .npmrc sets package-lock=false, so there is no lockfile. There are no tests and no CI. index.js calls sequelize.authenticate() and listens on 8080; express/app.js exports the app without listening, which is what makes it testable, and builds the REST routes from a map of users, instruments and orchestras controllers: GET /api/<name>, GET, PUT and DELETE /api/<name>/:id and POST /api/<name>, each wrapped in makeHandlerAwareOfAsyncErrors.
sequelize/index.js hard-codes dialect: 'sqlite' with storage: 'sqlite-example-database/example-db.sqlite', and sqlite-example-database/setup.js runs sync({ force: true }) and seeds four users, three orchestras and ten instruments each. Tests cannot share that file. The agent makes the smallest change that keeps the default: the storage path becomes process.env.DB_STORAGE || 'sqlite-example-database/example-db.sqlite', and the test setup sets DB_STORAGE=':memory:' before requiring the app, calls sequelize.sync({ force: true }) in beforeAll and seeds a known set of rows with the models rather than the random helper in setup.js, so every assertion has fixed data.
The agent adds jest and supertest as dev dependencies and a test script, and writes one file per route module under test/. users.test.js covers GET /api/users returning the seeded list, GET /api/users/:id for a seeded id and 404 for a missing one, POST returning 201 and persisting the row, POST with an id in the body returning 400 as routes/users.js requires, PUT with a mismatched body id returning 400 and a matching one returning 200 with the change visible on a follow-up GET, and DELETE returning 200 and the row gone. orchestras.test.js adds the ?includeInstruments query and asserts the nested instruments array from the hasMany association in sequelize/extra-setup.js. Each test reads the database afterwards through the models, not only the HTTP response.
Two tests document behaviour rather than approve it. GET /api/users/abc makes getIdParam in express/helpers.js throw a TypeError, which the async wrapper passes to next, and with no error handler registered Express answers 500 with an HTML page; the test asserts that 500 and carries a comment, and the pull request lists it as a finding. Likewise a POST /api/users with username: 'ab' fails the model's /^\w{3,}$/ validation and also surfaces as 500 rather than 400. The agent runs npm install and npm test in the sandbox, with jest --runInBand since the tests share one in-memory database, and leaves example-db.sqlite untouched.
Start it with one API call
POST https://api.phoenix.so/o/{org}/sessions with this body:
{
"agent": "claude",
"input": "Write integration tests for this Sequelize and Express application. Read package.json, .npmrc, index.js, express/app.js, express/helpers.js, express/routes/users.js, express/routes/orchestras.js, express/routes/instruments.js, sequelize/index.js, sequelize/extra-setup.js, the three model files and sqlite-example-database/setup.js first. Make the SQLite storage path in sequelize/index.js read DB_STORAGE from the environment with the current path as the default, and nothing else in the app. Add jest and supertest as dev dependencies and a test script. Write a test setup that sets DB_STORAGE to :memory:, syncs with force and seeds fixed rows through the models. Cover every route in express/app.js for users, orchestras and instruments: list, get by id, 404, create, create with an id in the body, update with matching and mismatched ids, delete, and the includeInstruments query on orchestras, checking the database through the models after each write. Where an invalid id or a failed validation currently produces a 500, assert the current status with a comment and report it as a finding rather than changing the app. Run npm test with --runInBand and 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 test/setup.js, test/users.test.js, test/orchestras.test.js and test/instruments.test.js, changes package.json for the dev dependencies and test script, and makes the one-line storage change in sequelize/index.js. The description lists each route and the cases covered, and separately lists the two findings: a non-numeric :id and a failed model validation both answer 500 today because no error handler is registered.
The run's record keeps the npm install and npm test output, so a reviewer sees every test pass against the in-memory database and that the committed example database was not written to.
Before merging, a reviewer decides whether to add an Express error handler that maps TypeError from getIdParam and SequelizeValidationError to 400, at which point the two documenting tests flip to assert the new status, and whether engines.node should move up, since Jest's own requirement is newer than the >=10 the file declares.
Run it on every pull request
Once the suite exists, an automation on the Project with a github trigger on pull_request.opened and pull_request.synchronize and the prompt "run npm test; if a route in express/app.js has no test in test/, write one in the same style and push it to this branch" keeps new routes covered as they arrive. The trigger puts the pull request after the prompt; only work by an owner, member or collaborator fires it, never a fork's.
A team with several Express services on Sequelize starts the first pass once per repository from its own server: a POST /o/{org}/sessions each, with the repository in resources and a request_id that is a UUID v5 of the repository's full name, so a retried call returns the run already started rather than opening a second pull request.
The use case this job follows, with its automation and trigger: Write the missing tests.
Why run it on Rush?
Tests for an existing API are only worth having if they run against the real routing and the real ORM, and that means a database the tests own. The agent finds the hard-coded storage path, makes the smallest change that frees it, and runs the whole suite in its own sandbox, so the pull request arrives with tests that pass rather than tests that would pass once something else is fixed.
Every command's output stays with the run, including the two 500 responses the tests document, so a reviewer sees the evidence for each finding. Several services can get a first suite at once, each on its own machine with its own record.
Frequently asked questions
Will the tests touch my example database?
No. The storage path now reads DB_STORAGE, the tests set it to :memory:, and the default stays the committed path, so npm start and npm run setup-example-db behave exactly as before. The agent checks the file's modification time after the suite to confirm.
Why jest and not the built-in node:test runner?
The project declares node >=10, and node:test arrived much later. Jest also needs a newer Node than 10, so either choice moves the floor; the pull request says so and leaves the engines field to the maintainer. The tests themselves use only describe, test and expect, so switching runners later is mechanical.
Why do some tests assert a 500?
Because that is what the app does today for a non-numeric id or a failed validation: the error reaches Express with no handler registered. Asserting the real status with a comment records the behaviour and makes the pull request that adds an error handler a visible, tested change rather than a silent one.
Do the tests run in parallel?
No. They share one in-memory SQLite connection, so the agent runs Jest with --runInBand and re-syncs the schema before each file. Splitting into one connection per file is possible once the connection is created per test module instead of at require time.
More Sequelize jobs
The same job on other stacks
- Write Integration Tests for a Socket.IO Chat Server (Socket.IO)
- Write Integration Tests for an ASP.NET Core API (ASP.NET Core)
- Write Integration Tests for a Knex and Express API (Knex.js)