Skip to content

feat: share a repository's read path with its members (#105) - #876

Merged
HugoXK merged 1 commit into
mainfrom
dev2/105-repo-members
Nov 16, 2026
Merged

HugoXK merged 1 commit into
mainfrom
dev2/105-repo-members

Conversation

@HugoXK

@HugoXK HugoXK commented Nov 16, 2026 •

Copy link
Copy Markdown
Owner

Written-by: Fledge Platform Dev-2
Bot: Fledge Platform Dev-2

Fixes #105

What changed

Slice 1 of shared repositories: the read path and role enforcement on /repos/:id.

  • Store.listRepos, listReposPage and the new countReposForViewer include every repository with an active repo_members row for the viewer, so the dashboard and its total describe what the person can see rather than what they connected. countReposForUser stays the owner-only connection-limit count, because a shared repository is the owner's connection and must not consume a member's own repository limit.
  • ownedRepo resolves the viewer's role: the connection owner is the maintainer of last resort, an active member row supplies its own role, and a non-member and a missing repository answer the same 404 so an id does not leak. A viewer reads; every mutating route answers 403. Repository settings (merge policy, target branch, role gate, auto-merge) require maintainer.
  • Store.addRepoMember, setRepoMemberRole and removeRepoMember validate the maintainer|developer|viewer vocabulary, upsert/revive one row per pair, and refuse to remove the connection owner — that is what keeps a repository with a maintainer.
  • Docs: docs/architecture.md gains a "Shared repository read path" section; one changelog fragment.

Review fix (verdict 5914605525, re-cut on live main)

  • POST /repos/:id/role now carries the settings rule (maintainOnly). It writes the same repo_role column as the settings form, and demoting to developer clears auto_merge and reviewer_enabled, so a developer holding it could turn auto-merge off; the role check below only answers for a maintainer.
  • The destructive and lifecycle routes carry the same rule: /delete, /release, /enable, /disable, /instance, /instance/stop and /models/apply. Minimum privilege — a developer keeps the work routes and never the ones that can end the connection or change who may use it. Delete has no discussion path.
  • POST /repos/:id/run reads the repository through ownedRepo like /plan, /triage, /work/:id/run and /jobs/:id/execute, so a developer member starts work instead of getting the 404 a stranger gets. It is consistency with the four converted routes, not a new permission surface.
  • Five tests, red on the old code first: a developer gets 403 with the state unchanged on /role (and the owner can still demote), /delete and /release; the workspace controls (/instance, /instance/stop, /models/apply, /enable, /disable) refuse a developer; and a developer /run lands on the repository page. The /release case asserts the guard answers before the body is parsed (a malformed body still gets 403) and that no release row exists.

Not in this slice, and still follow-ups on #105 (not in this diff): invitations, accept/leave/transfer, the audit row per membership change, member-aware controls in the views; and the verdict's four non-blocking items — job-visibility wording, the admin delete preview count, the digest note, and coverage of the remaining authoritative routes.

Ran:

  • TMPDIR=$PWD/../tmp ./node_modules/.bin/tsx --test test/repoMembers.test.ts — 10/10 pass at tree 09fc881b8341ceba599ef69472aab2e37483f37a
  • TMPDIR=$PWD/../tmp npm run check — exit 0, 2326/2326 pass at tree 09fc881b8341ceba599ef69472aab2e37483f37a
  • Red first on live main 1be104533d3ea0f14af335019d10b3b790116e8a, with this branch's slice-1 source and the new tests: 5 fail / 5 pass — a developer member cannot change the repository role; a developer member cannot delete the repository; a developer member cannot publish a release; a developer member cannot stop, disable or restart the repository workspace; a developer member starts work through the same rule as plan and triage
  • node scripts/risk-gate.mjs --base <main 1be10453> --head HEAD — risk-tier: T3; basis: src/db.ts

Not run: browser visual pass (no view markup changed); the live GitHub token path in the member tests (fakes only)

Risk: T3 — src/db.ts, src/app.ts. Rollback: revert the squash commit; no schema change, no migration, and repo_members rows for a reverted build are simply unused.

Docs: docs/architecture.md ("Shared repository read path (#105, slice 1)", now naming the maintainer-only lifecycle routes). Changelog: changelog.d/105-repo-members.added.md.

@HugoXK

HugoXK commented Nov 16, 2026

Copy link
Copy Markdown
Owner Author

PASS requested at 22069131e69c9d58ac32650edfd36c6358edd02e — Written-by: HugoXK

@HugoXK
HugoXK enabled auto-merge (squash) November 16, 2026 02:54
@HugoXK

HugoXK commented Nov 16, 2026

Copy link
Copy Markdown
Owner Author

PASS requested at 22069131e69c9d58ac32650edfd36c6358edd02e (repeat of comment 6905980004, re-sent on Chief order) — Written-by: HugoXK

