Skip to content

Commit 97f4adc

Browse files
committed
feat(abstractions): add async mutation policy contract
1 parent 0267129 commit 97f4adc

2 files changed

Lines changed: 29 additions & 5 deletions

File tree

src/Abstractions/MutationEngineOptions.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@ public sealed class MutationEngineOptions
3636
/// </remarks>
3737
public TimeSpan? ExecutionTimeout { get; set; }
3838

39+
/// <summary>
40+
/// The maximum allowed evaluation time for a single policy.
41+
/// </summary>
42+
/// <remarks>
43+
/// When specified, each registered policy evaluation gets its own timeout window.
44+
/// This is primarily intended for async policies that call external identity, ticketing,
45+
/// quota, or compliance systems.
46+
/// </remarks>
47+
public TimeSpan? PolicyEvaluationTimeout { get; set; }
48+
3949
/// <summary>
4050
/// Indicates whether batch execution should stop after the first failure.
4151
/// </summary>
@@ -49,7 +59,7 @@ public sealed class MutationEngineOptions
4959
/// Enables collection of detailed execution metrics.
5060
/// </summary>
5161
/// <remarks>
52-
/// Detailed metrics provide deep observability but may have a measurable
62+
/// Detailed metrics provide deep observability but may have measurable
5363
/// performance impact in high-throughput scenarios.
5464
/// </remarks>
5565
public bool EnableDetailedMetrics { get; set; } = false;
@@ -82,7 +92,7 @@ public sealed class MutationEngineOptions
8292
};
8393

8494
/// <summary>
85-
/// Performance-oriented configuration minimizing overhead.
95+
/// Performance oriented configuration minimizing overhead.
8696
/// </summary>
8797
/// <remarks>
8898
/// Intended for trusted environments where validation and detailed metrics

src/Abstractions/Policies/IMutationPolicy.cs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
namespace ModularityKit.Mutator.Abstractions.Policies;
44

55
/// <summary>
6-
/// Represents a policy that decides whether a mutation can be applied.
7-
/// Policies are a FIRST-CLASS governance mechanism in the mutation framework.
6+
/// Represents policy that decides whether a mutation can be applied.
7+
/// Policies are FIRST CLASS governance mechanism in the mutation framework.
88
/// </summary>
99
/// <typeparam name="TState">Type of the state the mutation operates on.</typeparam>
1010
public interface IMutationPolicy<TState>
@@ -31,5 +31,19 @@ public interface IMutationPolicy<TState>
3131
/// <param name="mutation">The mutation to evaluate.</param>
3232
/// <param name="state">The current state before applying the mutation.</param>
3333
/// <returns>A <see cref="PolicyDecision"/> representing the result of the evaluation.</returns>
34-
PolicyDecision Evaluate(IMutation<TState> mutation, TState state);
34+
PolicyDecision Evaluate(IMutation<TState> mutation, TState state)
35+
=> throw new NotSupportedException("This policy does not implement synchronous evaluation.");
36+
37+
/// <summary>
38+
/// Evaluates whether the given mutation is allowed on the current state asynchronously.
39+
/// </summary>
40+
/// <param name="mutation">The mutation to evaluate.</param>
41+
/// <param name="state">The current state before applying the mutation.</param>
42+
/// <param name="cancellationToken">Token used to cancel the policy evaluation.</param>
43+
/// <returns>A <see cref="PolicyDecision"/> representing the result of the evaluation.</returns>
44+
Task<PolicyDecision> EvaluateAsync(
45+
IMutation<TState> mutation,
46+
TState state,
47+
CancellationToken cancellationToken = default)
48+
=> Task.FromResult(Evaluate(mutation, state));
3549
}

0 commit comments

Comments
 (0)