What the agent does
The agent starts from what the repository runs and what it only half runs. In an Angular app shaped like realworld-apps/angular-realworld-example-app, package.json pins @angular/core 21.2.12, runs unit tests with vitest through @analogjs/vite-plugin-angular, and defines test, test:ui and test:coverage as vitest, vitest --ui and vitest --coverage, with Playwright scripts for e2e. vitest.config.ts uses jsdom, a src/test-setup.ts that initialises the Angular TestBed, includes src/**/*.spec.ts, and already declares coverage: { provider: 'v8', reporter: ['text', 'json', 'html'] }. There are six spec files under src/app, for the articles, comments, tags, profile, user and JWT services. But @vitest/coverage-v8 is not in devDependencies, so bun run test:coverage cannot produce a report, and none of the four workflows in .github/workflows runs the unit tests at all: lint.yml checks Prettier, playwright.yml and security-tests.yml run the e2e suites, and deploy.yml builds and releases on push to main.
The agent installs @vitest/coverage-v8 at the major that matches the installed vitest, since the package pins its peer to the exact vitest version, and confirms bun run test:coverage prints the text table locally with coverage/ written beside it. It adds coverage/ to .gitignore next to /dist and /out-tsc. It does not change vitest.config.ts beyond adding reportsDirectory explicitly and an include of src/app/**/*.ts with the spec and setup files excluded, so the table shows the services and components that could be tested rather than only the files the six specs import.
The workflow is new, .github/workflows/unit-tests.yml, written in the shape of playwright.yml: on: push and pull_request for main and master, actions/checkout@v4 with submodules: true because bun run setup expects the realworld submodule, oven-sh/setup-bun@v2, bun install, then bun run test:coverage with CI set so vitest runs once and exits rather than watching. The coverage/ directory is uploaded with actions/upload-artifact@v4 under if: always() with the same retention the Playwright report uses, and the text summary from the run is appended to the job summary so a reviewer sees the table without downloading anything.
A threshold is a decision for the maintainers, so the agent adds coverage.thresholds to vitest.config.ts set at the numbers the first run actually produced, rounded down, and says in the pull request that these are a floor to raise rather than a target. Before pushing it runs bun run format:check, because lint.yml fails on an unformatted YAML or TypeScript file, and bun run test to confirm the six specs still pass under the new config.
Start it with one API call
POST https://api.phoenix.so/o/{org}/sessions with this body:
{
"agent": "claude",
"input": "Add unit test coverage reporting to CI for this Angular app and open a pull request. Read package.json, vitest.config.ts, src/test-setup.ts, tsconfig.spec.json, .gitignore, CLAUDE.md and every file in .github/workflows first, and list the spec files under src. Install @vitest/coverage-v8 at the major matching the installed vitest so its exact peer requirement is met, and confirm bun run test:coverage prints a coverage table. Add coverage/ to .gitignore. In vitest.config.ts set reportsDirectory, add a coverage include of src/app/**/*.ts excluding spec and setup files, and add thresholds equal to the rounded-down numbers from your first run. Create .github/workflows/unit-tests.yml in the style of playwright.yml: push and pull_request on main and master, checkout with submodules, setup-bun, bun install, bun run test:coverage with CI set, upload the coverage directory as an artifact with if: always() and the same retention as the Playwright report, and append the text summary to the job summary. Run bun run format:check and bun run test, paste the coverage table and the test output in the pull request description, and state that the thresholds are a floor to raise. Do not change any spec or application file.",
"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 with @vitest/coverage-v8 in package.json and bun.lock, a coverage block in vitest.config.ts with reportsDirectory, include and thresholds, one line in .gitignore, and .github/workflows/unit-tests.yml. The description shows the coverage table from bun run test:coverage in the sandbox, the six spec files passing, and the format:check output.
The new workflow runs on the pull request itself, so the first coverage artifact and job summary appear on the pull request's checks beside the Prettier, Playwright and security jobs. The agent pushes one commit for the dependency and config and one for the workflow.
A reviewer checks that the thresholds match the table rather than a guessed number, that the include pattern does not count src/test-setup.ts or the specs themselves, that the workflow checks out the submodule the way the others do, and that no application file changed. Then they raise the thresholds as specs are added.
Run it on every new Angular repository
A team with several Angular front ends starts one run per repository with POST /o/{org}/sessions, this prompt and the repository in resources. The agent reads each repository's own test runner and package manager, so one still on Karma gets a ng test --code-coverage job and one on npm gets npm ci rather than bun install, and each run opens its own pull request.
The key's webhook_url receives run.completed for each run with a session_url, so a script can post the pull request links and the first coverage numbers to the team channel as they land.
The use case this job follows, with its automation and trigger: Write the missing tests.
Why run it on Rush?
The workflow is thirty lines, but the useful part is the first honest number: which services the six specs reach and which they do not. On a laptop that table is glanced at and lost. In a Rush sandbox the agent installs the exact coverage package the runner accepts, produces the table with real commands, and the output is kept in the transcript, so the pull request records where coverage starts and the thresholds are derived from it rather than invented.
The change follows the repository's own workflows, Bun setup, submodule checkout, artifact upload with the same retention, and passes format:check before a reviewer opens it. The same request works unchanged across every Angular repository the team owns.
Frequently asked questions
Why is @vitest/coverage-v8 missing when the config names the v8 provider?
The config declares the provider, but the provider is a separate package that must be installed at the exact vitest version it pins as a peer. Without it vitest --coverage fails at startup. The agent installs the matching major and names the resolved version in the pull request.
Will the unit tests run in watch mode on CI?
No. The test:coverage script is vitest --coverage, and vitest runs once and exits when CI is set in the environment, which the workflow does the way playwright.yml does for the e2e suite.
Where do the threshold numbers come from?
From the first bun run test:coverage run in the sandbox, rounded down, pasted in the pull request beside the table. They fail the job only if coverage drops below where it is today; raising them is a one-line change in vitest.config.ts.
Does this touch the Playwright workflows?
No. playwright.yml and security-tests.yml keep running the e2e suites as before. The new job is separate so a unit coverage dip and an e2e failure are reported as different checks.