@cratis/pi 7.137.1 → 7.138.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (24) hide show
  1. package/package/corpus/harnesses/copilot/instructions/glossary.instructions.md +4 -0
  2. package/package/corpus/hooks/README.md +14 -4
  3. package/package/corpus/hooks/scripts/cratis-guard-shell-writes.sh +24 -6
  4. package/package/corpus/hooks/scripts/cratis-guard-writes.sh +48 -14
  5. package/package/corpus/product-sync.json +1 -0
  6. package/package/corpus/rules/glossary.md +4 -0
  7. package/package/corpus/skills/cratis-arc-neo4j/LICENSE +2 -0
  8. package/package/corpus/skills/cratis-arc-neo4j/SKILL.md +166 -0
  9. package/package/corpus/skills/cratis-arc-neo4j/references/connection-resolution-and-single-mode.md +51 -0
  10. package/package/corpus/skills/cratis-chronicle-client-elixir/SKILL.md +12 -1
  11. package/package/corpus/skills/cratis-chronicle-client-elixir/references/graphs.md +123 -0
  12. package/package/corpus/skills/cratis-chronicle-projection/SKILL.md +18 -1
  13. package/package/corpus/skills/cratis-chronicle-projection/references/graph-projections.md +159 -0
  14. package/package/corpus/skills/cratis-screenplay-projections/SKILL.md +15 -2
  15. package/package/corpus/skills/cratis-screenplay-projections/references/graphs.md +150 -0
  16. package/package/corpus/skills/cratis-screenplay-specifications/SKILL.md +25 -23
  17. package/package/corpus/skills/cratis-screenplay-specifications/references/graph-steps.md +90 -0
  18. package/package/corpus/skills/cratis-screenplay-specifications/references/vocabulary.md +6 -0
  19. package/package/corpus/skills/cratis-screenplay-toolchain/references/screenplay-contract.json +7212 -1834
  20. package/package/corpus/skills/cratis-screenplay-toolchain/references/screenplay-contract.version +1 -1
  21. package/package/corpus/skills/cratis-stage-rendering-and-sandbox/SKILL.md +2 -0
  22. package/package/corpus/skills/cratis-stage-rendering-and-sandbox/references/graphs.md +52 -0
  23. package/package/profile-catalog.json +1 -0
  24. package/package.json +1 -1
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: cratis-chronicle-projection
3
- description: Use when populating an existing Chronicle read model through event mappings, structured joins or lifecycle variants, or diagnosing projection startup failures. Not for new query surfaces or external side effects.
3
+ description: Use when populating an existing Chronicle read model through event mappings, structured joins or lifecycle variants, projecting events onto a graph with nodes and edges, or diagnosing projection startup failures. Not for new query surfaces or external side effects.
4
4
  license: MIT
5
5
  ---
6
6
 
@@ -263,6 +263,23 @@ or a reactor rather than annotating the projection.
263
263
  Their two optional arguments are in **opposite order**: `[FromAll(contextProperty,
264
264
  property)]` and `[FromEvery(property, contextProperty)]`. Name them.
265
265
 
266
+ ## Graph projections — nodes and edges
267
+
268
+ A graph projection turns events into idempotent operations on a property graph
269
+ instead of folding them into a document. It uses the same observer, event routing,
270
+ key and property expressions, replay and failed-partition handling. Requires
271
+ Chronicle 19.129.0 (check the installed `Cratis.Chronicle` package version).
272
+
273
+ Choose a graph when the questions are traversals (membership, nesting, paths) and a
274
+ document read model when they are lookups by key. Design it by reading the graph
275
+ backwards: write each question as a path, make hops edge types and stops node labels,
276
+ then name the event that creates and removes each. Mark types with `[Node]` and
277
+ `[Edge("TYPE")]` (an edge's `[Source<T>]` and `[Target<T>]` members hold the end keys),
278
+ or declare the same definition with `IGraphProjection`. A type is never both a graph
279
+ element and a read model (CHR0068). Read
280
+ [references/graph-projections.md](references/graph-projections.md) for the attributes,
281
+ fluent builder, operation model, replay and idempotency, and the sinks.
282
+
266
283
  ## Definition changes replay
267
284
 
268
285
  Read [references/definition-changes.md](references/definition-changes.md) when a changed mapping, key, filter, join or child must replay, or when a corrected mapping does not repair existing counters and joins (replay rebuilds them; deploying alone does not).
@@ -0,0 +1,159 @@
1
+ # Graph projections
2
+
3
+ ## Contents
4
+
5
+ - Model-bound
6
+ - Fluent
7
+ - Counters and edge identity
8
+ - The operations
9
+ - Redelivery and replay
10
+ - Sinks
11
+ - Testing and analyzers
12
+
13
+ A **node** has a label (the type name), a unique key and properties. A property is a
14
+ primitive or an array of primitives; an object property is an error, so model the
15
+ object as a node and connect it with an edge. An **edge** has a type, a source node,
16
+ a target node and properties. By default it is identified by type, source and target.
17
+ Name the graph with `[Graph("Organization")]` on the types or the assembly; without
18
+ it the graph is named after the assembly's root namespace.
19
+
20
+ ## Model-bound
21
+
22
+ `[Key]` marks a node's unique key. `[Source<>]` and `[Target<>]` on an edge mark the
23
+ members holding the end keys; they are not properties of the edge. The node key is
24
+ the event source id unless `[FromEvent<>]` names an event property.
25
+
26
+ ```csharp
27
+ [Graph("Organization")]
28
+ [Node]
29
+ [FromEvent<PersonRegistered>]
30
+ [RemovedWith<PersonRemoved>(detach: true)]
31
+ public record Person([Key] Guid PersonId, string Name);
32
+
33
+ [Graph("Organization")]
34
+ [Node]
35
+ [FromEvent<GroupCreated>]
36
+ public record Group([Key] Guid GroupId, string Name);
37
+
38
+ [Graph("Organization")]
39
+ [Edge("MEMBER_OF")]
40
+ [EdgeFrom<MemberAdded>(sourceKey: nameof(MemberAdded.PersonId), targetKey: nameof(MemberAdded.GroupId))]
41
+ [EdgeRemovedWith<MemberRemoved>(sourceKey: nameof(MemberRemoved.PersonId), targetKey: nameof(MemberRemoved.GroupId))]
42
+ public record MemberOf(
43
+ [Source<Person>] Guid PersonId,
44
+ [Target<Group>] Guid GroupId,
45
+ [SetFromContext<MemberAdded>(nameof(EventContext.Occurred))] DateTimeOffset Since);
46
+ ```
47
+
48
+ Properties map by name from an event property of the same name, or with the
49
+ attributes of read-model projections: `[SetFrom<>]`, `[SetFromContext<>]`,
50
+ `[Increment<>]`, `[Decrement<>]`, `[Count<>]`, `[AddFrom<>]`, `[SubtractFrom<>]`.
51
+
52
+ ## Fluent
53
+
54
+ `IGraphProjection` builds exactly the same definition as the attributes:
55
+
56
+ ```csharp
57
+ [Graph("Organization")]
58
+ public class OrganizationGraph : IGraphProjection
59
+ {
60
+ public void Define(IGraphProjectionBuilder builder) => builder
61
+ .Node<Person>(n => n
62
+ .IdentifiedBy(p => p.PersonId)
63
+ .From<PersonRegistered>()
64
+ .RemovedWith<PersonRemoved>(b => b.Detach()))
65
+ .Node<Group>(n => n
66
+ .IdentifiedBy(g => g.GroupId)
67
+ .From<GroupCreated>())
68
+ .Edge<MemberOf, Person, Group>(e => e
69
+ .From<MemberAdded>(b => b
70
+ .UsingSourceKey(x => x.PersonId)
71
+ .UsingTargetKey(x => x.GroupId)
72
+ .Set(m => m.Since).ToEventContextProperty(c => c.Occurred))
73
+ .RemovedWith<MemberRemoved>(b => b
74
+ .UsingSourceKey(x => x.PersonId)
75
+ .UsingTargetKey(x => x.GroupId)));
76
+ }
77
+ ```
78
+
79
+ Chronicle also compiles the projection declaration language form (`graph Organization` with
80
+ `node` and `edge` declarations, then `projection X => graph Organization`), which is the text
81
+ `cratis-screenplay-projections` produces for a model.
82
+
83
+ ## Counters and edge identity
84
+
85
+ Counters work on node and edge properties:
86
+ `[Increment<MemberAdded>] [Decrement<MemberRemoved>] int MemberCount`.
87
+
88
+ Give an edge a `[Key]` member to allow several edges of one type between the same
89
+ two nodes. Every mapping of that edge must then say which event property holds the
90
+ identity (`identity:` argument or `UsingIdentity`). A sink that cannot hold several
91
+ edges between one pair rejects such an edge type.
92
+
93
+ ```csharp
94
+ [Edge("VISITED")]
95
+ [EdgeFrom<PlaceVisited>(
96
+ sourceKey: nameof(PlaceVisited.PersonId),
97
+ targetKey: nameof(PlaceVisited.PlaceId),
98
+ identity: nameof(PlaceVisited.VisitId))]
99
+ public record Visited(
100
+ [Source<Person>] Guid PersonId,
101
+ [Target<Place>] Guid PlaceId,
102
+ [Key] Guid VisitId,
103
+ [Count<PlaceVisited>] int Times);
104
+ ```
105
+
106
+ ## The operations
107
+
108
+ Each event yields a `GraphChangeset` of five idempotent operations: `UpsertNode`,
109
+ `SetProperties` (nothing is created), `DeleteNode` (with `detach` the attached edges
110
+ go too; without it a node that still has edges cannot be deleted), `UpsertEdge` and
111
+ `DeleteEdge` (the end nodes stay).
112
+
113
+ - An edge operation creates a bare end node when it does not exist; a node mapping
114
+ completes it later.
115
+ - A projection owns the edges and node properties it maps and never deletes a node it did not declare.
116
+ - Counters carry absolute values: the engine reads the current value from the sink
117
+ and the operation carries the result.
118
+
119
+ ## Redelivery and replay
120
+
121
+ Every node and edge stores a **watermark**, the sequence number of the event that last
122
+ wrote it. A write at or below the watermark is skipped, so redelivered and out-of-order
123
+ events do not apply twice. Replay is **mark and sweep**: a replay starts a new
124
+ generation for the projection, elements it has not rewritten read as absent (counters
125
+ rebuild from zero), and at the end elements it did not write are deleted. Elements
126
+ other projections wrote, and nodes only edges created, are never swept.
127
+
128
+ ## Sinks
129
+
130
+ A graph is stored by a graph sink, set per client with `DefaultGraphSinkTypeId`
131
+ (default `Neo4j`; `WellKnownSinkTypes.InMemoryGraph` keeps it in the kernel's memory).
132
+ The Neo4j sink uses one database per event store and namespace, with a single-database
133
+ mode for development; Cratis Arc reads those databases with `cratis-arc-neo4j`.
134
+
135
+ ```csharp
136
+ services.Configure<ChronicleOptions>(options =>
137
+ {
138
+ options.DefaultGraphSinkTypeId = WellKnownSinkTypes.InMemoryGraph;
139
+ });
140
+ ```
141
+
142
+ ## Testing and analyzers
143
+
144
+ `GraphScenario` runs a graph projection against the in-memory graph sink:
145
+
146
+ ```csharp
147
+ using var scenario = new GraphScenario();
148
+
149
+ await scenario.Append(personId, new PersonRegistered(personId, "Ada"));
150
+ await scenario.Append(personId, new MemberAdded(personId, groupId));
151
+
152
+ var person = await scenario.Node<Person>(personId);
153
+ var membership = await scenario.Edge<MemberOf>(personId, groupId);
154
+ var memberships = await scenario.Edges<MemberOf>();
155
+ ```
156
+
157
+ - CHR0066: a node or an edge has an object property.
158
+ - CHR0067: a node does not have exactly one key, or an edge has more than one.
159
+ - CHR0068: a type is both a node or an edge and a read model.
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: cratis-screenplay-projections
3
- description: Use when declaring Screenplay event-to-state mappings or diagnosing a .play projection's keys, joins, children or lifecycle variants. Not for hand-written C# Chronicle projections or read-model query contracts.
3
+ description: Use when declaring Screenplay event-to-state mappings, a graph projection onto nodes and edges, or diagnosing a .play projection's keys, joins, children or lifecycle variants. Not for hand-written C# Chronicle projections or read-model query contracts.
4
4
  license: MIT
5
5
  ---
6
6
 
@@ -238,6 +238,18 @@ coexist.
238
238
 
239
239
  Each `variant` is its own read model created only by its `enters on` events, and mutual exclusion works through the event source identity: keep the event source equal to the entity identifier or the issue stays in both variants. Read [references/variants.md](references/variants.md) when modeling an entity with exclusive lifecycle shapes or fixing `PLAY0382`–`PLAY0385`.
240
240
 
241
+ ## Graph targets — `projection X => graph G`
242
+
243
+ A `graph` declares node labels (one `key` each) and edge types; `projection X => graph G`
244
+ builds it with `node` and `edge` blocks. Nothing writes to a graph except events.
245
+ Requires Screenplay 5.7.0 (`screenplay --version`).
246
+
247
+ Choose a graph for traversals (membership, nesting, paths) and a document read model
248
+ for lookups by key. Design by **reading the graph backwards**: write each question
249
+ as a path, make every hop an edge type and every stop a node label, then name the
250
+ event that creates and the one that removes each. Read
251
+ [references/graphs.md](references/graphs.md) for syntax, operations and `PLAY0862`–`PLAY0877`.
252
+
241
253
  ## When PDL is not enough — the reducer
242
254
 
243
255
  Excerpt: the events and the `AccountBalance` read model are declared elsewhere.
@@ -332,6 +344,7 @@ method: `cratis-screenplay-modeling-lifecycle` and `cratis-screenplay-slice-desi
332
344
 
333
345
  - Deciding which read models exist at all: `cratis-screenplay-event-modeling`.
334
346
  - Read-model shape, queries and screens: `cratis-screenplay-read-surface`.
335
- - Specifying projection behavior: `cratis-screenplay-specifications`.
347
+ - Specifying projection behavior, including `given graph` and `then graph`: `cratis-screenplay-specifications`.
348
+ - Reading a graph from Arc code: `cratis-arc-neo4j`.
336
349
  - Hand-written C# Chronicle projections: `cratis-chronicle-projection`.
337
350
  - Hand-written C# Chronicle reducers: `cratis-chronicle-reducer`.
@@ -0,0 +1,150 @@
1
+ # Graph declarations and graph projections
2
+
3
+ ## Contents
4
+
5
+ - Declaring a graph
6
+ - Projecting events onto it
7
+ - Reading the graph backwards
8
+ - The five operations
9
+ - What a graph projection cannot say
10
+ - Diagnostics
11
+
12
+ ## Declaring a graph
13
+
14
+ A slice-level `graph`, a sibling of `readmodel`. Each `node` has typed properties and
15
+ exactly one `key`; each `edge` names existing node labels and may add properties.
16
+
17
+ ```screenplay
18
+ concept PersonId : Uuid
19
+ concept GroupId : Uuid
20
+ concept PersonName : String
21
+
22
+ module Organization
23
+ feature Chart
24
+ slice StateView OrganizationChart
25
+ graph Organization
26
+ node Person
27
+ personId PersonId key
28
+ name PersonName
29
+ node Group
30
+ groupId GroupId key
31
+ name String
32
+ edge MEMBER_OF source Person target Group
33
+ since DateTime
34
+ ```
35
+
36
+ - A property is a primitive, a concept over one, or an array of those. A nested
37
+ object, a `type` or a read model is `PLAY0863`: model it as another node and an edge.
38
+ - An edge is identified by type, source key and target key, so a repeated
39
+ `MEMBER_OF` between one pair is the same edge. For several edges of one type
40
+ between the same pair, write `edge HAS_ROLE source Person target Group identified by assignmentId`
41
+ and declare `assignmentId` on the edge (`PLAY0871`).
42
+ - Edge types read best in `UPPER_SNAKE_CASE`.
43
+
44
+ ## Projecting events onto it
45
+
46
+ Declared in the slice next to its graph; a standalone projection document cannot
47
+ hold one (`PLAY0877`). The model below is complete: events, graph and projection in one slice.
48
+
49
+ ```screenplay
50
+ concept PersonId : Uuid
51
+ concept GroupId : Uuid
52
+ concept PersonName : String
53
+
54
+ module Organization
55
+ feature Chart
56
+ slice StateView OrganizationChart
57
+ event PersonRegistered
58
+ name PersonName
59
+
60
+ event PersonRemoved
61
+
62
+ event GroupCreated
63
+ name String
64
+
65
+ event MemberAdded
66
+ groupId GroupId
67
+
68
+ event MemberRemoved
69
+ groupId GroupId
70
+
71
+ graph Organization
72
+ node Person
73
+ personId PersonId key
74
+ name PersonName
75
+ node Group
76
+ groupId GroupId key
77
+ name String
78
+ edge MEMBER_OF source Person target Group
79
+ since DateTime
80
+
81
+ projection OrganizationChart => graph Organization
82
+ node Person
83
+ from PersonRegistered key $eventSourceId
84
+ name = name
85
+ remove with PersonRemoved key $eventSourceId detach
86
+ node Group
87
+ from GroupCreated key $eventSourceId
88
+ name = name
89
+ edge MEMBER_OF
90
+ from MemberAdded source $eventSourceId target groupId
91
+ since = $eventContext.occurred
92
+ remove with MemberRemoved source $eventSourceId target groupId
93
+ ```
94
+
95
+ - `from <Event> key <expr>` creates or updates a node; `every` applies mappings to
96
+ every `from` of the block; `remove with ... key <expr> [detach]` deletes it.
97
+ - An edge `from` takes `source <expr> target <expr>`; with `identified by` on the
98
+ edge, every handler writes `identified by <expr>` after `target`.
99
+ - Mappings, counters (`increment`, `decrement`, `count`, `add ... by`, `subtract ... by`),
100
+ `$eventContext` and AutoMap behave as in a read-model projection. A property the
101
+ node or edge does not declare is `PLAY0868`.
102
+ - An edge `from` creates a missing endpoint as a bare node, so an event may draw an
103
+ edge before the events that create its nodes arrive. A projection owns the edges
104
+ and node properties it declares and never deletes a node it did not declare.
105
+
106
+ ## Reading the graph backwards
107
+
108
+ 1. List the questions the graph must answer ("who is in this group, including nested groups?").
109
+ 2. Write each as a path: `Person -MEMBER_OF-> Group -PART_OF-> Group`.
110
+ 3. Each hop is an edge type; each stop is a node label with a key.
111
+ 4. For each edge type and node label, name the event that creates it and the one
112
+ that removes it. Nothing creates it: add the fact to the event model, not a write
113
+ to the graph.
114
+ 5. Add `detach` to any node removal whose label has attached edges.
115
+ 6. A question that is a lookup by key, not a path, belongs in a document read model.
116
+
117
+ ## The five operations
118
+
119
+ Every sink applies the same idempotent operations: `UpsertNode`, `SetProperties`,
120
+ `DeleteNode` (with or without `detach`), `UpsertEdge`, `DeleteEdge`. Nodes are
121
+ identified by label and key; edges by type, source, target and the `identified by` value.
122
+
123
+ ## What a graph projection cannot say
124
+
125
+ `children`, `nested`, `join`, `all`, `clear with`, `remove via join`, `variant`, a
126
+ projection-level `key` or `sequence`, and `automap` blocks are `PLAY0872`. There is
127
+ no engine-native block: whatever the language cannot say is not supported. The event
128
+ model board, find-references and rename do not follow graph projections, so renaming
129
+ an event leaves a graph projection reported as unknown.
130
+
131
+ ## Diagnostics
132
+
133
+ | Code | Meaning |
134
+ | --- | --- |
135
+ | `PLAY0862` | Malformed graph, node or edge declaration |
136
+ | `PLAY0863` | Property type not a primitive, concept or array of those |
137
+ | `PLAY0864` | Node with no `key` or more than one |
138
+ | `PLAY0865` | Edge names an undeclared source or target label |
139
+ | `PLAY0866` | Projection targets an undeclared graph |
140
+ | `PLAY0867` | Block for a label or edge type the graph does not declare |
141
+ | `PLAY0868` | Mapped, identity or asserted property the node or edge lacks |
142
+ | `PLAY0869` | `detach` on an edge |
143
+ | `PLAY0870` | Warning: node removal without `detach` while edges attach to the label |
144
+ | `PLAY0871` | `identified by` names a property the edge does not declare |
145
+ | `PLAY0872` | Read-model-only construct in a graph projection |
146
+ | `PLAY0873` | Malformed block or handler, missing `key` or `source`/`target` |
147
+ | `PLAY0874` | Duplicate declaration or duplicate node/edge build in one projection |
148
+ | `PLAY0875` | Malformed `given graph` / `then graph` step |
149
+ | `PLAY0876` | Specification names an undeclared graph, label or edge type |
150
+ | `PLAY0877` | Graph projection declared outside a slice |
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: cratis-screenplay-specifications
3
- description: Use when writing Screenplay specification syntax or checking fixture, outcome-comparison, rejection and denial semantics. Not for choosing scenario coverage or writing C# and TypeScript tests.
3
+ description: Use when writing Screenplay specification syntax, including graph steps, or checking fixture, outcome-comparison, rejection and denial semantics. Not for choosing scenario coverage or writing C# and TypeScript tests.
4
4
  license: MIT
5
5
  ---
6
6
 
@@ -140,9 +140,7 @@ Rules the binder enforces:
140
140
  - **`then result` and `then no result` need `when query`**, and `when query`
141
141
  needs one of them, `then denied` or a sole validation `then error` (`PLAY0465`). Each argument is a `by` or
142
142
  `filter` parameter of the query (`PLAY0468`).
143
- - **A clock instant is ISO 8601 with an offset or `Z`** (PLAY0461); one `given clock` maximum.
144
- - **`given time zone "<id>"` is parsed, not runnable.** Executable binding refuses it with PLAY0268;
145
- a repeated or malformed line is PLAY0814. Do not author it into an executable model.
143
+ - **A clock instant is ISO 8601 with an offset or `Z`** (PLAY0461); one `given clock` maximum. `given time zone` is not runnable: read `references/vocabulary.md`.
146
144
  - **`then` contains either events or an error — never both.** A rejection
147
145
  specification has exactly one rejection and no success outcome.
148
146
  - **`then denied` stands alone**: not with events, errors or state assertions
@@ -153,18 +151,25 @@ Rules the binder enforces:
153
151
  - **`null` only in optional read-model values.** A `null` in a command or event
154
152
  value is `PLAY0350`: an optional fact is a separate event.
155
153
 
156
- V1 does not report binding-only outcome errors; read `references/vocabulary.md`
157
- for parse-versus-bind diagnostics and check executable diagnostics too.
154
+ Read `references/vocabulary.md` for parse-versus-bind diagnostics and check executable diagnostics too.
155
+
156
+ ## Graph specifications
157
+
158
+ `given graph <Graph>` seeds nodes and edges before the action (`has node`, `has edge`
159
+ only); `then graph <Graph>` asserts them and also states absence (`no node`,
160
+ `no edge`). A `has` step lists only the properties it checks. Use them with
161
+ `when append <Event>` for a graph projection. Requires
162
+ Screenplay 5.7.0 (`screenplay --version`). Read
163
+ [references/graph-steps.md](references/graph-steps.md) for the grammar and `PLAY0868`, `PLAY0875`, `PLAY0876`.
158
164
 
159
165
  ## How outcomes are compared
160
166
 
161
167
  Events compare as the complete new set in authored order (exact count). Read models and query rows: only the asserted properties must match (add `exactly` for all). Rejections: `then error "<message>"` matches the message, never severity. Bare `then error` never matches
162
- a denial. Read [references/outcome-comparison.md](references/outcome-comparison.md) when asserting events, rows, ordering or a localized rejection key.
168
+ a denial. Read [references/outcome-comparison.md](references/outcome-comparison.md) for events, rows, ordering or a localized rejection key.
163
169
 
164
170
  ## Worked example
165
171
 
166
- A command with an authorization gate, a validation rule and a uniqueness constraint, specified in full with inline events, optional-aware queries and read-model assertions.
167
- Read [references/worked-example.md](references/worked-example.md) when writing or checking a complete command, view or constraint specification and you need the full compiled model to copy the shape from.
172
+ Read [references/worked-example.md](references/worked-example.md) for a complete command, view or constraint specification (authorization, validation, uniqueness, queries) to copy the shape from.
168
173
 
169
174
  ## Choosing a strategy
170
175
 
@@ -239,20 +244,16 @@ concept rules to follow the general format-rule convention.
239
244
 
240
245
  ## Application-boundary coverage
241
246
 
242
- Every slice should carry at least one specification whose action is what a real
243
- caller does and whose `then` is observable at that same boundary — produced
244
- events, read-model state, query results, a rejection or a denial. A specification
245
- satisfiable only by an internal function describes a unit, not a slice acceptance
246
- criterion.
247
+ Every slice carries at least one specification whose action is what a real caller
248
+ does and whose `then` is observable at that boundary (events, read-model state, query
249
+ results, a rejection or a denial), not only through an internal function.
247
250
 
248
251
  ## Quality checklist
249
252
 
250
253
  For every specification:
251
254
 
252
- - [ ] Concrete, realistic values — never "valid user" or "some amount".
253
- - [ ] The values the outcome depends on are visible in the body, at the edge that matters.
254
- - [ ] Tests exactly one behavior, independent of other specifications.
255
- - [ ] Business language matching the event-model vocabulary.
255
+ - [ ] Concrete, realistic values, visible in the body where the outcome depends on them.
256
+ - [ ] Tests exactly one behavior, in the event-model vocabulary, independent of other specifications.
256
257
 
257
258
  For command specifications:
258
259
 
@@ -283,11 +284,12 @@ For view specifications:
283
284
 
284
285
  ## Run the specs before calling the work done
285
286
 
286
- Symptom: a model delivered with specifications that were never run. `screenplay test <root>` runs the
287
- reference evaluator; after rendering and building in Debug, run `dotnet test <destination>/<Project>.csproj -c Debug --no-build`
288
- for the generated specification classes (Stage-rendered apps use VSTest). Run a built spec executable only where spec projects are executables
289
- (see [specs.csharp](../../rules/specs.csharp.md)). Report both results separately (`cratis-screenplay-toolchain` V4 and V5.tests); a
290
- build that succeeds is not a test run, and `unbound`/`unsupported` is not a pass.
287
+ `screenplay test <root>` runs the reference evaluator. After rendering and building in Debug,
288
+ run `dotnet test <destination>/<Project>.csproj -c Debug --no-build` for the generated
289
+ specification classes (Stage-rendered apps use VSTest); run a built spec executable only where
290
+ spec projects are executables (see [specs.csharp](../../rules/specs.csharp.md)). Report both
291
+ results separately (`cratis-screenplay-toolchain` V4 and V5.tests); a build that succeeds is not a
292
+ test run, and `unbound`/`unsupported` is not a pass.
291
293
 
292
294
  ## Verify
293
295
 
@@ -0,0 +1,90 @@
1
+ # Graph specification steps
2
+
3
+ ## Contents
4
+
5
+ - Steps
6
+ - Example
7
+ - Rules
8
+
9
+ ## Steps
10
+
11
+ | Step | Meaning |
12
+ | --- | --- |
13
+ | `has node <Label> <key>` | The node exists and the properties listed under it hold the given values. |
14
+ | `has edge <TYPE> from <source> to <target> [identified by <value>]` | The edge exists and the properties listed under it hold the given values. |
15
+ | `no node <Label> <key>` | The node does not exist. `then graph` only. |
16
+ | `no edge <TYPE> from <source> to <target> [identified by <value>]` | The edge does not exist. `then graph` only. |
17
+
18
+ ## Example
19
+
20
+ ```screenplay
21
+ concept PersonId : Uuid
22
+ concept GroupId : Uuid
23
+ concept PersonName : String
24
+
25
+ module Organization
26
+ feature Chart
27
+ slice StateView OrganizationChart
28
+ event PersonRegistered
29
+ name PersonName
30
+
31
+ event PersonRemoved
32
+
33
+ event GroupCreated
34
+ name String
35
+
36
+ event MemberAdded
37
+ groupId GroupId
38
+
39
+ event MemberRemoved
40
+ groupId GroupId
41
+
42
+ graph Organization
43
+ node Person
44
+ personId PersonId key
45
+ name PersonName
46
+ node Group
47
+ groupId GroupId key
48
+ name String
49
+ edge MEMBER_OF source Person target Group
50
+ since DateTime
51
+
52
+ projection OrganizationChart => graph Organization
53
+ node Person
54
+ from PersonRegistered key $eventSourceId
55
+ name = name
56
+ remove with PersonRemoved key $eventSourceId detach
57
+ node Group
58
+ from GroupCreated key $eventSourceId
59
+ name = name
60
+ edge MEMBER_OF
61
+ from MemberAdded source $eventSourceId target groupId
62
+ since = $eventContext.occurred
63
+ remove with MemberRemoved source $eventSourceId target groupId
64
+
65
+ specification RemovingAPersonDetachesTheirEdges
66
+ given graph Organization
67
+ has node Person "6fa459ea-ee8a-4ca4-894e-db77e160355e"
68
+ name = "Ada Lovelace"
69
+ has node Group "0f8fad5b-d9cb-469f-a165-70867728950e"
70
+ has edge MEMBER_OF from "6fa459ea-ee8a-4ca4-894e-db77e160355e" to "0f8fad5b-d9cb-469f-a165-70867728950e"
71
+ when append PersonRemoved
72
+ for "6fa459ea-ee8a-4ca4-894e-db77e160355e"
73
+ then graph Organization
74
+ no node Person "6fa459ea-ee8a-4ca4-894e-db77e160355e"
75
+ no edge MEMBER_OF from "6fa459ea-ee8a-4ca4-894e-db77e160355e" to "0f8fad5b-d9cb-469f-a165-70867728950e"
76
+ has node Group "0f8fad5b-d9cb-469f-a165-70867728950e"
77
+ ```
78
+
79
+ The specification sits in the slice that declares the graph and its projection; they give
80
+ the steps their labels and keys. Check with `screenplay --warnaserror` and `screenplay test`.
81
+
82
+ ## Rules
83
+
84
+ - Keys are the values of the node's `key` property, written as literals.
85
+ - A `has` step checks only the properties listed under it.
86
+ - A malformed step is `PLAY0875`; an undeclared graph, node label or edge type is
87
+ `PLAY0876`; a property the node or edge does not declare is `PLAY0868`.
88
+ - The reference runner keeps an in-memory graph and applies the five operations of the
89
+ projection. Values read from `$eventContext` are not materialized there, so do not
90
+ assert an edge property mapped from `$eventContext`.
@@ -74,3 +74,9 @@ An enumeration value binds whether it is written bare
74
74
  An older compiler binds only the quoted member and the full round-trip instant
75
75
  (`"2026-10-05T08:00:00.0000000Z"`) although it accepts all forms - quote members when a
76
76
  model must bind on older versions.
77
+
78
+ ## Time zones
79
+
80
+ - `given time zone "<id>"` is parsed, not runnable. Executable binding refuses it with
81
+ `PLAY0268`; a repeated or malformed line is `PLAY0814`. Do not author it into an
82
+ executable model.