@cratis/pi 7.5.1 → 7.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package/corpus/rules/application-profile.md +2 -0
- package/package/corpus/rules/code-quality.csharp.md +1 -1
- package/package/corpus/rules/csharp.md +2 -0
- package/package/corpus/rules/reactors.md +1 -0
- package/package/corpus/rules/specs.scenarios.csharp.md +1 -0
- package/package/corpus/rules/vertical-slices.md +6 -1
- package/package/corpus/skills/cratis-arc-command/SKILL.md +27 -3
- package/package/corpus/skills/cratis-arc-command/references/handler-shapes.md +26 -7
- package/package/corpus/skills/cratis-arc-command-execution/SKILL.md +23 -2
- package/package/corpus/skills/cratis-arc-command-operation/LICENSE +2 -0
- package/package/corpus/skills/cratis-arc-command-operation/SKILL.md +277 -0
- package/package/corpus/skills/cratis-arc-command-operation/references/execution-and-recovery.md +229 -0
- package/package/corpus/skills/cratis-arc-command-operation/references/testing.md +252 -0
- package/package/corpus/skills/cratis-arc-command-operation/verification.json +19 -0
- package/package/corpus/skills/cratis-chronicle-reactor/SKILL.md +3 -0
- package/package/corpus/skills/cratis-screenplay-captures-and-reactions/SKILL.md +20 -0
- package/package/corpus/skills/cratis-screenplay-command-surface/SKILL.md +3 -0
- package/package/corpus/skills/cratis-screenplay-event-modeling/SKILL.md +31 -1
- package/package/corpus/skills/cratis-screenplay-model-authoring/references/language-reference.md +19 -5
- package/package/corpus/skills/cratis-screenplay-read-surface/SKILL.md +7 -0
- package/package/corpus/skills/cratis-screenplay-specifications/SKILL.md +61 -9
- package/package/corpus/skills/cratis-screenplay-specifications/verification.json +12 -0
- package/package/profile-catalog.json +1 -0
- package/package.json +1 -1
package/package/corpus/skills/cratis-arc-command-operation/references/execution-and-recovery.md
ADDED
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
# Operation execution and recovery reference
|
|
2
|
+
|
|
3
|
+
Verified at **Arc v22.48.1** against the
|
|
4
|
+
[product reference](https://github.com/Cratis/Arc/blob/v22.48.1/Documentation/backend/csharp/commands/operations/reference.md)
|
|
5
|
+
and `Source/DotNET/Arc.Core/Commands/`. Types below are in
|
|
6
|
+
`Cratis.Arc.Commands`. Start with [the skill](../SKILL.md) to choose the boundary.
|
|
7
|
+
|
|
8
|
+
## Declaration contract
|
|
9
|
+
|
|
10
|
+
| Surface | Contract |
|
|
11
|
+
| --- | --- |
|
|
12
|
+
| `ICommandOperation` | Marker; immutable business-data record is the convention, not a record-only runtime requirement |
|
|
13
|
+
| `Execute(...)` | Exactly one public, non-generic, non-abstract instance method |
|
|
14
|
+
| `Compensate(...)` | Optional single public, non-generic, non-abstract instance method |
|
|
15
|
+
| Method return | Only `void`, `Task`, `ValueTask`; no receipt or further pipeline values |
|
|
16
|
+
| Services | Required method parameters resolved from the command's provider; no service captures |
|
|
17
|
+
| `CancellationToken` | At most one per method, supplied by Arc |
|
|
18
|
+
| `CommandOperationFailure` | At most one, only on `Compensate` |
|
|
19
|
+
| Accessibility | Non-file-local, non-generic public/internal operation in accessible non-generic containing types |
|
|
20
|
+
|
|
21
|
+
No `async void`, static/generic methods, overloads, optional/`params`/by-ref or
|
|
22
|
+
pointer parameters. Service locators (`IServiceProvider`, `IServiceScopeFactory`,
|
|
23
|
+
`IServiceScope`, including implementing types) are forbidden parameters.
|
|
24
|
+
`ARC0016` checks method conventions, `ARC0017` checks bare operation collections,
|
|
25
|
+
and `ARC0018` checks accessibility for generated invokers. The generator emits
|
|
26
|
+
typed calls; validated reflection fallback covers source-free declarations.
|
|
27
|
+
This is not a claim of whole-host NativeAOT support.
|
|
28
|
+
|
|
29
|
+
## Returned values
|
|
30
|
+
|
|
31
|
+
| Return shape | Treatment |
|
|
32
|
+
| --- | --- |
|
|
33
|
+
| Concrete operation or `ICommandOperation` | Execute on the server |
|
|
34
|
+
| Nullable operation, including nullable value type | Null is absent; present value remains server-only |
|
|
35
|
+
| `CommandOperations` | Ordered immutable batch membership, materialized once; null elements rejected |
|
|
36
|
+
| `[]` / `default(CommandOperations)` | Empty batch |
|
|
37
|
+
| Nullable batch | Present value is server-only; prefer an empty non-nullable batch |
|
|
38
|
+
| Tuple | Flatten values; at most one ordinary client response |
|
|
39
|
+
| `Result` / `OneOf` | Flatten only the active alternative, including tuple alternatives |
|
|
40
|
+
| `Task<T>` / `ValueTask<T>` | Await the handler, then classify its result |
|
|
41
|
+
| Ordinary array/enumerable | Ordinary response classification, not an operation batch |
|
|
42
|
+
|
|
43
|
+
Bare collections of operations are rejected; use `CommandOperations`.
|
|
44
|
+
Participation is decided from the declared return type, and only tuples and
|
|
45
|
+
`Result`/`OneOf` are unwrapped: a top-level operation under an `object`
|
|
46
|
+
signature is rejected, while an operation inside `IEnumerable<object>`/`object[]`
|
|
47
|
+
is treated as response data and silently not executed. Combine events and
|
|
48
|
+
operations with a tuple, e.g. `(IEnumerable<object>, CommandOperations)`. Operations bypass
|
|
49
|
+
ordinary response handlers and never become client/proxy response types.
|
|
50
|
+
|
|
51
|
+
## Nine-step ordering
|
|
52
|
+
|
|
53
|
+
1. Run authorization, validation, `Provide()`, and `Handle()`.
|
|
54
|
+
2. Classify the return graph; validate operation metadata and preflight both
|
|
55
|
+
execution and compensation dependencies before starting work.
|
|
56
|
+
3. Process control values before other server values, regardless of tuple order;
|
|
57
|
+
enroll returned Chronicle events before operation execution.
|
|
58
|
+
4. If still successful and the commit boundary permits entry, execute operations
|
|
59
|
+
sequentially in declaration order.
|
|
60
|
+
5. Record each invocation immediately before entering `Execute()`, after
|
|
61
|
+
dependency resolution and cancellation checks.
|
|
62
|
+
6. Stop starting operations after execution failure or cancellation.
|
|
63
|
+
7. Complete required execution scopes in reverse scope order and obtain
|
|
64
|
+
conservative commitment facts, including when completion failed.
|
|
65
|
+
8. Run eligible compensators in reverse invocation order; a failed compensator
|
|
66
|
+
does not erase the original failure or prevent remaining eligible callbacks.
|
|
67
|
+
9. Publish backend observations and clear the result response if unsuccessful.
|
|
68
|
+
|
|
69
|
+
The throwing operation **is started** and eligible for compensation. Never-entered
|
|
70
|
+
operations are not. Dependency preflight is not entry. Direct calls to `Handle`,
|
|
71
|
+
`Execute`, or `Compensate` are ordinary C# calls without this orchestration.
|
|
72
|
+
|
|
73
|
+
## Commit and recovery
|
|
74
|
+
|
|
75
|
+
Failure plus started work requires a recovery decision; `!IsSuccess` does not
|
|
76
|
+
establish non-commit.
|
|
77
|
+
|
|
78
|
+
| `CommandCommitDisposition` | Meaning | Recovery on failure |
|
|
79
|
+
| --- | --- | --- |
|
|
80
|
+
| `NoCommit` | No coordinated participant | Attempt declared compensation |
|
|
81
|
+
| `NotCommitted` | Coordinated changes known not committed | Attempt declared compensation |
|
|
82
|
+
| `Committed` | Known committed business boundary | `Suppressed` |
|
|
83
|
+
| `Unknown` | Commitment cannot be safely established | `Indeterminate`; no reversal |
|
|
84
|
+
| `Mixed` | Some changes committed, others did not | `Indeterminate`; no blanket reversal |
|
|
85
|
+
|
|
86
|
+
With Chronicle, returned events enroll before operations; automatic transaction
|
|
87
|
+
completion follows them. A known commit rejection permits recovery. An uncertain
|
|
88
|
+
acknowledgment does not. Pending events still undergo real transaction rollback
|
|
89
|
+
on command failure; compensation does not un-append events. Explicit aggregate
|
|
90
|
+
commits are not supported within operation boundaries, and already successful
|
|
91
|
+
immediate appends cannot be undone. Operations cannot start after an observed
|
|
92
|
+
early, unknown, or mixed commit.
|
|
93
|
+
|
|
94
|
+
Recovery is best-effort, in-process **new business work**, not atomic rollback.
|
|
95
|
+
There is no durable journal, automatic retry, or promised crash recovery.
|
|
96
|
+
Serialization/result delivery after the pipeline and arbitrary service writes
|
|
97
|
+
outside returned operations are not covered.
|
|
98
|
+
|
|
99
|
+
## Backend observations
|
|
100
|
+
|
|
101
|
+
`CommandResult.Recovery` is nullable; processing that never participates can leave
|
|
102
|
+
it absent. `OperationOutcomes` is an immutable list of entered invocations. Both
|
|
103
|
+
carry `[JsonIgnore]`: neither is part of HTTP JSON or the TypeScript result.
|
|
104
|
+
|
|
105
|
+
| `CommandRecoverySummary` member | Meaning |
|
|
106
|
+
| --- | --- |
|
|
107
|
+
| `CommitDisposition` | Observed coordinated commitment, not command success |
|
|
108
|
+
| `Status` | `CommandRecoveryStatus` decision/outcome |
|
|
109
|
+
| `StartedCount` | Entered `Execute` invocations |
|
|
110
|
+
| `CompletedCount` | `Execute` methods that returned successfully |
|
|
111
|
+
| `CompensatedCount` | `Compensate` methods that returned successfully |
|
|
112
|
+
| `FailedCompensationCount` | Compensators that threw |
|
|
113
|
+
| `UncompensatedCount` | Started work requiring recovery without observed completed compensation |
|
|
114
|
+
|
|
115
|
+
| `CommandRecoveryStatus` | Meaning |
|
|
116
|
+
| --- | --- |
|
|
117
|
+
| `NotNeeded` | No started work requires recovery |
|
|
118
|
+
| `Completed` | Every required compensator returned; not proof of atomic reversal |
|
|
119
|
+
| `Incomplete` | Compensation unavailable, failed, or budget exhausted |
|
|
120
|
+
| `Suppressed` | Business changes committed |
|
|
121
|
+
| `Indeterminate` | Commitment unknown or mixed |
|
|
122
|
+
|
|
123
|
+
Each `CommandOperationOutcome` exposes `InvocationIndex`, `OperationType`,
|
|
124
|
+
`ExecutionCompleted`, `Compensation`, and optional `CompensationFailure` message.
|
|
125
|
+
It carries no operation business properties.
|
|
126
|
+
|
|
127
|
+
| `CommandOperationCompensation` | Meaning |
|
|
128
|
+
| --- | --- |
|
|
129
|
+
| `NotNeeded` | Recovery not required |
|
|
130
|
+
| `Completed` | Compensator returned |
|
|
131
|
+
| `Failed` | Compensator threw or attempted unsupported nesting |
|
|
132
|
+
| `NotAvailable` | No compensator declared |
|
|
133
|
+
| `BudgetExpired` | Recovery budget expired before callback entry |
|
|
134
|
+
| `Suppressed` | Commit facts prohibit automatic reversal |
|
|
135
|
+
|
|
136
|
+
Keep these observations and messages in trusted diagnostics, correlated with
|
|
137
|
+
`CommandResult.CorrelationId`. Do not treat `Completed` as permission to retry.
|
|
138
|
+
|
|
139
|
+
## Optional failure context
|
|
140
|
+
|
|
141
|
+
`CommandOperationFailure` is immutable context for specialized compensators,
|
|
142
|
+
not a mutable command result or an external execution receipt.
|
|
143
|
+
|
|
144
|
+
| Member | Meaning |
|
|
145
|
+
| --- | --- |
|
|
146
|
+
| `InvocationIndex` | Zero-based invocation index |
|
|
147
|
+
| `InvocationCompleted` | Its `Execute()` returned successfully |
|
|
148
|
+
| `IsFailingInvocation` | This invocation threw the original execution failure |
|
|
149
|
+
| `Source` | `CommandOperationFailureSource`: `Planning`, `ResponseHandling`, `Execution`, `Cancellation`, `ScopeCompletion` |
|
|
150
|
+
| `CommitDisposition` | Facts used to select recovery |
|
|
151
|
+
| `ExceptionMessages` | Defensive snapshot of original exception messages; recovery failures are separate |
|
|
152
|
+
|
|
153
|
+
A false `InvocationCompleted` does not prove the provider made no change. Do not
|
|
154
|
+
skip necessary reversal solely because forward execution threw.
|
|
155
|
+
|
|
156
|
+
## Cancellation and budget
|
|
157
|
+
|
|
158
|
+
`Execute` receives the command token (normally request-aborted over HTTP).
|
|
159
|
+
`Compensate` receives an independent recovery token so disconnection does not
|
|
160
|
+
immediately cancel cleanup. `CommandOperationOptions.CompensationTimeout` is
|
|
161
|
+
shared across the recovery attempt, defaults to 30 seconds, and must be positive
|
|
162
|
+
and at most 4294967294 milliseconds.
|
|
163
|
+
|
|
164
|
+
Host configuration fragment, with `System`, `Cratis.Arc.Commands`, and
|
|
165
|
+
`Microsoft.Extensions.DependencyInjection` imported:
|
|
166
|
+
|
|
167
|
+
```csharp
|
|
168
|
+
builder.Services.Configure<CommandOperationOptions>(options =>
|
|
169
|
+
options.CompensationTimeout = TimeSpan.FromSeconds(10));
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
The budget is cooperative. A callback ignoring cancellation is still awaited;
|
|
173
|
+
Arc neither terminates it nor disposes its services underneath it. Not-yet-entered
|
|
174
|
+
callbacks are reported `BudgetExpired` after expiry. No automatic execution or
|
|
175
|
+
compensation retries occur; provider/driver policies can still retry internally.
|
|
176
|
+
|
|
177
|
+
## Supported scopes
|
|
178
|
+
|
|
179
|
+
Flat, sequential execution; at most one deferred commit participant. No
|
|
180
|
+
parallel/detached participation or durable recovery. Any same-host nested
|
|
181
|
+
`ICommandPipeline` call is refused (the child never runs) when the parent or the
|
|
182
|
+
child is operation-capable — from `Provide`, `Handle`, validators, `Execute` or
|
|
183
|
+
`Compensate`. Explicit commits inside the boundary are refused too. From
|
|
184
|
+
`Execute` a nested call rejects the batch even when its failed result is ignored. From `Compensate` it fails that compensation;
|
|
185
|
+
remaining eligible compensators still run.
|
|
186
|
+
|
|
187
|
+
Custom scopes implement `ICommandOperationExecutionScope`, extending
|
|
188
|
+
`ICommandExecutionScope`. Verify against the actual provider:
|
|
189
|
+
|
|
190
|
+
- `Begin(CommandContext)` does not commit; partial initialization is safe to clean up.
|
|
191
|
+
- `IsCommitParticipant` is stable and names responsibility, not the latest outcome.
|
|
192
|
+
- A nonparticipant truly does not commit business changes.
|
|
193
|
+
- `GetCommitDisposition(CommandContext)` is read **before operations start** as
|
|
194
|
+
well as after completion. While the deferred commit is still pending it must
|
|
195
|
+
report `NotCommitted` (or `NoCommit`); report `Committed`/`Unknown`/`Mixed`
|
|
196
|
+
only when an early or uncertain commit actually happened, otherwise Arc
|
|
197
|
+
refuses to start operations.
|
|
198
|
+
- It reports authoritative facts after `Complete` fails too; unavailable facts
|
|
199
|
+
mean `Unknown`, not `NotCommitted`.
|
|
200
|
+
- Known commit remains committed after a later scope fails. Scope completion
|
|
201
|
+
order is unchanged; never infer disposition from `IsSuccess` or a completed flag.
|
|
202
|
+
- Compensation can use its dependencies after completion; a live DI scope does
|
|
203
|
+
not repair a failed transaction/context. Preserve tenant and ownership context.
|
|
204
|
+
- Cancellation/disposal cannot invalidate resources under running recovery.
|
|
205
|
+
|
|
206
|
+
| Integration | Boundary |
|
|
207
|
+
| --- | --- |
|
|
208
|
+
| Standalone Arc | Registered application services; no automatic database transaction |
|
|
209
|
+
| Chronicle | Compatible deferred event commit with conservative commitment observations |
|
|
210
|
+
| EF Core | No built-in operation commit participant; registration does not call `SaveChanges` or coordinate operation writes |
|
|
211
|
+
| MongoDB | No built-in operation commit participant; sessions and driver resilience remain provider concerns |
|
|
212
|
+
|
|
213
|
+
Independent EF and Chronicle commits do not become atomic by sharing a command.
|
|
214
|
+
Do not label a committing scope nonparticipating to evade validation.
|
|
215
|
+
|
|
216
|
+
## Troubleshooting
|
|
217
|
+
|
|
218
|
+
| Symptom | Check |
|
|
219
|
+
| --- | --- |
|
|
220
|
+
| `Handle()` returns work but nothing runs | Use `ICommandPipeline` / `CommandScenario`, not a direct decision call |
|
|
221
|
+
| Zero operations entered | Authorization, validation, `Provide`, declaration/DI preflight, early commit, scope compatibility; `Validate` never executes work |
|
|
222
|
+
| `Recovery` absent | HTTP intentionally omits it; backend processing may not have participated |
|
|
223
|
+
| `Incomplete` recovery | Per-operation missing compensator, thrown compensation, or exhausted budget |
|
|
224
|
+
| `Suppressed` recovery | Known commit; a later failure is not permission to reverse it |
|
|
225
|
+
| `Indeterminate` recovery | Reconcile storage/provider facts; Arc scheduled no durable recovery |
|
|
226
|
+
| Cleanup outlives cancellation | Independent cooperative token; check provider cancellation support |
|
|
227
|
+
| Work repeats | Caller/reactor retries or provider resilience; verify ownership-safe idempotency |
|
|
228
|
+
| Ignored child result still rejects batch | Compose declarations instead of nested commands |
|
|
229
|
+
| No cleanup after process loss | Use reactor/outbox/workflow durability rather than an in-memory operation journal |
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
# Specify decisions, adapters, and pipeline composition
|
|
2
|
+
|
|
3
|
+
Verified at **Arc v22.48.1**. These class excerpts follow the product's
|
|
4
|
+
[standalone lesson](https://github.com/Cratis/Arc/blob/v22.48.1/Documentation/backend/csharp/testing/command-operations.md)
|
|
5
|
+
and [Chronicle rejection lesson](https://github.com/Cratis/Arc/blob/v22.48.1/Documentation/backend/csharp/testing/command-operations-with-chronicle.md).
|
|
6
|
+
Use `Cratis.Specifications.XUnit`, NSubstitute, and matching Arc packages in a
|
|
7
|
+
separate spec project. Keep standalone and Chronicle scenarios in separate
|
|
8
|
+
projects: Chronicle's discovered scenario extender changes the test environment.
|
|
9
|
+
|
|
10
|
+
The standalone examples reuse `ReservationId`, `SeatId`, `ISeatReservations`,
|
|
11
|
+
`ReserveSeat`, `BookSeat`, `SeatReservation`, and `BookSeats` from the
|
|
12
|
+
[application declarations](https://github.com/Cratis/Arc/blob/v22.48.1/Documentation/backend/csharp/commands/operations/implementing.md).
|
|
13
|
+
Add these imports to each standalone spec file (and its own namespace):
|
|
14
|
+
|
|
15
|
+
```csharp
|
|
16
|
+
using System;
|
|
17
|
+
using System.Threading;
|
|
18
|
+
using System.Threading.Tasks;
|
|
19
|
+
using Cratis.Arc.Commands;
|
|
20
|
+
using Cratis.Arc.Testing.Commands;
|
|
21
|
+
using Cratis.Specifications;
|
|
22
|
+
using Microsoft.Extensions.DependencyInjection;
|
|
23
|
+
using NSubstitute;
|
|
24
|
+
using SeatBooking;
|
|
25
|
+
using Xunit;
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Decision: direct Handle
|
|
29
|
+
|
|
30
|
+
No provider or container is needed. Fixed inputs and record equality prove the
|
|
31
|
+
proposed work, not its execution or authorization.
|
|
32
|
+
|
|
33
|
+
```csharp
|
|
34
|
+
public class when_deciding_to_book : Specification
|
|
35
|
+
{
|
|
36
|
+
readonly ReservationId _id = new(Guid.Parse("757660b8-55ac-4c1a-89cb-8151c8fd3562"));
|
|
37
|
+
readonly SeatId _seat = new("A-12");
|
|
38
|
+
(ReservationId Response, ReserveSeat Operation) _decision;
|
|
39
|
+
|
|
40
|
+
void Because() => _decision = new BookSeat(_id, _seat).Handle();
|
|
41
|
+
|
|
42
|
+
[Fact] void should_return_the_request_identifier() => _decision.Response.ShouldEqual(_id);
|
|
43
|
+
[Fact] void should_declare_the_reservation() =>
|
|
44
|
+
_decision.Operation.ShouldEqual(new ReserveSeat(_id, _seat));
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
For batches assert membership and order, including conditional/empty decisions.
|
|
49
|
+
Do not infer that calling `Handle()` performed any external work.
|
|
50
|
+
|
|
51
|
+
## Adapter: direct Execute and Compensate
|
|
52
|
+
|
|
53
|
+
This tests the provider mapping, not Arc's recovery selection:
|
|
54
|
+
|
|
55
|
+
```csharp
|
|
56
|
+
public class when_reserving_directly : Specification
|
|
57
|
+
{
|
|
58
|
+
readonly ReservationId _id = new(Guid.Parse("757660b8-55ac-4c1a-89cb-8151c8fd3562"));
|
|
59
|
+
readonly SeatId _seat = new("A-12");
|
|
60
|
+
ISeatReservations _reservations = null!;
|
|
61
|
+
|
|
62
|
+
void Establish()
|
|
63
|
+
{
|
|
64
|
+
_reservations = Substitute.For<ISeatReservations>();
|
|
65
|
+
_reservations.Reserve(_id, _seat, CancellationToken.None).Returns(Task.CompletedTask);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
Task Because() => new ReserveSeat(_id, _seat).Execute(_reservations, CancellationToken.None);
|
|
69
|
+
|
|
70
|
+
[Fact] Task should_reserve_the_requested_seat() =>
|
|
71
|
+
_reservations.Received(1).Reserve(_id, _seat, CancellationToken.None);
|
|
72
|
+
[Fact] Task should_not_cancel() =>
|
|
73
|
+
_reservations.DidNotReceive().Cancel(Arg.Any<ReservationId>(), Arg.Any<CancellationToken>());
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
For the reversal's own spec, arrange `Cancel` to return `Task.CompletedTask`,
|
|
78
|
+
call `new ReserveSeat(_id, _seat).Compensate(_reservations, CancellationToken.None)`
|
|
79
|
+
in `Because`, and assert `Received(1).Cancel(_id, CancellationToken.None)` plus no
|
|
80
|
+
`Reserve` call. A direct throwing `Execute` does not automatically compensate.
|
|
81
|
+
|
|
82
|
+
## Composition: forward failure and reverse compensation
|
|
83
|
+
|
|
84
|
+
Reference `Cratis.Arc.Testing`. `CommandScenario<TCommand>` runs the real pipeline
|
|
85
|
+
and invokers, not a recording stub. Register substitutes through `Services`
|
|
86
|
+
before first execution; do not register a production external client.
|
|
87
|
+
|
|
88
|
+
This case fails the second reservation. Both entered invocations must be
|
|
89
|
+
compensated; the third must never start.
|
|
90
|
+
|
|
91
|
+
```csharp
|
|
92
|
+
public class ReservationProviderUnavailable() : Exception("Reservation provider unavailable.");
|
|
93
|
+
|
|
94
|
+
public class when_the_second_reservation_fails : Specification
|
|
95
|
+
{
|
|
96
|
+
readonly CommandScenario<BookSeats> _scenario = new();
|
|
97
|
+
readonly ReservationId _first = new(Guid.Parse("757660b8-55ac-4c1a-89cb-8151c8fd3562"));
|
|
98
|
+
readonly ReservationId _second = new(Guid.Parse("b52a8554-fab3-4050-af81-554d105d9b9d"));
|
|
99
|
+
readonly ReservationId _third = new(Guid.Parse("0aeb4b2f-0515-44fe-8e79-7c8f304d2c65"));
|
|
100
|
+
ISeatReservations _reservations = null!;
|
|
101
|
+
CommandResult _result = null!;
|
|
102
|
+
|
|
103
|
+
void Establish()
|
|
104
|
+
{
|
|
105
|
+
_reservations = Substitute.For<ISeatReservations>();
|
|
106
|
+
_reservations.Reserve(Arg.Any<ReservationId>(), Arg.Any<SeatId>(), Arg.Any<CancellationToken>())
|
|
107
|
+
.Returns(Task.CompletedTask);
|
|
108
|
+
_reservations.Reserve(_second, Arg.Any<SeatId>(), Arg.Any<CancellationToken>())
|
|
109
|
+
.Returns(Task.FromException(new ReservationProviderUnavailable()));
|
|
110
|
+
_reservations.Cancel(Arg.Any<ReservationId>(), Arg.Any<CancellationToken>())
|
|
111
|
+
.Returns(Task.CompletedTask);
|
|
112
|
+
_scenario.Services.AddSingleton(_reservations);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
async Task Because() => _result = await _scenario.Execute(new BookSeats(
|
|
116
|
+
[
|
|
117
|
+
new SeatReservation(_first, new SeatId("A-12")),
|
|
118
|
+
new SeatReservation(_second, new SeatId("A-13")),
|
|
119
|
+
new SeatReservation(_third, new SeatId("A-14"))
|
|
120
|
+
]));
|
|
121
|
+
|
|
122
|
+
[Fact] void should_preserve_failure() => _result.ShouldNotBeSuccessful();
|
|
123
|
+
[Fact] void should_preserve_the_original_error() =>
|
|
124
|
+
_result.ExceptionMessages.ShouldContain("Reservation provider unavailable.");
|
|
125
|
+
[Fact] void should_record_only_entered_invocations() => _scenario.Operations.Count.ShouldEqual(2);
|
|
126
|
+
[Fact] void should_observe_the_first_execution_completing() =>
|
|
127
|
+
_scenario.Operations[0].ExecutionCompleted.ShouldBeTrue();
|
|
128
|
+
[Fact] void should_observe_the_throwing_execution() =>
|
|
129
|
+
_scenario.Operations[1].ExecutionCompleted.ShouldBeFalse();
|
|
130
|
+
[Fact] Task should_not_start_the_third() =>
|
|
131
|
+
_reservations.DidNotReceive().Reserve(_third, Arg.Any<SeatId>(), Arg.Any<CancellationToken>());
|
|
132
|
+
[Fact] void should_compensate_in_reverse_order() => Received.InOrder(() =>
|
|
133
|
+
{
|
|
134
|
+
_ = _reservations.Cancel(_second, Arg.Any<CancellationToken>());
|
|
135
|
+
_ = _reservations.Cancel(_first, Arg.Any<CancellationToken>());
|
|
136
|
+
});
|
|
137
|
+
[Fact] void should_observe_both_compensations() => _result.Recovery!.CompensatedCount.ShouldEqual(2);
|
|
138
|
+
[Fact] void should_report_callback_completion() =>
|
|
139
|
+
_result.Recovery!.Status.ShouldEqual(CommandRecoveryStatus.Completed);
|
|
140
|
+
|
|
141
|
+
void Destroy() => _scenario.Dispose();
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
`Operations` snapshots the latest `Execute`'s entered invocations, including the
|
|
146
|
+
throwing one. `ShouldHaveExecutedOperation<T>()` requires at least one matching
|
|
147
|
+
execution to have **completed**; it does not mean every operation of that type
|
|
148
|
+
succeeded. Pair it with exact counts, indices, and provider arguments as needed.
|
|
149
|
+
`ShouldHaveCompensatedOperation<T>()` likewise proves a callback returned, not
|
|
150
|
+
provider durability. A lone unsuccessful-result assertion could pass because
|
|
151
|
+
DI failed before any work began.
|
|
152
|
+
|
|
153
|
+
## Chronicle: a real commit rejection
|
|
154
|
+
|
|
155
|
+
Reference `Cratis.Arc.Chronicle.Testing` and the `Cratis.Arc` test-host dependency.
|
|
156
|
+
Reuse the `Onboarding` declarations from the linked Chronicle lesson:
|
|
157
|
+
`StartOnboarding(EventSourceId, OrganizationNumber, ReservationKey)` returns
|
|
158
|
+
`OnboardingStarted` plus `ReserveOnboardingCapacity`. The event declares
|
|
159
|
+
`UniqueOrganizationNumber` uniqueness. Import `Onboarding` instead of
|
|
160
|
+
`SeatBooking`, plus `Cratis.Arc.Chronicle.Testing.Commands` and
|
|
161
|
+
`Cratis.Chronicle.Events`; retain the other imports above.
|
|
162
|
+
|
|
163
|
+
```csharp
|
|
164
|
+
public class when_the_organization_is_already_onboarding : Specification, IAsyncDisposable
|
|
165
|
+
{
|
|
166
|
+
CommandScenario<StartOnboarding> _scenario = null!;
|
|
167
|
+
readonly OrganizationNumber _organization = new("ORG-OPERATIONS");
|
|
168
|
+
readonly ReservationKey _key = new(Guid.Parse("96ce8c18-1e67-4e44-b5e7-4fb2b2cb3b97"));
|
|
169
|
+
EventSourceId _newPartner = null!;
|
|
170
|
+
IOnboardingReservations _reservations = null!;
|
|
171
|
+
CommandResult _result = null!;
|
|
172
|
+
|
|
173
|
+
async Task Establish()
|
|
174
|
+
{
|
|
175
|
+
_scenario = new();
|
|
176
|
+
_newPartner = EventSourceId.New();
|
|
177
|
+
_reservations = Substitute.For<IOnboardingReservations>();
|
|
178
|
+
_reservations.Reserve(_key, Arg.Any<CancellationToken>()).Returns(Task.CompletedTask);
|
|
179
|
+
_reservations.Cancel(_key, Arg.Any<CancellationToken>()).Returns(Task.CompletedTask);
|
|
180
|
+
_scenario.Services.AddSingleton(_reservations);
|
|
181
|
+
await _scenario.EventScenario.Given.ForEventSource(EventSourceId.New())
|
|
182
|
+
.Events(new OnboardingStarted(_organization));
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
async Task Because() =>
|
|
186
|
+
_result = await _scenario.Execute(new StartOnboarding(_newPartner, _organization, _key));
|
|
187
|
+
|
|
188
|
+
[Fact] void should_report_the_constraint() =>
|
|
189
|
+
_result.ShouldHaveConstraintViolationFor("UniqueOrganizationNumber");
|
|
190
|
+
[Fact] void should_observe_forward_execution() =>
|
|
191
|
+
_scenario.ShouldHaveExecutedOperation<ReserveOnboardingCapacity>();
|
|
192
|
+
[Fact] void should_observe_compensation() =>
|
|
193
|
+
_scenario.ShouldHaveCompensatedOperation<ReserveOnboardingCapacity>();
|
|
194
|
+
[Fact] void should_call_the_provider_in_order() => Received.InOrder(() =>
|
|
195
|
+
{
|
|
196
|
+
_ = _reservations.Reserve(_key, Arg.Any<CancellationToken>());
|
|
197
|
+
_ = _reservations.Cancel(_key, Arg.Any<CancellationToken>());
|
|
198
|
+
});
|
|
199
|
+
[Fact] void should_report_noncommit() =>
|
|
200
|
+
_result.Recovery!.CommitDisposition.ShouldEqual(CommandCommitDisposition.NotCommitted);
|
|
201
|
+
[Fact] void should_report_callback_completion() =>
|
|
202
|
+
_result.Recovery!.Status.ShouldEqual(CommandRecoveryStatus.Completed);
|
|
203
|
+
[Fact] async Task should_not_persist_the_rejected_event() =>
|
|
204
|
+
(await _scenario.EventScenario.EventLog.HasEventsFor(_newPartner)).ShouldBeFalse();
|
|
205
|
+
|
|
206
|
+
async Task Destroy() => await ((IAsyncDisposable)this).DisposeAsync();
|
|
207
|
+
ValueTask IAsyncDisposable.DisposeAsync() => _scenario.DisposeAsync();
|
|
208
|
+
}
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
Seed the constraint in the **event log** through `EventScenario.Given`, not only
|
|
212
|
+
in a read-model dictionary. This follows the maintained
|
|
213
|
+
[real-rejection spec](https://github.com/Cratis/Arc/blob/v22.48.1/Source/DotNET/Chronicle.Specs/Commands/for_CommandScenario/operations/when_a_real_constraint_rejects_the_commit.cs).
|
|
214
|
+
It proves known non-commit and eligible compensation with the in-process store,
|
|
215
|
+
not uncertain remote acknowledgments or the external provider's durability.
|
|
216
|
+
|
|
217
|
+
## Extend the failure coverage
|
|
218
|
+
|
|
219
|
+
- Happy path: assert provider arguments, `ShouldHaveExecutedOperation<ReserveSeat>()`,
|
|
220
|
+
`Recovery.Status == CommandRecoveryStatus.NotNeeded`, and the actual response.
|
|
221
|
+
- `Validate(command)`: no `Provide`, `Handle`, scope lifecycle, or operations;
|
|
222
|
+
assert the specific validation rule and `DidNotReceive` provider calls.
|
|
223
|
+
- Execution-path rejection: `Execute` invalid input, assert the specific verdict
|
|
224
|
+
and `ShouldHaveNoOperationInvocations()`.
|
|
225
|
+
- Cancellation: `Execute(command, cancellationToken)`; cancel deterministically
|
|
226
|
+
inside a substitute and prove compensation got a separate uncanceled token.
|
|
227
|
+
- Missing/throwing compensation: `Incomplete`, `NotAvailable`/`Failed`, exact
|
|
228
|
+
`UncompensatedCount`/`FailedCompensationCount`, and remaining callbacks attempted.
|
|
229
|
+
|
|
230
|
+
Arc's [failure recipes](https://github.com/Cratis/Arc/blob/v22.48.1/Documentation/backend/csharp/testing/command-operation-failures.md)
|
|
231
|
+
contain the full cases. Run `dotnet test <Your.Specs.csproj>`; assert behavior,
|
|
232
|
+
not just command success. These corpus excerpts are source-checked, not compiled
|
|
233
|
+
by the corpus text-verification gate. Test provider ownership, repeated finalized
|
|
234
|
+
requests, conflicting keys, and delayed creates at the provider integration boundary.
|
|
235
|
+
|
|
236
|
+
## Migrate an existing service-backed Handle
|
|
237
|
+
|
|
238
|
+
Follow the [migration recipe](https://github.com/Cratis/Arc/blob/v22.48.1/Documentation/backend/csharp/commands/operations/migrating.md):
|
|
239
|
+
|
|
240
|
+
1. Separate acquired inputs, decision, and service writes. Preserve the input,
|
|
241
|
+
endpoint, and response; move the write into an operation and return it with
|
|
242
|
+
the existing response. Remove the old call, including any manual `Execute`.
|
|
243
|
+
2. Keep a direct service interaction if its receipt is needed to construct the
|
|
244
|
+
decision/response. Do not hide the write in `Provide` or redesign persistence
|
|
245
|
+
solely for syntactic purity.
|
|
246
|
+
3. Keep provider DI; remove an obsolete custom response handler only if its sole
|
|
247
|
+
purpose was this side effect. Keep specialized framework handlers and events.
|
|
248
|
+
4. Audit custom scopes, early commits, and ownership-safe reversal before enabling
|
|
249
|
+
the new path. Do not add rollback stacks or relabel a committing scope.
|
|
250
|
+
5. Prove decision data, provider effects, response, validation/authorization,
|
|
251
|
+
failure/compensation, and (with Chronicle) actual commit rejection. Rebuild
|
|
252
|
+
the proxy: it must still expose the original response, not the operation.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"skill": "cratis-arc-command-operation",
|
|
3
|
+
"input": "Move a model-bound command's immediate seat reservation into an ICommandOperation, preserve its response, and specify forward failure and compensation without assuming a failed command means nothing committed.",
|
|
4
|
+
"fixtures": [],
|
|
5
|
+
"assertions": [
|
|
6
|
+
{ "kind": "skill-contains", "value": "Chronicle is not required." },
|
|
7
|
+
{ "kind": "skill-contains", "value": "operations cannot return receipts" },
|
|
8
|
+
{ "kind": "skill-contains", "value": "only on `Compensate()`" },
|
|
9
|
+
{ "kind": "skill-contains", "value": "Never return a raw array or `IEnumerable<ICommandOperation>` as a batch." },
|
|
10
|
+
{ "kind": "skill-contains", "value": "Calling `Handle()` directly does not execute operations." },
|
|
11
|
+
{ "kind": "skill-contains", "value": "C, B, A — never D" },
|
|
12
|
+
{ "kind": "skill-contains", "value": "A failed result is not proof that nothing committed." },
|
|
13
|
+
{ "kind": "skill-contains", "value": "`Unknown` / `Mixed`" },
|
|
14
|
+
{ "kind": "skill-contains", "value": "CommandOperationOptions.CompensationTimeout" },
|
|
15
|
+
{ "kind": "skill-contains", "value": "EF Core and MongoDB have no built-in operation commit participant." },
|
|
16
|
+
{ "kind": "skill-contains", "value": "CommandResult.Recovery" },
|
|
17
|
+
{ "kind": "skill-contains", "value": "references/testing.md" }
|
|
18
|
+
]
|
|
19
|
+
}
|
|
@@ -300,6 +300,9 @@ public class <ReactorName> : IReactor
|
|
|
300
300
|
A reactor runs with **no principal**; `[ExecuteCommandsAsSystem]` (class-level,
|
|
301
301
|
`Cratis.Arc.Chronicle.Reactors`) supplies one for the **returned** commands only.
|
|
302
302
|
A collection return is executed as commands when every element is a command.
|
|
303
|
+
A reactor retry can execute the command's operations again; inline operations
|
|
304
|
+
are not a substitute for reactor/outbox durability (see
|
|
305
|
+
`cratis-arc-command-operation`, verified at Arc v22.48.1).
|
|
303
306
|
|
|
304
307
|
The imperative form — inject `ICommandPipeline` (`Cratis.Arc.Commands`) and call
|
|
305
308
|
`Execute(command)` — is still supported and is the subject of the
|
|
@@ -39,6 +39,26 @@ is not admitted by ESM v1*), and so do reactions and declared triggers. A
|
|
|
39
39
|
specification's `when append` never runs reactions either. Model them when the
|
|
40
40
|
`.play` file is the deliverable; do not promise they execute.
|
|
41
41
|
|
|
42
|
+
**Specify what sets them off anyway** (v4.48.0, checked at tag `v4.48.0`, commit
|
|
43
|
+
`3baf4a4`): `when clock "<instant>"` for a reaction on `every` or `at`,
|
|
44
|
+
`when trigger <Trigger>` with its values for one on an application trigger, and
|
|
45
|
+
`given capture` / `when capture <Capture>` with the source record's fields for a
|
|
46
|
+
capture, then the events that should follow. `given clock` fixes the occurrence
|
|
47
|
+
time, so values mapped from `$context.occurred` can be asserted:
|
|
48
|
+
|
|
49
|
+
```screenplay
|
|
50
|
+
specification ChasingAnOverdueInvoiceOnMonday
|
|
51
|
+
given clock "2026-10-05T07:00:00Z"
|
|
52
|
+
when clock "2026-10-05T07:30:00Z"
|
|
53
|
+
then CollectionsDigestIssued
|
|
54
|
+
issuedAt = "2026-10-05T07:30:00Z"
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
These actions parse and are checked against the application, but they bind to
|
|
58
|
+
nothing yet: admitting them, and running reactions, is proposed as ESM v6 in
|
|
59
|
+
the Screenplay repository's decision 0022. Report such a specification as
|
|
60
|
+
parsed, not executed.
|
|
61
|
+
|
|
42
62
|
## `capture` — the Change Data Capture Language
|
|
43
63
|
|
|
44
64
|
Captures live in `Translate` slices and are the anti-corruption layer: external
|
|
@@ -208,6 +208,9 @@ A continuation line extends the clause.
|
|
|
208
208
|
- **`produces when <condition>`** takes the event name on the next indented line.
|
|
209
209
|
Conditions over command properties and constants bind; each is evaluated
|
|
210
210
|
independently, and when all are false the command is accepted with no events.
|
|
211
|
+
Compare an enumeration with a member bare (`status == sent`) or quoted
|
|
212
|
+
(`status == "sent"`); the bare form binds from v4.48.0, so quote it when a model
|
|
213
|
+
must bind on an older version.
|
|
211
214
|
Excerpt:
|
|
212
215
|
|
|
213
216
|
```screenplay
|
|
@@ -172,7 +172,37 @@ At the most granular layout, folders mirror the language, one folder per level:
|
|
|
172
172
|
one slice, whole. A slice file restates its `module` and `feature`; nothing is
|
|
173
173
|
written twice.
|
|
174
174
|
|
|
175
|
-
|
|
175
|
+
**Compose focused files with imports** (v4.48.0, checked at tag `v4.48.0`,
|
|
176
|
+
commit `3baf4a4`). `import "<path or glob>"` imports `.play` files relative to
|
|
177
|
+
the importing file - `**` crosses folders, `*` stays in one, `..` climbs. Where
|
|
178
|
+
the import is written decides where the files belong: at the top level it brings
|
|
179
|
+
in whole documents; inside a `module` or `feature` it places each imported file
|
|
180
|
+
there, so a file holds only its part of the story - a slice file is just the
|
|
181
|
+
`slice`. A root file that imports everything says what the application is made
|
|
182
|
+
of:
|
|
183
|
+
|
|
184
|
+
```screenplay
|
|
185
|
+
domain Acme.Commerce
|
|
186
|
+
|
|
187
|
+
import "Shared/*.play"
|
|
188
|
+
import "Ordering/Ordering.play"
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
```screenplay
|
|
192
|
+
module Ordering
|
|
193
|
+
description "Orders, from basket to doorstep"
|
|
194
|
+
feature Orders
|
|
195
|
+
import "Orders/*.play"
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
Every file is imported once. When a root glob and a module file both match a
|
|
199
|
+
file, the deepest placement wins; two placements where neither lies inside the
|
|
200
|
+
other are an error (`PLAY0457`), and so is a file placed in a module it does not
|
|
201
|
+
restate (`PLAY0459`). `import Customers.CustomerRegistered` without quotes still
|
|
202
|
+
names a contract from another bounded context.
|
|
203
|
+
|
|
204
|
+
⚠️ **Compile the folder, or its root file, as one application.**
|
|
205
|
+
`screenplay <root file>` compiles what the root imports. `screenplay <folder>` merges every
|
|
176
206
|
`.play` beneath the root *before* resolving, so an event declared in one file and
|
|
177
207
|
produced in another resolves. Compiling files individually reports unknown types,
|
|
178
208
|
events and policies (`PLAY0165`, `PLAY0166`, `PLAY0167`) that are not missing.
|
package/package/corpus/skills/cratis-screenplay-model-authoring/references/language-reference.md
CHANGED
|
@@ -15,11 +15,25 @@ repository is the full list; this page is the authoring summary.
|
|
|
15
15
|
`authentication`, `trigger`, `theme`, `layout`, `ui profile`, `behavior`,
|
|
16
16
|
`module`, `seed`.
|
|
17
17
|
|
|
18
|
-
**Inside a module:** `description`, `authorize`, `
|
|
19
|
-
`form`, `contribute`, `on`/`uses` behavior
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
`
|
|
18
|
+
**Inside a module:** `description`, `authorize`, `import "<glob>"`,
|
|
19
|
+
`screen`/`dialog` templates, `form`, `contribute`, `on`/`uses` behavior
|
|
20
|
+
attachments, `feature`.
|
|
21
|
+
|
|
22
|
+
**Inside a feature:** `description`, `authorize`, `import "<glob>"`, nested
|
|
23
|
+
`feature`, `slice`, `contribute`, `on`/`uses` behavior attachments.
|
|
24
|
+
|
|
25
|
+
**Files (v4.48.0).** `import "<path or glob>"` - quoted - imports `.play` files
|
|
26
|
+
relative to the importing file; unquoted, `import` still names a contract from
|
|
27
|
+
another bounded context. At the top level it brings in whole documents. Inside a
|
|
28
|
+
`module` or `feature` it places each imported file there, and that file's top
|
|
29
|
+
level is the module's or feature's body, alongside any application-level
|
|
30
|
+
declarations it makes. A file matched by several imports is imported once, at the
|
|
31
|
+
deepest placement; conflicting placements (`PLAY0457`), cycles (`PLAY0458`) and
|
|
32
|
+
imports that match nothing (`PLAY0455`, `PLAY0456`) are reported where the import
|
|
33
|
+
is written. `screenplay <file>` compiles the application that file is the root
|
|
34
|
+
of; `screenplay <folder>` treats every file as a root and still places what the
|
|
35
|
+
imports place. The VS Code extension validates a workspace folder the same way,
|
|
36
|
+
as one application.
|
|
23
37
|
|
|
24
38
|
| Slice type | Meaning | Typical contents |
|
|
25
39
|
| --- | --- | --- |
|
|
@@ -131,6 +131,13 @@ precondition. It takes a `file` reference or an inline block in a tagged fence
|
|
|
131
131
|
a nonsensical one, so the choice is yours to get right. Performer code is opaque:
|
|
132
132
|
Screenplay never runs it.
|
|
133
133
|
|
|
134
|
+
A read model a performer composes needs no projection, and no event builds it.
|
|
135
|
+
Specify it from state with `given readmodel`, then `when query <Query>` with the
|
|
136
|
+
arguments and `then result` (v4.48.0) - see `cratis-screenplay-specifications`.
|
|
137
|
+
|
|
138
|
+
A query's key goes on its own `by` line in the body. `query X => RM? by id Type`
|
|
139
|
+
on the header line is a declaration error, not a shorthand.
|
|
140
|
+
|
|
134
141
|
### What runs
|
|
135
142
|
|
|
136
143
|
In the executable model today, only the keyed snapshot shape binds:
|