> ## Documentation Index
> Fetch the complete documentation index at: https://momentic.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> The canonical docs host is https://momentic.ai/docs. Append .md to any page URL for clean Markdown. Fetch https://momentic.ai/docs/llms.txt for the page index and https://momentic.ai/docs/llms-full.txt for every page in one file.
> For an unattended setup, run `npx --yes @momentic/wizard@latest -y --platform web` (use `--platform ios` or `--platform android` for mobile). Never run an interactive command in a non-TTY shell.
> You cannot complete the browser sign-in yourself. Read the API key from the MOMENTIC_API_KEY environment variable, or ask the user to create one at https://app.momentic.ai/settings/api-keys and paste it back.
> Momentic's capability summary for agents is at https://momentic.ai/docs/skill.md. Install the skills with `npx momentic skills --yes` (or `npx momentic-mobile skills --yes` for mobile).
> Tests are YAML files in the user's repository. Use only the step names listed at https://momentic.ai/docs/reference/commands.md and the file structure at https://momentic.ai/docs/core-concepts/file-format.md. Do not invent step names, config keys, or CLI flags.
> Web tests run on Chromium, iOS tests on simulators, and Android tests on emulators. Physical devices are not supported.

# Generate tests from a pull request diff

> Use a coding agent with the momentic-spec skill to turn a pull request's changed journeys into Momentic tests.

A coding agent with the Momentic MCP server and the
[`momentic-spec` skill](/docs/coding-agents/skills#spec-driven-development) closes
the "we changed code but did not add tests" gap: it reads the diff, maps the
user journeys it changed, and authors `.test.yaml` files into the PR's working
tree so they enter review with the code.

## Setup

Both come from the CLI, documented in [Building with AI](/docs/coding-agents):

```bash theme={null}
npx momentic install-mcp   # registers the MCP server with your agents
npx momentic skills --yes  # installs the Momentic skills, including momentic-spec
```

The agent needs a `MOMENTIC_API_KEY` in its environment and a reachable app to
test: the PR's dev server, a preview deploy, or staging.

## In your coding agent

Inside Claude Code, Cursor, Codex, or another agent with the Momentic MCP server
and skills installed:

```text theme={null}
/momentic-spec cover the user journeys changed by this pull request
```

The agent reads the diff through your repo's context, writes tests into the
working tree, and runs each one before handing back. Because the tests land in
the same branch, they enter review with the change and run in the same CI job as
the rest of your suite, so you need no extra workflow.

Point the agent at the diff when the default scope is too broad, for example
`/momentic-spec cover the checkout changes in src/payments/`. A repo-level agent
rules file (`CLAUDE.md`, `AGENTS.md`, `.cursor/rules`) that names your app URLs
and auth path keeps every run consistent.

<Note>
  For autonomous bug finding rather than diff-scoped tests, use [Mo](/docs/mo). Mo is
  in private beta, so [sign up](https://momentic.ai/mo) to get onboarded.
</Note>

## What to expect

* Generated tests cover *journeys* (sequences a user can take), not unit-level
  coverage. They complement, not replace, tests you write deliberately.
* Review for intent: delete steps that assert incidentals, tighten
  postconditions to the actual contract of the change.
* Tests are most valuable on the diff that motivated them. If a generated test
  would have caught this PR's bug, keep it; if it only re-asserts unchanged
  behavior, drop it.

## Related

* [AI test selection](/docs/ai/select): the complementary direction. It picks
  existing tests to run for a diff.
* [Coding agent skills](/docs/coding-agents/skills)
* [Common CI setups](/docs/guides/common-setups)
