|
| 1 | +using ModularityKit.Mutator.Abstractions.Context; |
| 2 | +using ModularityKit.Mutator.Abstractions.Intent; |
| 3 | +using ModularityKit.Mutator.Abstractions.Policies; |
| 4 | +using ModularityKit.Mutator.Governance.Abstractions.Approval.Model; |
| 5 | +using ModularityKit.Mutator.Governance.Abstractions.Requests.Factory; |
| 6 | +using ModularityKit.Mutator.Governance.Abstractions.Requests.Model; |
| 7 | + |
| 8 | +namespace ModularityKit.Mutator.Benchmarks.Governance.Approval.Support; |
| 9 | + |
| 10 | +/// <summary> |
| 11 | +/// Builds repeatable approval workflow benchmark fixtures. |
| 12 | +/// </summary> |
| 13 | +internal static class ApprovalWorkflowBenchmarkSupport |
| 14 | +{ |
| 15 | + /// <summary> |
| 16 | + /// Creates a pending approval request with one approval requirement. |
| 17 | + /// </summary> |
| 18 | + public static MutationRequest CreatePendingApprovalRequest( |
| 19 | + string requestId, |
| 20 | + DateTimeOffset? expiresAt = null) |
| 21 | + => MutationRequestFactory.PendingApproval( |
| 22 | + stateId: "governance-benchmark:approval", |
| 23 | + stateType: "GovernanceState", |
| 24 | + mutationType: "ApproveGovernanceMutation", |
| 25 | + intent: CreateIntent(), |
| 26 | + context: MutationContext.User("requester", "Requester", "Need approval"), |
| 27 | + requirements: |
| 28 | + [ |
| 29 | + PolicyRequirement.Approval("alice", "Manager approval") |
| 30 | + ], |
| 31 | + expectedStateVersion: "v10", |
| 32 | + expiresAt: expiresAt) |
| 33 | + with |
| 34 | + { |
| 35 | + RequestId = requestId |
| 36 | + }; |
| 37 | + |
| 38 | + /// <summary> |
| 39 | + /// Creates a pending approval request with two sequential approval requirements. |
| 40 | + /// </summary> |
| 41 | + public static MutationRequest CreateTwoStepApprovalRequest(string requestId) |
| 42 | + => MutationRequestFactory.PendingApproval( |
| 43 | + stateId: "governance-benchmark:approval", |
| 44 | + stateType: "GovernanceState", |
| 45 | + mutationType: "ApproveGovernanceMutation", |
| 46 | + intent: CreateIntent(), |
| 47 | + context: MutationContext.User("requester", "Requester", "Need approval"), |
| 48 | + requirements: |
| 49 | + [ |
| 50 | + PolicyRequirement.Approval("alice", "Manager approval"), |
| 51 | + PolicyRequirement.Approval("bob", "Security approval") |
| 52 | + ], |
| 53 | + expectedStateVersion: "v10") |
| 54 | + with |
| 55 | + { |
| 56 | + RequestId = requestId |
| 57 | + }; |
| 58 | + |
| 59 | + /// <summary> |
| 60 | + /// Creates a request that already has an expired approval requirement. |
| 61 | + /// </summary> |
| 62 | + public static MutationRequest CreateExpiredApprovalRequest(string requestId) |
| 63 | + => CreatePendingApprovalRequest( |
| 64 | + requestId, |
| 65 | + DateTimeOffset.UtcNow.AddMinutes(-5)); |
| 66 | + |
| 67 | + /// <summary> |
| 68 | + /// Creates a pending approval request driven by role metadata. |
| 69 | + /// </summary> |
| 70 | + public static MutationRequest CreateRoleBasedApprovalRequest(string requestId) |
| 71 | + => MutationRequestFactory.PendingApproval( |
| 72 | + stateId: "governance-benchmark:approval-role", |
| 73 | + stateType: "GovernanceState", |
| 74 | + mutationType: "ApproveGovernanceMutation", |
| 75 | + intent: CreateIntent(), |
| 76 | + context: MutationContext.User("requester", "Requester", "Need role-based approval"), |
| 77 | + requirements: |
| 78 | + [ |
| 79 | + new PolicyRequirement |
| 80 | + { |
| 81 | + Type = "Approval", |
| 82 | + Description = "Role approval", |
| 83 | + Data = new |
| 84 | + { |
| 85 | + ApproverRole = "security-approver", |
| 86 | + StepOrder = 1, |
| 87 | + Reason = "Role-based sign-off" |
| 88 | + } |
| 89 | + } |
| 90 | + ], |
| 91 | + expectedStateVersion: "v10") |
| 92 | + with |
| 93 | + { |
| 94 | + RequestId = requestId |
| 95 | + }; |
| 96 | + |
| 97 | + /// <summary> |
| 98 | + /// Creates the intent used by approval workflow benchmark scenarios. |
| 99 | + /// </summary> |
| 100 | + public static MutationIntent CreateIntent() |
| 101 | + => new() |
| 102 | + { |
| 103 | + OperationName = "ApproveGovernanceChange", |
| 104 | + Category = "Governance", |
| 105 | + Description = "Approve governance request in benchmark workflow" |
| 106 | + }; |
| 107 | + |
| 108 | + /// <summary> |
| 109 | + /// Creates a user context used for benchmark approval decisions. |
| 110 | + /// </summary> |
| 111 | + public static MutationContext CreateDecisionContext(string actorId, string reason) |
| 112 | + => MutationContext.User(actorId, actorId, reason); |
| 113 | + |
| 114 | + /// <summary> |
| 115 | + /// Creates structured rejection payload for benchmark scenarios. |
| 116 | + /// </summary> |
| 117 | + public static MutationApprovalRejectionReason CreateRejectionReason() |
| 118 | + => new() |
| 119 | + { |
| 120 | + Code = "benchmark-rejection", |
| 121 | + Category = "policy", |
| 122 | + Message = "Benchmark rejection path" |
| 123 | + }; |
| 124 | + |
| 125 | + /// <summary> |
| 126 | + /// Creates a mutation context that carries approval roles for role-based resolution. |
| 127 | + /// </summary> |
| 128 | + public static MutationContext CreateRoleDecisionContext( |
| 129 | + string actorId, |
| 130 | + string actorName, |
| 131 | + string reason, |
| 132 | + params string[] roles) |
| 133 | + => MutationContext.User(actorId, actorName, reason) with |
| 134 | + { |
| 135 | + Metadata = new Dictionary<string, object> |
| 136 | + { |
| 137 | + ["ActorRoles"] = roles |
| 138 | + } |
| 139 | + }; |
| 140 | +} |
0 commit comments