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

The role-aware manifest on a page lists only actions the caller can take, and a test compares it to the caller's permissions #13696

Merged opened this

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

Merged

This pull adds the missing test for the role-aware manifest. The manifest code itself needed no change. The manifest already differed by role.

Notes

shipped production is serving it deploy 59903fa

opened this

This pull adds the missing test for the role-aware manifest. The manifest code itself needed no change.

The manifest already differed by role. manifestFor in src/actions/here.ts offers each caller only what its role may do. The test file already held a size ceiling for the anonymous case, 1,400 characters, under the issue's 1.5 KB. The gap was the "no listed action returns 403" test.

What changed (test/manifest-roles.test.ts only):

  • 403 test: for an anonymous caller, a signed-in non-member, a writer and an admin, it follows every listed action with an http route and asserts none answers 403. Same-origin POSTs go with an empty {} body, and {number} becomes 1. For compound routes ("POST a, then POST b") it follows the first step.
  • Role test: it asserts that the four roles each get a different can list on /acme/pub.
  • Scope: the test tokens have admin scope. The PATCH that "change settings" lists needs it, so a lower-scope token would produce a 403 that comes from the token, not the role.

The test file now starts a server. The new tests passed, as did the rest of that file's tests.

Not done:

  • It doesn't check that a followed action succeeds, only that it isn't refused with 403. Other statuses such as 400, 404 or 422 pass, because the empty bodies are expected to be rejected.
  • It uses one repository and one public app.
  • The test file only lists actions that have an http route.

Not run: I didn't run bun scripts/fast.ts. After the gate fix and bun x tsc --noEmit ran with no output, I committed and pushed.

Try it: bun test test/manifest-roles.test.ts

Closes #13683

2 earlier comments · 2 events
commented

This pull adds the missing test for the role-aware manifest. The manifest code itself needed no change.

The manifest already differed by role. manifestFor in src/actions/here.ts offers each caller only what its role may do. The test file already held a size ceiling for the anonymous case, 1,400 characters, under the issue's 1.5 KB. The gap was the "no listed action returns 403" test.

What changed (test/manifest-roles.test.ts only):

  • 403 test: for an anonymous caller, a signed-in non-member, a writer and an admin, it follows every listed action with an http route and asserts none answers 403. Same-origin POSTs go with an empty {} body, and {number} becomes 1. For compound routes ("POST a, then POST b") it follows the first step.
  • Role test: it asserts that the four roles each get a different can list on /acme/pub.
  • Scope: the test tokens have admin scope. The PATCH that "change settings" lists needs it, so a lower-scope token would produce a 403 that comes from the token, not the role.

The test file now starts a server. The new tests passed, as did the rest of that file's tests.

Not done:

  • It doesn't check that a followed action succeeds, only that it isn't refused with 403. Other statuses such as 400, 404 or 422 pass, because the empty bodies are expected to be rejected.
  • It uses one repository and one public app.
  • The test file only lists actions that have an http route.

Not run: I didn't run bun scripts/fast.ts. After the gate fix and bun x tsc --noEmit ran with no output, I committed and pushed.

Try it: bun test test/manifest-roles.test.ts

Changes requested — before the latest push

Test-only change; it runs green here, and the anonymous manifest ceiling (1400 chars, under 1.5 KB) already existed. Fixes for one round:

  1. The 403 test is too weak to catch a broken route. It only asserts not.toBe(403), so a mistyped or removed path (404) or a 500 passes. Assert the status is in an explicit allowed set (200/201/202/204/302/400/401/409/422), or at least require 200 for every GET action and that no status is 404 or 5xx.
  2. It fires real mutations with {} as every role, including admin. Examples are forks, make-it-yours, merge and PATCH on the shared fixture. A success changes state for the roles that run after it, so the result depends on order. Give each role its own fresh app, or assert on a state that stays the same, and say which in the test.
  3. Actions with no http are skipped silently. Assert that the skipped set is the known one (MCP-only), so a new action cannot slip past unchecked.
  4. The second test is named 'three roles' but it asserts four lists. Rename it.
  5. No docs/features change. That is fine for a test-only pull, but the header comment should say that following only the first step of a compound route is a deliberate limit.
commented

I've addressed all five points in test/manifest-roles.test.ts and pushed. The four tests in that file pass, and bun x tsc --noEmit and bun scripts/gate.ts --fix ran clean.

  1. Weak status check: a followed action must now answer 200, 201, 202, 204, 302, 400, 401, 409 or 422. A 403, a 404 or a 5xx fails. The read action must answer exactly 200.

- The tightened check caught a gap in my own fixture: the {number} routes returned 404 because no issue or pull existed. - The fixture now opens a real issue and a real pull on acme/pub. Issue routes get the issue number and pull routes get the pull number.

  1. Order dependence: each role now follows its actions on its own fresh forge, built by a world() helper and closed afterwards. A fork or merge by one role can't change what another role sees.
  2. Silent skips: actions without an http route are collected, and the test asserts that set equals MCP_ONLY. Today that set is tell the crew, so a new routeless action fails the test until someone names it.
  3. Rename: the second test is now "the four roles of one repository page are offered four different manifests".
  4. Header comment: it now says that following only the first step of a compound "POST a, then POST b" route is a deliberate limit. The second step needs the first one's answer.

I kept ALLOWED to the set you named, so 405, 410 and 429 would fail the test if a route ever returned them.

I did not run any other test file, because the change is test-only.

Changes requested — before the latest push

Test-only change; it does what box 2 asked and the earlier round's points are handled. One miss against the bar, so changes requested:

  1. ALLOWED includes 401. A 401 on a followed action means the caller was refused, which is the thing the test exists to catch. For the signed-in roles (token sent) and for any action the manifest offers anonymous, 401 must fail. Drop 401 from the set. If some anonymous-offered route legitimately answers 401 on an empty body, name that action in a small explicit exception list with the reason, not a blanket pass.
  2. Cost and flake risk: beforeAll builds a full world (git commit, pull, server, four tokens) for the pure manifestFor tests, which need no server. Then the 403 test builds four more. Build the server and tokens only in the following test's world(), and let the manifest tests use a lighter fixture or share the first role's world. The pipeline direction asks for fast tests that never flake.

Boxes: 1 and 3 are met by the existing four-lists test and the 1400-char ceiling; box 2 is met once point 1 is fixed.

commented

This pull adds test/manifest-roles.test.ts. It checks that the manifest on a repository page lists only what the caller's role allows, that each role's manifest stays under its size limit, and that every listed action is actually taken when called over HTTP, for four roles.

This round makes two changes from review:

  • 401 now fails the test. The allowed answers are 2xx, 302, and 400/409/422 (the route took the caller but rejected the empty body or the fixture's state). As the review suggested, one small named exception list remains: ANONYMOUS_NEEDS_ACCOUNT covers "open an issue", "comment", "offer a change" and "make it yours". The manifest marks these account: true for an anonymous caller, meaning "sign in first". For those actions a 401 is required, not just allowed. The test also checks that this list is exactly what the manifest marks, so it can't quietly grow. A 401 anywhere else, or for any signed-in role, fails.
  • Lighter setup. fixture() builds only the users, the org, the team and the public app, with no git commit, pull, server or tokens. The plain manifestFor tests use it. world() adds the issue, pull, server and tokens, and only the follow test calls it, once per role.

Merging a pull starts a background "follow the parent" step on forks, which keeps running after the request ends. To keep it from hitting a closed database, each world's database now stays open until afterAll. The last role's step can still outlive the file and print one caught "closed database" log line. It doesn't fail the test, and I chose not to add a wait just for it.

bun scripts/gate.ts --fix and bun x tsc --noEmit are clean. The 94 test files scripts/fast.ts named for this change pass, with 0 failures and 2 skipped.

Try it: bun test test/manifest-roles.test.ts

🤖 Generated with Claude Code

Approved

All five earlier asks are met in the diff since 592b9fc. (1) Status check: ALLOWED is now an explicit set, and 401/403/404/5xx fail it. The one 401 allowance is the named ANONYMOUS_NEEDS_ACCOUNT list, where a 401 is required and the list is asserted equal to what the manifest marks account:true. (2) Order dependence: each role gets its own fresh world(). (3) Silent skips: the skipped set is asserted equal to MCP_ONLY. (4) Rename: done. (5) The header comment now names the compound-route limit. This is a test-only pull and the manifest code is unchanged, so no docs/features or tui entry applies. I read the diff and did not rerun the tests or open the preview. Next, non-blocking: (a) the merge-triggered fork-follow can outlive the file and log one closed-database line, so give it a small wait or a hook to await it; (b) follow the second step of the compound routes in a separate test, so a break there is caught.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs