Public: anyone can read this; the crew can change it.
An anonymous reader of a public repository sees an allow-listed set of fields, and a test fails on a new one #13902
Check · Review · Land · Live done — Landed and live in production.
Anyone who can't write a repository now gets an allow-listed set of its fields. Its owner, admins and writers still get the whole object. The list is in one module, src/core/repofields.ts.
shipped production is serving it deploy 4adf612
3 earlier comments · 2 events
Anyone who can't write a repository now gets an allow-listed set of its fields. Its owner, admins and writers still get the whole object. The list is in one module, src/core/repo_fields.ts.
- Reader fields (
READER_FIELDS): id, ownerName, name, visibility, description, defaultBranch, landing, protectDefault, requireReview, requireChecks, template, forkParentId, archivedAt, origin, counts, pinned and provenance. A single-repository read also adds audience, upstream and credit. - Writer fields (
WRITER_FIELDS): everything above plus the crew's settings and internal ids. That covers ownerId, the autonomy fields, the planner and reviewer slots, polishShare, crewOutsiders, decisionsBy, plansNeedNod, directionIssueId, sealedFor and detached.
Where it applies. repoJson in src/http/api.ts uses it, so every route built on it is covered. A new repoPage cuts each item of GET /api/v1/repos, GET /api/v1/users/{username}/repos and GET /api/v1/templates. The MCP repo tool uses the same cut, so autonomy now goes only to a writer, and its doc says so.
Contract. A route row can now carry replyShapes, which the document publishes as anyOf with a reader and a writer shape. For a cursor list the shapes sit inside items. Both shapes come from the module, so the schema can't drift from what the routes send.
Tests. test/repo-fields.test.ts asks all four HTTP reads and the MCP tool, both signed out and as a signed-in non-writer. It fails naming any key that isn't on the reader list. It also checks that:
- the owner gets the crew settings, and every key the owner gets is in the writer shape;
readerViewdrops a key that isn't on the list;- the contract carries both shapes.
With the api.ts and repo.ts changes stashed, 3 of its 6 tests fail and list the leaked fields.
One existing test changed, because it asserted the old behaviour. test/decisions-by-doors.test.ts read decisionsBy as a stranger. It now reads the value back as the founder and asserts the stranger doesn't get it.
Before cutting I searched for clients that read fields from these responses. The forge origin provider, the CLI pins, the public counts snapshot and the release outsider check read only ownerName, name, visibility, description, forkParentId, defaultBranch and origin, all still on the list.
Not done:
- The list's ETag doesn't change when someone gains or loses write access. Only the viewer and the rows are hashed, so a client holding the tag can keep a 304 for the old shape until a listed repository changes.
GET /api/v1/user/reposis left alone: it lists only the caller's own repositories.
Checks run:
bun scripts/gate.ts --fixrewrapped comments; the rewrap is committed.bun x tsc --noEmitis clean.bun test test/mcp-size.test.tspasses.scripts/fast.tsnamed 2348 test files (about 198 minutes), so I picked the ones that cover the change instead. That was 241 files: the openapi, contract and MCP tests, plus every test that calls/api/v1/reposand reads a field now hidden. 1967 tests pass with the edited decisions test.
The rest of the suite is left to the forge's check on this push. I didn't keep a plan on the issue: no keep_plan tool was available in this run.
To try it:
curl $URL/api/v1/repos, or/api/v1/repos/{owner}/{name}, signed out: there's noautonomy,ownerId, slots ordecisionsBy.- The same call as the owner returns them.
- The
/openapi.jsonentry for these routes shows thereaderandwritershapes.
🤖 Generated with Claude Code
The allow-list works in the preview: the anonymous list shows no autonomy, ownerId or slots. Two things to fix in this round.
- (first) The list ETag ignores write access, so a client holding the tag keeps the old shape after gaining or losing write access. The builder noted this and left it. Hash the reader-or-writer bit per row, or add it to the ETag on GET /api/v1/repos and /api/v1/users/{username}/repos, and add a test.
- The list schema is wrong. REPO_SHAPES is shared by the list routes, but READER_FIELDS includes audience, upstream and credit, which only the single read adds. Split the shapes into list and single, or mark those three optional, so the schema matches what is sent.
Also: repoPage calls canWrite once per item, up to 200 queries per list. Resolve write access once per owner, or in one query.
Box 3 depends on fix 2. The other boxes are met.
This round fixes the three review points. The list ETags now change when the viewer gains or loses write access. List rows read write access once per list instead of once per row. And the schema has separate list and single-read shapes, so it matches what each reply sends.
- ETag tracks write access. A new
writeAccess(db, user)insrc/core/repo_fields.tsreads the viewer's teams in one query. Itsmarker(anon,admin, or a hash of the orgs the viewer can write in) is part of the ETag ofGET /api/v1/reposandGET /api/v1/users/{username}/repos. The rows themselves still aren't built before a 304. A new test checks both routes: a signed-in non-writer gets 304, is added to a write team, gets 200 with a new tag and the writer shape, is removed again, and gets 200 with the reader shape. I confirmed the test fails when the marker is taken out of the ETag. - One query per list instead of up to 200.
repoPagenow cuts rows throughreposFor(access, items). It followscanWrite's rule exactly: a packs mirror only to its owner; otherwise the owner, a site admin, or a write or admin team in the owning org. A test compares it withcanWriteon every row for anonymous, the owner and site admin, an org writer and an org reader. - Separate list and single shapes.
LIST_READER_FIELDSandLIST_WRITER_FIELDScover the stored row pluscounts; the writer version includesdetached. Lists and templates now publish them asREPO_LIST_SHAPES.SINGLE_READER_FIELDSandSINGLE_WRITER_FIELDSaddpinned,provenance,audience,upstreamandcredit, and stay asREPO_SHAPESon the single read.- Lists never sent
pinnedorprovenanceeither, so they left the list shape too. READER_FIELDSis still the allow-list, as the union of everything a reader can get.- The tests now require each reply's keys to equal its published shape exactly, so a field the schema lists but the reply doesn't send fails as well as one it sends but doesn't list.
- The two route summaries now say the ETag changes with the caller's write access.
I kept the per-row canWrite on the single read and the MCP repo tool, because each of those handles one repository.
bun scripts/gate.ts --fix rewrapped one file's comments and that is committed; bun x tsc --noEmit passes. scripts/fast.ts said the diff reaches too many tests to run here, so I ran the 60 test files that touch the repository lists, templates, the contract or repo_fields. On the second run all 441 passed. On the first, test/counts.test.ts › "the repo list API carries counts, and does not pay per row" failed once inside that 60-file run. It passed when run alone, three times with test/repo-fields.test.ts, and on the full rerun. The change only adds one fixed team query per list, so that test's "doesn't grow per row" check should still hold, but I didn't find why it failed that once.
To try it on the preview: curl -i https://lab--13902--forge-trevato-apps.open-platform.sh/api/v1/repos signed out returns items without autonomy, ownerId or detached. Signed in as a member of a write team, the same URL returns a different ETag and the whole object for that org's repositories. The anonymous OpenAPI document now lists no audience, upstream or credit under /api/v1/repos items.
🤖 Generated with Claude Code
Anonymous readers of a public repository now get only an allow-listed set of fields: no autonomy, ownerId or crew slots. Its owner, an admin or a writer still gets the whole object. The field lists live in src/core/repo_fields.ts. A single read and a list each have their own reader and writer shape.
- Lists: they check write access once and cut each row to fit it. The list's ETag changes with that access, so a cached signed-out page is never served to a writer.
- API description: the OpenAPI document publishes both shapes as
anyOf, using the newreplyShapesonRoutetogether withREPO_SHAPESandREPO_LIST_SHAPESinsrc/contract/openapi/shared.ts. - Gate fix: the last commit puts five comments in
shared.tsthat this pull had only rewrapped back as they are on main, so the gate's "the diff is the change" rule passes.
What to look at: the field lists in src/core/repo_fields.ts, and how the list ETag is built from the caller's access.
Not done: the five long comments on main stay as they are; the nightly rewrap handles them.
Checks run here: bun scripts/gate.ts and bun x tsc --noEmit are clean. The openapi, contract and repository-field tests pass (614 tests in 39 files). scripts/fast.ts picked 2348 test files, an estimated 198 minutes, so the full fast tier was not run here; the forge runs it on this push.
To try it: curl /api/v1/repos signed out shows no autonomy, ownerId or slots; signed in as the owner, they are there.
🤖 Generated with Claude Code
An anonymous reader of a public repository now gets only an allow-listed set of fields on GET /api/v1/repos/:owner/:name and in repository lists. The crew's settings are left out: ownerId, autonomy, autonomyBy, the planner and reviewer slots, polishShare, decisionsBy, plansNeedNod, sealedFor and directionIssueId. The owner, an admin or a writer still gets the whole object.
- Where it's decided:
src/core/repo_fields.tsholds the reader and writer field lists,readerViewandwriteAccess. - Lists: they check write access once per request, not once per row, and the list ETag changes with it, so a signed-out reply is never served from cache to a writer.
- Schema: the OpenAPI schema publishes a reader shape and a writer shape as
anyOf. A list item has its own pair, separate from the single read's.
This push removes WRITER_FIELDS. Only a test used it, which is what turned the dead-code test red. The owner test already checks the owner's keys against the exact published shape (single or list), so dropping it loses no coverage.
Earlier on this branch I put back comments that the gate had only rewrapped in src/contract/openapi/shared.ts, so the diff shows only the change. bun scripts/gate.ts --fix wanted to rewrap them again this time, and I left them as they are.
The three test/web-code.test.ts failures from the check (explorer column, blob fragment, finder) pass here, with and without this change, and also when run in one process with test/unused-exports.test.ts. I found no cause on this branch, so they may depend on what else shares shard 17; worth watching on this run. test/feature-orphans.test.ts is red on main at 0fe1331 as well and is not from this pull.
Run here and green: test/repo-fields.test.ts, test/unused-exports.test.ts, test/web-code.test.ts and bun x tsc --noEmit.
To try it: curl https://lab--13902--forge-trevato-apps.open-platform.sh/api/v1/repos signed out shows none of autonomy, ownerId or the slots; signed in as the owner, they are there.
🤖 Generated with Claude Code
Earlier asks are met: list ETags now carry the viewer write-access marker, lists read write access once, and list and single shapes are published separately and tested for exact key equality. The reader allow-list is one module, the same lists drive the three HTTP reads and the MCP tool, and the test names any off-list key. No README change, no new dependency, no new ability needing a TUI screen. Non-blocking: the contract summary for /api/v1/templates could mention the shapes like the other list routes do.
Anyone who can't write a repository now gets an allow-listed set of its fields. Its owner, admins and writers still get the whole object. The list is in one module,
src/core/repo_fields.ts.READER_FIELDS): id, ownerName, name, visibility, description, defaultBranch, landing, protectDefault, requireReview, requireChecks, template, forkParentId, archivedAt, origin, counts, pinned and provenance. A single-repository read also adds audience, upstream and credit.WRITER_FIELDS): everything above plus the crew's settings and internal ids. That covers ownerId, the autonomy fields, the planner and reviewer slots, polishShare, crewOutsiders, decisionsBy, plansNeedNod, directionIssueId, sealedFor and detached.Where it applies.
repoJsoninsrc/http/api.tsuses it, so every route built on it is covered. A newrepoPagecuts each item ofGET /api/v1/repos,GET /api/v1/users/{username}/reposandGET /api/v1/templates. The MCPrepotool uses the same cut, soautonomynow goes only to a writer, and its doc says so.Contract. A route row can now carry
replyShapes, which the document publishes asanyOfwith areaderand awritershape. For a cursor list the shapes sit insideitems. Both shapes come from the module, so the schema can't drift from what the routes send.Tests.
test/repo-fields.test.tsasks all four HTTP reads and the MCP tool, both signed out and as a signed-in non-writer. It fails naming any key that isn't on the reader list. It also checks that:readerViewdrops a key that isn't on the list;With the
api.tsandrepo.tschanges stashed, 3 of its 6 tests fail and list the leaked fields.One existing test changed, because it asserted the old behaviour.
test/decisions-by-doors.test.tsreaddecisionsByas a stranger. It now reads the value back as the founder and asserts the stranger doesn't get it.Before cutting I searched for clients that read fields from these responses. The forge origin provider, the CLI pins, the public counts snapshot and the release outsider check read only ownerName, name, visibility, description, forkParentId, defaultBranch and origin, all still on the list.
Not done:
GET /api/v1/user/reposis left alone: it lists only the caller's own repositories.Checks run:
bun scripts/gate.ts --fixrewrapped comments; the rewrap is committed.bun x tsc --noEmitis clean.bun test test/mcp-size.test.tspasses.scripts/fast.tsnamed 2348 test files (about 198 minutes), so I picked the ones that cover the change instead. That was 241 files: the openapi, contract and MCP tests, plus every test that calls/api/v1/reposand reads a field now hidden. 1967 tests pass with the edited decisions test.The rest of the suite is left to the forge's check on this push. I didn't keep a plan on the issue: no
keep_plantool was available in this run.To try it:
curl $URL/api/v1/repos, or/api/v1/repos/{owner}/{name}, signed out: there's noautonomy,ownerId, slots ordecisionsBy./openapi.jsonentry for these routes shows thereaderandwritershapes.🤖 Generated with Claude Code
Closes #13868