feat(reconcile): unify custom and predefined role handling under one field model#1779
feat(reconcile): unify custom and predefined role handling under one field model#1779rohilsurana wants to merge 2 commits into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
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 29741017461Coverage decreased (-0.07%) to 46.072%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
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 -> 8 lines / 2 rulesIt 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 states (a predefined field emptied on the server, a
custom role whose permissions were emptied).
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.
are gone: an empty set is a legal, explicit value now.
Testing
go build,go test ./internal/reconcile/...,go vet,gofmt,golangci-lintallpass. Test updates were mostly mechanical (pointer literals), plus three new cases: a
zero-permission custom role round-trips, an omitted custom title clears, and a predefined
field emptied on the server round-trips.
Follow-up
RFC 0001 should be updated to describe the one field model and drop the predefined-role
"two edges" paragraph, since those cases no longer exist. That is a separate change.