Skip to content

Commit 5e6814a

Browse files
committed
Feat: Add soutions for composition example
1 parent c67063d commit 5e6814a

3 files changed

Lines changed: 87 additions & 0 deletions

File tree

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using ModularityKit.Mutator.Abstractions.Changes;
2+
using ModularityKit.Mutator.Abstractions.Context;
3+
using ModularityKit.Mutator.Abstractions.Engine;
4+
using ModularityKit.Mutator.Abstractions.Results;
5+
using PolicyComposition.State;
6+
7+
namespace PolicyComposition.Mutations;
8+
9+
/// <summary>
10+
/// Submits a release and carries the governance metadata consumed by the policies.
11+
/// </summary>
12+
/// <remarks>
13+
/// The mutation itself only moves the release into the submitted stage. The
14+
/// interesting governance behavior lives in the composed policies, which read the
15+
/// approval count, emergency flag, and target environment from the mutation
16+
/// context metadata.
17+
/// </remarks>
18+
internal sealed class SubmitReleaseMutation(
19+
string releaseName,
20+
int approvals,
21+
bool emergency,
22+
string environment) : MutationBase<ReleaseGateState>(
23+
CreateIntent(
24+
operationName: "SubmitRelease",
25+
category: "ReleaseGovernance",
26+
description: "Submit a release through composed governance policies"),
27+
MutationContext.User("release-manager", "Release Manager", "Release composition example")
28+
with
29+
{
30+
StateId = releaseName,
31+
Metadata = new Dictionary<string, object>
32+
{
33+
["approvals"] = approvals,
34+
["emergency"] = emergency,
35+
["environment"] = environment
36+
}
37+
})
38+
{
39+
/// <summary>
40+
/// Marks the release as submitted before policy composition evaluates it.
41+
/// </summary>
42+
/// <param name="state">The current release state.</param>
43+
/// <returns>A mutation result that moves the release into the submitted stage.</returns>
44+
public override MutationResult<ReleaseGateState> Apply(ReleaseGateState state)
45+
=> Success(
46+
state with { Stage = "Submitted" },
47+
StateChange.Modified("Stage", state.Stage, "Submitted"));
48+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net10.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
<GenerateDocumentationFile>true</GenerateDocumentationFile>
9+
<NoWarn>$(NoWarn);1591</NoWarn>
10+
<UseAppHost>false</UseAppHost>
11+
</PropertyGroup>
12+
13+
<ItemGroup>
14+
<ProjectReference Include="..\..\..\src\ModularityKit.Mutator.csproj" />
15+
</ItemGroup>
16+
17+
</Project>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using PolicyComposition.Scenarios;
2+
3+
namespace PolicyCompositionExample;
4+
5+
/// <summary>
6+
/// Entry point for the policy composition example.
7+
/// </summary>
8+
internal static class Program
9+
{
10+
/// <summary>
11+
/// Runs the four sample scenarios for composed governance policies.
12+
/// </summary>
13+
private static async Task Main()
14+
{
15+
Console.WriteLine("=== Policy Composition Example ===\n");
16+
17+
await AllOfScenario.Run();
18+
await AnyOfScenario.Run();
19+
await PriorityScenario.Run();
20+
await ConflictScenario.Run();
21+
}
22+
}

0 commit comments

Comments
 (0)