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

A sealed pull's diff and files answer whoever may see it, and 404 to everyone else #15015

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

A sealed pull's diff and files now answer whoever may see the pull and 404 to everyone else. I ran test/sealed-git.test.ts, test/body-caps.test.ts, test/contract.test.ts and test/contract-openapi-tags.test.ts, which pass, and bun x tsc --noEmit, which is clean. I did not run the full suite.

Notes

shipped production is serving it deploy cfe12e4

opened this

A sealed pull's diff and files now answer whoever may see the pull and 404 to everyone else. I ran test/sealed-git.test.ts, test/body-caps.test.ts, test/contract.test.ts and test/contract-openapi-tags.test.ts, which pass, and bun x tsc --noEmit, which is clean. I did not run the full suite. scripts/fast.ts named a list too broad to run here, so the forge's check will cover the rest. The release hold on the desk ("production is rolling, hold changes") did not touch this change, which goes to a pull preview.

What changed

  • API routes: GET /api/v1/repos/:owner/:name/pulls/:number/diff answers text/plain with git's unified diff of the pull against its merge base. …/files answers JSON [{path, status, additions, deletions, binary}].
  • Web route: /:owner/:name/pulls/:number.diff answers the same text. It is registered in src/http/server.ts ahead of /:owner/:name/pulls/:number, because that route's :number would otherwise take 2.diff whole and 404.
  • Access: all three use loadPull, which applies mayView, so a stranger, a signed-out caller or a missing pull gets the same 404. A sealed pull is read from its sealed fork through pullDir.
  • Where the code lives: the handlers are in src/http/api/app_pulls.ts (header updated) rather than a new module, to stay under the gate's limit of two feature files. src/git/diff.ts gained diffRangeText, the raw-text twin of diffRange. Two openapi route files were added and exported from routes/index.ts.
  • Test: test/sealed-git.test.ts seals a pull from a builder's sealed fork. The reviewer gets 200 text/plain containing the hunk, the file list, and the same hunk from the web route with a session cookie. A stranger and a signed-out caller get 404 on all three routes.

What to look at

  • I raised the pulls-slice size bound in test/contract-openapi-tags.test.ts from 40,000 to 43,000 bytes. Each new route adds about 680 bytes to the slice, and it was already close to the old bound. The alternative is trimming other pull routes' docs, which I left alone.
  • I did not add a terminal screen or a docs/features/ page. The commit says No door: because the pull page and terminal already show this diff.
  • Bearer tokens work on the API routes. The web .diff route follows the web convention of a session cookie only.

Try it

  • Call GET /api/v1/repos/<owner>/<name>/pulls/<n>/diff with a token, or open /<owner>/<name>/pulls/<n>.diff in a browser.
  • bun test test/sealed-git.test.ts.

🤖 Generated with Claude Code

Closes #15008

4 earlier comments · 1 event
commented

A sealed pull's diff and files now answer whoever may see the pull and 404 to everyone else. I ran test/sealed-git.test.ts, test/body-caps.test.ts, test/contract.test.ts and test/contract-openapi-tags.test.ts, which pass, and bun x tsc --noEmit, which is clean. I did not run the full suite. scripts/fast.ts named a list too broad to run here, so the forge's check will cover the rest. The release hold on the desk ("production is rolling, hold changes") did not touch this change, which goes to a pull preview.

What changed

  • API routes: GET /api/v1/repos/:owner/:name/pulls/:number/diff answers text/plain with git's unified diff of the pull against its merge base. …/files answers JSON [{path, status, additions, deletions, binary}].
  • Web route: /:owner/:name/pulls/:number.diff answers the same text. It is registered in src/http/server.ts ahead of /:owner/:name/pulls/:number, because that route's :number would otherwise take 2.diff whole and 404.
  • Access: all three use loadPull, which applies mayView, so a stranger, a signed-out caller or a missing pull gets the same 404. A sealed pull is read from its sealed fork through pullDir.
  • Where the code lives: the handlers are in src/http/api/app_pulls.ts (header updated) rather than a new module, to stay under the gate's limit of two feature files. src/git/diff.ts gained diffRangeText, the raw-text twin of diffRange. Two openapi route files were added and exported from routes/index.ts.
  • Test: test/sealed-git.test.ts seals a pull from a builder's sealed fork. The reviewer gets 200 text/plain containing the hunk, the file list, and the same hunk from the web route with a session cookie. A stranger and a signed-out caller get 404 on all three routes.

What to look at

  • I raised the pulls-slice size bound in test/contract-openapi-tags.test.ts from 40,000 to 43,000 bytes. Each new route adds about 680 bytes to the slice, and it was already close to the old bound. The alternative is trimming other pull routes' docs, which I left alone.
  • I did not add a terminal screen or a docs/features/ page. The commit says No door: because the pull page and terminal already show this diff.
  • Bearer tokens work on the API routes. The web .diff route follows the web convention of a session cookie only.

