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

opened this

Merged 20d 20h ago, live in production

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

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
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

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.
  2. 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.
  3. 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.
  4. Rename: the second test is now "the four roles of one repository page are offered four different manifests".
  5. 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.

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

Sign in to join this conversation.

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

Keyboard shortcuts

Docs