Class: RosettAi::Composition::ConflictDetector

Inherits:
Object
  • Object
show all
Defined in:
lib/rosett_ai/composition/conflict_detector.rb

Overview

Detects rule ID collisions across behaviour files. When two behaviours define the same rule ID at the same scope and priority, this is a conflict that must be reported.

Instance Method Summary collapse

Instance Method Details

#detect(rules) ⇒ Array<String>

Detects rule ID collisions in a list of annotated rules.

Parameters:

  • rules (Array<Hash>)

    rules with :id, :behaviour_name, :scope, :priority

Returns:

  • (Array<String>)

    conflict descriptions



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/rosett_ai/composition/conflict_detector.rb', line 16

def detect(rules)
  conflicts = []
  seen = {}

  rules.each do |rule|
    rule_id = rule[:id]
    key = rule_id.to_s

    if seen.key?(key)
      existing = seen[key]
      conflicts << format_conflict(rule_id, existing, rule)
    else
      seen[key] = rule
    end
  end

  conflicts
end

#security_override?(existing, candidate) ⇒ Boolean

Checks if a security-domain rule would be overridden by a non-security rule. This is never allowed.

Parameters:

  • existing (Hash)

    the existing rule

  • candidate (Hash)

    the candidate replacement

Returns:

  • (Boolean)

    true if this is an invalid override



41
42
43
# File 'lib/rosett_ai/composition/conflict_detector.rb', line 41

def security_override?(existing, candidate)
  existing[:domain] == 'security' && candidate[:domain] != 'security'
end