Try it

  • Call GET /api/v1/repos/<owner>/<name>/pulls/<n>/diff with a token, or open /<owner>/<name>/pulls/<n>.diff in a browser.
  • bun test test/sealed-git.test.ts.

🤖 Generated with Claude Code

commented

The three failing tests are fixed and pushed. The three test files now pass locally, along with test/sealed-git.test.ts and the asset-miss tests, and tsc is clean. The rest of the suite is left to the forge's check.

  • Route index: src/contract/openapi/routes/index.ts was stale, so I regenerated it with bun scripts/openapi-routes.ts. The diff and files entries now sit where the generator puts them.
  • JSON 404 to a browser: /:owner/:name/pulls/:number.diff answered a browser a JSON 404. A path ending in .diff now counts as a file in src/http/asset_miss.ts, so a miss there is plain text, as for .txt or .md. Only a request that matched no route reaches that rule. A real pull the caller may not see still gets the JSON notFound() from loadPull. docs-not-found passes only because its check skips file-like paths.
  • Unfixtured routes: the pulls-budget fixture has no pull for the web .diff route or the API diff and files routes. I raised MAX_UNFIXTURED from 151 to 154 in test/pages-budget.test.ts and noted why next to it.

bun scripts/gate.ts --fix left one comment over 100 columns in src/http/api/app_pulls.ts, and it reports that the nightly rewrap handles it on main.

Changes requested — before the latest push

Changes needed (one round, all listed):

  1. Both doors (fix first): the pull adds a read surface (diff text, file list) with no terminal screen in src/tui/ and no docs/features/<name>.md how-to. "No door: the pull page already shows it" does not meet the rule. Add the TUI entry where AGENTS.md says, gated exactly as the web route (guest sees nothing private, sealed pulls 404), and the feature doc.
  2. Unbounded output: diffRangeText decodes the whole git diff into memory with a 60s timeout and no byte cap, and filesJson then parses it all. One huge pull is a memory/CPU DoS on an anonymous-reachable route. Cap the bytes read (truncate or 413/422 with a clear message) and add a test for the cap.
  3. patchOf does not handle failures of pullDir/pullStatus (sealed fork missing or unreadable): they must map to a clean API error or the same 404, never a thrown 500 or a path leak. Add a test.
  4. Tests miss: a public, non-sealed pull answering 200 to a signed-out caller (the positive half of the title), and the files route with binary/renamed entries.
  5. Direction: the repo is PIPELINE FIRST; this is a feature outside the listed pipeline items. State which issue/priority justifies it. Also the pull raises three budgets (MAX_UNFIXTURED 151->154, openapi slice 40k->43k) instead of adding a pull fixture / trimming docs; add a fixture for the pull routes rather than raising the unfixtured cap, which the file says to lower, not raise.
  6. Clean: a comment in app_pulls.ts is still over 100 columns (rewrap it); the diffText import in server.ts is out of order among the web imports; the web .diff route is cookie-only while the API takes bearer, so say so in docs.

Security otherwise looks right: access goes through loadPull/mayView, 404 is identical for stranger/anonymous/missing, securityFloor and private no-cache with Vary are set.

commented

A pull's diff and file list now answer whoever may see the pull, read from the sealed fork when the pull is sealed, and 404 to everyone else. The review comments are addressed except the openapi size budget, which still rises 40k → 43k (see the disagreement below). The new and touched tests pass locally, and tsc and the gate are clean. I did not run the whole suite; the forge's check does that.

Routes

  • GET /api/v1/repos/<owner>/<name>/pulls/<n>/diff returns text/plain, and …/files returns JSON with path, status, additions, deletions and binary.
  • The web /<owner>/<name>/pulls/<n>.diff answers the same text.
  • A stranger, a signed-out caller or a missing pull gets the same 404. The responses are private, no-cache with Vary.
  • The web route takes a session cookie only; the API also takes a bearer token. docs/features/pull-diff.md says so.

Review items

  1. Both doors. D on a pull opens a new terminal screen, src/tui/screens/pull_patch.ts, showing the file list and then the text. It checks mayView itself and shows "No such pull." otherwise. The how-to is docs/features/pull-diff.md, and the features index builds from its front matter.
  2. Unbounded output. The new readPatch in src/core/pull_patch.ts caps the diff at 2 MiB. Over that, the API answers 413 diff_too_large and the screen says so. The routes and the terminal share this one read.
  3. Failures. readPatch catches errors from pullDir, pullStatus and git. They become 503 diff_unavailable, with no path in the body. A test removes the repository directory and checks all three routes.
  4. Tests. test/pull-patch.test.ts covers:
    • a signed-out caller getting 200 on a public pull, on both the API and the web route;
    • the files route with an added binary, a delete-plus-add that git reports as a rename (R100) and a normal added file;
    • the 413 cap, and the 503 for an unreadable pull.

    test/tui-pull-patch.test.ts covers the terminal screen, including a sealed pull shown to a stranger.

  5. Budgets. The pages-budget fixture now has a real topic branch under its pull and entries for the three routes. MAX_UNFIXTURED is back at 151.
  6. Clean.
    • The comment in app_pulls.ts is rewrapped.
    • The diffText import in server.ts now sits with the other ./api/ import instead of among the web imports.
    • The docs state that the web .diff route is cookie-only.

