Skip to content

Add BFSDetector as second default cycle detector#1667

Closed
Copilot wants to merge 5 commits into
masterfrom
copilot/add-second-default-detector
Closed

Add BFSDetector as second default cycle detector#1667
Copilot wants to merge 5 commits into
masterfrom
copilot/add-second-default-detector

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 8, 2026

Adds a second default detector implementing Kahn's algorithm (topological sort) for cycle detection in role inheritance graphs, running alongside the existing DFS-based detector.

Implementation

  • detector/bfs_detector.go: New BFSDetector implementing the Detector interface using Kahn's algorithm with container/list for O(1) queue operations
  • detector/bfs_detector_test.go: Comprehensive test suite mirroring DefaultDetector tests (nil checks, simple/complex cycles, self-loops, disconnected components, diamond patterns, performance with 10K nodes)
  • enforcer.go: Initialize with both detectors by default: []detector.Detector{detector.NewDefaultDetector(), detector.NewBFSDetector()}
  • enforcer_test.go: Integration test verifying both detectors work together

Algorithm Difference

  • DefaultDetector (DFS): Detects cycles during traversal, returns exact cycle path
  • BFSDetector (Kahn's): Topological sort approach, identifies all nodes involved in any cycle

Both run on policy load via RunDetections(). Users can still override with SetDetector() or SetDetectors() if desired.

e, _ := NewEnforcer("model.conf", "policy.csv")
// Both detectors automatically initialized and run during LoadPolicy
Original prompt

This section details on the original issue you should resolve

<issue_title>[feature] add second default detector</issue_title>
<issue_description></issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@hsluoyz hsluoyz marked this pull request as ready for review January 8, 2026 16:32
Copilot AI and others added 4 commits January 8, 2026 16:37
Co-authored-by: hsluoyz <3787410+hsluoyz@users.noreply.github.com>
Co-authored-by: hsluoyz <3787410+hsluoyz@users.noreply.github.com>
…code review feedback

Co-authored-by: hsluoyz <3787410+hsluoyz@users.noreply.github.com>
Co-authored-by: hsluoyz <3787410+hsluoyz@users.noreply.github.com>
Copilot AI changed the title [WIP] Add second default detector feature Add BFSDetector as second default cycle detector Jan 8, 2026
Copilot AI requested a review from hsluoyz January 8, 2026 16:50
@hsluoyz hsluoyz closed this Jan 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[feature] add second default detector: EffectConflictDetector

3 participants