@cratis/pi 7.11.3 → 7.11.5
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/agents/planner.md +1 -1
- package/package/corpus/agents/slice-implementer.md +3 -3
- package/package/corpus/agents/spec-writer.md +10 -8
- package/package/corpus/prompts/add-reactor.prompt.md +1 -1
- package/package/corpus/prompts/new-vertical-slice.prompt.md +1 -1
- package/package/corpus/prompts/write-specs.prompt.md +2 -2
- package/package/corpus/rules/application-profile.md +1 -1
- package/package/corpus/rules/framework.md +1 -1
- package/package/corpus/rules/local-work-artifacts.md +13 -0
- package/package/corpus/rules/reactors.md +2 -2
- package/package/corpus/rules/specs.csharp.md +1 -1
- package/package/corpus/rules/specs.scenarios.csharp.md +34 -14
- package/package/corpus/rules/vertical-slices.md +1 -1
- package/package/corpus/skills/cratis-application-slice-conformance/references/checklists.md +4 -2
- package/package/corpus/skills/cratis-application-slice-specifications/SKILL.md +24 -15
- package/package/corpus/skills/cratis-arc-command-operation/references/testing.md +4 -2
- package/package/corpus/skills/cratis-arc-command-typescript/SKILL.md +10 -2
- package/package/corpus/skills/cratis-arc-command-validation/SKILL.md +4 -2
- package/package/corpus/skills/cratis-arc-validation-typescript/SKILL.md +5 -2
- package/package/corpus/skills/cratis-chronicle-event-constraints/SKILL.md +8 -3
- package/package/corpus/skills/cratis-chronicle-event-specifications/SKILL.md +5 -3
- package/package/corpus/skills/cratis-chronicle-reactor/SKILL.md +8 -5
- package/package/corpus/skills/cratis-chronicle-read-model-specifications/SKILL.md +12 -6
- package/package/corpus/skills/cratis-chronicle-reducer/SKILL.md +5 -2
- package/package/corpus/skills/cratis-code-review/SKILL.md +7 -2
- package/package/corpus/skills/cratis-screenplay-captures-and-reactions/SKILL.md +3 -3
- package/package/corpus/skills/cratis-screenplay-captures-and-reactions/references/complete-examples.md +1 -1
- package/package/corpus/skills/cratis-screenplay-command-surface/SKILL.md +49 -7
- package/package/corpus/skills/cratis-screenplay-command-surface/verification.json +8 -2
- package/package/corpus/skills/cratis-screenplay-discovery/SKILL.md +1 -1
- package/package/corpus/skills/cratis-screenplay-event-modeling/SKILL.md +11 -7
- package/package/corpus/skills/cratis-screenplay-event-modeling/references/parsed-not-runnable.md +11 -6
- package/package/corpus/skills/cratis-screenplay-legacy-extraction/SKILL.md +1 -1
- package/package/corpus/skills/cratis-screenplay-model-authoring/SKILL.md +7 -5
- package/package/corpus/skills/cratis-screenplay-model-authoring/references/language-reference.md +19 -12
- package/package/corpus/skills/cratis-screenplay-model-authoring/references/mcp-loop.md +3 -3
- package/package/corpus/skills/cratis-screenplay-model-authoring/references/mcp-tools.md +12 -4
- package/package/corpus/skills/cratis-screenplay-model-authoring/references/provenance.md +1 -1
- package/package/corpus/skills/cratis-screenplay-projections/SKILL.md +1 -1
- package/package/corpus/skills/cratis-screenplay-read-surface/SKILL.md +1 -1
- package/package/corpus/skills/cratis-screenplay-render-and-gap-fill/SKILL.md +8 -2
- package/package/corpus/skills/cratis-screenplay-render-and-gap-fill/references/renderability-gate.md +1 -1
- package/package/corpus/skills/cratis-screenplay-render-and-gap-fill/verification.json +3 -1
- package/package/corpus/skills/cratis-screenplay-scenario-coverage/SKILL.md +3 -2
- package/package/corpus/skills/cratis-screenplay-scenario-coverage/references/scenario-catalogue.md +8 -0
- package/package/corpus/skills/cratis-screenplay-scenario-coverage/references/spec-forms-by-mode.md +1 -0
- package/package/corpus/skills/cratis-screenplay-scenario-coverage/verification.json +1 -0
- package/package/corpus/skills/cratis-screenplay-slice-design/SKILL.md +1 -1
- package/package/corpus/skills/cratis-screenplay-slice-design/references/field-lineage.md +1 -1
- package/package/corpus/skills/cratis-screenplay-specifications/SKILL.md +47 -4
- package/package/corpus/skills/cratis-screenplay-specifications/verification.json +4 -0
- package/package/corpus/skills/cratis-screenplay-streams-and-consistency/SKILL.md +7 -3
- package/package/corpus/skills/cratis-screenplay-streams-and-consistency/references/stream-patterns.md +2 -2
- package/package/corpus/skills/cratis-screenplay-streams-and-consistency/verification.json +3 -1
- package/package/corpus/skills/cratis-screenplay-toolchain/SKILL.md +13 -12
- package/package/corpus/skills/cratis-screenplay-toolchain/references/cheat-sheet.md +1 -1
- package/package/corpus/skills/cratis-screenplay-toolchain/references/doc-contradictions.md +3 -3
- package/package/corpus/skills/cratis-screenplay-toolchain/references/executable-subset.md +41 -4
- package/package/corpus/skills/cratis-screenplay-toolchain/references/generated-responses-example.md +59 -0
- package/package/corpus/skills/cratis-screenplay-toolchain/references/provenance.md +1 -0
- package/package/corpus/skills/cratis-screenplay-toolchain/references/renderable-subset.md +2 -2
- package/package/corpus/skills/cratis-screenplay-toolchain/references/sources-and-streams.md +6 -6
- package/package/corpus/skills/cratis-screenplay-toolchain/references/traps.md +3 -3
- package/package/corpus/skills/cratis-screenplay-toolchain/references/verdicts.md +2 -2
- package/package/corpus/skills/cratis-screenplay-toolchain/references/versions.md +17 -15
- package/package/corpus/skills/cratis-screenplay-toolchain/verification.json +4 -0
- package/package/corpus/skills/cratis-screenplay-ui-composition/SKILL.md +4 -3
- package/package/corpus/skills/cratis-screenplay-ui-composition/references/worked-flow.md +3 -3
- package/package/corpus/skills/cratis-specification-by-example/SKILL.md +13 -7
- package/package/corpus/skills/cratis-specifications-csharp/SKILL.md +7 -4
- package/package/corpus/skills/cratis-specifications-csharp/references/application-scenarios.md +14 -7
- package/package/corpus/skills/cratis-specifications-csharp/references/csharp-patterns.md +3 -2
- package/package/corpus/skills/cratis-specifications-typescript/references/typescript-patterns.md +3 -1
- package/package/corpus/skills/cratis-stage-rendering-and-sandbox/references/admission.md +1 -1
- 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
|
|
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.
|
|
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
|
|
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 (
|
|
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.
|
|
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 —
|
|
46
|
+
## C# specs — start with the plain call
|
|
46
47
|
|
|
47
|
-
|
|
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
|
-
|
|
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
|
|
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()`.
|
|
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
|
-
- [ ]
|
|
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
|
-
-
|
|
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,
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
-
##
|
|
15
|
+
## Start with the plain call; add a scenario where it adds proof
|
|
16
16
|
|
|
17
|
-
For
|
|
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` (
|
|
22
|
-
| `CommandScenario<TCommand>` | the real Arc command pipeline — authorization + validators + `Provide()` + `Handle()` + appended events |
|
|
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
|
-
**
|
|
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
|
-
###
|
|
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,
|
|
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. **
|
|
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
|
|
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>` —
|
|
129
|
+
### `ReadModelScenario<TReadModel>` — declarative projections and reducer wiring
|
|
110
130
|
|
|
111
|
-
|
|
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
|
|
76
|
-
|
|
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
|
|
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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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 **
|
|
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`
|
|
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 —
|
|
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
|
-
|
|
|
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. **
|
|
197
|
-
string** — it is presentation text
|
|
198
|
-
|
|
199
|
-
|
|
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
|
|
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
|
|
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
|
-
-
|
|
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.
|
|
216
|
-
assert on a message string — it is presentation text.
|
|
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;
|
|
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
|
|
180
|
-
|
|
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
|
-
-
|
|
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
|
|
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
|
|
155
|
-
|
|
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
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
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
|
|