|
| 1 | +using ModularityKit.Mutator.Abstractions.Context; |
| 2 | +using ModularityKit.Mutator.Abstractions.Intent; |
| 3 | +using ModularityKit.Mutator.Governance.Abstractions.Lifecycle.Model; |
| 4 | +using ModularityKit.Mutator.Governance.Abstractions.Requests.Factory; |
| 5 | +using ModularityKit.Mutator.Governance.Abstractions.Requests.Model; |
| 6 | + |
| 7 | +namespace ModularityKit.Mutator.Benchmarks.Governance.Lifecycle.Support; |
| 8 | + |
| 9 | +/// <summary> |
| 10 | +/// Builds repeatable request lifecycle benchmark fixtures. |
| 11 | +/// </summary> |
| 12 | +internal static class RequestLifecycleBenchmarkSupport |
| 13 | +{ |
| 14 | + /// <summary> |
| 15 | + /// Creates a pending request used for lifecycle submission and terminal transition benchmarks. |
| 16 | + /// </summary> |
| 17 | + public static MutationRequest CreatePendingRequest( |
| 18 | + string requestId, |
| 19 | + DateTimeOffset? expiresAt = null) |
| 20 | + => MutationRequestFactory.Pending( |
| 21 | + stateId: "governance-benchmark:lifecycle", |
| 22 | + stateType: "GovernanceState", |
| 23 | + mutationType: "ManageGovernanceMutation", |
| 24 | + intent: CreateIntent(), |
| 25 | + context: MutationContext.User("requester", "Requester", "Need lifecycle processing"), |
| 26 | + pendingReason: PendingMutationReason.Approval, |
| 27 | + expectedStateVersion: "v12", |
| 28 | + expiresAt: expiresAt) |
| 29 | + with |
| 30 | + { |
| 31 | + RequestId = requestId |
| 32 | + }; |
| 33 | + |
| 34 | + /// <summary> |
| 35 | + /// Creates a pending request that is already due for expiration sweeps. |
| 36 | + /// </summary> |
| 37 | + public static MutationRequest CreateExpiredRequest(string requestId) |
| 38 | + => CreatePendingRequest( |
| 39 | + requestId, |
| 40 | + DateTimeOffset.UtcNow.AddMinutes(-5)); |
| 41 | + |
| 42 | + /// <summary> |
| 43 | + /// Creates an approved request used to exercise the lifecycle manager approval path. |
| 44 | + /// </summary> |
| 45 | + public static MutationRequest CreateApprovedRequest(string requestId) |
| 46 | + => MutationRequestFactory.Approved( |
| 47 | + stateId: "governance-benchmark:lifecycle", |
| 48 | + stateType: "GovernanceState", |
| 49 | + mutationType: "ManageGovernanceMutation", |
| 50 | + intent: CreateIntent(), |
| 51 | + context: MutationContext.User("requester", "Requester", "Need lifecycle processing"), |
| 52 | + expectedStateVersion: "v12") |
| 53 | + with |
| 54 | + { |
| 55 | + RequestId = requestId |
| 56 | + }; |
| 57 | + |
| 58 | + /// <summary> |
| 59 | + /// Creates the intent used by request lifecycle benchmark scenarios. |
| 60 | + /// </summary> |
| 61 | + public static MutationIntent CreateIntent() |
| 62 | + => new() |
| 63 | + { |
| 64 | + OperationName = "ManageGovernanceRequest", |
| 65 | + Category = "Governance", |
| 66 | + Description = "Manage governance request lifecycle in benchmark" |
| 67 | + }; |
| 68 | + |
| 69 | + /// <summary> |
| 70 | + /// Creates a decision context used for lifecycle transitions. |
| 71 | + /// </summary> |
| 72 | + public static MutationContext CreateDecisionContext( |
| 73 | + string actorId, |
| 74 | + string actorName, |
| 75 | + string reason) |
| 76 | + => MutationContext.User(actorId, actorName, reason); |
| 77 | + |
| 78 | + /// <summary> |
| 79 | + /// Creates a sweep context used for expiration benchmarks. |
| 80 | + /// </summary> |
| 81 | + public static MutationContext CreateSweepContext() |
| 82 | + => MutationContext.Service("lifecycle-sweeper", "Expire pending governance requests"); |
| 83 | +} |
0 commit comments