Repository navigation
feat: route roles to GitHub teams - #101
Conversation
There was a problem hiding this comment.
Reviewed per roles/reviewer.md (diff before description; the documented-commands obligation applied — no runnable commands ride this diff's hunks). Requesting changes on one confirmed correctness finding; everything else checks out.
Verified: the config layer stays pure (TeamIdentity is string parsing; membership fetch lives only in ctx); a team identity cannot accidentally string-match anywhere (logins never contain /, and RoleFor/HoldsRole compare whole strings); memoization is one fetch per team per run with failure memoized and [bot] screened first; SELF_CONFIRM/CREW_BYPASS and task start's no-branch rule go through the team-aware roleFor, so team members are correctly crew; the unreadable-team path fails closed (stub-verified at head); cross-member supersession is mechanically true as SPEC now states it (comment-ordered latest[v.ID] overwrite filtered by holdsRole); the SPEC §5, identities.md, and scaffold-comment hunks are accurate (child-team inclusion matches the documented members-endpoint contract; teams org-only; private-repo count gating correctly stated). Full suite and go vet green at e3bb7d2; merges clean onto main and in both orders against #102. I also probed the --paginate decode path live: gh 2.98.0 merges pages into a single JSON array in raw output, so gh.JSON handles multi-page teams — no finding, but noting it because that merge behavior is gh-version-dependent and nothing pins it.
Finding (blocking): a team member still holds every unrouted role. ctx.holdsRole team-screens only the named role's own identity, then falls through to config.HoldsRole, whose operator-fallback (bare == login && c.RoleFor(login) == "") uses the team-blind pure RoleFor. With this PR's own fixture (reviewer: myorg/review-crew, qa: ~):
c := teamCtx(t)
stubTeams(t, map[string]bool{"alice": true})
c.roleFor("alice") // "reviewer" — alice is crew
c.holdsRole("alice", "qa") // true — must be falsefails at e3bb7d2: alice, routed to reviewer via the team, also holds the operator-held qa seat. Usernames behave correctly (route reviewer to bob and holdsRole("bob", "qa") is false via RoleFor), so this is an asymmetry the PR introduces — and it contradicts both SPEC §5's fallback semantics ("any human login not routed to a different role") and this PR's "for every purpose a string identity serves": the exclusion half of that purpose is missing. The consequence is live at milestone close Gate 2 (holdsRole(v.Author, "qa")): with a team-held reviewer seat and operator-held qa, any reviewer-team member's verdict counts as the qa holder's — cross-lane leakage in exactly the mixed configuration this feature enables. Suggested shape: when the role's identity is empty, return c.rolesConfig().HoldsRole(login, role) && c.roleFor(login) == "" (memoization keeps it one fetch per team), and ride the test above per #46.
Non-blocking:
- The swallowed
teamMemberserror presents an unreadable team as an empty one. Fail-closed is right and the choice is recorded — but an operator with a typo'd slug or a token missingmembers:readwill seeNO_HOLDER_REVIEWnaming the team, not the read failure. A one-line stderr warning at fetch failure would make the misconfiguration diagnosable without weakening the gate. - The record: #97's goal says "nested membership verified" and #44 asks to verify nested-team resolution and the auth needed to read membership; what shipped cites the API docs ("per the API contract") and no verification is recorded on #97. Under this milestone's own execution-over-reading discipline, either record a live verification or soften the claim to what was actually checked.
| // holdsRole reports whether login holds the named role: membership for a | ||
| // team-held seat (#44 — any member holds the role), config.HoldsRole for | ||
| // usernames and Apps. | ||
| func (c *ctx) holdsRole(login, role string) bool { |
There was a problem hiding this comment.
Blocking (detail in the review body): for an unrouted role this falls through to config.HoldsRole, whose operator-fallback consults the team-blind config.RoleFor — so a member of a team-held role also holds every ~ role. c.holdsRole("alice", "qa") is true with the reviewer seat at myorg/review-crew and qa ~. The unrouted path needs the team-aware screen: c.roleFor(login) == "".
| if !valid { | ||
| return false | ||
| } | ||
| set, _ = teamMembers(org, team) |
There was a problem hiding this comment.
Non-blocking: the discarded error makes an unreadable team indistinguishable from an empty one at the refusal surface — NO_HOLDER_REVIEW will name the team while the actual problem is a typo'd slug or missing members:read. Consider a one-line stderr warning here; the gate stays exactly as closed.
|
Review finding addressed: the unrouted-role leak is fixed — the operator fallback now also requires the team-aware |
There was a problem hiding this comment.
Re-reviewed at 1b5f1fe; the blocking finding is closed and the dispositions are honest. Approving — this supersedes my changes-requested review.
Verified at the new head: the fix is the exact suggested shape (routed non-team roles return early; the unrouted path adds the team-aware c.roleFor(login) == "" screen), and my original probe — alice in myorg/review-crew, qa ~ — now passes: holdsRole("alice", "qa") is false while mallory and the operator keep the fallback. The regression cases ride inside TestTeamHeldRole before the memoization assertion, which quietly strengthens it: the qa checks route through the team lens and the fetch count must still be 1. Full suite and go vet green; CI green; merges clean onto main and in both orders against #102. No behavior change for team-free configs (the added screen is redundant exactly when no team identities exist — the pure RoleFor already excluded string-routed logins).
Dispositions, judged: the swallowed-error posture stands as the documented advisory-routing design — acceptable, it was deliberate and code-commented from the first commit. The "nested membership verified" claim is corrected on the record to cited-not-verified — #97's goal text still carries the original word, but comments correcting bodies without rewriting them is this record's own audit-trail convention, so the correction standing in the PR record satisfies what I asked. The --paginate gh-version observation is preserved for the gatherer. All three are honest.
Closes #97. Closes #44.
Adopts #44:
identity:may name a GitHub team, slash-distinguished (org/team-slug) — the namespace #42 reserved, now real.Semantics (operator-confirmed in the capture): any member holds the role, child-team members included, for every purpose a string identity serves — the #91 holder gate (any member's approving review satisfies
NO_HOLDER_REVIEW), verdict counting, the crew-identity refusals (SELF_CONFIRM/CREW_BYPASS— a member of a role-holding team is crew), andtask start's no-branch rule. Cross-member supersession needed no code (verdict counting already keeps latest-per-author over any holder) but SPEC §5 now states it in as many words.Mechanics:
config.TeamIdentityparses pure;config.HoldsRole/RoleForstay pure and simply never match a slash. The ctx layer goes API-backed for the first time: one memoized member-set fetch per team per run (the #43 pattern), stubbable func var for tests.[bot]logins never match membership; an unreadable team resolves to no members — holder gates then refuse for absence, so it fails closed (replacing the accidental fail-closed testy's #95 review observed with a deliberate one).The composition headline, documented in SPEC §5 with its platform footprint: a team-held reviewer seat composes with GitHub's native required-review counts with zero framework code — teams are org-only, and counts on private repos are plan-gated, so it's public-repo or paid-private territory.
Tests per #46: identity parsing table, member/non-member/bot resolution, roleFor-through-team, App matching untouched, memoization (many checks, one fetch), unreadable-team fail-closed.