feat(reconcile): unify custom and predefined role handling under one field model#1779
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
🚧 Files skipped from review as they are similar to previous changes (4)
📝 WalkthroughSummary by CodeRabbit
WalkthroughRole reconciliation now tracks YAML field presence with pointers, resolves desired roles over defaults, compares normalized fields, accounts for server roles, exports explicit differences, and applies operations using resolved role data. ChangesRole reconciliation
Estimated code review effort: 4 (Complex) | ~45 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 2✅ Passed checks (2 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Coverage Report for CI Build 29913290645Coverage decreased (-0.07%) to 46.209%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
b98d0ba to
34fdba8
Compare
34fdba8 to
da32e66
Compare
What
Collapses the Role kind's two code paths (custom roles and predefined roles) into one field
model, part of adopting rules v2. A role's managed fields now follow a single rule: a field
written in the file is the whole desired value; an omitted field takes the role's default;
an explicitly empty field means empty. Custom and predefined roles differ only in their
default (empty for custom, the shipped definition for predefined) and in that a predefined
role is never created or deleted by the flow.
Why
Role was the most complex kind. The old code had a separate
diffPredefinedRolewith fourcarve-out conditions, keep-if-omitted guards on custom roles, and three empty-list
rejections, all to protect the export round trip. Measured effect of the unification on
role.go:&&/||) 13 -> 1diffPredefinedRole(53 lines) deleted, folded into onediffRolesvalidateRoleSpec24 lines / 4 rules -> ~14 lines / 3 rules (name, no predefined delete, at least one permission)It also closes Role's two gaps on the rules-v2 compatibility audit (Rule 2, the field model,
and Rule 5, the export round trip).
The model
roleDefault(name)returns the default fields: the shipped definition for a predefinedrole, empty for a custom role.
resolvelays the spec's present fields over the default;diffFieldsreports whatchanged. One path for both role types.
*string,*[]string) so an omitted field and anexplicitly empty field are distinguishable, and so export can write
scopes: []for afield that is empty on the server. This removes the carve-outs entirely; the round trip
was verified over the tricky reachable state (a predefined field emptied on the server).
Behavior changes to know
role an omitted title clears it; for a predefined role an omitted field converges to the
definition (unchanged from before). Files generated by
frontier exportwrite everymanaged field, so the normal edit-the-export workflow is unaffected; only a hand-trimmed
file behaves differently.
instead of staying frozen. More predictable, and export keeps such roles listed so the
round trip never triggers a surprise.
scopes: []toblank scopes, and an omitted custom field clears it. Permissions are the exception. The
server rejects a role with no permissions, so a role must still resolve to at least one.
A custom role with omitted or
permissions: [], or a predefined role set to[], failsthe plan up front with a clear message rather than late at the API. (This guard was briefly
dropped in an earlier revision of this PR and is restored.)
Testing
go build,go test ./internal/reconcile/...,go vet,gofmt,golangci-lintallpass. Test updates were mostly mechanical (pointer literals), plus new cases: an omitted
custom title clears, a predefined field emptied on the server round-trips, and a role that
resolves to no permissions (a custom role with omitted or empty permissions, or a predefined
role set to
[]) fails the plan.Status
RFC 0001 now describes this one field model (#1751), so this PR implements
what the RFC specifies. It targets
main, now that theValidateinterface change (#1776)it built on has merged. The branch is rebased on the current
mainand merges cleanly. Theframework's "validate every document before applying" commit that this branch used to carry
has since landed in
mainon its own, so it is dropped here. The branch now holds just thetwo role commits: the field-model unification and the no-permissions plan-time guard.