What the agent does
The agent starts from what the project already measures. In a React app laid out like alan2207/bulletproof-react, apps/react-vite/vite.config.ts carries a test block with globals, a jsdom environment, setupFiles: './src/testing/setup-tests.ts', an exclude that keeps **/e2e/** out of Vitest, and a coverage block that names only include: ['src/**']: no provider, no reporter, no thresholds. package.json pins vitest at ^2.1.4 and has a test script of plain vitest, with no @vitest/coverage-v8 or @vitest/coverage-istanbul among the devDependencies, so vitest --coverage would stop and ask for one. .github/workflows/react-vite-ci.yml runs yarn test in its all-cli-checks job after yarn build, and .gitignore already lists /coverage.
It then installs @vitest/coverage-v8 on the same major line as vitest, so the two agree on the Vitest version they were built for, and adds a test:coverage script that runs vitest run --coverage. In vite.config.ts the coverage block gains provider: 'v8', reporters of text, lcov and json-summary, and an exclude for what is not product code: the eleven *.stories.tsx files, src/testing/** (the MSW handlers, the mock database and test-utils.tsx), src/main.tsx and **/*.d.ts. Without that exclusion the mock server would count as uncovered application code and the numbers would describe the wrong thing.
The thresholds come from a measurement, not a guess. The agent runs the coverage report once over the twelve existing test files, which cover the dialog, drawer, form and notification components, the login and register forms, the authorization helper, and the discussions route, and sets thresholds.lines, functions, branches and statements just under the figures that run prints, rounded down to whole percentages. That makes the pull request green on the day it lands and turns any later drop into a failure, which is the point. It leaves thresholds.autoUpdate off and explains in the description how to raise the numbers as tests are added.
In CI, yarn test in the all-cli-checks job becomes yarn test:coverage, and an actions/upload-artifact@v4 step keeps the coverage/ directory with if: always(), the same way the e2e job already keeps playwright-report/. The agent runs yarn lint and yarn check-types too, since lint-staged runs both on every commit and the config file is TypeScript, and it quotes the coverage table from its own run in the pull request.
Start it with one API call
POST https://api.phoenix.so/o/{org}/sessions with this body:
{
"agent": "claude",
"input": "Add coverage thresholds to the Vitest suite in apps/react-vite. Read package.json, vite.config.ts, src/testing/setup-tests.ts, .gitignore and .github/workflows/react-vite-ci.yml first. Install @vitest/coverage-v8 on the same major version as vitest, add a test:coverage script that runs vitest run --coverage, and in vite.config.ts set coverage.provider to v8, reporters text, lcov and json-summary, and exclude stories, src/testing, src/main.tsx and d.ts files from the report. Run the report once and set lines, functions, branches and statements thresholds just under the measured numbers, rounded down to whole percentages. In the CI workflow run yarn test:coverage instead of yarn test and upload the coverage directory as an artifact with if: always(). Run yarn lint and yarn check-types, and open a pull request that quotes the coverage table.",
"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 touching four files: package.json and the lockfile for the provider and the script, vite.config.ts for the coverage block, and .github/workflows/react-vite-ci.yml for the step and the artifact. The description quotes the text reporter's table, names the four thresholds and the measured figure each sits under, and lists what was excluded and why.
The run's record keeps the full vitest run --coverage output, so a reviewer can see the per-file lines rather than a summary of them, and check that the exclusions removed the mocks and not a component.
Before merging, a reviewer decides whether the thresholds should sit at the measured level or at a target the team means to reach, and whether src/app/routes/** should be excluded as well, since route files are mostly composition. Either is a one-line change to the config.
Run it on every repository with a Vitest suite and no coverage floor
A team with several Vite apps starts one run per repository with one POST /o/{org}/sessions each, this prompt as input and the repository in resources. Each run measures its own suite and sets thresholds from its own numbers, so an app with thin tests gets a low floor it can clear and one with good tests keeps the bar where it is.
Send a request_id that is a UUID v5 of the repository's full name, so a retried call returns the run it already started. The key's webhook_url reports when each run the key starts finishes, with session_url to read the pull request from and the run's final answer in result.
The use case this job follows, with its automation and trigger: Hand off a long task.
Why run it on Rush?
A coverage floor set from memory is either too high, and blocks the first pull request after it, or too low, and catches nothing. The number has to come from running the suite, and the exclusions have to come from reading what is in src/. The agent does both in its own sandbox, with the same yarn install the workflow runs, and keeps the output.
The pull request carries the config, the workflow change and the measured table, so the review is a diff plus one number per threshold rather than a local checkout and a coverage run of your own. Several apps can be done at once, one sandbox each, each with its own pull request and its own figures.
Frequently asked questions
Why V8 rather than Istanbul?
V8 coverage comes from the engine and needs no instrumentation of the source, so it runs faster and does not change the code under test. Istanbul is more precise on branches in some TypeScript output. The provider is one string in the config, so switching later is cheap.
Will the thresholds block the next pull request?
Only one that lowers coverage. They are set just under what the suite measures today, so the pull request that adds them passes, and a change that deletes tests or adds untested code without tests fails the all-cli-checks job with the threshold that was missed.
What about the Playwright tests?
They stay out. The config's exclude already keeps e2e/ away from Vitest, and the e2e job runs them separately, so the coverage figure describes the unit and integration tests only.
Can the thresholds rise on their own?
Vitest has thresholds.autoUpdate, which rewrites the config whenever coverage goes up. The agent leaves it off, because a config file that changes during a test run surprises reviewers; raising the numbers is a deliberate edit in the pull request that adds the tests.