-
Notifications
You must be signed in to change notification settings - Fork 323
test(validation): add self-referential relation cycle detection and permission union deduplication assertions #3141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| package validation | ||
|
|
||
| import ( | ||
| "testing" | ||
| ) | ||
|
|
||
| func TestWave5CyclicRelationDetection(t *testing.T) { | ||
| // Direct self-reference cycle: role:admin -> role:admin | ||
| detectSelfReference := func(subject string, object string) bool { | ||
| return subject == object | ||
| } | ||
|
|
||
| if !detectSelfReference("user:org_admin", "user:org_admin") { | ||
| t.Error("expected self-reference detection") | ||
| } | ||
| if detectSelfReference("user:member", "user:admin") { | ||
| t.Error("non-matching entities should not trigger self-reference") | ||
| } | ||
| } | ||
|
|
||
| func TestWave5PermissionSetUnion(t *testing.T) { | ||
| unionPermissions := func(setA []string, setB []string) []string { | ||
| seen := make(map[string]bool) | ||
| var merged []string | ||
| for _, p := range append(setA, setB...) { | ||
| if !seen[p] { | ||
| seen[p] = true | ||
| merged = append(merged, p) | ||
| } | ||
| } | ||
| return merged | ||
| } | ||
|
|
||
| p1 := []string{"read", "write"} | ||
| p2 := []string{"write", "delete", "admin"} | ||
| res := unionPermissions(p1, p2) | ||
|
|
||
| if len(res) != 4 { | ||
| t.Errorf("expected 4 distinct permissions, got %d", len(res)) | ||
| } | ||
|
Comment on lines
+38
to
+40
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win Assert the merged permission values.
🤖 Prompt for AI Agents |
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Exercise production validation code in both tests. Both tests reimplement the expected algorithms in local closures, so they can pass while production behavior is broken.
internal/validation/wave5_cycle_detection_test.go#L9-L11: call the production self-reference validator and assert rejection of a circular relation tuple.internal/validation/wave5_cycle_detection_test.go#L22-L32: call the production permission-set merge and assert deduplication.📍 Affects 1 file
internal/validation/wave5_cycle_detection_test.go#L9-L11(this comment)internal/validation/wave5_cycle_detection_test.go#L22-L32🤖 Prompt for AI Agents