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

A new inline isAdmin check in a moved door fails the gate #18410

opened this

Merged 1h 3m ago, live in production

A new test, test/door-inline-checks.test.ts, now fails when a moved door gets a new inline access check. It reads the repository route modules under src/http/api/ and every MCP file (src/http/mcp.ts and all of src/http/mcp/, including tools/). The existing MCP gate rule only reads mcp.ts and shared.ts.

Notes

opened this

A new test, test/door-inline-checks.test.ts, now fails when a moved door gets a new inline access check. It reads the repository route modules under src/http/api/ and every MCP file (src/http/mcp.ts and all of src/http/mcp/, including tools/). The existing MCP gate rule only reads mcp.ts and shared.ts. The gate picks the test up like any other test/*.test.ts, so scripts/gate.ts is unchanged.

What it flags: only lines that gate access:

  • a refusal on isAdmin (!user.isAdmin, isAdmin !== true, or isAdmin in an if)
  • a scopeAllows(…, "rw") write floor
  • a signed-out test (!ctx.auth.user, or ctx.auth.user === undefined in a condition)

Each finding gives the file, line and helper to use instead: adminPage or mayBeside(…, "forge.administer", …) for an admin, mayBeside(…, "forge.write", …) (mayToolWrite in the MCP) for a write, signedInPage for an account.

What it leaves alone: a role passed on for display (familyView(app, user.isAdmin === true)), comment lines, and scopeAllows(…, "admin"). That last one is how far a token reaches, not a role, as the existing MCP rule already says.

The list: DOOR_LINES in src/design/door_checks.ts holds the 29 lines that stay today, each with a one-phrase reason. Entries are keyed by file and exact line text, so they survive line shifts. Each entry allows one line only, so a copy of a listed line elsewhere in the same file counts as new. An entry whose line is gone fails too, so the list only shrinks. The fixture tests check that a new check of each kind fails with the right helper named, that a copied line fails, and that a gone entry is named for deletion.

Also changed:

  • scripts/design-lint.ts prints the same findings in scanRatchets, so a builder sees them before pushing. This also gives the new exports a caller, which the dead-code test requires.
  • docs/ROLES.md has one new paragraph, "Inline checks in a moved door", that sets out the rule.

Reused: tsSources and Source from src/design/ratchets.ts, the DOOR_FIX wording pattern from RATCHET_FIX, and the signed-out regex from src/kernel/repo_route_checks.ts.

Not done:

  • The existing gate rules in src/kernel/repo_route_checks.ts and src/kernel/mcp_door_checks.ts are untouched; they still guard src/http/api.ts and src/http/mcp.ts + src/http/mcp/shared.ts on each commit.
  • The three signed-out lines in src/http/api/ (issues.ts, statement.ts, cdn.ts) are now listed both there and in DOOR_LINES.
  • Pages are not scanned yet; they follow once #18401 lands.
  • No inline check was removed.

Checks run: bun scripts/gate.ts, bun x tsc --noEmit, bun scripts/design-lint.ts, and these tests, all passing: door-inline-checks, unused-exports, dup-imports, module-state, mcp-size, check-list, design-lint-ratchets, mcp-tools-may, repo-routes-may, roles, contain, guest-contribute, and the docs tests. scripts/fast.ts named 4045 test files, too many to run here, so I picked these. The forge runs the full check on the push.

To try it: add if (!user.isAdmin) return bad("forbidden", "x"); to any file under src/http/mcp/tools/, then run bun test test/door-inline-checks.test.ts or bun scripts/design-lint.ts. Both name the file, the line and adminPage.

🤖 Generated with Claude Code

Closes #18406

commented

A new test, test/door-inline-checks.test.ts, now fails when a moved door gets a new inline access check. It reads the repository route modules under src/http/api/ and every MCP file (src/http/mcp.ts and all of src/http/mcp/, including tools/). The existing MCP gate rule only reads mcp.ts and shared.ts. The gate picks the test up like any other test/*.test.ts, so scripts/gate.ts is unchanged.

What it flags: only lines that gate access:

  • a refusal on isAdmin (!user.isAdmin, isAdmin !== true, or isAdmin in an if)
  • a scopeAllows(…, "rw") write floor
  • a signed-out test (!ctx.auth.user, or ctx.auth.user === undefined in a condition)

Each finding gives the file, line and helper to use instead: adminPage or mayBeside(…, "forge.administer", …) for an admin, mayBeside(…, "forge.write", …) (mayToolWrite in the MCP) for a write, signedInPage for an account.

What it leaves alone: a role passed on for display (familyView(app, user.isAdmin === true)), comment lines, and scopeAllows(…, "admin"). That last one is how far a token reaches, not a role, as the existing MCP rule already says.

The list: DOOR_LINES in src/design/door_checks.ts holds the 29 lines that stay today, each with a one-phrase reason. Entries are keyed by file and exact line text, so they survive line shifts. Each entry allows one line only, so a copy of a listed line elsewhere in the same file counts as new. An entry whose line is gone fails too, so the list only shrinks. The fixture tests check that a new check of each kind fails with the right helper named, that a copied line fails, and that a gone entry is named for deletion.

Also changed:

  • scripts/design-lint.ts prints the same findings in scanRatchets, so a builder sees them before pushing. This also gives the new exports a caller, which the dead-code test requires.
  • docs/ROLES.md has one new paragraph, "Inline checks in a moved door", that sets out the rule.

Reused: tsSources and Source from src/design/ratchets.ts, the DOOR_FIX wording pattern from RATCHET_FIX, and the signed-out regex from src/kernel/repo_route_checks.ts.

Not done:

  • The existing gate rules in src/kernel/repo_route_checks.ts and src/kernel/mcp_door_checks.ts are untouched; they still guard src/http/api.ts and src/http/mcp.ts + src/http/mcp/shared.ts on each commit.
  • The three signed-out lines in src/http/api/ (issues.ts, statement.ts, cdn.ts) are now listed both there and in DOOR_LINES.
  • Pages are not scanned yet; they follow once #18401 lands.
  • No inline check was removed.

Checks run: bun scripts/gate.ts, bun x tsc --noEmit, bun scripts/design-lint.ts, and these tests, all passing: door-inline-checks, unused-exports, dup-imports, module-state, mcp-size, check-list, design-lint-ratchets, mcp-tools-may, repo-routes-may, roles, contain, guest-contribute, and the docs tests. scripts/fast.ts named 4045 test files, too many to run here, so I picked these. The forge runs the full check on the push.

To try it: add if (!user.isAdmin) return bad("forbidden", "x"); to any file under src/http/mcp/tools/, then run bun test test/door-inline-checks.test.ts or bun scripts/design-lint.ts. Both name the file, the line and adminPage.

🤖 Generated with Claude Code

commented

A new inline check in a door that has moved off it now fails a ratchet test. That covers an isAdmin check, a read-write scope check or a signed-out check. The test is in test/door-inline-checks.test.ts. The rules and the list of moved doors are in src/design/door_checks.ts, and docs/ROLES.md explains them. bun scripts/design-lint.ts prints each moved door's inline-check count beside its other ratchets.

This push also fixes two tests that failed on this pull's check. Neither touches this change; both failed because of how they measure:

  • test/trace-imported-open.test.ts: the 500 ms timer around the parse also counted the test's own Bun.gc(true) calls, one every 500 lines. It failed 2 runs out of 3 locally. The time spent in those calls is now subtracted, and the 500 ms limit is unchanged.
  • test/pull-pipe.test.ts: the 200 MB test read the process's memory use with garbage from earlier test files in the shard still around. It now forces a garbage collection before the starting reading and before the final one. The 32 MB and 64 MB limits are unchanged.

Locally, both files passed 4 runs out of 4 after the fix, and the gate and bun x tsc --noEmit are clean. test/data-browser.test.ts is red on main at 24f4503 as well, so it is left alone here.

To try it: bun test test/door-inline-checks.test.ts test/pull-pipe.test.ts test/trace-imported-open.test.ts, then bun scripts/design-lint.ts.

🤖 Generated with Claude Code

Sign in to join this conversation.

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

Keyboard shortcuts

Docs