# Add Missing Tests to Every Pull Request in a SvelteKit App

On each pull request an agent writes Vitest tests for the SvelteKit loads, endpoints and matchers it changes, runs them and posts them as a patch.

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

## What the agent does

In a pnpm workspace like sveltejs/svelte.dev, the app is `apps/svelte.dev`, whose `test` script is `node scripts/get_svelte_template.js && vitest run`. Its tests are plain `*.test.ts` files beside the code, like `src/lib/playground-download.test.ts`, importing `describe`, `test` and `expect` from `vitest`, so new tests take that shape.

Server code is tested by calling it. The docs page's `load` in `src/routes/docs/[topic]/[...path=documentation]/+page.server.js` gets a hand-built event with `params` and a `URL`, and a test asserts the `error(404)` it throws for an unknown page. The `match()` matcher in `src/params/documentation.js`, which refuses paths ending in `llms.txt` or `llms-small.txt`, gets a `test.each` table. The app has no component test setup, so a component change is named in the review, not tested.

## Start it with one API call

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

```json
{
  "agent": "claude",
  "input": "This pull request changes routes or helpers in apps/svelte.dev. Read its diff against the base branch, taking the head and base commits from the pull request itself, and list the new or changed behavior no test covers, with file and line. Write Vitest tests for it as *.test.ts files next to the changed modules, in the style of src/lib/playground-download.test.ts. Test load functions and +server handlers by calling them with a constructed event, and cover their error branches; test param matchers with test.each. Run them with pnpm --filter svelte.dev test until they pass, and format the new files with pnpx prettier --write as AGENTS.md asks. Add no component test framework; name a changed component's logic in the review as untested. Do not change application code, do not commit or push, and do not open a pull request. Post one review on the pull request that lists each untested behavior with file and line, the test that covers it, the Vitest result, and the new tests as one patch. A test that fails because the change is wrong goes in the review as a possible bug. 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/123"
    }
  ]
}
```

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

What comes back is one review on the pull request and no commit. It lists each uncovered `load`, `+server` handler or helper by file and line, the `*.test.ts` case written for it, and Vitest's summary line from `pnpm --filter svelte.dev test`. The patch is in the review.

Left to the reviewer: whether to apply the patch, and whether a failing case means the route is wrong or the test built the wrong event.

## 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` (the repository's default branch), runs once per new pull request and once per push to one. Only an owner, member or collaborator fires it, and a fork's pull request never does, which on a project with many outside contributors means those need a run started by hand. The event names the pull request's URL, title, author and base branch but carries no SHAs, so the agent reads the head and base from the URL.

## Why run it on Rush?

The app's `test` script first runs `get_svelte_template.js`, which builds the playground's download templates with `sv`, and the existing `playground-download.test.ts` reads those files, so a bare `vitest run` fails on a clean clone. The CI test job in this repository is commented out, so the sandbox's run of the full script on each pull request is the only test result the review can quote.

## Frequently asked questions

### Will it add @testing-library/svelte or Playwright?

No. Adding a test framework is a dependency change the author should decide on, so the review names a component change it could not test without one and leaves it there.

### Why are the tests a patch rather than a commit?

The per-pull-request review never pushes. Applying the patch from the review puts the `*.test.ts` files on the branch, already formatted with prettier.

## More SvelteKit jobs

- [Upgrade SvelteKit Dependencies Every Week](https://getrush.ai/run/upgrade-dependencies-weekly/sveltekit/)
- [Write Playwright Tests for a SvelteKit App](https://getrush.ai/run/write-playwright-tests/sveltekit/)
- [Write Vitest Tests for a SvelteKit App](https://getrush.ai/run/write-vitest-tests/sveltekit/)

## The same job on other stacks

- [Add Missing Tests to Every Pull Request in a Symfony App](https://getrush.ai/run/test-every-pull-request/symfony/)
- [Add Missing Tests to Every Pull Request in an Angular App](https://getrush.ai/run/test-every-pull-request/angular/)
- [Add Missing Tests to Every Pull Request in an ASP.NET Core App](https://getrush.ai/run/test-every-pull-request/aspnet-core/)

## 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/)