Earlier fix. .diff is now treated as a file path in asset_miss.ts, so a miss on a route that doesn't exist answers plain text, not JSON. A route that exists but refuses still answers JSON.

Where I disagree: the openapi pulls slice limit still rises from 40k to 43k. Each operation in the slice is about 1.2–1.9 kB of generated structure, and the two new routes are minimal. They bring the slice to 41.3 kB. There is no prose to trim without gutting other routes.

Direction: this is part 1 of #14917, which is about a crew reviewer being unable to read a sealed pull's code. I can't say which PIPELINE FIRST item justifies it; it goes to a person.

To try it: run a pull's /diff and /files with a token, open /<owner>/<name>/pulls/<n>.diff signed in, or press D on a pull in the terminal.

commented

This pull now covers only the API half of #15008: GET …/pulls/:number/diff and …/files, plus the web .diff route. The terminal screen and the how-to are cut from it, so a sealed pull's change is still unreadable in the terminal until a follow-up lands.

The check failed the "small and single-purpose" rule: five added feature files, where a pull that goes ahead of the pipeline may add at most two. bun scripts/gate.ts is clean on the new commit, tsc --noEmit is clean, and the four test files covering the change pass: pull-patch, sealed-git, contract-openapi-tags and pages-budget. I have not run the forge's full check on this push.

  • Folded in: the read (readPatch, one cap and the refusals) moved from src/core/pull_patch.ts into src/http/api/app_pulls.ts, and the new file is gone.
  • Left for the follow-up: the D terminal screen (src/tui/screens/pull_patch.ts, its test, and the pull.ts hook) and docs/features/pull-diff.md. The follow-up needs a pull of its own, with the terminal screen and the how-to together.
  • Still added: the two generated route files, which is the two the rule allows.
  • Behaviour: unchanged for the API and the web route.
  • Gate warning: it also flagged test/tui-pull-patch.test.ts#open as near-identical to test/tui-pull-review.test.ts#open. Removing that test clears it for now, so the follow-up will have to share the helper instead of copying it.

To try it, curl -H "authorization: Bearer $TOKEN" $URL/api/v1/repos/<owner>/<name>/pulls/<n>/diff (or /files) against the preview.

🤖 Generated with Claude Code

commented

This pull adds GET …/pulls/:number/diff and …/files for a pull, including a sealed one, plus the web /:owner/:name/pulls/:number.diff route. Two of the three failures I found in the check are not caused by this change, so the check may still show red.

I merged main into the branch and reran the failing tests locally. The one that was mine passes now. The diff_unavailable 503 was missing a retry-after, so it now goes through tryAgain with 5 seconds. That fixes the "every 429 and 503 site" test (test/retry-after.test.ts), which passes locally.

Two other failures come from main itself. I copied a clean origin/main into a scratch directory and reproduced both there:

  • openapi-drift and openapi-coverage: POST /api/v1/repos/{}/{}/deepsec, added by #15025, has no OpenAPI row. I did not add one, because the route is someone else's and another pull may already be adding it.
  • test/wallet.test.ts: the ledger page costs 42 statements against a limit of 41.

A third failure may be main's too, but I did not check that on main. test/pages-budget.test.ts shows the pull page at 116 SQL statements against a budget of 115. It happens without my fixture change, and this pull doesn't touch that page. I did not raise any of these budgets.

I did not rerun the other tests the check listed (the report and toolbar timing tests, the wider ledger and fork tests, and the needsYouCard test). Only toolbar-page-timing and fork-last-follow were rerun, and they passed.

The terminal D screen and docs/features/pull-diff.md are still left out, as in the earlier push, for the rule that a pull may add at most two feature files. They need a pull of their own.

To try it: curl -H "authorization: Bearer $TOKEN" $URL/api/v1/repos/<owner>/<name>/pulls/<n>/diff (or /files).

🤖 Generated with Claude Code

Approved

Re-review. I could not diff against b41d8f434430 (not in the clone), so I judged the current change. Security holds: all three routes go through loadPull/mayView, so a stranger, a signed-out caller and a missing pull get the same 404. A sealed pull is read from its fork via pullDir. The read is capped by bytes git actually writes (413 past 2 MiB), failures are a 503 with retry-after and no path, and responses are private/no-cache with Vary. The tests cover public, sealed, cap and unreadable cases. The earlier ask to fold the read into one module and drop the extra feature files is met. The earlier ask for the terminal door and docs/features page was cut deliberately, because of the two-feature-file rule. Non-blocking here, but the follow-up pull must carry the D screen in src/tui/ and docs/features/pull-diff.md together, sharing the test helper rather than copying it. Also non-blocking: the openapi slice bound rise 40k to 43k is justified by generated structure.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs