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

Access 4a: one read-only view over every grant table, and a gate test that none is missing #18118

opened this

Merged 6h 57m ago, live in production

This adds one read-only function, everyGrant(db, account?) in src/core/grantsview.ts, that lists the rows of all 16 grant tables in one shape. That shape is principal, action or role, resource, granted by, and when. It adds no table and changes no access, page or route.

Notes

opened this

This adds one read-only function, everyGrant(db, account?) in src/core/grants_view.ts, that lists the rows of all 16 grant tables in one shape. That shape is principal, action or role, resource, granted by, and when. It adds no table and changes no access, page or route.

How each table is read. Each table has one mapping row in MAPPINGS: SQL over the table's own columns. The rows are joined with UNION ALL into a single query. Grantees typed differently are turned into text, not migrated:

  • device_grant stores an integer device id; it becomes text.
  • subscription_grant grants to an agent, or to a repo or org when no agent is named.
  • In secret_grant and egress_grant the grantee is a repository.
  • In pull_run_grant the pull is the grantee and user_id is the person who granted it.

Unrecorded fields. grantedBy and at are { notRecorded: true } when the table has no such column (team_member, game_grant, subscription_grant, crew_team_member). They are null when the column exists but this row is empty, for example a granter whose account was deleted.

Missing tables. A table that doesn't exist yet lists nothing. client_cloud_member is only created on first use, so a fresh forge doesn't have it.

Filtering by account. Given account, the view returns only grants whose principal is that person or agent. The filter runs in SQL, and an account with no grants gets [].

Tests. test/grants-view.test.ts:

  • grants one row in each of the 16 tables and checks the view lists all of them in the shape above;
  • checks one account's grants, an account with none, and a fresh forge;
  • is the gate: it finds every CREATE TABLE under src/ named _grant or _member, plus the migrated schema, and fails naming any table the view doesn't read.

Look at:

  • Two allow-list entries. Nothing under src/ calls this yet, as the issue intends: the page is #18105, the MCP tool and terminal screen are #18106. So scripts/unreached-allow.json names the module and scripts/unused-exports-allow.json names everyGrant. Both entries should go when #18105 lands.
  • Why it's called everyGrant. I first named it grantsView, but a private function of that name in src/web/pages/grants.ts (OAuth grants) made the dead-code test think it had a caller, so I renamed it.
  • share rows are all listed, dropped ones included. The state shows in the action (receive, dropped). Decide in #18105 whether the page should leave dropped shares out.
  • bun scripts/similar.ts found nothing like this under src/, so nothing was reused. The gate test lists files with Bun.Glob, the way scripts/unused-exports.ts does.

Checks run: bun x tsc --noEmit and bun scripts/gate.ts --explain pass (33 of 33 rules). Of the 156 files scripts/fast.ts named, all pass except one test in test/scripts-fast.test.ts ("a clean tree and a docs-only diff exit 3"). It hits its 5 s timeout in this sandbox and fails the same way on main, so it is unrelated to this change. The keep_plan and estimate tools weren't available in this session, so no plan or estimate was recorded on the issue.

To try it: bun test test/grants-view.test.ts. To see the gate fail, delete one row from MAPPINGS and run it again.

🤖 Generated with Claude Code

Closes #18104

commented

This adds one read-only function, everyGrant(db, account?) in src/core/grants_view.ts, that lists the rows of all 16 grant tables in one shape. That shape is principal, action or role, resource, granted by, and when. It adds no table and changes no access, page or route.

How each table is read. Each table has one mapping row in MAPPINGS: SQL over the table's own columns. The rows are joined with UNION ALL into a single query. Grantees typed differently are turned into text, not migrated:

  • device_grant stores an integer device id; it becomes text.
  • subscription_grant grants to an agent, or to a repo or org when no agent is named.
  • In secret_grant and egress_grant the grantee is a repository.
  • In pull_run_grant the pull is the grantee and user_id is the person who granted it.

Unrecorded fields. grantedBy and at are { notRecorded: true } when the table has no such column (team_member, game_grant, subscription_grant, crew_team_member). They are null when the column exists but this row is empty, for example a granter whose account was deleted.

Missing tables. A table that doesn't exist yet lists nothing. client_cloud_member is only created on first use, so a fresh forge doesn't have it.

Filtering by account. Given account, the view returns only grants whose principal is that person or agent. The filter runs in SQL, and an account with no grants gets [].

Tests. test/grants-view.test.ts:

  • grants one row in each of the 16 tables and checks the view lists all of them in the shape above;
  • checks one account's grants, an account with none, and a fresh forge;
  • is the gate: it finds every CREATE TABLE under src/ named _grant or _member, plus the migrated schema, and fails naming any table the view doesn't read.

Look at:

  • Two allow-list entries. Nothing under src/ calls this yet, as the issue intends: the page is #18105, the MCP tool and terminal screen are #18106. So scripts/unreached-allow.json names the module and scripts/unused-exports-allow.json names everyGrant. Both entries should go when #18105 lands.
  • Why it's called everyGrant. I first named it grantsView, but a private function of that name in src/web/pages/grants.ts (OAuth grants) made the dead-code test think it had a caller, so I renamed it.
  • share rows are all listed, dropped ones included. The state shows in the action (receive, dropped). Decide in #18105 whether the page should leave dropped shares out.
  • bun scripts/similar.ts found nothing like this under src/, so nothing was reused. The gate test lists files with Bun.Glob, the way scripts/unused-exports.ts does.

Checks run: bun x tsc --noEmit and bun scripts/gate.ts --explain pass (33 of 33 rules). Of the 156 files scripts/fast.ts named, all pass except one test in test/scripts-fast.test.ts ("a clean tree and a docs-only diff exit 3"). It hits its 5 s timeout in this sandbox and fails the same way on main, so it is unrelated to this change. The keep_plan and estimate tools weren't available in this session, so no plan or estimate was recorded on the issue.

To try it: bun test test/grants-view.test.ts. To see the gate fail, delete one row from MAPPINGS and run it again.

🤖 Generated with Claude Code

commented

Left #18104 open: 1 unticked item remain (A read-only function (no new table) over member, team_member, app_member, game_grant, model_grant, subscription_grant, secret_grant, egress_grant, device_grant, child_reach_grant, origin_read_grant, pull_run_grant, telemetry_grant, client_cloud_member, crew_team_member, share. A table that does not record who granted it says so in that field.).

Sign in to join this conversation.

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

Keyboard shortcuts

Docs