All jobs

Add Missing Tests to Every Pull Request in a Django App

An agent reads each pull request to a Django project, writes TestCase tests for the behavior it leaves untested, runs them, and posts them as a patch.

Run this on RushOpens the console with this prompt ready to send, in a Project that has your repository.

What the agent does

The agent starts from the pull request's diff, not a coverage report. In django/djangoproject.com a blog change lands in blog/models.py, blog/views.py or blog/feeds.py; for each changed function it searches the tests for one that reaches the new branch and lists, with file and line, the behavior nothing exercises.

New tests go where each app keeps them: the matching class in blog/tests.py (EntryTestCase, EventTestCase, ViewsTestCase, with DateTimeMixin and time_machine for dates), or the module in docs/tests/ such as test_views.py. Tests that need a default docs release reuse ReleaseMixin from djangoproject/tests.py. The database is set up as .github/workflows/tests.yml does it: Python 3.12, requirements/tests.txt, Postgres 17, tracdb/trac.sql and a conf/secrets.json.

Start it with one API call

POST https://api.phoenix.so/o/{org}/sessions with this body:

{
  "agent": "claude",
  "input": "Check out this pull request and diff it against its base branch. List the new or changed behavior in docs/ and blog/ that no existing test covers, with file and line. Set up the project the way .github/workflows/tests.yml does: Python 3.12, requirements/tests.txt, a Postgres database with tracdb/trac.sql loaded, and conf/secrets.json. Write Django TestCase tests for each item next to the existing ones: blog/tests.py for the blog app, the matching module in docs/tests/ for the docs app. Reuse ReleaseMixin, DateTimeMixin and time_machine where they fit. Change no application code and leave the Playwright tests alone. Run python -m manage test blog docs --verbosity 2. Do not push commits or open a pull request. Post one review on the pull request listing each untested behavior with file and line, the tests you wrote, the test run's result, any test that fails against the branch's code with its failing assertion, and the tests as a patch. 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

One review lands on the pull request: each untested behavior with its file and line, the test method written for it, the manage test result against a real Postgres, and a patch that touches blog/tests.py or docs/tests/ only. Nothing reaches the branch.

The reviewer decides whether the author applies the patch, and, for a test the review marks as failing, whether the manager or view is wrong or the test expected the wrong thing.

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 pull request to djangoproject.com's default branch and each later push. Only an owner, member or collaborator fires it, and a fork's pull request never does. A contributor's pull request from a fork needs the same request started by hand with its URL. The event carries no SHAs, so the agent checks out the head from the pull request URL.

The use case this job follows, with its automation and trigger: Review every pull request.

Why run it on Rush?

A Django test run that cannot reach its database proves nothing, and this project needs two of them plus a Trac dump before manage test starts. The sandbox builds that the way the CI workflow does, so a new test in blog/tests.py runs against Postgres 17 with frozen time, not against SQLite on someone's laptop.

Frequently asked questions

Why does the review carry a patch rather than a commit?

The review recipe never pushes. The author applies the patch from the review, or copies one test method from it, and the branch keeps only what they chose.

Does it run the Playwright tests too?

No. They need the browsers tests.yml installs with python -m playwright install and passes to make ci with --browser, and the request asks for model and view tests. The agent runs manage test for the blog and docs apps only.

More Django jobs

The same job on other stacks

Keep reading