# Add Missing Tests to Every Pull Request in an Angular App

An agent reads each pull request to an Angular app, writes the Vitest specs it lacks, runs them, and posts them as a patch in one review.

[Run this on Rush](https://cloud.getrush.ai/run/test-every-pull-request/angular/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent checks out the pull request, reads `vitest.config.ts`, `src/test-setup.ts` and the existing specs, then diffs against the base branch. In realworld-apps/angular-realworld-example-app all six spec files cover services, so a change to `token.interceptor.ts`, `error.interceptor.ts`, the `requireAuth` guard in `app.routes.ts` or any component arrives with no spec to extend.

New specs follow `src/app/core/auth/services/user.service.spec.ts`: explicit imports from `vitest`, `HttpTestingController` for API calls, `vi.fn()` doubles for injected services and `firstValueFrom` for observables. A component spec uses `TestBed.createComponent` and asserts on the rendered DOM. The agent runs `bun run test` and `bun run format:check` on the result, and leaves the Playwright suite alone.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "Check out this pull request and diff it against its base branch. Read vitest.config.ts, src/test-setup.ts and the existing spec files under src/app first. List each new or changed behaviour in services, interceptors, guards, pipes, directives and components that no spec covers, with file and line. For each, write a Vitest spec in the style of src/app/core/auth/services/user.service.spec.ts: explicit imports from vitest, TestBed with HttpTestingController for anything that calls the API, vi.fn() doubles for injected services, firstValueFrom for observables; for a component, TestBed.createComponent, fixture.detectChanges() and assertions on the rendered DOM. Change no application code and do not touch the Playwright tests or the realworld submodule. Run bun install, bun run test and bun run format:check. Do not push commits or open a pull request. Post one review on the pull request listing each untested behaviour with file and line, the specs you wrote, the vitest and format:check results, any spec that fails against the branch's code with its failing assertion, and the specs as a patch. If nothing under src/app changed, say so in the review. If this run names no pull request, in resources or after this prompt, stop and say so.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app/pull/42"
    }
  ]
}
```

1. **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.
2. **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.
3. **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

One review lands on the pull request: each untested behaviour with its file and line, the spec written for it, the `vitest` summary and the `format:check` result from the sandbox, and a patch that touches `*.spec.ts` files only. Nothing is pushed to the branch.

Left to the reviewer: whether to apply the patch, and, for a spec marked failing, whether the interceptor or guard under change is wrong or the spec's expectation is.

## Run it on every pull request opened against main

An automation with this request as its prompt and a `github` trigger on `pull_request.opened` and `pull_request.synchronize`, `branch_patterns` `main`, reviews each new pull request and each push to one. Only an owner, member or collaborator fires it; a fork's pull request never does. The event text carries the pull request's URL, title, author, labels, base branch and body but no SHAs, so the agent checks out the head from the URL. No trigger filters on paths, so a pull request that only bumps `@angular/core` still fires, and the review says no behaviour under `src/app` changed.

## Why run it on Rush?

In this app the code most likely to change without a test is the code with no spec file at all: three interceptors, a guard, two pipes and every component. The agent writes the first spec for such a file in the service specs' shape and runs it under the same jsdom and `@analogjs/vite-plugin-angular` setup, so the review shows a spec that ran, not a note that one is missing.

## Frequently asked questions

### Why do the specs come back as a patch, not a commit?

The review recipe never pushes, so the branch holds only what its author wrote. The author applies the patch from the review with `git apply`, keeping only the specs they want.

### Will it write Playwright tests?

No. `playwright.config.ts` extends a base config from the shared `realworld` submodule, so end-to-end specs belong there. The agent adds Vitest specs under `src/app` only.

## More Angular jobs

- [Upgrade Angular to the Latest Version](https://getrush.ai/run/upgrade-angular/angular/)
- [Write Unit Tests for an Angular App](https://getrush.ai/run/write-angular-unit-tests/angular/)
- [Write Playwright Tests for an Angular App](https://getrush.ai/run/write-playwright-tests/angular/)

## The same job on other stacks

- [Add Missing Tests to Every Pull Request in an ASP.NET Core App](https://getrush.ai/run/test-every-pull-request/aspnet-core/)
- [Add Missing Tests to Every Pull Request in a Django App](https://getrush.ai/run/test-every-pull-request/django/)
- [Add Missing Tests to Every Pull Request in an Express API](https://getrush.ai/run/test-every-pull-request/express/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
