All jobs

Add Missing Tests to Every Pull Request in a Rails App

An agent added 12 RSpec examples for the labels option in chatwoot pull request #16491; its spec passes; the full suite's failures predate them.

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

What the agent does

Pull request #16491 lets ConversationBuilder in app/builders/conversation_builder.rb accept labels when creating a conversation; its other six files are swagger, none a spec. The agent reads that diff, the builder's two controller callers and spec/controllers/api/v1/accounts/conversations_controller_spec.rb. The public inbox controller permits only custom_attributes, so only the account API passes labels.

With no Ruby or services, it builds Ruby 3.4.4, installs PostgreSQL 15 and Redis, and builds pgvector 0.8.0 from source, since apt had no package. The 12 examples sit under POST /conversations: labels saved and returned, none or [], labels with a message, four malformed shapes returning 422 with nothing created, and four on an inbox locked to one conversation, where labels merge without duplicates.

Start it with one API call

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

{
  "agent": "claude",
  "input": "This pull request changes the conversations API. Read its diff, the existing Rails request specs and test environment. Find new or changed behavior without coverage and add focused RSpec examples beside the existing specs, using the real request and database paths. Do not change application code or replace the behavior under test with stubs. Prepare disposable PostgreSQL and Redis services as required. Run the affected spec file and bundle exec rspec, reporting focused and full-suite results separately. Push passing test additions to the authorized pull request branch and comment with what each test covers. Report implementation defects and blocked checks honestly.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}

The trial ran this request with its push and comment steps turned off: the tests stayed on a local branch and the comment was reported back, not posted.

  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

Tried on chatwoot/chatwoot at 7bd12a4f3f: the head of pull request #16491, from a fork against develop; 1 file changed, 122 insertions(+) in the conversations spec. That file went from 99 examples, 0 failures to 111 examples, 0 failures, and RuboCop found no offenses. The full bundle exec rspec exited 1 both times: 11235 examples, 137 failures, 140 pending before, 11247 examples, 136 failures, 140 pending after, none in the conversations spec. The one difference, evaluator_spec.rb:554, failed only before; the run calls it flaky.

For the reviewer: two inline # rubocop:disable RSpec/NestedGroups comments, or flatter contexts. From the code alone, the run notes the PR accepts any label string and creates a new tag. The first turn ended mid-suite; a follow-up asked it to finish. Nothing was pushed or posted.

Run it on every pull request opened against develop

An automation with a github trigger on pull_request.opened and pull_request.synchronize and branch_patterns develop saves this request without its opening sentence, and with its push and comment steps replaced by the recipe's: do not push commits, and post one review listing each test, its result and the tests as a patch. The event carries no SHAs, so the saved prompt must take the head and base from the URL. Only an owner, member or collaborator fires it, never a fork's pull request such as #16491, so this trial started by hand.

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

Why run it on Rush?

The full suite exits 1 with or without the new tests, so the run compared both failure lists: the only change was one monitor spec; four of the 12 examples pin the locked-inbox merge, which the PR shipped untested.

Frequently asked questions

Did the agent change application code?

No. The diff is one spec file; its only stub is the Rails.configuration.dispatcher stub neighbouring examples already use.

What did it leave untested?

The swagger changes and the public inbox endpoint, which never passes labels. It found no defect in the ConversationBuilder change.

More Ruby on Rails jobs

The same job on other stacks

Keep reading