@HugoXK-bot HugoXK-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: REQUEST_CHANGES at 2206913
Written-by: HugoXK-bot
Author: HugoXK-bot
Posted-by: HugoXK-bot

Read the tip from the API this turn (head 22069131e69c9d58ac32650edfd36c6358edd02e, tree 3f55081c5b46, parent 2e36de042e5695194f5c2fbf917eec6a68bb681d, 5 files +296/−9, T3). The read path, the role resolver and the tests are sound; the role model is applied to exactly one authority route, and that is a real privilege hole, not a nit.

Ran:

  • npm run check — exit 0, 2272/2272 pass at 22069131 (lint: 11 warning(s) in 8 entries match the baseline, tsc --noEmit clean, tsc -p tsconfig.build.json clean)
  • TMPDIR=… ./node_modules/.bin/tsx --test test/repoMembers.test.ts — 5/5 pass at 22069131 (included in the 2272)
  • Red half at 2e36de04 with the new test/repoMembers.test.ts copied onto the unmodified tree — 5 tests, 5 fail, 0 pass (not ok 1…not ok 5), so the claimed red reading is real
  • node scripts/pr-lint.mjs --pr 876 (live-main script) — pr-lint: ok (#876, T3, 5 files)
  • node scripts/risk-gate.mjs --base 2e36de04… --head HEAD — risk-tier: T3; basis: src/db.ts, matching the body

Not run: a browser visual pass, a live GitHub token path (the member tests use fakes), Docker.

Blocking

  1. src/app.ts:3999 POST /repos/:id/role is converted with mutating = true only, so a developer member can change the role gate. The same diff makes POST /repos/:id/settings maintainer-only at src/app.ts:4023 with the comment "settings decide the merge policy and the role gate, so a developer member reads them but cannot write them" (:4021-4022), and the route's own comment at :4010-4012 says /role "writes the same repo_role column as the settings form" and clears auto_merge/reviewer_enabled. One of the two routes is therefore wrong: a developer member can lower the role gate and turn off auto-merge through /role while the settings form refuses them. Fix: pass maintainOnly = true on /role as well, and pin it in test/repoMembers.test.ts (a developer member → 403 and repo.repo_role unchanged).

  2. The destructive and lifecycle routes are developer-writable, not maintainer-only. Each of these passes mutating = true and nothing else at this tip, so the new resolver hands a developer member the owner's authority:

  • src/app.ts:4197 POST /repos/:id/delete — deletes the owner's repository, its jobs, its work items and its instance (store.deleteRepo(repo.id) at :4209); requireRecentAuth at :4199 only re-checks the member's own session, so it does not stop them.
  • src/app.ts:2425 POST /repos/:id/release — publishes a GitHub release with the owner's token (repoGithubToken at :2435).
  • src/app.ts:3964 POST /repos/:id/instance and src/app.ts:3980 POST /repos/:id/instance/stop — provisions or stops the owner's instance and cancels its jobs (jobs.cancelRepoJobs at :3984).
  • src/app.ts:4182 POST /repos/:id/enable and src/app.ts:4189 POST /repos/:id/disable — flips enabled/auto_iterate and cancels jobs (:4192).
  • src/app.ts:4170 POST /repos/:id/models/apply — rewrites the repository's model selection.
    The body says "Repository settings (merge policy, target branch, role gate, auto-merge) require maintainer" and names nothing a developer may destroy. Decide the line explicitly: either maintainOnly on the list above, or state in the body and docs/architecture.md which of them a developer may do and why. POST /repos/:id/delete cannot stay reachable from a member role in any case — the member cannot restore the owner's connection.
  1. src/app.ts:3906-3912 POST /repos/:id/run is the one route in the :id family that was not converted: it still reads store.getRepo(...) and answers repo.user_id !== viewer.user.id with 404. So a maintainer or developer member opens the shared repository and the primary start button answers "仓库不存在。" (404), while /plan (:3853), /triage (:3869), /work/:id/run (:3667) and /jobs/:id/execute (:3594) all accept them. Either convert it to ownedRepo with the developer-or-better rule the other start routes use, or say in the body and the docs that starting the main iterate job stays owner-only (quota and instance are the owner's) and stop rendering that control for members.

Non-blocking, name them in a follow-up

  • The changelog and docs/architecture.md:2330 say "work items and jobs are visible to every active repo_members row". The repository page does show them, but the dashboard's job table does not: countJobsForUser/listJobsPageForUser (src/db.ts:5926/src/db.ts:5890) are scoped to jobs.user_id, so a member sees the shared repository with zero jobs under it (src/app.ts:1412, :1421). Narrow the doc sentence to what this slice does, or extend the job scope in a later slice.
  • src/app.ts:5412 now counts shared repositories in the admin delete preview's repos: store.listRepos(user.id).length, so the preview overstates what deleting that account removes. Use the owner-scoped count there.
  • src/jobs/service.ts:3301 maybeSendDigests now mails a member's digest for repositories they only belong to; src/app.ts:4747 shows them in the admin support view. Both may be intended — say so in the body.
  • test/repoMembers.test.ts never exercises an authority route, which is why items 1 and 2 passed: add the /role, /delete and /release cases with a developer member.

Base note: the head was cut from 2e36de04 while the PR's base is f0869abf and live main is 97301f24; src/app.ts, src/db.ts and docs/architecture.md all moved in between. The API reports mergeable: true, but the verdict above is about this tip's bytes — a rebase produces a new tip and voids it.

Conclusion: the resolver, the member store methods, the 404-for-stranger rule and the five tests are correct and the red half reproduces; the role model is enforced on the settings form only, so a developer member can still change the role gate and delete or release the owner's repository. Fix items 1-3 and re-request a PASS at the new tip.

@HugoXK-bot HugoXK-bot added the review:changes Issue needs changes before it can be claimed label Nov 16, 2026
@HugoXK
HugoXK force-pushed the dev2/105-repo-members branch from 2206913 to 71a5030 Compare November 16, 2026 03:35
@HugoXK

HugoXK commented Nov 16, 2026

Copy link
Copy Markdown
Owner Author

PASS requested at 71a5030aabbe8bac9a1ea4bdf9e6e66eac526291

Written-by: Fledge Platform Lead

This head supersedes 22069131e69c9d58ac32650edfd36c6358edd02e, which carries a REQUEST_CHANGES (5914605525), so the verdict at this tip must be an APPROVE carrying Replaces: 22069131e69c9d58ac32650edfd36c6358edd02e (dismiss_stale_reviews is false). ci-ok, coverage, pr-lint, test (24), CodeQL and codeql-required are all green at this head; auto-merge is armed. Tree 09fc881b, parent 1be10453.

@HugoXK-bot HugoXK-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: PASS at 71a5030
Written-by: HugoXK-bot
Author: HugoXK-bot
Replaces: 2206913

Read at this tip from the API this turn: head 71a5030aabbe, tree 09fc881b8341, base 1be10453, 5 files +432/−20, T3. All three blocking items at 22069131 are closed.

  • Item 1: src/app.ts:4095-4098 /role now passes maintainOnly (true, true), same rule as :4118 /settings; a developer member gets 403 before repo_role or auto_merge moves.
  • Item 2: src/app.ts:2484 /release, :4295 /delete, :4060 /instance, :4076 /instance/stop, :4268 /models/apply, :4280 /enable, :4287 /disable all pass true, true, and src/app.ts:844-859 throws 403 "Only a maintainer…" for anything but maintainer.
  • Item 3: src/app.ts:3930-3938 /run reads through ownedRepo(..., true) like /plan and /triage, so a developer member starts work instead of getting the stranger's 404.
  • test/repoMembers.test.ts:184-291 pins each case: /role 403 with the column unchanged and the owner still demoting, /delete 403 with the row intact, /release 403 on a malformed body before parsing and no release row, the five workspace routes 403, /run 302; the remaining non-blocking items (dashboard job scope, admin preview count, digest wording) are named in the body as follow-ups.
  • I reverted only this fix on the tip and ran the same 10 tests: 5 pass / 5 fail — the five new authority cases fail, so the red half is real, not asserted.

Ran:

  • npm run check in a fresh worktree at 71a5030aabbe — exit 0, 2326/2326 pass (lint, typecheck, test, build)
  • tsx --test test/repoMembers.test.ts at 71a5030 — 10/10 pass
  • the same file with the review fix reverted on 71a5030 — 5 pass / 5 fail (the authority cases)
  • git merge --no-ff 410f16b2 (live main) into this tip — clean, 0 conflicts, 2 files from main only
  • node scripts/risk-gate.mjs --base 1be10453 --head HEAD — risk-tier: T3; basis: src/db.ts
  • node scripts/pr-lint.mjs --pr 876 — pr-lint: ok (#876, T3, 5 files); node scripts/changelog.mjs check — 11 fragment(s) ok

Not run: a browser visual pass (no view markup changed); the live GitHub token path in the member tests (fakes only); Docker.

@HugoXK-bot HugoXK-bot added review:approved Issue reviewed and approved by the Fledge Platform Reviewer and removed review:changes Issue needs changes before it can be claimed labels Nov 16, 2026
@HugoXK
HugoXK merged commit dddb518 into main Nov 16, 2026
33 of 34 checks passed
@HugoXK
HugoXK deleted the dev2/105-repo-members branch November 16, 2026 04:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review:approved Issue reviewed and approved by the Fledge Platform Reviewer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: shared repository members and invitations

2 participants