-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPriorityScenario.cs
More file actions
64 lines (56 loc) · 2.5 KB
/
Copy pathPriorityScenario.cs
File metadata and controls
64 lines (56 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using ModularityKit.Mutator.Abstractions.Policies;
using PolicyComposition.Mutations;
using PolicyComposition.Policies;
using PolicyComposition.State;
namespace PolicyComposition.Scenarios;
/// <summary>
/// Demonstrates the priority-based composition mode for deterministic policy selection.
/// </summary>
/// <remarks>
/// This scenario evaluates the deployment gate twice: once for a staging release
/// and once for a production release. The first path shows the fallback branch
/// being selected, while the second path shows the guard policy short-circuiting
/// the composition with a decisive denial.
/// </remarks>
internal static class PriorityScenario
{
/// <summary>
/// Evaluates the deployment gate for staging and production inputs.
/// </summary>
/// <remarks>
/// The two inputs only differ by environment, which keeps the example focused
/// on priority ordering rather than on unrelated mutation state.
/// </remarks>
public static async Task Run()
{
var state = new ReleaseGateState("release-42", "Draft", "platform");
var stagingMutation = new SubmitReleaseMutation(
releaseName: state.ReleaseName,
approvals: 1,
emergency: false,
environment: "staging");
var productionMutation = new SubmitReleaseMutation(
releaseName: state.ReleaseName,
approvals: 1,
emergency: false,
environment: "production");
Console.WriteLine(" staging path:");
WriteDecision(await ReleaseGovernancePolicies.DeploymentGate().EvaluateAsync(stagingMutation, state));
Console.WriteLine(" production path:");
WriteDecision(await ReleaseGovernancePolicies.DeploymentGate().EvaluateAsync(productionMutation, state));
}
/// <summary>
/// Writes the outcome of the priority-based composition.
/// </summary>
/// <param name="decision">The composed policy decision returned by the gate.</param>
private static void WriteDecision(PolicyDecision decision)
{
Console.WriteLine($" allowed: {decision.IsAllowed}");
Console.WriteLine($" reason: {decision.Reason}");
Console.WriteLine($" selected: {string.Join(", ", (string[])decision.Metadata!["PolicyComposition.WinningPolicies"])}");
if (decision.Modifications is not null && decision.Modifications.TryGetValue("State", out var value) && value is ReleaseGateState state)
{
Console.WriteLine($" stage: {state.Stage}");
}
}
}