@cratis/pi 7.193.1 → 7.194.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.
@@ -87,13 +87,17 @@ anti-pattern fixes must not scatter a vertical slice across folders.
87
87
  Read the **cratis-arc-elixir** and **cratis-chronicle-client-elixir** skills before touching a slice.
88
88
 
89
89
  - **Folders are Module, Feature, Slice, and sub-features nest.** One folder per behavior, named for what
90
- it does as a gerund (`RotatingSecrets`); the command inside is the verb. Group slices that act on one
90
+ it does as a gerund, without repeating what its sub-feature already names (`Secrets.Rotating`, not
91
+ `Secrets.RotatingSecrets`; see [vertical-slices.md](./vertical-slices.instructions.md)); the command inside is the verb and keeps
92
+ its noun (`RotateSecret`). Group slices that act on one
91
93
  thing into a sub-feature (`Secrets`, `Credentials`, `Viewing`), and put a reactor with the facts it
92
94
  reacts to, not in a folder named for the third party it calls. No folders named for a kind of file.
93
95
  - **Names are ids.** `use Cratis.Arc.Command, id: "rotate-secret"`, an event type's `id:`, a reactor's
94
96
  `id:`; the model shows the id in PascalCase, so a module can be renamed without renaming the model.
95
97
  - **A command and its events live in one file**, events first. An event is past tense, one fact, and
96
- never carries a secret.
98
+ never carries a secret or anything derived from one (no hint, hash or last characters): the system that
99
+ owns a secret, such as an identity provider, is the only one that holds it, and a secret is shown once to
100
+ the person who asked for it.
97
101
  - **Every slice tells a whole story**: a state change has a command and the events it appends; a view
98
102
  has a read model and consumes events (`consumes:` when it reads the event log); an automation reacts to
99
103
  an event, runs a command and records the fact that command appends, so the event model shows what it
@@ -64,64 +64,118 @@ Folder names are `snake_case`. A spec's **module name mirrors its path** below t
64
64
  `PascalCase`, so it can never clash with the module it specifies and is never named `...Test`:
65
65
 
66
66
  ```elixir
67
- # lib/access/credentials/adding_credentials/for_add_credential/when_adding/with_selected_vessels.exs
68
- defmodule Prism.Access.Credentials.AddingCredentials.ForAddCredential.WhenAdding.WithSelectedVessels do
67
+ # lib/access/credentials/adding/for_add_credential/when_adding/with_selected_vessels.exs
68
+ defmodule Prism.Access.Credentials.Adding.ForAddCredential.WhenAdding.WithSelectedVessels do
69
69
  use ExUnit.Case, async: true
70
70
  ```
71
71
 
72
72
  ## One scenario, several `should` assertions
73
73
 
74
- The `setup` establishes the context and performs the behavior once per assertion (ExUnit runs `setup` for each
75
- `test`); each `test` states one expectation and starts with **`should`**, so the file reads as a sentence:
74
+ Use the **scenarios** of Arc and Chronicle for Elixir: the counterpart of the C# `Specification` with its
75
+ `CommandScenario`, `EventScenario`, `ReadModelScenario`, `ReactorScenario` and `QueryScenario`. Facts are given,
76
+ the behavior happens **once** (`setup_all`: the shared lifecycle), and each `test` is one expectation, a
77
+ `should_*` function that starts the test name with **`should`**:
76
78
 
77
79
  ```elixir
78
- defmodule Prism.Access.ApiCredentials.ForState.WhenDerivingTheStatus do
79
- use ExUnit.Case, async: true
80
+ defmodule MyApp.Authors.ForRegisterAuthor.WhenRegistering.WithAValidName do
81
+ use Cratis.Arc.Test.CommandScenario,
82
+ application: MyApp.Arc,
83
+ event_types: [MyApp.Authors.AuthorRegistered]
84
+
85
+ alias MyApp.Authors.{AuthorRegistered, RegisterAuthor}
86
+
87
+ setup_all %{scenario: scenario} do
88
+ scenario =
89
+ scenario
90
+ |> given_events("ada", %AuthorRegistered{name: "Ada"})
91
+ |> execute(%RegisterAuthor{id: "grace", name: "Grace"}, as: principal("tester", ["maintainer"]))
92
+
93
+ %{scenario: scenario}
94
+ end
80
95
 
81
- alias Prism.Access.ApiCredentials.State
96
+ test "should be successful", %{scenario: scenario}, do: should_be_successful(scenario)
82
97
 
83
- test "should be active by default" do
84
- assert State.status(%State{id: "c", exists?: true}, ~U[2026-03-01 12:00:00Z]) == :active
98
+ test "should append the author as registered", %{scenario: scenario} do
99
+ should_have_appended(scenario, %AuthorRegistered{name: "Grace"}, event_source_id: "grace")
85
100
  end
86
101
  end
87
102
  ```
88
103
 
89
- - `test "should refuse a duplicate label"`, not `test "a duplicate label is refused"` and not
90
- `test "refuses..."`. Name the expected result, not the call.
91
- - A file with several unrelated scenarios is several files. Split `describe` blocks into
92
- `when_<behavior>/<preposition>_<condition>.exs` files; do not use `describe` to group scenarios.
104
+ A scenario is an immutable value: **given** and **because** functions (`given_events/3`, `execute/3`, `query/5`,
105
+ `append/3`) return the next scenario, **should** functions return the one they checked, so they chain. Use
106
+ `lifecycle: :per_test` (and `setup`) only for a spec whose tests change the shared state. Only the events the
107
+ behavior appended count for `should_have_appended`, not the given ones.
108
+
109
+ | Scenario | Module | Use for |
110
+ |---|---|---|
111
+ | Command | `Cratis.Arc.Test.CommandScenario` | a command through the real pipeline: result, validation, authorization, constraints, events |
112
+ | Query | `Cratis.Arc.Test.QueryScenario` | a query's arguments, authorization and data (the in-memory kernel runs no read-model queries) |
113
+ | Event | `Cratis.Chronicle.Testing.EventScenario` | an event's constraints (`unique/2`, `unique_event_type/1`), concurrency, sequence numbers |
114
+ | Read model | `Cratis.Chronicle.Testing.ReadModelScenario` | what a projection or reducer builds from given events, by module and key |
115
+ | Reactor | `Cratis.Chronicle.Testing.ReactorScenario` | the events a reactor produced and whether it failed |
116
+
117
+ For assertions on any other value use `Cratis.Arc.Test.Should` (`should_equal`, `should_contain_only`,
118
+ `should_match`, ...): the value first, so they pipe, and they return it. A plain `ExUnit.Case` with `assert` is
119
+ fine for a pure function; there is no scenario to set up.
120
+
121
+ - Name the expected result, not the call: `test "should refuse a duplicate label"`.
122
+ - A file with several unrelated scenarios is several files; do not use `describe` to group them.
93
123
  - Assert on the **contract**: the result, the events appended, what a collaborator was asked to do. Do not
94
124
  assert on internals, and do not spec logging or trivial delegation.
95
125
  - `doctest Module` belongs in its own spec (`when_building/with_the_documented_examples.exs`).
96
126
 
97
- ## Shared context: `given/`
127
+ ## Shared context: `given/` contexts
98
128
 
99
- Contexts that several specs share (a table of people, a started kernel) go in `for_<unit>/given/<name>.exs`
100
- as a module, and a spec loads it by relative path. The filter above keeps `given/` out of the specs ExUnit
101
- runs, so it is loaded once, by the spec that needs it:
129
+ Facts that several specs start from are a **given context**, named for the situation (`a_credential`,
130
+ `a_rotated_credential`), the counterpart of the `given` classes of the C# specs. A context is a module in a
131
+ script under a `given/` folder beside the specs that use it, with `given/1` that returns the next scenario
132
+ (`given/2` takes an argument, `{Context, argument}` passes it):
102
133
 
103
134
  ```elixir
104
- Code.require_file("../given/people.exs", __DIR__)
135
+ # lib/access/api/given/a_credential.exs
136
+ defmodule Prism.Access.Api.Given.ACredential do
137
+ use Cratis.Arc.Test.Given
105
138
 
106
- defmodule Prism.Access.Components.DataTable.ForDataTable.WhenFiltering.WithASingleFilter do
107
- use ExUnit.Case, async: true
139
+ @impl true
140
+ def given(scenario), do: __MODULE__.given(scenario, %{})
108
141
 
109
- alias Prism.Access.Components.DataTable.ForDataTable.Given.People
110
- import People, only: [names: 1, table: 1]
111
- ...
142
+ @impl true
143
+ def given(scenario, attrs), do: given_command(scenario, AddCredential, Map.merge(@defaults, attrs))
144
+ end
145
+ ```
146
+
147
+ A spec applies contexts with the `given:` option of its scenario, which runs them in order before its own
148
+ `setup_all`; contexts compose with `given_context/2` (`a_rotated_credential` is `a_credential` and a
149
+ rotation). Put a context where its users are: next to the one spec folder that needs it
150
+ (`for_rotate_secret/given/`), or in the feature's `given/` folder when several slices share it
151
+ (`secrets/given/`, `api/given/`). A fact that is only reachable through the real pipeline (a client created in
152
+ Ory) is given with a command that must succeed; the scenario goes on from before it, so only what the spec's
153
+ own behavior appended counts.
154
+
155
+ Load the scripts once, in `lib/test_helper.exs` (the helper sits in the first of `test_paths`), and keep
156
+ `mix test` from running them:
157
+
158
+ ```elixir
159
+ for file <- Path.wildcard("lib/**/given/*.exs") |> Enum.sort(), do: Code.require_file(file)
160
+ ```
161
+
162
+ ```elixir
163
+ test_ignore_filters: [&String.contains?(&1, "/given/")]
112
164
  ```
113
165
 
114
- A context that needs a compiled module (a `Case` with `setup`, an in-memory stand-in) is a `test/support/*.ex`
115
- module that the spec `use`s, like `Prism.Access.Case` in a Cratis application: it starts the in-memory
116
- Chronicle kernel and gives `exec/3`, `facts/2` and the stand-ins.
166
+ A thing the scenarios cannot express (fakes that need `start_supervised!`, application environment, a fixed
167
+ clock) is prepared by `setup: {Module, :function}`, run before the contexts in the setup's own process. An
168
+ application wraps that in its own `use` (`use Prism.Access.Scenario, given: [...]`) so a spec states only the
169
+ contexts and the behavior. Pure ExUnit specs of a function or a component keep a plain `given/` module that
170
+ they load with `Code.require_file("../given/people.exs", __DIR__)`.
117
171
 
118
172
  ## What to specify, by kind
119
173
 
120
174
  | Kind | Run it through | Assert |
121
175
  |---|---|---|
122
- | Command | the real pipeline (`Cratis.Arc.Test.execute/3`, in-memory Chronicle) | result, events appended (types and data), what the integration was asked |
123
- | Reactor / automation | the real reactor against the in-memory kernel | the command it ran, the event that records the outcome |
124
- | Read model, projection | the events folded (`State`, projection function) | the document, never `Process.sleep` |
176
+ | Command | `CommandScenario` (the real pipeline, in-memory Chronicle) | result, events appended (types and data), what the integration was asked |
177
+ | Reactor / automation | `ReactorScenario` (the real reactor against the in-memory kernel) | the command it ran, the event that records the outcome |
178
+ | Read model, projection | `ReadModelScenario`, or the events folded (`State`) for the pure part | the document, never `Process.sleep` |
125
179
  | Pure function | a direct call | return values; one file per rule |
126
180
  | LiveView / component | `Phoenix.LiveViewTest` (`render_component/2`, `live/2`) | the markup that matters: structure, state classes, the events wired, not every attribute |
127
181
 
@@ -49,6 +49,8 @@ A single `<Slice>.cs` therefore contains ALL of: `[Command]` records with `Handl
49
49
 
50
50
  **❌ Never split by artifact type** (`Commands/`, `Handlers/`, `Events/` folders) — that is the layered structure the slice replaces.
51
51
 
52
+ **[convention] A name does not repeat what its path already says.** A slice is named for what it does *within its feature*, so the feature's noun is not repeated: `Credentials/Adding`, `Credentials/Renaming`, `Secrets/Rotating`, not `Credentials/AddingCredentials` or `Secrets/RotatingSecrets`. Keep the noun when the feature does not name it (`Credentials/AddingLabels`, `Credentials/SyncingClients`, `Credentials/TransferringOwnership`), and never drop it into ambiguity: if two slices of a feature would end up with the same name, the nouns stay. The same holds up the tree: a module's root feature is named for what it is (`Prism.Access.Api`, not `Prism.Access.ApiCredentials` beside `Api.Credentials`), a view's query module is `Queries` inside its slice folder, and a spec is named for the unit and the behavior, not for the folders above it. The command, event and read model keep their full names (`AddCredential`, `CredentialAdded`): they are read away from the path, in the event model, the log and the proxies, where the path is gone.
53
+
52
54
  ## Concepts
53
55
 
54
56
  Every domain identifier or named value is a typed record — raw `string`/`Guid`/`int` should not appear on commands, events, or read models for domain values. Primitives stay primitive only when the meaning *is* the base type (`bool`, a plain count, `DateOnly`).
@@ -86,13 +86,17 @@ anti-pattern fixes must not scatter a vertical slice across folders.
86
86
  Read the **cratis-arc-elixir** and **cratis-chronicle-client-elixir** skills before touching a slice.
87
87
 
88
88
  - **Folders are Module, Feature, Slice, and sub-features nest.** One folder per behavior, named for what
89
- it does as a gerund (`RotatingSecrets`); the command inside is the verb. Group slices that act on one
89
+ it does as a gerund, without repeating what its sub-feature already names (`Secrets.Rotating`, not
90
+ `Secrets.RotatingSecrets`; see [vertical-slices.md](./vertical-slices.md)); the command inside is the verb and keeps
91
+ its noun (`RotateSecret`). Group slices that act on one
90
92
  thing into a sub-feature (`Secrets`, `Credentials`, `Viewing`), and put a reactor with the facts it
91
93
  reacts to, not in a folder named for the third party it calls. No folders named for a kind of file.
92
94
  - **Names are ids.** `use Cratis.Arc.Command, id: "rotate-secret"`, an event type's `id:`, a reactor's
93
95
  `id:`; the model shows the id in PascalCase, so a module can be renamed without renaming the model.
94
96
  - **A command and its events live in one file**, events first. An event is past tense, one fact, and
95
- never carries a secret.
97
+ never carries a secret or anything derived from one (no hint, hash or last characters): the system that
98
+ owns a secret, such as an identity provider, is the only one that holds it, and a secret is shown once to
99
+ the person who asked for it.
96
100
  - **Every slice tells a whole story**: a state change has a command and the events it appends; a view
97
101
  has a read model and consumes events (`consumes:` when it reads the event log); an automation reacts to
98
102
  an event, runs a command and records the fact that command appends, so the event model shows what it
@@ -63,64 +63,118 @@ Folder names are `snake_case`. A spec's **module name mirrors its path** below t
63
63
  `PascalCase`, so it can never clash with the module it specifies and is never named `...Test`:
64
64
 
65
65
  ```elixir
66
- # lib/access/credentials/adding_credentials/for_add_credential/when_adding/with_selected_vessels.exs
67
- defmodule Prism.Access.Credentials.AddingCredentials.ForAddCredential.WhenAdding.WithSelectedVessels do
66
+ # lib/access/credentials/adding/for_add_credential/when_adding/with_selected_vessels.exs
67
+ defmodule Prism.Access.Credentials.Adding.ForAddCredential.WhenAdding.WithSelectedVessels do
68
68
  use ExUnit.Case, async: true
69
69
  ```
70
70
 
71
71
  ## One scenario, several `should` assertions
72
72
 
73
- The `setup` establishes the context and performs the behavior once per assertion (ExUnit runs `setup` for each
74
- `test`); each `test` states one expectation and starts with **`should`**, so the file reads as a sentence:
73
+ Use the **scenarios** of Arc and Chronicle for Elixir: the counterpart of the C# `Specification` with its
74
+ `CommandScenario`, `EventScenario`, `ReadModelScenario`, `ReactorScenario` and `QueryScenario`. Facts are given,
75
+ the behavior happens **once** (`setup_all`: the shared lifecycle), and each `test` is one expectation, a
76
+ `should_*` function that starts the test name with **`should`**:
75
77
 
76
78
  ```elixir
77
- defmodule Prism.Access.ApiCredentials.ForState.WhenDerivingTheStatus do
78
- use ExUnit.Case, async: true
79
+ defmodule MyApp.Authors.ForRegisterAuthor.WhenRegistering.WithAValidName do
80
+ use Cratis.Arc.Test.CommandScenario,
81
+ application: MyApp.Arc,
82
+ event_types: [MyApp.Authors.AuthorRegistered]
83
+
84
+ alias MyApp.Authors.{AuthorRegistered, RegisterAuthor}
85
+
86
+ setup_all %{scenario: scenario} do
87
+ scenario =
88
+ scenario
89
+ |> given_events("ada", %AuthorRegistered{name: "Ada"})
90
+ |> execute(%RegisterAuthor{id: "grace", name: "Grace"}, as: principal("tester", ["maintainer"]))
91
+
92
+ %{scenario: scenario}
93
+ end
79
94
 
80
- alias Prism.Access.ApiCredentials.State
95
+ test "should be successful", %{scenario: scenario}, do: should_be_successful(scenario)
81
96
 
82
- test "should be active by default" do
83
- assert State.status(%State{id: "c", exists?: true}, ~U[2026-03-01 12:00:00Z]) == :active
97
+ test "should append the author as registered", %{scenario: scenario} do
98
+ should_have_appended(scenario, %AuthorRegistered{name: "Grace"}, event_source_id: "grace")
84
99
  end
85
100
  end
86
101
  ```
87
102
 
88
- - `test "should refuse a duplicate label"`, not `test "a duplicate label is refused"` and not
89
- `test "refuses..."`. Name the expected result, not the call.
90
- - A file with several unrelated scenarios is several files. Split `describe` blocks into
91
- `when_<behavior>/<preposition>_<condition>.exs` files; do not use `describe` to group scenarios.
103
+ A scenario is an immutable value: **given** and **because** functions (`given_events/3`, `execute/3`, `query/5`,
104
+ `append/3`) return the next scenario, **should** functions return the one they checked, so they chain. Use
105
+ `lifecycle: :per_test` (and `setup`) only for a spec whose tests change the shared state. Only the events the
106
+ behavior appended count for `should_have_appended`, not the given ones.
107
+
108
+ | Scenario | Module | Use for |
109
+ |---|---|---|
110
+ | Command | `Cratis.Arc.Test.CommandScenario` | a command through the real pipeline: result, validation, authorization, constraints, events |
111
+ | Query | `Cratis.Arc.Test.QueryScenario` | a query's arguments, authorization and data (the in-memory kernel runs no read-model queries) |
112
+ | Event | `Cratis.Chronicle.Testing.EventScenario` | an event's constraints (`unique/2`, `unique_event_type/1`), concurrency, sequence numbers |
113
+ | Read model | `Cratis.Chronicle.Testing.ReadModelScenario` | what a projection or reducer builds from given events, by module and key |
114
+ | Reactor | `Cratis.Chronicle.Testing.ReactorScenario` | the events a reactor produced and whether it failed |
115
+
116
+ For assertions on any other value use `Cratis.Arc.Test.Should` (`should_equal`, `should_contain_only`,
117
+ `should_match`, ...): the value first, so they pipe, and they return it. A plain `ExUnit.Case` with `assert` is
118
+ fine for a pure function; there is no scenario to set up.
119
+
120
+ - Name the expected result, not the call: `test "should refuse a duplicate label"`.
121
+ - A file with several unrelated scenarios is several files; do not use `describe` to group them.
92
122
  - Assert on the **contract**: the result, the events appended, what a collaborator was asked to do. Do not
93
123
  assert on internals, and do not spec logging or trivial delegation.
94
124
  - `doctest Module` belongs in its own spec (`when_building/with_the_documented_examples.exs`).
95
125
 
96
- ## Shared context: `given/`
126
+ ## Shared context: `given/` contexts
97
127
 
98
- Contexts that several specs share (a table of people, a started kernel) go in `for_<unit>/given/<name>.exs`
99
- as a module, and a spec loads it by relative path. The filter above keeps `given/` out of the specs ExUnit
100
- runs, so it is loaded once, by the spec that needs it:
128
+ Facts that several specs start from are a **given context**, named for the situation (`a_credential`,
129
+ `a_rotated_credential`), the counterpart of the `given` classes of the C# specs. A context is a module in a
130
+ script under a `given/` folder beside the specs that use it, with `given/1` that returns the next scenario
131
+ (`given/2` takes an argument, `{Context, argument}` passes it):
101
132
 
102
133
  ```elixir
103
- Code.require_file("../given/people.exs", __DIR__)
134
+ # lib/access/api/given/a_credential.exs
135
+ defmodule Prism.Access.Api.Given.ACredential do
136
+ use Cratis.Arc.Test.Given
104
137
 
105
- defmodule Prism.Access.Components.DataTable.ForDataTable.WhenFiltering.WithASingleFilter do
106
- use ExUnit.Case, async: true
138
+ @impl true
139
+ def given(scenario), do: __MODULE__.given(scenario, %{})
107
140
 
108
- alias Prism.Access.Components.DataTable.ForDataTable.Given.People
109
- import People, only: [names: 1, table: 1]
110
- ...
141
+ @impl true
142
+ def given(scenario, attrs), do: given_command(scenario, AddCredential, Map.merge(@defaults, attrs))
143
+ end
144
+ ```
145
+
146
+ A spec applies contexts with the `given:` option of its scenario, which runs them in order before its own
147
+ `setup_all`; contexts compose with `given_context/2` (`a_rotated_credential` is `a_credential` and a
148
+ rotation). Put a context where its users are: next to the one spec folder that needs it
149
+ (`for_rotate_secret/given/`), or in the feature's `given/` folder when several slices share it
150
+ (`secrets/given/`, `api/given/`). A fact that is only reachable through the real pipeline (a client created in
151
+ Ory) is given with a command that must succeed; the scenario goes on from before it, so only what the spec's
152
+ own behavior appended counts.
153
+
154
+ Load the scripts once, in `lib/test_helper.exs` (the helper sits in the first of `test_paths`), and keep
155
+ `mix test` from running them:
156
+
157
+ ```elixir
158
+ for file <- Path.wildcard("lib/**/given/*.exs") |> Enum.sort(), do: Code.require_file(file)
159
+ ```
160
+
161
+ ```elixir
162
+ test_ignore_filters: [&String.contains?(&1, "/given/")]
111
163
  ```
112
164
 
113
- A context that needs a compiled module (a `Case` with `setup`, an in-memory stand-in) is a `test/support/*.ex`
114
- module that the spec `use`s, like `Prism.Access.Case` in a Cratis application: it starts the in-memory
115
- Chronicle kernel and gives `exec/3`, `facts/2` and the stand-ins.
165
+ A thing the scenarios cannot express (fakes that need `start_supervised!`, application environment, a fixed
166
+ clock) is prepared by `setup: {Module, :function}`, run before the contexts in the setup's own process. An
167
+ application wraps that in its own `use` (`use Prism.Access.Scenario, given: [...]`) so a spec states only the
168
+ contexts and the behavior. Pure ExUnit specs of a function or a component keep a plain `given/` module that
169
+ they load with `Code.require_file("../given/people.exs", __DIR__)`.
116
170
 
117
171
  ## What to specify, by kind
118
172
 
119
173
  | Kind | Run it through | Assert |
120
174
  |---|---|---|
121
- | Command | the real pipeline (`Cratis.Arc.Test.execute/3`, in-memory Chronicle) | result, events appended (types and data), what the integration was asked |
122
- | Reactor / automation | the real reactor against the in-memory kernel | the command it ran, the event that records the outcome |
123
- | Read model, projection | the events folded (`State`, projection function) | the document, never `Process.sleep` |
175
+ | Command | `CommandScenario` (the real pipeline, in-memory Chronicle) | result, events appended (types and data), what the integration was asked |
176
+ | Reactor / automation | `ReactorScenario` (the real reactor against the in-memory kernel) | the command it ran, the event that records the outcome |
177
+ | Read model, projection | `ReadModelScenario`, or the events folded (`State`) for the pure part | the document, never `Process.sleep` |
124
178
  | Pure function | a direct call | return values; one file per rule |
125
179
  | LiveView / component | `Phoenix.LiveViewTest` (`render_component/2`, `live/2`) | the markup that matters: structure, state classes, the events wired, not every attribute |
126
180
 
@@ -48,6 +48,8 @@ A single `<Slice>.cs` therefore contains ALL of: `[Command]` records with `Handl
48
48
 
49
49
  **❌ Never split by artifact type** (`Commands/`, `Handlers/`, `Events/` folders) — that is the layered structure the slice replaces.
50
50
 
51
+ **[convention] A name does not repeat what its path already says.** A slice is named for what it does *within its feature*, so the feature's noun is not repeated: `Credentials/Adding`, `Credentials/Renaming`, `Secrets/Rotating`, not `Credentials/AddingCredentials` or `Secrets/RotatingSecrets`. Keep the noun when the feature does not name it (`Credentials/AddingLabels`, `Credentials/SyncingClients`, `Credentials/TransferringOwnership`), and never drop it into ambiguity: if two slices of a feature would end up with the same name, the nouns stay. The same holds up the tree: a module's root feature is named for what it is (`Prism.Access.Api`, not `Prism.Access.ApiCredentials` beside `Api.Credentials`), a view's query module is `Queries` inside its slice folder, and a spec is named for the unit and the behavior, not for the folders above it. The command, event and read model keep their full names (`AddCredential`, `CredentialAdded`): they are read away from the path, in the event model, the log and the proxies, where the path is gone.
52
+
51
53
  ## Concepts
52
54
 
53
55
  Every domain identifier or named value is a typed record — raw `string`/`Guid`/`int` should not appear on commands, events, or read models for domain values. Primitives stay primitive only when the meaning *is* the base type (`bool`, a plain count, `DateOnly`).
@@ -32,8 +32,8 @@ arc: [application: MyApp.Arc, event_model_strict: true]
32
32
 
33
33
  - A slice is the module namespace after `segments_to_skip` as `[module, feature..., slice]`: the first
34
34
  segment is the module, the last the slice, **everything between is a feature path**, so
35
- `Prism.Access.ApiCredentials.Secrets.RotatingSecrets.RotateSecret` with `segments_to_skip: 1` is the
36
- slice `RotatingSecrets` of the sub-feature `Secrets` of the feature `ApiCredentials` of the module
35
+ `Prism.Access.Api.Secrets.Rotating.RotateSecret` with `segments_to_skip: 1` is the
36
+ slice `Rotating` of the sub-feature `Secrets` of the feature `Api` of the module
37
37
  `Access`. The board nests sub-features as `subFeatures`, the Screenplay source nests `feature` inside
38
38
  `feature`, and each depth has its own document. Fewer than three segments fill the deepest parts first.
39
39
  - A slice with a command is a state change; with a read model, reducer or projection a state view; with
@@ -34,6 +34,17 @@ Cratis.Arc.Test.assert_invalid(result, :name)
34
34
  Cratis.Arc.Test.refute_appended(arc, AuthorRegistered)
35
35
  ```
36
36
 
37
+ For specs in the shape of a Specification use the scenarios: `use Cratis.Arc.Test.CommandScenario,
38
+ application: MyApp.Arc, event_types: [...]` (or `QueryScenario`) starts the kernel once per module, gives the
39
+ scenario as `:scenario`, and you chain `given_events/3`, `execute/3` (`as:` a `principal/2`) or `query/5`, then one
40
+ `should_*` per test: `should_be_successful/1`, `should_not_be_authorized/1`, `should_have_validation_errors/1,2`,
41
+ `should_have_constraint_violation/1,2`, `should_respond_with/2`, `should_have_appended/2,3`,
42
+ `should_have_appended_exactly/2`, `should_not_have_appended_any_events/1`, `should_return_items/2`. The
43
+ `Cratis.Arc.Test.Should` module is the counterpart of the C# `Should` extensions (`should_equal/2`,
44
+ `should_contain_only/2`, `should_match/2`, ...). Reusable facts are given contexts (`use Cratis.Arc.Test.Given`, a `given/1` that returns the scenario) applied with
45
+ `given: [Context]` or `given/2`, and `setup: {Module, :function}` prepares fakes before they run. Read
46
+ `rules/specs.elixir.md` for the layout of the files and the contexts.
47
+
37
48
  Also `Cratis.Arc.Test.query/5`, `principal/2`, `assert_success/1`, `assert_forbidden/1`,
38
49
  `assert_appended/3` and `wait_for_observers/1`. For a plain Plug application without
39
50
  Chronicle, call `Cratis.Arc.execute/3` and `Cratis.Arc.query/5` with `principal:` and `tenant:` and assert
@@ -28,7 +28,7 @@
28
28
 
29
29
  | Mistake | What happens | Do this |
30
30
  | --- | --- | --- |
31
- | A read model module in the parent namespace (`ApiCredentials.Listing` beside `ApiCredentials.Listing.Reducer`) | The view is grouped with the parent feature, not its slice | Put the query module inside the slice folder (`Listing.Queries`) |
31
+ | A read model module in the parent namespace (`Api.Listing` beside `Api.Listing.Reducer`) | The view is grouped with the parent feature, not its slice | Put the query module inside the slice folder (`Listing.Queries`) |
32
32
  | A reactor that appends events itself or returns nothing | The automation slice shows no command or no events | Have the reactor run a command in its slice folder that appends the fact; Arc shows reaction, command and event |
33
33
  | A view over a model another slice builds | Old Arc showed no events | Arc 1.4 reads them from the reducer; use `consumes:` for a model read from the event log |
34
34
  | Reading the last module segment as the name | The model shows the `id:` | Name by `id:` and keep `display_names:` in mind |
@@ -36,8 +36,8 @@ arc: [application: MyApp.Arc, output: "assets/src/arc"]
36
36
  A feature that holds more than about six slices is usually several features. Look for these seams
37
37
  before adding the next slice, and review them whenever a feature grows:
38
38
 
39
- - **One noun, many verbs.** The slices that act on one thing (`rotating_secrets`, `revoking_previous_secrets`,
40
- `expiring_previous_secrets`, `retiring_secrets`) belong together in a sub-feature named for the
39
+ - **One noun, many verbs.** The slices that act on one thing (`rotating`, `revoking_previous`,
40
+ `expiring_previous`, `retiring`) belong together in a sub-feature named for the
41
41
  thing (`secrets/`), not spread across a flat feature.
42
42
  - **A reactor belongs with the facts it reacts to.** An automation that retires a secret after it was
43
43
  revoked lives in `secrets/`, not in a folder named for the third party it calls (`ory/`). A third
@@ -48,8 +48,8 @@ before adding the next slice, and review them whenever a feature grows:
48
48
  Have it record the fact that its effect happened (`SecretRetiredInOry`), so the automation shows
49
49
  what it produced.
50
50
 
51
- The folder is the namespace: `Prism.Access.ApiCredentials.Secrets.RotatingSecrets` is the slice
52
- `RotatingSecrets` of the sub-feature `Secrets`. Arc's structure and event model show each
51
+ The folder is the namespace: `Prism.Access.Api.Secrets.Rotating` is the slice
52
+ `Rotating` of the sub-feature `Secrets`. Arc's structure and event model show each
53
53
  sub-feature as a feature of its own, so the grouping is what readers and tools see. Keep
54
54
  `segments_to_skip` equal to the segments above the module.
55
55
 
@@ -302,7 +302,7 @@ compiler checks and sink choice. Pin `id:`; renaming it registers a different pr
302
302
  Read the reference that matches the task:
303
303
 
304
304
  - [references/decision-reads.md](references/decision-reads.md) when an append depends on state a concurrent append could change: `Cratis.Chronicle.decide/2`, `DecisionReads`, `ConcurrencyScope` builders, the optimistic default.
305
- - [references/testing.md](references/testing.md) when writing specs: `Cratis.Chronicle.Testing.Case`, assertions, the in-memory kernel's limits.
305
+ - [references/testing.md](references/testing.md) when writing specs: `Cratis.Chronicle.Testing.Case`, assertions, the in-memory kernel's limits, and the `EventScenario`, `ReadModelScenario` and `ReactorScenario` that state one behavior in the shape of a Specification (given, because, `should_*`).
306
306
  - [references/constraints.md](references/constraints.md) when declaring uniqueness, standalone constraint modules, `remove_constraint/2`, violation details or closing events.
307
307
  - [references/discovery-and-generations.md](references/discovery-and-generations.md) when pinning ids, setting `:drift_policy`, running `mix chronicle.discover`, or handling older event generations.
308
308
  - [references/captures.md](references/captures.md) when turning external API, webhook or other-store data into events.
@@ -39,6 +39,19 @@ end
39
39
 
40
40
  `start_supervised_client/1` (outside ExUnit templates; pair with `stop_supervised_client/1`) accepts `:event_types`, `:event_sources`, `:constraints` (standalone constraint modules), `:reactors`, `:reducers`, `:projections`, `:name`, `:event_store` and `:namespace`.
41
41
 
42
+ ## Scenarios: one behavior, one `should_*` per test
43
+
44
+ `use Cratis.Chronicle.Testing.EventScenario` (events and their constraints), `ReadModelScenario` (a projection
45
+ or reducer, asked for by module and key) or `ReactorScenario` (what a reactor produced, and whether it failed)
46
+ starts the kernel once per spec module (`lifecycle: :per_test` for one per test) and gives the scenario as
47
+ `:scenario`. Chain `given_events/3` and `append/3,4`, then assert with `should_be_successful/1`,
48
+ `should_have_constraint_violation/1,2`, `should_have_concurrency_violation/1`, `should_have_appended/2,3`,
49
+ `should_have_appended_exactly/2`, `should_not_have_appended_any_events/1`, `should_have_tail_sequence_number/2`,
50
+ `should_have_read_model/4`, `should_have_observer_failures/1,2`. Only what the `append` added counts, not the
51
+ given events. Reusable facts are given contexts (`use Cratis.Chronicle.Testing.Given`) applied with
52
+ `given: [Context]`, and `setup: {Module, :function}` prepares fakes. The layout and naming of the files is
53
+ `rules/specs.elixir.md`.
54
+
42
55
  ## Waiting and reading
43
56
 
44
57
  An append returns once the event is committed; reactors and reducers run afterward in `Cratis.Chronicle.Testing.Dispatcher`, synchronously after each committed append. Call `Cratis.Chronicle.Testing.wait_for_observers(client)` before asserting on their effects; it is a sleep-free barrier that returns `{:error, failures}` when a reactor or reducer raised.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cratis/pi",
3
- "version": "7.193.1",
3
+ "version": "7.194.0",
4
4
  "description": "Configuration-aware Cratis AI integration for Pi",
5
5
  "type": "module",
6
6
  "files": [