|
| 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.Lifecycle.Model; |
| 6 | +using ModularityKit.Mutator.Governance.Abstractions.Requests.Factory; |
| 7 | +using ModularityKit.Mutator.Governance.Abstractions.Requests.Model; |
| 8 | +using ModularityKit.Mutator.Governance.Runtime.Storage; |
| 9 | + |
| 10 | +namespace ModularityKit.Mutator.Benchmarks.Governance.Queries.Support; |
| 11 | + |
| 12 | +/// <summary> |
| 13 | +/// Seeds pending approval queue scenarios. |
| 14 | +/// </summary> |
| 15 | +internal static class PendingApprovalQueryBenchmarkSeed |
| 16 | +{ |
| 17 | + private static readonly DateTimeOffset BaseTime = new(2026, 6, 1, 14, 0, 0, TimeSpan.Zero); |
| 18 | + |
| 19 | + /// <summary> |
| 20 | + /// Creates a store preloaded with pending approval queue and noise data. |
| 21 | + /// </summary> |
| 22 | + public static InMemoryMutationRequestStore CreateStore() |
| 23 | + { |
| 24 | + var store = new InMemoryMutationRequestStore(); |
| 25 | + |
| 26 | + for (var index = 0; index < 64; index++) |
| 27 | + { |
| 28 | + var approverId = index % 2 == 0 ? "security-lead" : "platform-lead"; |
| 29 | + var category = index % 2 == 0 ? "Security" : "Platform"; |
| 30 | + |
| 31 | + var request = MutationRequestFactory.PendingApproval( |
| 32 | + stateId: "governance-benchmark:query-approval", |
| 33 | + stateType: "GovernanceState", |
| 34 | + mutationType: "GovernanceBenchmarkApprovalMutation", |
| 35 | + intent: CreateIntent(), |
| 36 | + context: MutationContext.User("requester", "Requester", "List pending approvals"), |
| 37 | + requirements: |
| 38 | + [ |
| 39 | + PolicyRequirement.Approval(approverId, "Benchmark approval") |
| 40 | + ], |
| 41 | + expectedStateVersion: "v10") |
| 42 | + with |
| 43 | + { |
| 44 | + RequestId = $"approval-request-{index:000}", |
| 45 | + Lifecycle = new MutationRequestLifecycleDetails |
| 46 | + { |
| 47 | + Status = MutationRequestStatus.Pending, |
| 48 | + PendingReason = PendingMutationReason.Approval, |
| 49 | + CreatedAt = BaseTime.AddMinutes(index), |
| 50 | + UpdatedAt = BaseTime.AddMinutes(index) |
| 51 | + }, |
| 52 | + ApprovalRequirements = |
| 53 | + [ |
| 54 | + new MutationApprovalRequirement |
| 55 | + { |
| 56 | + ApproverId = approverId, |
| 57 | + ApproverRole = category == "Security" ? "SecurityLead" : "PlatformLead", |
| 58 | + ApproverGroup = category.ToLowerInvariant(), |
| 59 | + Status = MutationApprovalRequirementStatus.Pending, |
| 60 | + StepOrder = 1 |
| 61 | + } |
| 62 | + ] |
| 63 | + }; |
| 64 | + |
| 65 | + store.Create(request).GetAwaiter().GetResult(); |
| 66 | + } |
| 67 | + |
| 68 | + for (var index = 0; index < 48; index++) |
| 69 | + { |
| 70 | + var request = new MutationRequest |
| 71 | + { |
| 72 | + RequestId = $"approval-noise-{index:000}", |
| 73 | + Scope = new MutationRequestScopeDetails |
| 74 | + { |
| 75 | + StateId = "governance-benchmark:query-approval", |
| 76 | + StateType = "GovernanceState", |
| 77 | + MutationType = "GovernanceBenchmarkCompletedMutation" |
| 78 | + }, |
| 79 | + Payload = new MutationRequestPayloadDetails |
| 80 | + { |
| 81 | + Intent = CreateIntent("CompletedApprovalNoise", "Completed governance approval noise"), |
| 82 | + Context = MutationContext.User("requester", "Requester", "Completed request") |
| 83 | + }, |
| 84 | + Lifecycle = new MutationRequestLifecycleDetails |
| 85 | + { |
| 86 | + Status = MutationRequestStatus.Approved, |
| 87 | + CreatedAt = BaseTime.AddHours(1).AddMinutes(index), |
| 88 | + UpdatedAt = BaseTime.AddHours(1).AddMinutes(index + 1) |
| 89 | + } |
| 90 | + }; |
| 91 | + |
| 92 | + store.Create(request).GetAwaiter().GetResult(); |
| 93 | + } |
| 94 | + |
| 95 | + return store; |
| 96 | + } |
| 97 | + |
| 98 | + private static MutationIntent CreateIntent() |
| 99 | + => new() |
| 100 | + { |
| 101 | + OperationName = "ListPendingApprovals", |
| 102 | + Category = "Governance", |
| 103 | + Description = "List pending approval queue entries", |
| 104 | + RiskLevel = MutationRiskLevel.Low, |
| 105 | + IsReversible = true |
| 106 | + }; |
| 107 | + |
| 108 | + private static MutationIntent CreateIntent(string operationName, string description) |
| 109 | + => new() |
| 110 | + { |
| 111 | + OperationName = operationName, |
| 112 | + Category = "Governance", |
| 113 | + Description = description, |
| 114 | + RiskLevel = MutationRiskLevel.Low, |
| 115 | + IsReversible = true |
| 116 | + }; |
| 117 | +} |
0 commit comments