< Summary

Information
Class: Intentum.Runtime.Engine.ContextAwarePolicyEngine
Assembly: Intentum.Runtime
File(s): /home/runner/work/Intentum/Intentum/src/Intentum.Runtime/Engine/ContextAwarePolicyEngine.cs
Line coverage
100%
Covered lines: 9
Uncovered lines: 0
Coverable lines: 9
Total lines: 36
Line coverage: 100%
Branch coverage
100%
Covered branches: 4
Total branches: 4
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
Evaluate(...)100%22100%
EvaluateWithRule(...)100%22100%

File(s)

/home/runner/work/Intentum/Intentum/src/Intentum.Runtime/Engine/ContextAwarePolicyEngine.cs

#LineLine coverage
 1using Intentum.Core.Intents;
 2using Intentum.Runtime.Policy;
 3
 4namespace Intentum.Runtime.Engine;
 5
 6/// <summary>
 7/// Context-aware policy evaluation: decides using both intent and context (system load, region, etc.).
 8/// </summary>
 9public static class ContextAwarePolicyEngine
 10{
 11    /// <summary>
 12    /// Evaluates the intent with the given context and context-aware policy.
 13    /// First matching rule wins; default is Observe.
 14    /// </summary>
 15    public static PolicyDecision Evaluate(
 16        Intent intent,
 17        PolicyContext context,
 18        ContextAwareIntentPolicy policy)
 319    {
 520        var matchingRule = policy.Rules.FirstOrDefault(rule => rule.Condition(intent, context));
 321        return matchingRule?.Decision ?? PolicyDecision.Observe;
 322    }
 23
 24    /// <summary>
 25    /// Evaluates and returns the decision plus the matched rule (if any).
 26    /// </summary>
 27    public static (PolicyDecision Decision, ContextAwarePolicyRule? MatchedRule) EvaluateWithRule(
 28        Intent intent,
 29        PolicyContext context,
 30        ContextAwareIntentPolicy policy)
 231    {
 332        var matchingRule = policy.Rules.FirstOrDefault(rule => rule.Condition(intent, context));
 233        var decision = matchingRule?.Decision ?? PolicyDecision.Observe;
 234        return (decision, matchingRule);
 235    }
 36}