All jobs

Add Pagination to a Vapor API from a Linear Issue

An agent makes a Vapor GET /todos return a Fluent Page with page and per parameters and a stable sort, and tests a partial and empty page.

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 reads Package.swift, TodoController.swift, routes.swift, AppTests.swift, the template's manifest.yml and the CI workflow test-template.yml, then FluentKit's QueryBuilder+Paginate.swift. vapor/template is a Mustache template: Package.swift says name: "{{name}}", so swift test cannot build the repository as it stands, and CI renders it with vapor new first.

index in Sources/App/Controllers/TodoController.swift now returns Page<TodoDTO>: it sorts by title, then id, calls .paginate(for: req) and maps each item to TodoDTO. The existing list test decodes the page and checks page, per and total, and a new test covers page=2&per=2, the partial last page and a page past the end.

Start it with one API call

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

{
  "agent": "claude",
  "input": "A Linear issue labeled agent says: \"Add Pagination to a Vapor API. Make GET /todos return a page of results with Fluent's paginate, with page and per query parameters and the page metadata in the response.\" Do the work in this repository, add tests for it, run swift test, and open a pull request that links back to the issue.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
  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 vapor/template at cd62b46: 2 files changed, 42 insertions(+), 6 deletions(-) in TodoController.swift and Tests/AppTests/AppTests.swift. swift test fails in the repository itself, before and after, on the {{name}} placeholder. On a copy rendered for SQLite without Leaf by the agent's own script, with Swift 6.3.3, the baseline ended āœ” Test run with 4 tests in 1 suite passed after 0.083 seconds. and the change āœ” Test run with 5 tests in 1 suite passed after 0.106 seconds. There was no Linear issue to read.

For the reviewer: GET /todos changes from a bare array to {items, metadata}, which breaks existing clients. Fluent sets no pageSizeLimit, so ?per=1000000 is accepted until app.fluent.pagination.pageSizeLimit is set. The Postgres, MySQL, no-Fluent and Leaf variants CI builds were not run.

Run it on every Linear issue labeled agent

An automation with a linear trigger on linear.issue.labeled and the label agent runs the linear-label-to-pr recipe's prompt when someone in your Rush org labels an issue. Because the change alters a response shape, an issue that names the clients of the endpoint gives the agent what it needs to describe the break in the pull request.

The use case this job follows, with its automation and trigger: Turn a Linear label into a PR.

Why run it on Rush?

The repository could not run its own tests, and the run said so instead of skipping them: it installed the Swift version CI uses, rendered the template with its own script, standing in for vapor new, for SQLite without Leaf, and ran both the baseline and the change there. It also caught that Todo has no timestamp to sort by, so it added a title-then-id order rather than ship pages that overlap or skip items.

Frequently asked questions

What does the response look like now?

{"items": [...], "metadata": {"page": 1, "per": 10, "total": 2}}. With no parameters, Fluent's paginate(for:) defaults to page 1 and 10 per page.

What does a page past the end return?

Empty items with the real total. The new test asks for page=4&per=2 with five todos and expects no items, page 4 and total 5.

More Vapor jobs

More jobs like this: Turn a Linear label into a PR

Keep reading