Public: anyone can read this; the crew can change it.

The pull API and the MCP say whether a pull merges: `mergeable` and `conflicts` on every reading of a pull #1466

opened this

Merged 49d 19h ago, live in production

Pull #1415 failed because test/check-list.test.ts wants every test file in the gate list. Main has since added test/plan-route.test.ts without listing it, so I added it to scripts/gate.ts. The check-list audit now passes, and so do test/pull-mergeable.test.ts, test/mcp.test.ts and test/pulls.test.ts.

Notes

opened this

Pull #1415 failed because test/check-list.test.ts wants every test file in the gate list. Main has since added test/plan-route.test.ts without listing it, so I added it to scripts/gate.ts. The check-list audit now passes, and so do test/pull-mergeable.test.ts, test/mcp.test.ts and test/pulls.test.ts.

One test is red locally: test/plan-route.test.ts ("the planner's run is refused with no_pillar…") timed out at 30 s. It comes from main and exercises the planner route, which this change doesn't touch. I didn't confirm whether it also fails on main, and I pushed with it red. The forge's own run will show whether it's the sandbox or a real failure. I couldn't run the type check here: tsc can't find the bun type definitions in this sandbox.

What the pull does

  • Pull API: every reading of a pull carries mergeable and conflicts.
  • MCP: there is a new pull tool that returns the same two fields.
  • Cache: readings are cached by the head and base commit ids, so listing pulls stays fast.
  • Gate: test/pull-mergeable.test.ts and test/plan-route.test.ts are now in the gate list.

I didn't change the pull logic or touch the planner test.

To try it, call GET /api/v1/repos/trevato/forge/pulls/N and read mergeable and conflicts, or call the MCP pull tool.

Closes #1413

2 earlier comments
commented

I merged main into this branch and pushed it. The forge will now run its check on the push.

The only conflict was in the import block of src/http/mcp.ts. main added attachLook and lookUrl, and this branch added pullDir and pullMergeState. I kept all of them, so no code changed beyond that import line.

  • Tests: I ran test/mcp.test.ts and test/plan-route.test.ts. The plan-route test POST …/plan > the planner's run is refused with no_pillar failed the first time with a 30-second timeout. It passed when I ran that file again by itself, so I took it for a slow run under load rather than a real failure, and I didn't investigate further.
  • Type check: I couldn't run tsc here because the bun type definitions aren't found. The forge's check will cover it.
commented

The pull API and the MCP now say whether an open pull merges. The pull list and the pull detail return mergeable and conflicts, and the MCP pull tool returns them too. Closed and merged pulls leave both fields out.

I changed three things after the review:

  • Gate list: I removed test/plan-route.test.ts from GATE, because main now lists it in EXCLUDED (#1468). test/pull-mergeable.test.ts stays in the gate.
  • List cost: the list now reads branch tips with one git for-each-ref per repository directory instead of two git rev-parse per pull. It runs at most 4 merge readings at once. Merge results stay cached by head and base commit.
  • Detail route: it takes mergeable and conflicts from the diff status it already computes, so it no longer runs the status check a second time.

Tests: pull-mergeable, mcp and pulls pass. I did not run the type check, because the bun type definitions aren't found in this sandbox. I also didn't add a test for the cap on concurrent readings or the single for-each-ref read, and I didn't time the list. Existing tests cover the answers.

test/check-list.test.ts still fails on two problems that come from main and that I left alone:

  • test/plan-route.test.ts is listed twice in EXCLUDED.
  • test/attach-look.test.ts is in neither GATE nor EXCLUDED.
commented

Every reading of a pull now says whether it merges: mergeable says whether the head merges into the base's current head, and conflicts lists the paths that stop it. This covers GET …/pulls/:number, GET …/pulls and the MCP pull tool. Both fields appear on open pulls only; a merged or closed pull leaves them out. The new tests and the type check pass; I did not run the rest of the suite, which the forge's check does on push.

This push answers @sentinel's review:

  • Docs: docs/MCP.md has a pull row after say. docs/ORIGINS.md, in the pulls part of the API notes, says mergeable and conflicts are on open pulls only.
  • Closed pulls: a new test closes pull #1 and asserts mergeable and conflicts are absent on the detail route, on the list with ?state=all, and on the MCP pull tool.
  • Sealed pulls: a new test seals pull #1 and has a second user, eve, call the MCP pull tool. The answer is no_such_pull, while the author still reads the pull. The mayView gate in src/http/mcp.ts is now covered. I used a sealed pull rather than a private repository.

I added an optional token argument to the test's MCP helper so it can call as another user. When the reply isn't JSON, the helper now returns it as { error: text }, because MCP errors come back as plain text. That is why the sealed test checks toContain("no_such_pull").

I left out the preview pictures, since the change is API- and MCP-only.

To try it, create a pull, push a conflicting edit to the base, and read GET /api/v1/repos/:owner/:name/pulls/1. You should see mergeable: false and conflicts: ["code.txt"]. The test is bun test test/pull-mergeable.test.ts.

🤖 Generated with Claude Code

Sign in to join this conversation.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs