@cratis/pi 7.11.4 → 7.12.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.
Files changed (31) hide show
  1. package/package/corpus/agents/planner.md +1 -1
  2. package/package/corpus/agents/slice-implementer.md +3 -3
  3. package/package/corpus/agents/spec-writer.md +10 -8
  4. package/package/corpus/prompts/add-reactor.prompt.md +1 -1
  5. package/package/corpus/prompts/new-vertical-slice.prompt.md +1 -1
  6. package/package/corpus/prompts/write-specs.prompt.md +2 -2
  7. package/package/corpus/rules/application-profile.md +1 -1
  8. package/package/corpus/rules/framework.md +1 -1
  9. package/package/corpus/rules/local-work-artifacts.md +13 -0
  10. package/package/corpus/rules/reactors.md +2 -2
  11. package/package/corpus/rules/specs.csharp.md +1 -1
  12. package/package/corpus/rules/specs.scenarios.csharp.md +34 -14
  13. package/package/corpus/rules/vertical-slices.md +1 -1
  14. package/package/corpus/skills/cratis-application-slice-conformance/references/checklists.md +4 -2
  15. package/package/corpus/skills/cratis-application-slice-specifications/SKILL.md +24 -15
  16. package/package/corpus/skills/cratis-arc-command-operation/references/testing.md +4 -2
  17. package/package/corpus/skills/cratis-arc-command-typescript/SKILL.md +10 -2
  18. package/package/corpus/skills/cratis-arc-command-validation/SKILL.md +4 -2
  19. package/package/corpus/skills/cratis-arc-validation-typescript/SKILL.md +5 -2
  20. package/package/corpus/skills/cratis-chronicle-event-constraints/SKILL.md +8 -3
  21. package/package/corpus/skills/cratis-chronicle-event-specifications/SKILL.md +5 -3
  22. package/package/corpus/skills/cratis-chronicle-reactor/SKILL.md +8 -5
  23. package/package/corpus/skills/cratis-chronicle-read-model-specifications/SKILL.md +12 -6
  24. package/package/corpus/skills/cratis-chronicle-reducer/SKILL.md +5 -2
  25. package/package/corpus/skills/cratis-code-review/SKILL.md +7 -2
  26. package/package/corpus/skills/cratis-specification-by-example/SKILL.md +13 -7
  27. package/package/corpus/skills/cratis-specifications-csharp/SKILL.md +7 -4
  28. package/package/corpus/skills/cratis-specifications-csharp/references/application-scenarios.md +14 -7
  29. package/package/corpus/skills/cratis-specifications-csharp/references/csharp-patterns.md +3 -2
  30. package/package/corpus/skills/cratis-specifications-typescript/references/typescript-patterns.md +3 -1
  31. package/package.json +1 -1
@@ -84,7 +84,7 @@ For an explicitly requested large application scope, adapt this optional numbere
84
84
  1. Create `<AppSourceRoot>/<Module?>/<Feature>/<Slice>/<Slice>.cs` with all backend artifacts. Omit `<Module?>` when no natural domain grouping exists; never introduce a top-level `Features/` wrapper.
85
85
 
86
86
  ### Phase 2 — Specs [delegate to: spec-writer]
87
- 2. Write in-process scenario specs in `<AppSourceRoot>/<Module?>/<Feature>/<Slice>/when_<behavior>/` for every slice type.
87
+ 2. Write specs in `<AppSourceRoot>/<Module?>/<Feature>/<Slice>/when_<behavior>/` for every slice type: `Specification` plus a direct call by default for pure decisions; add in-process scenarios only where the pipeline, validation, constraints, projections or wiring contribute proof.
88
88
 
89
89
  ### Phase 3 — Build [run: Debug, then Release]
90
90
  3. Run `dotnet build -c Debug` to validate spec code and generate TypeScript proxies.
@@ -55,7 +55,7 @@ Read the skill before writing the artifact it covers; the rules alone are not th
55
55
  |---|---|---|
56
56
  | State Change | `cratis-arc-command`, `cratis-arc-command-validation`, `cratis-fundamentals-concept`; `cratis-chronicle-event-constraints` for uniqueness | `cratis-application-slice-specifications`; `cratis-chronicle-event-specifications` for constraints |
57
57
  | State View | `cratis-chronicle-read-model`, `cratis-chronicle-projection` (`cratis-chronicle-reducer` only as a last resort) | `cratis-chronicle-read-model-specifications` |
58
- | Automation | `cratis-chronicle-reactor`; `cratis-arc-command-execution` or `cratis-arc-command-operation`; `cratis-engineering-effect-boundaries` for any outside call | `ReactorScenario` (`cratis-specifications-csharp`), plus the invoked command's specs |
58
+ | Automation | `cratis-chronicle-reactor`; `cratis-arc-command-execution` or `cratis-arc-command-operation`; `cratis-engineering-effect-boundaries` for any outside call | Plain calls for pure reactor decisions; `ReactorScenario` for invocation/side effects (`cratis-specifications-csharp`), plus the invoked command's specs |
59
59
  | Translation | by the actual construct and trigger, not the label: a `capture` is an ingestion adapter (`cratis-engineering-effect-boundaries`); a translator `reaction` is `cratis-chronicle-reactor` (cross-service: inbox/`[EventStore]`); a clock or application trigger is a scheduler or host signal | as Automation |
60
60
  | UI | `cratis-arc-react-page`, `cratis-arc-command-typescript`, `cratis-arc-query-typescript` | `cratis-application-react-specifications` |
61
61
 
@@ -68,7 +68,7 @@ Write `<Module>/<Feature>/<Slice>/<Slice>.cs` with all backend artifacts (declar
68
68
  ### Phase 3 — Specs
69
69
  When a slice is re-delivered (the contract gained specifications), diff the contract's specification list against the existing spec classes first: each missing specification is the work list, even when the backend is unchanged. A slice is done only when every contract specification has an executable spec that passes; there is no contract specification without a spec equivalent. A spec changes only after an approved contract revision, and unaffected assertions are preserved.
70
70
 
71
- Mandatory for every slice type. Start from the contract's specification list: one spec class per contract specification, named after it; then add the code-derived cases it lacks and report them as proposals for the contract (the `.play` model when one covers the slice, otherwise the agreed outline). **Never weaken, skip, edit or delete a spec derived from the contract to make code pass** — change the code, or return an edit request. Use the scenario family: `CommandScenario<T>` (state change), `EventScenario` (constraints), `ReadModelScenario<T>` (projections/reducers), `ReactorScenario<T>` (reactors). Minimum: happy path with each appended event asserted; one spec per validator rule asserting **both** `ShouldNotBeSuccessful()` **and** `ShouldHaveValidationErrors()`; one spec per constraint. **Gate:** tests pass.
71
+ Mandatory for every slice type. Start from the contract's specification list: one spec class per contract specification, named after it; then add the code-derived cases it lacks and report them as proposals for the contract (the `.play` model when one covers the slice, otherwise the agreed outline). **Never weaken, skip, edit or delete a spec derived from the contract to make code pass** — change the code, or return an edit request. Start with plain-call specs for pure decisions (`Handle()`, `Handle(providedValue)`, reducers and reactor logic). Add scenarios where the pipeline, validation, constraints or projections contribute proof: `CommandScenario<T>` (command pipeline), `EventScenario` (constraints), `ReadModelScenario<T>` (projections/reducers), `ReactorScenario<T>` (reactor invocation). Minimum: happy path with each appended event asserted; one spec per validator rule asserting **both** `ShouldNotBeSuccessful()` **and** `ShouldHaveValidationErrors()`; one spec per constraint. **Gate:** tests pass.
72
72
 
73
73
  ### Phase 4 — Frontend (when needed)
74
74
  Proxies now exist. Build React components from the generated proxies (`react.md`/`components.md`/`dialogs.md`); register in the composition page; wire routing. **Gate:** lint, conditional test, build — all clean. Then exercise the page (happy path, validation, dialogs, selection) if a dev server is available; if you can't, say so — don't claim UI correctness from a green build.
@@ -88,7 +88,7 @@ Proxies now exist. Build React components from the generated proxies (`react.md`
88
88
  - Model-bound projections default; **never `.AutoMap()`**; reducers only as a last resort with justification.
89
89
  - Events: no arguments on `[EventType]`, non-nullable, past tense, `<summary>`, never carry the event-source id.
90
90
  - `[OnceOnly]` on non-idempotent reactor side effects; reactors return side-effect events or use `ICommandPipeline` (never `IEventLog`).
91
- - Specs `#if DEBUG`, command aliased, per-test unique values.
91
+ - Specs compiled into the application assembly use `#if DEBUG`; dedicated spec projects need no wrapper. Command aliased, per-test unique values.
92
92
  - Never hand-edit Stage-managed (rendered) output, and never leave a modeled rule living only in code.
93
93
  - Every contract element is realised and nothing is invented (no field, default, filter, rule or event the contract does not state); see **cratis-application-slice-conformance**.
94
94
  - Frontend via `withViewModel` + Arc proxy hooks + Cratis Components; never edit generated proxies; never use a vendor or hand-rolled modal (dialogs come from `@cratis/components/CommandDialog` and `/Dialogs`).
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: Spec Writer
3
3
  description: >
4
- Specialist for writing C# specs (the in-process scenario family) and
4
+ Specialist for writing C# specs (plain calls and focused in-process scenarios) and
5
5
  TypeScript/React specs for vertical slices. Ensures every slice has
6
6
  comprehensive behavior coverage following the project's BDD conventions.
7
7
  tools:
@@ -26,7 +26,8 @@ Your responsibility is to write **comprehensive specs** for vertical slices.
26
26
 
27
27
  Select from these canonical rules in `.cratis/ai/rules/` only after applying the profile and lane scope above:
28
28
  - `specs.md` — folder structure, naming, BDD philosophy
29
- - `specs.scenarios.csharp.md` — the in-process scenario family
29
+ - `specs.csharp.md` — plain `Specification` specs and direct calls
30
+ - `specs.scenarios.csharp.md` — add in-process scenarios where they contribute proof
30
31
  - `frontend-testing.md` — application frontend specs (view models, components)
31
32
  - `vertical-slices.md` — what each artifact promises (the contract under spec)
32
33
 
@@ -42,9 +43,9 @@ Select from these canonical rules in `.cratis/ai/rules/` only after applying the
42
43
 
43
44
  ---
44
45
 
45
- ## C# specs — lead with the scenario family
46
+ ## C# specs — start with the plain call
46
47
 
47
- Prefer the four in-process scenario helpers over out-of-process Chronicle host specs:
48
+ Specify pure decisions with plain calls first: `Handle()`, `Handle(providedValue)`, reducers and reactor logic. Add the four in-process scenario helpers where the pipeline, validation, constraints or projections contribute proof; prefer them over out-of-process Chronicle host specs for those behaviors:
48
49
 
49
50
  | Tool | Use for |
50
51
  |---|---|
@@ -57,7 +58,7 @@ Reserve out-of-process integration specs for host/transport/infra boundaries the
57
58
 
58
59
  ### Placement & wrapping
59
60
 
60
- Specs live in the slice folder; **every spec file is wrapped in `#if DEBUG … #endif`**:
61
+ Application specs live in the slice folder. **Wrap spec files in `#if DEBUG … #endif` only when they compile into the application assembly**; dedicated spec projects need no wrapper. The example below shows application-assembly specs:
61
62
 
62
63
  ```
63
64
  <Feature>/<Slice>/
@@ -92,9 +93,9 @@ public class and_all_information_is_valid : Specification
92
93
 
93
94
  ### What to specify
94
95
 
95
- 0. **Every contract specification first** — one spec each, named after it, using the contract's example values. Then add the code-derived cases below that the contract lacks and report them as proposals for the contract (the `.play` model when one covers the slice, otherwise the agreed outline); never present them as contract coverage. A `.play` specification maps to the scenario helper for its slice type; never edit, skip or delete a spec derived from the contract to make code pass — change the code or return an edit request.
96
+ 0. **Every contract specification first** — one spec each, named after it, using the contract's example values. Then add the code-derived cases below that the contract lacks and report them as proposals for the contract (the `.play` model when one covers the slice, otherwise the agreed outline); never present them as contract coverage. A `.play` specification maps to a plain-call spec for a pure decision, with a scenario added where the pipeline, validation, constraints or projections matter; never edit, skip or delete a spec derived from the contract to make code pass — change the code or return an edit request.
96
97
  1. **Happy path** — succeeds, correct event(s) appended.
97
- 2. **Each validation failure** — assert **both** `ShouldNotBeSuccessful()` and `ShouldHaveValidationErrors()`. Never assert on message strings. Violate **only** the rule the spec is named after (build the command valid in every other respect), or a neighbouring rule makes it pass.
98
+ 2. **Each validation failure** — assert **both** `ShouldNotBeSuccessful()` and `ShouldHaveValidationErrors()`. Do not assert on message strings by default; assert exact text only when that wording is the specified behavior, and name that behavior in the fact. Violate **only** the rule the spec is named after (build the command valid in every other respect), or a neighbouring rule makes it pass.
98
99
  3. **Business-rule violations** — each `Result<,>` rejection / DCB condition.
99
100
  4. **Constraint violations** — `ShouldHaveConstraintViolationFor(name)` via `EventScenario`.
100
101
  5. **Authorization** — `ShouldNotBeAuthorized()` (an unauthorized result has no validation errors).
@@ -148,7 +149,8 @@ Before handing back:
148
149
  - [ ] Specs cover all meaningful outcomes of the slice's behavior
149
150
  - [ ] Happy-path spec exists
150
151
  - [ ] Each validation/business-rule/constraint failure has a spec (unhappy paths assert both not-successful and has-validation-errors)
151
- - [ ] C# spec files wrapped in `#if DEBUG`; folder follows `when_<behavior>/`
152
+ - [ ] Pure decisions have plain-call specs; scenarios cover pipeline, validation, constraints or projections where needed
153
+ - [ ] C# specs compiled into the application assembly are wrapped in `#if DEBUG`; dedicated spec projects need no wrapper; folder follows `when_<behavior>/`
152
154
  - [ ] TypeScript `it()` descriptions use spaces and start with "should"; `.should` assertions only
153
155
  - [ ] Specs pass (C# and, when written, frontend)
154
156
  - [ ] No spec for a simple property getter or constructor-parameter passthrough
@@ -19,6 +19,6 @@ Add a reactor that observes events and produces side effects. Invoke the **crati
19
19
  - Reactors are **idempotent** and **stateless**; use event data directly (don't query the read model back).
20
20
  - To change state elsewhere, return side-effect events or inject `ICommandPipeline` — **never** `IEventLog`.
21
21
  - `[OnceOnly]` on any non-idempotent side effect (emails, payments, external writes).
22
- - Test with `ReactorScenario<TReactor>`, including a case for each skip condition and one for repeated delivery.
22
+ - Specify pure reactor decisions with `Specification` plus a direct call by default; add `ReactorScenario<TReactor>` only where invocation, dependency wiring or side effects contribute proof. Cover each skip condition and repeated delivery.
23
23
 
24
24
  The skill carries the detail; don't duplicate it here.
@@ -26,4 +26,4 @@ Whether the Screenplay skills are installed is a separate question from consent:
26
26
 
27
27
  ## How it runs
28
28
 
29
- Contract → backend (hand-written parts only) → build (Debug + Release) → specs (the in-process `*Scenario` family, one per contract specification) → frontend → compose/route, with each quality gate green before the next phase. Before reporting done, check that every contract element is realized and nothing is invented (`cratis-application-slice-conformance`). The authoritative rules are `.cratis/ai/rules/general.md` and `.cratis/ai/rules/vertical-slices.md`; the rules carry the step-by-step detail. Do not duplicate that detail here.
29
+ Contract → backend (hand-written parts only) → build (Debug + Release) → specs (one per contract specification: `Specification` plus a direct call by default for pure decisions; add the in-process `*Scenario` family only where the pipeline, validation, constraints, projections or wiring contribute proof) → frontend → compose/route, with each quality gate green before the next phase. Before reporting done, check that every contract element is realized and nothing is invented (`cratis-application-slice-conformance`). The authoritative rules are `.cratis/ai/rules/general.md` and `.cratis/ai/rules/vertical-slices.md`; the rules carry the step-by-step detail. Do not duplicate that detail here.
@@ -18,11 +18,11 @@ If no contract can be found, decide once:
18
18
 
19
19
  ## Coverage (every slice type)
20
20
 
21
- Lead with the in-process scenario family: `CommandScenario<T>` (state change), `EventScenario` (constraints), `ReadModelScenario<T>` (projections/reducers), `ReactorScenario<T>` (reactors). Reserve out-of-process Chronicle integration specs for host/transport boundaries.
21
+ Start with plain-call specs for pure decisions: `Handle()`, `Handle(providedValue)`, reducers and reactor logic. Add in-process scenarios where the pipeline, validation, constraints or projections contribute proof: `CommandScenario<T>` (command pipeline), `EventScenario` (constraints), `ReadModelScenario<T>` (projections/reducers), `ReactorScenario<T>` (reactor invocation). Reserve out-of-process Chronicle integration specs for host/transport boundaries.
22
22
 
23
23
  0. **Every contract specification first**, one spec each, named after it, using the contract's example values (fresh values only where uniqueness requires). Then add the code-derived cases below that the contract lacks, and report them as proposals for the contract (the `.play` model when one covers the slice, otherwise the agreed outline); never leave them as silent coverage.
24
24
  1. Happy path with each appended event asserted.
25
25
  2. One spec per validator rule, asserting **both** `ShouldNotBeSuccessful()` and `ShouldHaveValidationErrors()`. Build the command valid in every other respect so the spec violates only the rule it is named after.
26
26
  3. One spec per constraint (`ShouldHaveConstraintViolationFor(name)`); authorization via `ShouldNotBeAuthorized()`.
27
27
 
28
- Spec files are wrapped in `#if DEBUG`. Run the specs and fix failures before completing. The skill carries the detail; don't duplicate it here.
28
+ Wrap spec files in `#if DEBUG` only when they compile into the application assembly; dedicated spec projects need no wrapper. Run the specs and fix failures before completing. The skill carries the detail; don't duplicate it here.
@@ -58,7 +58,7 @@ Tagged **[contract]** (framework-enforced) or **[convention]** (house default).
58
58
  3. **Code level** — infrastructure (hosting, DI composition, identity wiring, CI, deployment), clients, Screenplay code attachments and handlers, adapters in the render's customization area, and scope Stage cannot render yet (the model remains the contract). Framework repositories and brownfield work that is not opted in also stay code-first. Only the entry-point session may propose a model, at most once per session and never for trivial, bug-fix, infrastructure, client, framework or brownfield-maintenance work; if declined, do not ask again. Confirm Module/Feature, slice name, slice type and domain requirements as before; for new behavior or unclear event vocabulary run **cratis-chronicle-event-modeling** first, and record the agreed outline (fields, events, rules, scenarios) where the team tracks work, if anywhere. If you write code first where a model exists, say the model now lags.
59
59
  4. **Trivial changes** keep the proportional-delegation policy; Phases 1–3 below apply to code you write at either level.
60
60
  - **Phase 1 — Backend.** Implement a coherent slice change. **Gate:** incremental Debug build of the affected project (regenerates proxies, compiles `#if DEBUG` spec code).
61
- - **Phase 2 — Specs.** Mandatory for every slice type, in-process scenario family first (`CommandScenario<T>`, `EventScenario`, `ReadModelScenario<T>`, `ReactorScenario<T>`). **Gate:** tests pass.
61
+ - **Phase 2 — Specs.** Mandatory for every slice type. Start with plain-call specs for pure decisions; add in-process scenarios (`CommandScenario<T>`, `EventScenario`, `ReadModelScenario<T>`, `ReactorScenario<T>`) where pipelines, validation, constraints or projections contribute proof. **Gate:** tests pass.
62
62
  - **Phase 3 — Frontend.** Build from the generated proxies, register in the composition page, wire routing. **Gate:** lint, conditional test, build.
63
63
 
64
64
  **Backend before frontend, always** — the frontend depends on proxies that exist only after a successful build. Generate proxies from the **Debug** build (house convention); verify Release without re-running the generator: `dotnet build -c Release -p:CratisProxiesOutputPath=`. Why that property, and what to do when nothing is generated: the **cratis-arc-command** skill's proxy-generation reference.
@@ -11,7 +11,7 @@ The framework repos are **libraries**, not event-sourced applications. The appli
11
11
 
12
12
  ## What still applies (universal rules)
13
13
 
14
- Everything tagged `profile: universal` holds in framework repos exactly as in apps: **C# conventions** (`csharp.md`), **TypeScript conventions** (`typescript.md`), **code quality** (`code-quality*.md`), **specs** (`specs.md` / `specs.csharp.md` / `specs.typescript.md` — `Cratis.Specifications` is how the framework tests itself, using the plain `Specification` base + NSubstitute against the classes under test — this is the dominant mode in framework repos. The in-process `*Scenario` family lives in `specs.scenarios.csharp.md` (`profile: application`); it is the *application* default, and a framework repo reaches for it only to test the very engine it provides — Arc → `CommandScenario`, Chronicle → `EventScenario`/`ReadModelScenario`/`ReactorScenario` — not as a general testing mode. The **cratis-application-slice-specifications** skill is application-oriented), **documentation**, **git-commits**, **pull-requests**, **concepts** (`ConceptAs<T>` / `EventSourceId<T>` are Fundamentals/Chronicle primitives the framework defines and uses), and **American English**.
14
+ Everything tagged `profile: universal` holds in framework repos exactly as in apps: **C# conventions** (`csharp.md`), **TypeScript conventions** (`typescript.md`), **code quality** (`code-quality*.md`), **specs** (`specs.md` / `specs.csharp.md` / `specs.typescript.md` — `Cratis.Specifications` is how the framework tests itself, using the plain `Specification` base + NSubstitute against the classes under test — this is the dominant mode in framework repos. The in-process `*Scenario` family lives in `specs.scenarios.csharp.md` (`profile: application`); applications add it where pipelines, validation, constraints or projections contribute proof, starting with plain calls for pure decisions; a framework repo reaches for it only to test the very engine it provides — Arc → `CommandScenario`, Chronicle → `EventScenario`/`ReadModelScenario`/`ReactorScenario` — not as a general testing mode. The **cratis-application-slice-specifications** skill is application-oriented), **documentation**, **git-commits**, **pull-requests**, **concepts** (`ConceptAs<T>` / `EventSourceId<T>` are Fundamentals/Chronicle primitives the framework defines and uses), and **American English**.
15
15
 
16
16
  ## What does NOT apply
17
17
 
@@ -21,6 +21,19 @@ dumps, and similar coordination files. These are **work records, not documentati
21
21
  - Knowledge that must outlive the session (real documentation, ADRs, operator
22
22
  guides) is written deliberately into the repository's documentation structure
23
23
  through normal review — not left behind as a work record.
24
+ - **A session prompt or handover states when it is valid.** A fresh-session prompt,
25
+ continuation prompt or handover in `.ai-work/` opens with its preconditions: the
26
+ repository, the branch, the expected `HEAD` commit, every worktree path it names,
27
+ and the date it was written. Without them nothing tells a later session whether
28
+ the prompt still describes reality.
29
+ - **Check the preconditions before acting on a prompt.** A session that starts from
30
+ one compares them with `git rev-parse --show-toplevel`, `git rev-parse HEAD`,
31
+ `git branch --show-current` and `git worktree list` first. A mismatch (a moved
32
+ `HEAD`, a missing worktree, another branch) means **the prompt is stale — not
33
+ that the work is lost.** Do not recreate
34
+ a worktree, reset, or discard anything because of it; look at the branches, the
35
+ reflog and the open pull requests for where the work is now, then update or
36
+ replace the prompt.
24
37
  - **A worktree is a work record too.** Create it outside the repository tree, for
25
38
  example in a sibling `../.worktrees/` directory. A nested worktree inherits the
26
39
  parent's `.globalconfig` alongside its own, causing .NET's `MultipleGlobalAnalyzerKeys`
@@ -264,7 +264,7 @@ The command is returned, not executed: Arc runs it through validation and author
264
264
 
265
265
  ## Testing Reactors
266
266
 
267
- Use `ReactorScenario<TReactor>` (from `Cratis.Chronicle.Testing.Reactors`) — construct it with an `IServiceProvider` of NSubstitute mocks, fire events through `Given`, and assert on the mocks:
267
+ Start with `Specification` plus a direct call for pure reactor decisions, passing the event and supplied values explicitly. Add `ReactorScenario<TReactor>` (from `Cratis.Chronicle.Testing.Reactors`) only where invocation, dependency wiring or side effects contribute proof — construct it with an `IServiceProvider` of NSubstitute mocks, fire events through `Given`, and assert on the mocks:
268
268
 
269
269
  ```csharp
270
270
  void Establish()
@@ -275,7 +275,7 @@ void Establish()
275
275
 
276
276
  async Task Because() => await _scenario.Given.ForEventSource(_id).Events(new InvoiceIssued("INV-1001"));
277
277
 
278
- [Fact] async Task should_notify() => await _notifications.Received(1).Notify("Invoice 'INV-1001' was issued.");
278
+ [Fact] async Task should_notify_about_the_issued_invoice() => await _notifications.Received(1).Notify(Arg.Is<string>(_ => _.Contains("INV-1001")));
279
279
  ```
280
280
 
281
281
  For reactors that return side-effect events, assert the resulting appends through the scenario's event store; for non-event side effects, assert on the mocked services (as above). See [specs.scenarios.csharp.md](./specs.scenarios.csharp.md) for the full `*Scenario` family.
@@ -11,7 +11,7 @@ Extends the base [specs.md](./specs.md) (folder structure, naming, philosophy) w
11
11
 
12
12
  > **Which spec surface?**
13
13
  > - **Framework / library code** (Chronicle kernel, Arc pipeline, source generators, Fundamentals): the `Specification` base + NSubstitute in this file is the dominant mode — unit-test the classes under test in isolation. Reach for a `*Scenario` helper (in [specs.scenarios.csharp.md](./specs.scenarios.csharp.md)) **only** when testing the very engine your repo provides — Arc → `CommandScenario`, Chronicle → the event/projection/reactor scenarios. The **cratis-application-slice-specifications** skill is application-oriented, not for general framework specs.
14
- > - **Event-sourced applications on Cratis** (commands, projections, reducers, reactors, constraints): use this base **plus** the in-process scenario family — see **[specs.scenarios.csharp.md](./specs.scenarios.csharp.md)** (`profile: application`) and the **cratis-application-slice-specifications** skill.
14
+ > - **Event-sourced applications on Cratis** (commands, projections, reducers, reactors, constraints): use this base plus a direct call by default for pure decisions; add the in-process scenario family only where pipelines, validation, constraints, projections or wiring contribute proof — see **[specs.scenarios.csharp.md](./specs.scenarios.csharp.md)** (`profile: application`) and the **cratis-application-slice-specifications** skill.
15
15
 
16
16
  `Cratis.Specifications` keeps the approach of Machine.Specifications (MSpec): `Establish → Because → should_` maps to "Given → When → Then" and keeps each spec focused on *one setup, one action, one set of assertions*.
17
17
 
@@ -8,27 +8,47 @@ profile: application
8
8
 
9
9
  # Application Specs — the in-process scenario family
10
10
 
11
- > **Application profile.** This file covers spec-writing for **event-sourced Cratis applications** — exercising commands, projections, reducers, reactors, and constraints with the in-process scenario family. It builds on the universal [specs.csharp.md](./specs.csharp.md) (the `Specification` base + NSubstitute). **Framework / library** specs predominantly use that plain base instead; a framework repo reaches for a scenario helper here only when testing the very engine it provides — Arc tests its command pipeline with `CommandScenario`, Chronicle tests its event/projection/reactor engine with `EventScenario`/`ReadModelScenario`/`ReactorScenario`. That is the minority case, not the general framework testing mode.
11
+ > **Application profile.** This file covers spec-writing for **event-sourced Cratis applications** — exercising commands, projections, reducers, reactors, and constraints with plain-call specs for pure decisions and the in-process scenario family where the pipeline matters. It builds on the universal [specs.csharp.md](./specs.csharp.md) (the `Specification` base + NSubstitute). **Framework / library** specs predominantly use that plain base instead; a framework repo reaches for a scenario helper here only when testing the very engine it provides — Arc tests its command pipeline with `CommandScenario`, Chronicle tests its event/projection/reactor engine with `EventScenario`/`ReadModelScenario`/`ReactorScenario`. That is the minority case, not the general framework testing mode.
12
12
 
13
13
  Specs are **mandatory for every slice type**, including reactors.
14
14
 
15
- ## Lead with the in-process scenario family
15
+ ## Start with the plain call; add a scenario where it adds proof
16
16
 
17
- For Cratis application behavior, prefer the four in-process scenario helpers over full out-of-process Chronicle host specs. They target different concerns and are additive.
17
+ A command's `Handle()` is an ordinary method; with dependencies resolved by `Provide()`, its decision can be a pure function of its arguments. Reducer logic and a reactor's decision can be pure functions too. **Write the plain call as the default spec for a pure decision**, with no host, services or harness. Add a scenario helper where the framework's composition is part of what you must prove: the command pipeline, validation, authorization, constraints, and projections (declarative, so only a scenario can exercise them). The scenario helpers are additive; use both only when the slice needs both kinds of proof. For application behavior prefer the in-process helpers over full out-of-process Chronicle host specs.
18
18
 
19
19
  | Tool | Tests | Use when |
20
20
  |---|---|---|
21
- | `Specification` (unit) | an isolated class with mocked collaborators | pure function / injected services to mock |
22
- | `CommandScenario<TCommand>` | the real Arc command pipeline — authorization + validators + `Provide()` + `Handle()` + appended events | **default for State Change slices** |
21
+ | `Specification` (plain call) | `Handle()`, `Handle(providedValue)`, reducer logic or a reactor's decision as a method call; or an isolated class with mocked collaborators | **default** for a decision that is a pure function of its arguments |
22
+ | `CommandScenario<TCommand>` | the real Arc command pipeline — authorization + validators + `Provide()` + `Handle()` + appended events | the pipeline, validation, authorization, or appended events matter (State Change slices) |
23
23
  | `EventScenario` | Chronicle-level append semantics, no command pipeline | constraint violations, raw stream sequencing/concurrency |
24
- | `ReadModelScenario<TReadModel>` | projection/reducer state from a sequence of events (auto-detects model-bound / fluent / reducer) | **default for State View slices** |
25
- | `ReactorScenario<TReactor>` | reactor handler invocation + side effects via mocked services | Automation / Translation slices |
24
+ | `ReadModelScenario<TReadModel>` | projection/reducer state from a sequence of events (auto-detects model-bound / fluent / reducer) | **default for projections**, which are declarative (State View slices) |
25
+ | `ReactorScenario<TReactor>` | reactor handler invocation + side effects via mocked services | the reactor wiring and side effects (Automation / Translation slices) |
26
26
 
27
27
  > **Out-of-process Chronicle integration specs are an advanced case** — reserve them for host wiring, real infrastructure, serialization/transport, or end-to-end boundaries the scenario helpers can't exercise. They are not the default vertical-slice test shape.
28
28
 
29
- **Every spec file is wrapped in `#if DEBUG … #endif`** so spec code ships only in Debug (the Debug build gate validates it and also regenerates proxies).
29
+ **Wrap every spec file in `#if DEBUG … #endif` when the specs live in the application assembly** beside the slice, as vertical slices place them, so spec code ships only in Debug (the Debug build gate validates it and also regenerates proxies). A dedicated spec project (`<Source>.Specs`) is never shipped and needs no wrapper; that is the case Arc's documentation describes.
30
30
 
31
- ### `CommandScenario<TCommand>` — State Change default
31
+ ### The plain call — the default for a pure decision
32
+
33
+ ```csharp
34
+ #if DEBUG
35
+ namespace MyApp.Authors.Registration.when_registering_an_author;
36
+
37
+ public class and_all_information_is_valid : Specification
38
+ {
39
+ readonly AuthorId _id = AuthorId.New();
40
+ AuthorRegistered _event;
41
+
42
+ void Because() => _event = new RegisterAuthor(_id, "Jane Austen").Handle();
43
+
44
+ [Fact] void should_register_the_author() => _event.Name.ShouldEqual("Jane Austen");
45
+ }
46
+ #endif
47
+ ```
48
+
49
+ Calling `Handle()` yourself runs no validation, authorization, `Provide()` or operations, so it proves the decision only. Add a `CommandScenario` spec for what the pipeline contributes.
50
+
51
+ ### `CommandScenario<TCommand>` — the command pipeline
32
52
 
33
53
  Runs authorization, validators, `Provide()` (when present), and `Handle()` in-process, and exposes the appended events.
34
54
 
@@ -56,7 +76,7 @@ public class and_all_information_is_valid : Specification
56
76
  - **`CommandResult` assertions** (Arc extensions): `ShouldBeSuccessful()`, `ShouldNotBeSuccessful()`, `ShouldBeValid()`, `ShouldHaveValidationErrors()`, `ShouldHaveValidationErrorFor(message)`, `ShouldBeAuthorized()`, `ShouldNotBeAuthorized()`, `ShouldHaveExceptions()`/`ShouldNotHaveExceptions()`.
57
77
  - **Seed prior state through `_scenario.Given` or `_scenario.Services`.** `_scenario.Given.ForEventSource(id).Events(...)` materializes the seeded events into an **in-memory read-model dictionary** the harness answers keyed reads from — it never reaches the event log (see the false-greens list below). To populate the DCB read models the validator/`Provide()`/`Handle()` inject, substitute `IReadModels` and register it (`_scenario.Services.Replace(new ServiceDescriptor(typeof(IReadModels), mock))`, mocking `GetInstanceById(...)`) or register projections with `_scenario.Services.AddReadModels(...)`.
58
78
  - **Validator/`Provide()` dependencies:** register them in `_scenario.Services`; Arc testing discovers the concrete validator automatically. When several specs need different injected validator states, test rejected variants by instantiating the validator directly (per-scenario state can be order-sensitive under parallel xUnit).
59
- - **`Provide()`:** drive it through `CommandScenario` end-to-end; when the handler's decision is pure given provided data, also test `Handle(providedValue)` directly.
79
+ - **`Provide()`:** drive it through `CommandScenario` end-to-end; when the handler's decision is pure given provided data, test `Handle(providedValue)` directly as the default decision spec and keep the scenario for the wiring.
60
80
  - **Command operations:** use **cratis-arc-command-operation** for decision/adapter specs and real `CommandScenario` execution, forward failure, compensation, and Chronicle commit rejection; a direct `Handle()` does not execute operations.
61
81
 
62
82
  #### Validation-failure assertions — non-negotiable
@@ -68,7 +88,7 @@ Every unhappy-path spec asserts **both**:
68
88
  [Fact] void should_have_validation_errors() => _result.ShouldHaveValidationErrors();
69
89
  ```
70
90
 
71
- `ShouldNotBeSuccessful()` alone can't tell a validation rejection from an unhandled exception. **Never assert on message strings** — they're presentation text. Authorization failures use `ShouldNotBeAuthorized()` (an unauthorized result has *no* validation errors, so `ShouldHaveValidationErrors()` would silently flip). To exercise a command that carries authorization attributes, register the identity the authorization evaluator reads into `_scenario.Services` (substitute the identity provider your app uses). **Adding `[Roles]` to an existing command breaks its happy-path AND validation-failure `.Execute()` specs** — an unauthorized result is not successful and carries no validation errors; switch those assertions to `ShouldNotBeAuthorized()`.
91
+ `ShouldNotBeSuccessful()` alone can't tell a validation rejection from an unhandled exception. **Do not assert on message strings by default** — they're presentation text; say which kind of rejection happened with `ShouldHaveValidationErrorBecauseOf(reason)`, or a constraint by name. Assert message text only when that exact text is the specified behavior, for example a rule whose wording the model pins, and say so in the fact's name. `ShouldHaveValidationErrorFor(message)` matches a substring, so it does not prove exact wording; compare for equality instead, for example `_result.ValidationResults.Select(_ => _.Message).ShouldContain("<exact text>")`. Authorization failures use `ShouldNotBeAuthorized()` (an unauthorized result has *no* validation errors, so `ShouldHaveValidationErrors()` would silently flip). To exercise a command that carries authorization attributes, register the identity the authorization evaluator reads into `_scenario.Services` (substitute the identity provider your app uses). **Adding `[Roles]` to an existing command breaks its happy-path AND validation-failure `.Execute()` specs** — an unauthorized result is not successful and carries no validation errors; switch those assertions to `ShouldNotBeAuthorized()`.
72
92
 
73
93
  `CommandResult` assertions (from `Cratis.Arc.Testing.Commands`; failures throw `CommandResultAssertionException`): `ShouldBeSuccessful()` (`isAuthorized && isValid && !hasExceptions`), `ShouldNotBeSuccessful()`, `ShouldBeValid()` (no validation errors — does *not* check authz/exceptions), `ShouldHaveValidationErrors()`, `ShouldHaveValidationErrorFor(message)`, `ShouldHaveValidationErrorBecauseOf(ValidationResultReason)`, `ShouldHaveConstraintViolationFor(name)`, `ShouldBeAuthorized()`, `ShouldNotBeAuthorized()`, `ShouldHaveExceptions()`.
74
94
 
@@ -104,11 +124,11 @@ async Task Because() =>
104
124
  [Fact] void should_violate_unique_constraint() => _result.ShouldHaveConstraintViolationFor(AuthorConstraintNames.UniqueName);
105
125
  ```
106
126
 
107
- `IAppendResult` assertions (failures throw `AppendResultAssertionException`): `ShouldBeSuccessful()`, `ShouldBeFailed()`, `ShouldHaveConstraintViolations()`/`ShouldNotHave…`, `ShouldHaveConstraintViolationFor(name)`, `ShouldHaveConcurrencyViolations()`/`ShouldNotHave…`, `ShouldHaveErrors()`/`ShouldNotHave…`. Assert the constraint **name**, never the message.
127
+ `IAppendResult` assertions (failures throw `AppendResultAssertionException`): `ShouldBeSuccessful()`, `ShouldBeFailed()`, `ShouldHaveConstraintViolations()`/`ShouldNotHave…`, `ShouldHaveConstraintViolationFor(name)`, `ShouldHaveConcurrencyViolations()`/`ShouldNotHave…`, `ShouldHaveErrors()`/`ShouldNotHave…`. Assert the constraint **name** by default; assert exact message text only when that wording is the specified behavior, and name that behavior in the fact.
108
128
 
109
- ### `ReadModelScenario<TReadModel>` — State View default
129
+ ### `ReadModelScenario<TReadModel>` — declarative projections and reducer wiring
110
130
 
111
- Drives events into the projection/reducer and asserts the resulting state. Use xUnit `Assert.*` on `_scenario.Instance`.
131
+ The default for declarative projections; pure reducer decisions start with a direct call. Add this scenario for reducer dispatch, filtering, metadata or read-model wiring. It drives events into the projection/reducer and asserts the resulting state. Use xUnit `Assert.*` on `_scenario.Instance`.
112
132
 
113
133
  ```csharp
114
134
  ReadModelScenario<Author> _scenario = null!;
@@ -20,7 +20,7 @@ This file is the reference for *what* goes in each part of a slice. Layout, slic
20
20
 
21
21
  - .NET / C# (ASP.NET Core) — **Cratis Arc** for CQRS / model-bound commands and queries, **Cratis Chronicle** for event sourcing, MongoDB or EF Core for read models.
22
22
  - React + TypeScript (Vite) — Cratis Components 4.x + Arc-generated proxies, MVVM. Vitest + Mocha/Chai/Sinon for frontend specs.
23
- - xUnit + Cratis.Specifications + NSubstitute for C# specs (the `*Scenario` family — see [specs.md](./specs.md)).
23
+ - xUnit + Cratis.Specifications + NSubstitute for C# specs (`Specification` plus a direct call by default for pure decisions; add the `*Scenario` family only where pipelines, validation, constraints, projections or wiring contribute proof — see [specs.md](./specs.md)).
24
24
 
25
25
  ## Proxy generation — the build dependency
26
26
 
@@ -72,8 +72,10 @@ the renderer no right to browse managed output or implement rejected semantics.
72
72
  or specifications; no condition was invented.
73
73
  - Exercise the reaction boundary itself: for a reactor, `ReactorScenario<TReactor>` invokes it
74
74
  with the trigger event and asserts what it produced (`ShouldHaveProduced<T>(predicate)`), which
75
- covers the field mapping from the trigger; the command it runs is specified separately with
76
- `CommandScenario`. Where the boundary cannot be reached in process, use an integration
75
+ covers the field mapping from the trigger. Specify the invoked command's pure decision
76
+ separately with `Specification` plus a direct call by default; add `CommandScenario` only
77
+ where its pipeline, validation, constraints or wiring contribute proof. Where the reaction
78
+ boundary cannot be reached in process, use an integration
77
79
  specification.
78
80
  - A failed handling is not swallowed: failure behavior follows `cratis-chronicle-reactor`
79
81
  (failure and quarantine), never a catch that continues.
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: cratis-application-slice-specifications
3
- description: Specify the backend behavior of an event-sourced Cratis application slice with the in-process scenario family — CommandScenario, EventScenario, ReadModelScenario and ReactorScenario — including what to cover for each slice type and where the specification files live. Use when adding or changing backend behavior in an application built on Cratis. Do not use for framework library specifications and do not use for frontend behavior.
3
+ description: Specify the backend behavior of an event-sourced Cratis application slice — plain-call specs for pure decisions, plus CommandScenario, EventScenario, ReadModelScenario and ReactorScenario where the pipeline, validation, constraints or projections matter — including what to cover for each slice type and where the specification files live. Use when adding or changing backend behavior in an application built on Cratis. Do not use for framework library specifications and do not use for frontend behavior.
4
4
  license: MIT
5
5
  metadata:
6
6
  cratis-hint-paths: "**/when_*/**/*.cs **/for_*/**/*.cs"
@@ -8,12 +8,14 @@ metadata:
8
8
 
9
9
  # Cratis application slice specifications
10
10
 
11
- A slice is specified from the outside, through the pipeline it actually runs on.
12
- The scenario family exercises the real Arc and Chronicle code paths in-process —
13
- no HTTP, no fixture, no server — so a specification says what the slice does
14
- rather than what its classes do.
11
+ Start a pure decision with a plain method call: `Handle()`,
12
+ `Handle(providedValue)`, reducer logic or a reactor's decision needs no host,
13
+ services or harness. Add a scenario where the pipeline, validation,
14
+ authorization, constraints or projections contribute proof. The scenario family
15
+ exercises the real Arc and Chronicle code paths in-process — no HTTP, no fixture,
16
+ no server.
15
17
 
16
- This skill decides **which scenario** and **what to cover**. The C# mechanics
18
+ This skill decides **when to add a scenario** and **what to cover**. The C# mechanics
17
19
  (`Establish`/`Because`, substitutes, contexts) live in
18
20
  `cratis-specifications-csharp`.
19
21
 
@@ -76,8 +78,9 @@ you did.
76
78
  ## Step 1 — Place the files
77
79
 
78
80
  Specifications live **in the slice folder**, beside the `.cs` they specify, each
79
- file wrapped in `#if DEBUG … #endif` so specification code compiles only in
80
- Debug.
81
+ file wrapped in `#if DEBUG … #endif` when it compiles into the application
82
+ assembly, so specification code ships only in Debug. A dedicated `<Source>.Specs`
83
+ project is not shipped and needs no wrapper.
81
84
 
82
85
  ```
83
86
  <Feature>/<Slice>/
@@ -94,11 +97,16 @@ Debug.
94
97
  A behavior covering several subjects groups under
95
98
  `<Slice>/for_<Subject>/when_<behavior>/`.
96
99
 
97
- ## Step 2 — Pick the scenario by slice type
100
+ ## Step 2 — Start with the decision; add the scenario by slice type
101
+
102
+ Specify a pure decision with the plain `Specification` base first. A direct
103
+ `Handle()` call does not run validation, authorization, `Provide()` or operations;
104
+ keep a scenario for that wiring and for appended-event behavior.
98
105
 
99
106
  | Slice type | Scenario | Skill |
100
107
  | --- | --- | --- |
101
- | State Change — a command appends events | `CommandScenario<TCommand>` | this one |
108
+ | Pure command decision, reducer logic or reactor decision | Plain method call with `Specification` (default) | `cratis-specifications-csharp` |
109
+ | State Change — command pipeline and appended events | `CommandScenario<TCommand>` | this one |
102
110
  | Append semantics, a constraint | `EventScenario` | `cratis-chronicle-event-specifications` |
103
111
  | State View — a projection or reducer | `ReadModelScenario<TReadModel>` | `cratis-chronicle-read-model-specifications` |
104
112
  | Automation or Translation — a reactor | `ReactorScenario<TReactor>` | `cratis-specifications-csharp` |
@@ -193,10 +201,11 @@ the concrete validator itself is discovered automatically.
193
201
  ```
194
202
 
195
203
  `ShouldNotBeSuccessful()` alone cannot distinguish a validation rejection from an
196
- unhandled exception, so both facts are required. **Never assert on a message
197
- string** — it is presentation text. A `.play` specification may pin the message
198
- (`then error "<message>"`); the C# specification for the same rejection pins the
199
- *kind* instead, and the two together cover the rule.
204
+ unhandled exception, so both facts are required. **Do not assert on a message
205
+ string by default** — it is presentation text; assert one only when that exact
206
+ text is the specified behavior, and name that requirement in the fact. A `.play`
207
+ specification may pin the message (`then error "<message>"`); prefer pinning the
208
+ *kind* in C# unless the exact wording is part of the behavior being specified.
200
209
 
201
210
  **Isolate the rule.** Each rejection specification violates **only** the rule it
202
211
  is named after: build the command valid in every other respect. Otherwise
@@ -213,7 +222,7 @@ proven*.
213
222
  | `ShouldBeSuccessful()` / `ShouldNotBeSuccessful()` | Authorized, valid, no exceptions — or not |
214
223
  | `ShouldBeValid()` | Validation only; it checks neither authorization nor exceptions |
215
224
  | `ShouldHaveValidationErrors()` | At least one validation error |
216
- | `ShouldHaveValidationErrorFor(message)` | A validation error with that **message** |
225
+ | `ShouldHaveValidationErrorFor(message)` | A validation error whose message **contains** that text (a substring match; compare messages for equality when exact wording is specified) |
217
226
  | `ShouldHaveValidationErrorBecauseOf(reason)` | A validation error with that `ValidationResultReason` |
218
227
  | `ShouldBeAuthorized()` / `ShouldNotBeAuthorized()` | The authorization outcome |
219
228
  | `ShouldHaveExceptions()` / `ShouldNotHaveExceptions()` | Whether the handler threw |
@@ -86,7 +86,9 @@ and invokers, not a recording stub. Register substitutes through `Services`
86
86
  before first execution; do not register a production external client.
87
87
 
88
88
  This case fails the second reservation. Both entered invocations must be
89
- compensated; the third must never start.
89
+ compensated; the third must never start. It also explicitly specifies that the
90
+ original provider error wording is preserved verbatim, so the fact names that
91
+ requirement and asserts the exact message.
90
92
 
91
93
  ```csharp
92
94
  public class ReservationProviderUnavailable() : Exception("Reservation provider unavailable.");
@@ -120,7 +122,7 @@ public class when_the_second_reservation_fails : Specification
120
122
  ]));
121
123
 
122
124
  [Fact] void should_preserve_failure() => _result.ShouldNotBeSuccessful();
123
- [Fact] void should_preserve_the_original_error() =>
125
+ [Fact] void should_preserve_the_specified_provider_error_wording() =>
124
126
  _result.ExceptionMessages.ShouldContain("Reservation provider unavailable.");
125
127
  [Fact] void should_record_only_entered_invocations() => _scenario.Operations.Count.ShouldEqual(2);
126
128
  [Fact] void should_observe_the_first_execution_completing() =>
@@ -406,6 +406,10 @@ Express's `cratisArc(arc)` **before** any body parser, or every command answers
406
406
 
407
407
  ## Specify the command
408
408
 
409
+ Start with a direct `handle()` call for pure command decisions, passing any
410
+ provided values explicitly. Add `CommandScenario` only where binding,
411
+ authorization, validation or dependency wiring contribute proof.
412
+
409
413
  `@cratis/arc.testing` runs a command through the real pipeline in-process —
410
414
  binding, authorization, validators, services, `provide()`, `handle()` — without
411
415
  a listener. From `Samples/Tasks`:
@@ -461,6 +465,10 @@ describe('when registering a task with a valid title', given(a_task_registration
461
465
  `shouldHaveValidationErrorForMember(member)`, `shouldHaveValidationErrorFor(text)`,
462
466
  `shouldHaveValidationErrorBecauseOf(reason)`, `shouldBeAuthorized()`,
463
467
  `shouldNotBeAuthorized()`, `shouldHaveExceptions()`, `shouldNotHaveExceptions()`.
468
+ Do not assert presentation text by default; assert exact wording only when it
469
+ is the specified behavior, named in the fact. A text-matching helper alone
470
+ does not prove exact equality; compare the actual message when equality is
471
+ the requirement.
464
472
  - Specify authorization for three callers — anonymous, without the role, with
465
473
  it — and on `validate()` too.
466
474
 
@@ -489,7 +497,7 @@ Folder and naming conventions for specs are `cratis-specifications-typescript`.
489
497
  results, never thrown errors.
490
498
  - Generated metadata is regenerated and `--check-metadata` passes; `build()`
491
499
  succeeds at startup.
492
- - The command's `CommandScenario` specs pass, including the unauthorized and
493
- `/validate` cases.
500
+ - Plain-call specs cover pure command decisions; `CommandScenario` specs
501
+ cover the pipeline, including the unauthorized and `/validate` cases.
494
502
  - Guidance never claims the server packages are on npm, and never substitutes
495
503
  `@cratis/arc` (the client) for `@cratis/arc.core` (the server).
@@ -212,8 +212,10 @@ and that it failed *as a validation*:
212
212
  ```
213
213
 
214
214
  `ShouldNotBeSuccessful()` alone cannot tell a rejection from an unhandled
215
- exception, which is precisely the mistake this skill exists to prevent. Never
216
- assert on a message string — it is presentation text. See
215
+ exception, which is precisely the mistake this skill exists to prevent. Do not
216
+ assert on a message string by default — it is presentation text. Assert exact
217
+ wording only when it is the specified behavior, and name that requirement in
218
+ the fact. See
217
219
  `cratis-application-slice-specifications` for the scenario mechanics.
218
220
 
219
221
  ## What breaks
@@ -282,9 +282,12 @@ describe('when validating a task with an empty title', given(a_task_registration
282
282
 
283
283
  - Use `scenario.validate(...)` to prove the rule answers on `/validate`, and
284
284
  `execute(...)` to prove `handle()` never ran.
285
- - Assert the member with `shouldHaveValidationErrorForMember('title')`.
285
+ - Assert the member with `shouldHaveValidationErrorForMember('title')` by
286
+ default, not presentation text. Assert exact wording only when it is the
287
+ specified behavior, and name that requirement in the fact.
286
288
  `shouldHaveValidationErrorFor(text)` passes for any message **containing** the
287
- text; pass the full message when the wording matters.
289
+ text; even a full-message argument does not prove exact equality. Compare
290
+ the actual message for equality when exact wording is the requirement.
288
291
  - `validatorFailed` and `dependencyUnavailable` never satisfy
289
292
  `shouldHaveValidationErrors()` or the member assertion — they mean no authored
290
293
  rule was established. Assert them explicitly with
@@ -176,8 +176,12 @@ plaintext-derived hashes, not the personal value itself.
176
176
  Specify the constraint with `EventScenario`: seed the conflicting state through
177
177
  `Given`, append again, and assert
178
178
  `ShouldHaveConstraintViolationFor(<Module>ConstraintNames.UniqueX)` — **the
179
- constraint name, never the message**. A message is presentation text and will
180
- change without the behavior changing.
179
+ constraint name by default**. A message is presentation text and will change
180
+ without the behavior changing. Assert exact message text only when that wording
181
+ is the specified behavior, and name that behavior in the fact.
182
+
183
+ The example compiles into the application assembly, so it uses `#if DEBUG`.
184
+ Dedicated spec projects need no wrapper.
181
185
 
182
186
  ```csharp
183
187
  #if DEBUG
@@ -240,5 +244,6 @@ exercisable there; concurrency violations need the real kernel.
240
244
  `CHR0020` are all clean.
241
245
  - Every constraint has an `EventScenario` specification that seeds the conflict
242
246
  and asserts `ShouldHaveConstraintViolationFor(<name>)` on the name.
243
- - No specification asserts on a violation message string.
247
+ - Violation message strings are not asserted by default. Exact wording is
248
+ asserted only when it is the specified behavior, named in the fact.
244
249
  - Build clean in Debug and Release, and the specifications pass.
@@ -147,12 +147,14 @@ scenario and the second passes vacuously.
147
147
  The constraint name parameter is a `ConstraintName`, which converts implicitly
148
148
  from `string`, so a literal compiles. Prefer a shared constant
149
149
  (`<Module>ConstraintNames.UniqueX`) so a rename moves both sides at once.
150
- **Assert the name, never the message.**
150
+ **Assert the name by default.** Assert exact message text only when that wording
151
+ is the specified behavior, and name that behavior in the fact.
151
152
 
152
153
  ## Step 5 — Write the specification
153
154
 
154
- Specification files live in the slice folder, wrapped in `#if DEBUG … #endif` so
155
- specification code ships only in Debug.
155
+ Specification files live in the slice folder. Wrap them in `#if DEBUG … #endif`
156
+ only when they compile into the application assembly, so specification code
157
+ ships only in Debug. Dedicated spec projects need no wrapper.
156
158
 
157
159
  ```csharp
158
160
  #if DEBUG
@@ -375,11 +375,14 @@ when they serve that concern.
375
375
 
376
376
  ## Specifications
377
377
 
378
- Drive events through the reactor scenario helper with a service provider of
379
- substitutes, and assert on those substitutes for non-event side effects. For
380
- handlers that return events, assert the resulting appends through the scenario's
381
- event store. Cover the replay path separately when the reactor has `[OnceOnly]`
382
- or `[Replay]` handlers.
378
+ Start with `Specification` plus a direct call for pure reactor decisions,
379
+ passing the trigger and supplied values explicitly and asserting the returned
380
+ command or event. Add `ReactorScenario<TReactor>` only where invocation,
381
+ dependency wiring or side effects contribute proof. In those scenarios, drive
382
+ events with a service provider of substitutes and assert on the substitutes for
383
+ non-event side effects; for handlers that return events, assert the resulting
384
+ appends through the scenario's event store. Cover the replay path separately
385
+ when the reactor has `[OnceOnly]` or `[Replay]` handlers.
383
386
 
384
387
  Specify the contract, not only the happy path:
385
388
 
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: cratis-chronicle-read-model-specifications
3
- description: Specify projection and reducer behavior with ReadModelScenario from Cratis.Chronicle.Testing — seeding events through Given and asserting on the materialized instance. Use when the behavior under specification is how events become read-model state. Do not use to create a read model and do not use for raw event append behavior.
3
+ description: Specify declarative projections and reducer wiring with ReadModelScenario from Cratis.Chronicle.Testing — seeding events through Given and asserting on the materialized instance; start with Specification plus a direct call for pure reducer decisions. Use when the behavior under specification is how events become read-model state. Do not use to create a read model and do not use for raw event append behavior.
4
4
  license: MIT
5
5
  ---
6
6
 
@@ -10,8 +10,13 @@ license: MIT
10
10
  against a sequence of events. No Chronicle server, no database, no network — the
11
11
  events go in, the materialized instance comes out.
12
12
 
13
- For a read-model specification the **`Given` *is* the act**. There is no
14
- separate `When`: seeding the events is what makes the projection run.
13
+ Pure reducer decisions use `Specification` plus a direct method call by
14
+ default, with the event and current state supplied explicitly. Add
15
+ `ReadModelScenario<TReadModel>` only where declarative projection behavior,
16
+ event dispatch, filtering, metadata or read-model wiring contribute proof.
17
+
18
+ For a read-model scenario specification the **`Given` *is* the act**. There
19
+ is no separate `When`: seeding the events is what makes the projection run.
15
20
 
16
21
  ## Verified product sources
17
22
 
@@ -56,7 +61,7 @@ version.
56
61
 
57
62
  ## When you need this
58
63
 
59
- - A reducer builds state from a sequence of events.
64
+ - A reducer's event dispatch, filtering or read-model wiring needs proof.
60
65
  - A fluent `IProjectionFor<T>` maps event properties onto read-model properties.
61
66
  - A model-bound projection — `[FromEvent<T>]`, `[SetFrom<T>]`, `[Key]` — maps
62
67
  correctly.
@@ -167,8 +172,9 @@ public class and_two_items_are_priced : Specification
167
172
  #endif
168
173
  ```
169
174
 
170
- Wrap every file in `#if DEBUG … #endif` so specification code ships only in
171
- Debug, and keep one outcome per `should_` fact.
175
+ Wrap files in `#if DEBUG … #endif` only when they compile into the application
176
+ assembly, so specification code ships only in Debug. Dedicated spec projects
177
+ need no wrapper. Keep one outcome per `should_` fact.
172
178
 
173
179
  ## Step 6 — Cover the read model, not just one event
174
180
 
@@ -166,8 +166,11 @@ Mind the parameter order on `Append`: `eventStreamType` comes before
166
166
 
167
167
  ## Specifications
168
168
 
169
- Drive a sequence of events through the read-model scenario helper for the read
170
- model and assert on the resulting instance. Cover, at minimum:
169
+ Start with `Specification` plus a direct call for pure reducer decisions:
170
+ pass the event and current state explicitly and assert the returned next state.
171
+ Add `ReadModelScenario<TReadModel>` only where event dispatch, filtering,
172
+ metadata or read-model wiring contribute proof; drive the event sequence and
173
+ assert on the resulting instance there. Cover, at minimum:
171
174
 
172
175
  - the first event, where `current` is `null`;
173
176
  - accumulation across several events on one event source;
@@ -129,13 +129,18 @@ degradations a reviewer can see without measuring:
129
129
 
130
130
  ## Step 6 — Specification coverage
131
131
 
132
+ - Pure command, reducer and reactor decisions have plain-call specifications
133
+ (`Specification` plus a direct call); scenarios are added where pipelines,
134
+ validation, constraints, projections or wiring contribute proof.
132
135
  - Every State Change command has a happy-path specification.
133
136
  - Every validation rule has a failure specification asserting **both**
134
137
  `ShouldNotBeSuccessful()` and `ShouldHaveValidationErrors()`.
135
138
  - Every business-rule rejection has a specification.
136
139
  - Every constraint has an `EventScenario` specification asserting the constraint
137
- **name**, not its message.
138
- - No specification asserts on a presentation message string.
140
+ **name** by default.
141
+ - Presentation message strings are not asserted by default. Exact wording is
142
+ asserted only when it is the specified behavior, and the fact names that
143
+ requirement.
139
144
  - Nothing trivial is specified — a property getter, a constructor pass-through,
140
145
  a delegation.
141
146
  - No specification sleeps to let the system catch up.
@@ -169,16 +169,21 @@ getter, not a behavior. Delete it rather than maintaining it.
169
169
 
170
170
  A specification is only as good as the signal it reads.
171
171
 
172
- - **Assert on the outcome, not the message.** A presentation string is copy;
172
+ - **Assert on the outcome by default.** A presentation string is copy;
173
173
  it changes for reasons that have nothing to do with the behavior. Assert on
174
174
  the identity of what failed — an error code, a constraint name, a typed
175
- result — never on the sentence shown to a user.
176
- - **In code (C#, TypeScript):** never assert a message string.
175
+ result — rather than the sentence shown to a user, unless exact wording is
176
+ the specified behavior.
177
+ - **In code (C#, TypeScript):** do not assert message strings by default;
178
+ assert exact text only when that wording is the specified behavior, and
179
+ name that behavior in the fact.
177
180
  - **In a `.play` model:** a rejection specification pins the message, or
178
181
  its localization key, with `then error "<message>"` or
179
182
  `then error "$strings.<key>"`, because the model has no reason codes. Bare
180
- `then error` leaves the reason to the specification's name. The model pins
181
- the message; the code specification pins the kind. They do not conflict.
183
+ `then error` leaves the reason to the specification's name. The code
184
+ specification pins the kind by default; assert the model's exact message
185
+ too only when its wording is
186
+ the specified behavior, and name that behavior in the fact.
182
187
 
183
188
  ```screenplay
184
189
  concept InvoiceId : Uuid
@@ -225,7 +230,8 @@ edge someone chose is a different thing from one nobody saw.
225
230
  - One specification per file; one outcome per specification.
226
231
  - No action and no assertion sits on a `given/` context.
227
232
  - Nothing trivial, delegated, or compiler-verified is specified.
228
- - No code assertion reads a presentation message string; a `.play` rejection
229
- pins its message or key deliberately.
233
+ - Code assertions do not pin presentation messages by default. Exact wording
234
+ is asserted only when it is the specified behavior, named in the fact; a
235
+ `.play` rejection pins its message or key deliberately.
230
236
  - No sleep, bare delay, or poll loop stands in for a completion signal.
231
237
  - The suite runs green, and the report names what was not covered.
@@ -50,6 +50,7 @@ another version. Never translate an assertion or helper name from memory.
50
50
 
51
51
  | Situation | Surface |
52
52
  | --- | --- |
53
+ | Pure `Handle()` / `Handle(providedValue)`, reducer logic or reactor decision (default) | Plain method call with `Specification` |
53
54
  | Isolated class, collaborators can be substituted | `Specification` + NSubstitute |
54
55
  | Arc command pipeline (validators, `Provide()`, `Handle()`, appended events) | `CommandScenario<TCommand>` |
55
56
  | Chronicle append semantics, constraints, concurrency | `EventScenario` |
@@ -59,8 +60,9 @@ another version. Never translate an assertion or helper name from memory.
59
60
  | Setup shared by many specifications | Reusable context under `given/` |
60
61
 
61
62
  The plain `Specification` base is the universal foundation and the dominant mode
62
- in library and framework code. The four scenario helpers are the default for
63
- event-sourced *application* behavior; read
63
+ in library and framework code. In applications, start pure decisions with a
64
+ plain call and add the scenario helpers where the pipeline, validation,
65
+ constraints or declarative projections contribute proof; read
64
66
  [application-scenarios.md](references/application-scenarios.md) before using
65
67
  one. Out-of-process integration specifications are an advanced case reserved for
66
68
  boundaries the scenario helpers cannot reach — see
@@ -234,8 +236,9 @@ between collaborators. That is where defects hide.
234
236
  - Field access modifiers and `_camelCase` naming match the surface.
235
237
  - No `Thread.Sleep`, bare `Task.Delay`, or poll loop stands in for a signal; any
236
238
  remaining delay carries a comment naming which allowed case it is.
237
- - Assertions use the `ShouldXxx` extension methods and never assert on a
238
- presentation message string.
239
+ - Assertions use the `ShouldXxx` extension methods. Do not assert on presentation
240
+ message strings by default; assert exact text only when it is the specified
241
+ behavior, and name that requirement in the fact.
239
242
  - Nothing trivial or compiler-verified is specified.
240
243
  - The file carries the repository license header.
241
244
  - The specification project builds and its specifications pass against the
@@ -1,9 +1,11 @@
1
1
  # In-process scenario specifications
2
2
 
3
3
  The four scenario helpers exercise the real Arc and Chronicle pipelines
4
- in-process. They are the default for event-sourced *application* behavior. A
5
- library or framework repository reaches for one only to test the very engine it
6
- provides.
4
+ in-process. Use them for event-sourced *application* behavior where the pipeline,
5
+ validation, constraints or projections matter; a pure decision (`Handle()`,
6
+ `Handle(providedValue)`, reducer or reactor logic) is specified first as a plain
7
+ call. A library or framework repository reaches for a scenario only to test the
8
+ very engine it provides.
7
9
 
8
10
  Verified against `Cratis.Arc.Testing` `22.16.0` and `Cratis.Chronicle.Testing`
9
11
  `18.3.0`.
@@ -15,8 +17,10 @@ Verified against `Cratis.Arc.Testing` `22.16.0` and `Cratis.Chronicle.Testing`
15
17
  | `ReadModelScenario<TReadModel>` | Projection or reducer state from a sequence of events | State View behavior |
16
18
  | `ReactorScenario<TReactor>` | Reactor invocation and its side effects | Automation and Translation behavior |
17
19
 
18
- Wrap every scenario specification file in `#if DEBUG … #endif` so specification
19
- code compiles only in Debug.
20
+ Wrap scenario specification files in `#if DEBUG … #endif` only when they compile
21
+ into the application assembly, so specification code ships only in Debug.
22
+ Dedicated spec projects need no wrapper. The example below uses the application
23
+ assembly convention.
20
24
 
21
25
  ## `CommandScenario<TCommand>`
22
26
 
@@ -88,7 +92,9 @@ different: an unauthorized result carries **no** validation errors, so assert
88
92
  existing command therefore breaks both its happy-path and its validation-failure
89
93
  specifications — switch those assertions rather than patching around them.
90
94
 
91
- Never assert on a message string.
95
+ Do not assert on message strings by default — they are presentation text.
96
+ Assert exact text only when that wording is the specified behavior, and name
97
+ that behavior in the fact.
92
98
 
93
99
  > **Validator state can be order-sensitive.** The command-scenario pipeline can
94
100
  > cache enough state that injected-validator branches depend on execution order
@@ -121,7 +127,8 @@ async Task Because() =>
121
127
  and `ShouldNotHaveConstraintViolations()`,
122
128
  `ShouldHaveConstraintViolationFor(name)`,
123
129
  `ShouldHaveConcurrencyViolations()` and its negation, `ShouldHaveErrors()` and
124
- its negation. Assert the constraint **name**, never the message.
130
+ its negation. Assert the constraint **name** by default. Assert exact message
131
+ text only when that wording is the specified behavior, and name it in the fact.
125
132
 
126
133
  ⚠️ `EventScenario` wires a strategy that always answers `ConcurrencyScope.None`,
127
134
  which the validator skips, so an append that lets the strategy choose the scope
@@ -94,8 +94,9 @@ From `Cratis.Specifications`:
94
94
  | `.ShouldBeOfExactType<T>()` | `_event.ShouldBeOfExactType<<EventType>>()` |
95
95
  | `.ShouldBeGreaterThan(n)` / `.ShouldBeLessThan(n)` | `_count.ShouldBeGreaterThan(0)` |
96
96
 
97
- Assert on values and types. Never assert on a presentation message string — it
98
- is text, not behavior.
97
+ Assert on values and types. Do not assert on presentation message strings by
98
+ default; assert exact text only when that wording is the specified behavior,
99
+ and name that behavior in the fact.
99
100
 
100
101
  ## Catching exceptions
101
102
 
@@ -46,7 +46,9 @@ value.should.be.instanceOf(<Type>);
46
46
  (() => <throwingCall>()).should.throw(<ErrorType>);
47
47
  ```
48
48
 
49
- Assert on values and types, never on a presentation message string.
49
+ Assert on values and types. Do not assert on presentation message strings by
50
+ default; assert exact text only when that wording is the specified behavior,
51
+ and name that behavior in the fact.
50
52
 
51
53
  ## Sinon stubbing
52
54
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cratis/pi",
3
- "version": "7.11.4",
3
+ "version": "7.12.0",
4
4
  "description": "Configuration-aware Cratis AI integration for Pi",
5
5
  "type": "module",
6
6
  "files": [