nukadoko 0.1.0 → 0.2.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +291 -0
- data/README.ja.md +58 -5
- data/README.md +15 -3
- data/exe/nuka +8 -0
- data/lib/nukadoko/aria_snapshot.rb +1008 -0
- data/lib/nukadoko/aria_tree.rb +150 -0
- data/lib/nukadoko/base.rb +274 -0
- data/lib/nukadoko/check.rb +669 -22
- data/lib/nukadoko/claim_check.rb +177 -0
- data/lib/nukadoko/claim_check_run.rb +293 -0
- data/lib/nukadoko/claim_line.rb +381 -0
- data/lib/nukadoko/claim_rules.rb +519 -0
- data/lib/nukadoko/claims.rb +407 -30
- data/lib/nukadoko/cli.rb +802 -19
- data/lib/nukadoko/codes.json +942 -0
- data/lib/nukadoko/codes.rb +19 -0
- data/lib/nukadoko/command.rb +214 -12
- data/lib/nukadoko/criteria.rb +172 -0
- data/lib/nukadoko/definition.rb +33 -41
- data/lib/nukadoko/env_check.rb +90 -0
- data/lib/nukadoko/features.rb +80 -10
- data/lib/nukadoko/fixtures.rb +296 -10
- data/lib/nukadoko/http_recording.rb +68 -0
- data/lib/nukadoko/init.rb +130 -0
- data/lib/nukadoko/judge.rb +221 -0
- data/lib/nukadoko/judgment_file.rb +78 -0
- data/lib/nukadoko/judgments.rb +256 -0
- data/lib/nukadoko/literal.rb +129 -0
- data/lib/nukadoko/measured.rb +105 -0
- data/lib/nukadoko/order.rb +84 -0
- data/lib/nukadoko/parts.rb +42 -21
- data/lib/nukadoko/pattern.rb +11 -1
- data/lib/nukadoko/poll.rb +17 -6
- data/lib/nukadoko/program.rb +105 -17
- data/lib/nukadoko/project_fixtures.rb +17 -2
- data/lib/nukadoko/report_allure.rb +751 -0
- data/lib/nukadoko/report_messages.rb +167 -0
- data/lib/nukadoko/report_run.rb +169 -0
- data/lib/nukadoko/run.rb +865 -88
- data/lib/nukadoko/run_record.rb +532 -0
- data/lib/nukadoko/scaffold.rb +1015 -0
- data/lib/nukadoko/schema.rb +61 -4
- data/lib/nukadoko/secrets.rb +359 -0
- data/lib/nukadoko/selection.rb +163 -0
- data/lib/nukadoko/signature.rb +4 -1
- data/lib/nukadoko/skill.rb +36 -0
- data/lib/nukadoko/step.rb +62 -21
- data/lib/nukadoko/summary.rb +662 -0
- data/lib/nukadoko/table.rb +34 -2
- data/lib/nukadoko/text_fit.rb +179 -0
- data/lib/nukadoko/trace.rb +244 -0
- data/lib/nukadoko/trace_actions.rb +116 -0
- data/lib/nukadoko/tree_passes.rb +119 -0
- data/lib/nukadoko/verdict.rb +128 -0
- data/lib/nukadoko/version.rb +2 -1
- data/lib/nukadoko/vocabulary.rb +6 -0
- data/lib/nukadoko/walk.rb +305 -0
- data/lib/nukadoko/walk_files.rb +473 -0
- data/lib/nukadoko/walk_step.rb +149 -0
- data/lib/nukadoko.rb +36 -0
- data/llms.txt +296 -0
- data/sig/generated/nukadoko/aria_snapshot.rbs +331 -0
- data/sig/generated/nukadoko/aria_tree.rbs +142 -0
- data/sig/generated/nukadoko/base.rbs +136 -0
- data/sig/generated/nukadoko/check.rbs +255 -0
- data/sig/generated/nukadoko/claim_check.rbs +118 -0
- data/sig/generated/nukadoko/claim_check_run.rbs +88 -0
- data/sig/generated/nukadoko/claim_line.rbs +158 -0
- data/sig/generated/nukadoko/claim_rules.rbs +172 -0
- data/sig/generated/nukadoko/claims.rbs +165 -0
- data/sig/generated/nukadoko/cli.rbs +182 -0
- data/sig/generated/nukadoko/codes.rbs +16 -0
- data/sig/generated/nukadoko/command.rbs +109 -0
- data/sig/generated/nukadoko/criteria.rbs +83 -0
- data/sig/generated/nukadoko/definition.rbs +30 -0
- data/sig/generated/nukadoko/env_check.rbs +38 -0
- data/sig/generated/nukadoko/features.rbs +101 -0
- data/sig/generated/nukadoko/fixtures.rbs +152 -0
- data/sig/generated/nukadoko/http_recording.rbs +29 -0
- data/sig/generated/nukadoko/init.rbs +66 -0
- data/sig/generated/nukadoko/judge.rbs +64 -0
- data/sig/generated/nukadoko/judgment_file.rbs +39 -0
- data/sig/generated/nukadoko/judgments.rbs +120 -0
- data/sig/generated/nukadoko/literal.rbs +71 -0
- data/sig/generated/nukadoko/measured.rbs +42 -0
- data/sig/generated/nukadoko/order.rbs +54 -0
- data/sig/generated/nukadoko/parts.rbs +35 -0
- data/sig/generated/nukadoko/pattern.rbs +28 -0
- data/sig/generated/nukadoko/poll.rbs +40 -0
- data/sig/generated/nukadoko/program.rbs +101 -0
- data/sig/generated/nukadoko/project_fixtures.rbs +57 -0
- data/sig/generated/nukadoko/report_allure.rbs +268 -0
- data/sig/generated/nukadoko/report_messages.rbs +68 -0
- data/sig/generated/nukadoko/report_run.rbs +102 -0
- data/sig/generated/nukadoko/run.rbs +257 -0
- data/sig/generated/nukadoko/run_record.rbs +174 -0
- data/sig/generated/nukadoko/scaffold.rbs +328 -0
- data/sig/generated/nukadoko/schema.rbs +137 -0
- data/sig/generated/nukadoko/secrets.rbs +157 -0
- data/sig/generated/nukadoko/selection.rbs +73 -0
- data/sig/generated/nukadoko/signature.rbs +17 -0
- data/sig/generated/nukadoko/skill.rbs +20 -0
- data/sig/generated/nukadoko/step.rbs +115 -0
- data/sig/generated/nukadoko/summary.rbs +204 -0
- data/sig/generated/nukadoko/table.rbs +43 -0
- data/sig/generated/nukadoko/text_fit.rbs +70 -0
- data/sig/generated/nukadoko/trace.rbs +127 -0
- data/sig/generated/nukadoko/trace_actions.rbs +40 -0
- data/sig/generated/nukadoko/tree_passes.rbs +48 -0
- data/sig/generated/nukadoko/verdict.rbs +56 -0
- data/sig/generated/nukadoko/version.rbs +5 -0
- data/sig/generated/nukadoko/vocabulary.rbs +25 -0
- data/sig/generated/nukadoko/walk.rbs +139 -0
- data/sig/generated/nukadoko/walk_files.rbs +189 -0
- data/sig/generated/nukadoko/walk_step.rbs +50 -0
- data/sig/generated/nukadoko.rbs +15 -0
- data/sig/nukadoko.rbs +5 -48
- data/skills/nukadoko/SKILL.md +120 -0
- data/skills/nukadoko/references/checking-steps.md +200 -0
- data/skills/nukadoko/references/diagnosing.md +200 -0
- data/skills/nukadoko/references/done.md +99 -0
- data/skills/nukadoko/references/evidence.md +124 -0
- data/skills/nukadoko/references/examples/cli.md +230 -0
- data/skills/nukadoko/references/examples/http-api.md +339 -0
- data/skills/nukadoko/references/examples/workflow.md +173 -0
- data/skills/nukadoko/references/exploring.md +184 -0
- data/skills/nukadoko/references/fixtures.md +198 -0
- data/skills/nukadoko/references/from-prose.md +51 -0
- data/skills/nukadoko/references/judgments.md +95 -0
- data/skills/nukadoko/references/maintenance.md +97 -0
- data/skills/nukadoko/references/merge-risk.md +74 -0
- data/skills/nukadoko/references/parts.md +152 -0
- data/skills/nukadoko/references/perturbed-worlds.md +107 -0
- data/skills/nukadoko/references/program.md +200 -0
- data/skills/nukadoko/references/reviewing.md +200 -0
- data/skills/nukadoko/references/running.md +200 -0
- data/skills/nukadoko/references/scenario-rules.md +188 -0
- data/skills/nukadoko/references/states.md +66 -0
- data/skills/nukadoko/references/step-files.md +200 -0
- data/skills/nukadoko/references/verdicts.md +200 -0
- data/skills/nukadoko/references/writing-steps.md +200 -0
- data/skills/nukadoko/references/writing-the-feature.md +165 -0
- data/skills/nukadoko/scripts/claude-code-verdict-hook.mjs +99 -0
- data/skills/nukadoko/scripts/merge-risk.jq +56 -0
- data/skills/nukadoko-verification/SKILL.md +263 -0
- metadata +121 -1
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
# Worked example: an HTTP API
|
|
2
|
+
|
|
3
|
+
A finished project for an API on `node:http`, built with nukadoko 0.16.1
|
|
4
|
+
on Node 24.22.0, with its Thens moved to claims and its server moved to
|
|
5
|
+
`nukadoko.program.ts` in the release after 0.21.0, which also put the
|
|
6
|
+
count behind a switch. Every output block below is copied from a real run of
|
|
7
|
+
that project, which is `examples/acceptance/http-api/` in the nukadoko
|
|
8
|
+
repository; CI runs it. The rules it follows are in
|
|
9
|
+
`../scenario-rules.md`.
|
|
10
|
+
|
|
11
|
+
## The ticket
|
|
12
|
+
|
|
13
|
+
An items API. `POST /items` with a name creates the item and answers 201
|
|
14
|
+
with its id and name. `GET /items/<id>` answers the item, or 404 with an
|
|
15
|
+
error for an unknown id. A body that is not JSON answers 400; a missing
|
|
16
|
+
name answers 422. `GET /items` lists every item created so far.
|
|
17
|
+
`GET /items/count` answers how many items exist, and is behind the
|
|
18
|
+
`ITEM_COUNT` switch while it rolls out.
|
|
19
|
+
|
|
20
|
+
## The feature
|
|
21
|
+
|
|
22
|
+
`features/items.feature`. One server serves every scenario of the run,
|
|
23
|
+
so a scenario claims only on what it created: the name it sent, an id the
|
|
24
|
+
API assigned, and the item a Given created, read back or listed (S8). The
|
|
25
|
+
count needs `ITEM_COUNT` on, so its scenario says so with
|
|
26
|
+
`@with:item_count`.
|
|
27
|
+
|
|
28
|
+
```gherkin
|
|
29
|
+
Feature: items API
|
|
30
|
+
|
|
31
|
+
Acceptance criteria (from the request):
|
|
32
|
+
- POST /items with a name creates the item and answers 201 with its id and name
|
|
33
|
+
- GET /items/<id> answers the item, or 404 with an error for an unknown id
|
|
34
|
+
- A body that is not JSON answers 400; a missing name answers 422
|
|
35
|
+
- GET /items lists every item created so far
|
|
36
|
+
- GET /items/count answers how many items exist, where ITEM_COUNT turns it on
|
|
37
|
+
|
|
38
|
+
Scenario: creating an item
|
|
39
|
+
When I POST this body to /items
|
|
40
|
+
"""
|
|
41
|
+
{"name":"lamp"}
|
|
42
|
+
"""
|
|
43
|
+
Then the response status is 201
|
|
44
|
+
And the response body has the name "lamp"
|
|
45
|
+
And the response body has an id of at least 1
|
|
46
|
+
|
|
47
|
+
Scenario: reading an item back
|
|
48
|
+
Given an item named "lamp" exists
|
|
49
|
+
When I request that item
|
|
50
|
+
Then the response status is 200
|
|
51
|
+
And the response body is the item that was created
|
|
52
|
+
|
|
53
|
+
Scenario: an unknown id
|
|
54
|
+
When I request item 0
|
|
55
|
+
Then the response status is 404
|
|
56
|
+
And the response body is
|
|
57
|
+
"""
|
|
58
|
+
{"error":"not found"}
|
|
59
|
+
"""
|
|
60
|
+
|
|
61
|
+
Scenario Outline: a bad request body: <body> answers <status>
|
|
62
|
+
When I POST this body to /items
|
|
63
|
+
"""
|
|
64
|
+
<body>
|
|
65
|
+
"""
|
|
66
|
+
Then the response status is <status>
|
|
67
|
+
And the response body is
|
|
68
|
+
"""
|
|
69
|
+
{"error":"<error>"}
|
|
70
|
+
"""
|
|
71
|
+
|
|
72
|
+
Examples:
|
|
73
|
+
| body | status | error |
|
|
74
|
+
| not json | 400 | body is not JSON |
|
|
75
|
+
| {} | 422 | name is required |
|
|
76
|
+
| {"name":""}| 422 | name is required |
|
|
77
|
+
|
|
78
|
+
Scenario: the list holds what was created
|
|
79
|
+
Given an item named "desk" exists
|
|
80
|
+
When I request the item list
|
|
81
|
+
Then the response status is 200
|
|
82
|
+
And the list has the item that was created
|
|
83
|
+
|
|
84
|
+
@with:item_count
|
|
85
|
+
Scenario: counting the items
|
|
86
|
+
Given an item named "chair" exists
|
|
87
|
+
When I request the item count
|
|
88
|
+
Then the response status is 200
|
|
89
|
+
And the response body has a count of at least 1
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## The steps and the program
|
|
93
|
+
|
|
94
|
+
- `nukadoko.program.ts`: starts the API once for each environment, on a
|
|
95
|
+
free port, waits until `GET /items` answers, and stops it after the
|
|
96
|
+
scenarios. The steps read its URL from `baseURL`. Its two
|
|
97
|
+
environments are the two sides of `ITEM_COUNT`, `count-off` and
|
|
98
|
+
`count-on`, and each names its side in `conditions`, so a run without
|
|
99
|
+
`--env` runs both, and `counting the items` is a control in
|
|
100
|
+
`count-off`. `ITEM_COUNT` is `{condition.item_count}`, so the server
|
|
101
|
+
reads the side its environment declares. The server starts each log line with
|
|
102
|
+
the request's `traceparent`, so each step record holds the server's
|
|
103
|
+
lines for its own requests in `program-log.txt`.
|
|
104
|
+
- `an-item-exists` (Given): POSTs a name and returns the `id` the API
|
|
105
|
+
assigned and the `body` it answered.
|
|
106
|
+
- `create-item` (When): `I POST this body to \/items`; sends the docstring
|
|
107
|
+
as it is and returns `status` and `body`.
|
|
108
|
+
- `get-item` (When): reads `id` from `an-item-exists` through `from`.
|
|
109
|
+
- `get-item-by-id`, `list-items`, `count-items` (When): a literal id,
|
|
110
|
+
the list, and the count.
|
|
111
|
+
- `status-is` (Then): lists all five request steps in `from`, so exactly
|
|
112
|
+
one of them runs before it in each scenario, and declares one claim.
|
|
113
|
+
- `body-is`, `body-has-name`, `body-has-id` (Then): each lists the four
|
|
114
|
+
request steps that answer an item or the list, and declares one claim. `body-is` reads the
|
|
115
|
+
docstring with `expected_view: "json"`, so the claim compares two JSON
|
|
116
|
+
values, key order does not count, and the record keeps the docstring as
|
|
117
|
+
written.
|
|
118
|
+
- `body-is-created-item`, `list-has-created-item` (Then): compare the
|
|
119
|
+
response with the `body` `an-item-exists` returned, by `equal` and by
|
|
120
|
+
`has-item`.
|
|
121
|
+
- `body-has-count` (Then): the `count` that `count-items` got, by
|
|
122
|
+
`at-least` 1, since other scenarios share the server.
|
|
123
|
+
|
|
124
|
+
The two steps that POST keep the default `mutates: true`: they change the
|
|
125
|
+
API's state. They need no go-ahead before `nuka do`, because the only
|
|
126
|
+
server they reach is the one the program file started.
|
|
127
|
+
|
|
128
|
+
`nukadoko.program.ts`:
|
|
129
|
+
|
|
130
|
+
```ts
|
|
131
|
+
import { defineProgram } from "nukadoko";
|
|
132
|
+
|
|
133
|
+
// One API server for each environment of the run, on a port of its own.
|
|
134
|
+
// It keeps its items in memory, so a scenario sees the items earlier
|
|
135
|
+
// scenarios created, and each one claims only on what it created itself
|
|
136
|
+
// (S8). ITEM_COUNT switches GET /items/count on; the two environments are
|
|
137
|
+
// its two sides, and conditions says which side each one is, so the
|
|
138
|
+
// scenario tagged @with:item_count runs in count-off as a control.
|
|
139
|
+
// ITEM_COUNT is the condition itself, so the switch the server reads and
|
|
140
|
+
// the side a cell counts for cannot disagree.
|
|
141
|
+
export default defineProgram({
|
|
142
|
+
serve: { command: "node src/server.ts", ready: "/items" },
|
|
143
|
+
env: { PORT: "{port}", ITEM_COUNT: "{condition.item_count}" },
|
|
144
|
+
environments: {
|
|
145
|
+
"count-off": { conditions: { item_count: false } },
|
|
146
|
+
"count-on": { conditions: { item_count: true } },
|
|
147
|
+
},
|
|
148
|
+
});
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
`features/steps/create-item.ts`:
|
|
152
|
+
|
|
153
|
+
```ts
|
|
154
|
+
import { defineStep, z } from "nukadoko";
|
|
155
|
+
|
|
156
|
+
export default defineStep({
|
|
157
|
+
description: "POST /items with this JSON body, verbatim",
|
|
158
|
+
pattern: "I POST this body to \\/items",
|
|
159
|
+
args: z.object({ body: z.string().describe("The request body, sent as-is") }),
|
|
160
|
+
returns: z.object({
|
|
161
|
+
status: z.number().describe("HTTP status"),
|
|
162
|
+
body: z.unknown().describe("The parsed JSON response"),
|
|
163
|
+
}),
|
|
164
|
+
async run({ baseURL }, { body }) {
|
|
165
|
+
const res = await fetch(`${baseURL}/items`, { method: "POST", body });
|
|
166
|
+
return { status: res.status, body: await res.json() };
|
|
167
|
+
},
|
|
168
|
+
});
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
`features/steps/list-has-created-item.ts`:
|
|
172
|
+
|
|
173
|
+
```ts
|
|
174
|
+
import { defineStep, z } from "nukadoko";
|
|
175
|
+
import anItemExists from "./an-item-exists.ts";
|
|
176
|
+
import listItems from "./list-items.ts";
|
|
177
|
+
|
|
178
|
+
// Other scenarios share the server, so the list holds their items too; the
|
|
179
|
+
// claim is that this scenario's item is among them.
|
|
180
|
+
export default defineStep({
|
|
181
|
+
description: "The item list holds the item an earlier step created, id and name",
|
|
182
|
+
pattern: "the list has the item that was created",
|
|
183
|
+
args: z.object({
|
|
184
|
+
body: z.unknown().describe("The list the request got"),
|
|
185
|
+
created: anItemExists.returns.shape.body,
|
|
186
|
+
}),
|
|
187
|
+
from: { body: [listItems, "body"], created: [anItemExists, "body"] },
|
|
188
|
+
claims: [{ actual: "body", compare: "has-item", expected: { from: "created" } }],
|
|
189
|
+
});
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
`features/steps/status-is.ts`:
|
|
193
|
+
|
|
194
|
+
```ts
|
|
195
|
+
import { defineStep, z } from "nukadoko";
|
|
196
|
+
import countItems from "./count-items.ts";
|
|
197
|
+
import createItem from "./create-item.ts";
|
|
198
|
+
import getItem from "./get-item.ts";
|
|
199
|
+
import getItemById from "./get-item-by-id.ts";
|
|
200
|
+
import listItems from "./list-items.ts";
|
|
201
|
+
|
|
202
|
+
export default defineStep({
|
|
203
|
+
description: "The last response's HTTP status is exactly this",
|
|
204
|
+
pattern: "the response status is {expected:int}",
|
|
205
|
+
args: z.object({
|
|
206
|
+
expected: z.number().describe("The expected HTTP status"),
|
|
207
|
+
status: z.number().describe("The status the last request got"),
|
|
208
|
+
}),
|
|
209
|
+
from: { status: [[createItem, "status"], [getItem, "status"], [getItemById, "status"], [listItems, "status"], [countItems, "status"]] },
|
|
210
|
+
claims: [{ actual: "status", compare: "equal", expected: "expected" }],
|
|
211
|
+
});
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
## The commands, in order
|
|
215
|
+
|
|
216
|
+
A `/` in a pattern is Cucumber Expression syntax for alternative text, so
|
|
217
|
+
the path in the sentence is refused until it is escaped:
|
|
218
|
+
|
|
219
|
+
```
|
|
220
|
+
$ npx nuka scaffold create-item --pattern 'I POST this body to /items'
|
|
221
|
+
refused invalid-value - Refusing to scaffold: This Cucumber Expression has a problem at column 21: I POST this body to /items ^ Alternative may not be empty. If you did not mean to use an alternative you can use '\/' to escape the '/'
|
|
222
|
+
fix: Correct the flag's value as the message says.
|
|
223
|
+
do: nuka scaffold --help
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
`--pattern 'I POST this body to \/items'` wrote the pattern
|
|
227
|
+
`"I POST this body to \\/items"`, and the feature line stays `I POST this
|
|
228
|
+
body to /items`.
|
|
229
|
+
|
|
230
|
+
With the Outline named `a bad request body` and no column in the name,
|
|
231
|
+
`nuka check` warned (S7):
|
|
232
|
+
|
|
233
|
+
```
|
|
234
|
+
warning outline-rows-share-name probe/outline.feature:37 Scenario outline "a bad request body" has 3 Examples rows, and its name uses none of the columns (<body>, <status>, <error>), so every row is reported under the same name.
|
|
235
|
+
fix: Add a column to the name, such as: a bad request body <body>
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
The first version of the feature expected the exact bodies a new, empty
|
|
239
|
+
server answers: `{"id":1,"name":"lamp"}` read back, and a list of
|
|
240
|
+
exactly lamp and desk. Against the one server of the run, two scenarios
|
|
241
|
+
read items an earlier scenario created (S8):
|
|
242
|
+
|
|
243
|
+
```
|
|
244
|
+
step 4/4 failed 0.0s the response body is
|
|
245
|
+
claim broken: {"id":2,"name":"lamp"} (from:get-item@22.body) equal {"id":1,"name":"lamp"} (sentence:expected); first difference at id: actual 2, expected 1
|
|
246
|
+
...
|
|
247
|
+
step 5/5 failed 0.0s the response body is
|
|
248
|
+
claim broken: [{"id":1,"name":"lamp"},{"id":2,"name":"lamp"},{"id":3,"name":"lamp"},{"id":4,"name":"desk"}] (from:list-items@57.body) equal [{"id":1,"name":"lamp"},{"id":2,"name":"desk"}] (sentence:expected); 1 expected item is missing: {"id":2,"name":"desk"} (item 1); 3 actual items are extra: {"id":2,"name":"lamp"} (item 1), {"id":3,"name":"lamp"} (item 2), {"id":4,"name":"desk"} (item 3)
|
|
249
|
+
...
|
|
250
|
+
7 scenarios: 5 passed, 2 failed (1s)
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
The claim line names both values and the step each came from (S11): the
|
|
254
|
+
body is the one `get-item` on line 22 got, and the id the server assigned
|
|
255
|
+
is 2.
|
|
256
|
+
|
|
257
|
+
The run that passed, with claims on what each scenario created:
|
|
258
|
+
|
|
259
|
+
```
|
|
260
|
+
$ npx nuka check
|
|
261
|
+
ok: no issues found
|
|
262
|
+
$ npx nuka run
|
|
263
|
+
environment count-off
|
|
264
|
+
...
|
|
265
|
+
scenario 4/16 features/items.feature:46 a bad request body: not json answers 400
|
|
266
|
+
...
|
|
267
|
+
scenario 5/16 features/items.feature:47 a bad request body: {} answers 422
|
|
268
|
+
...
|
|
269
|
+
scenario 6/16 features/items.feature:48 a bad request body: {"name":""} answers 422
|
|
270
|
+
...
|
|
271
|
+
scenario 8/16 features/items.feature:57 counting the items (control)
|
|
272
|
+
step 1/4 passed 0.0s an item named "chair" exists
|
|
273
|
+
step 2/4 passed 0.0s I request the item count
|
|
274
|
+
step 3/4 failed 0.0s the response status is 200
|
|
275
|
+
claim broken: 404 (from:count-items@59.status) equal 200 (sentence:expected)
|
|
276
|
+
...
|
|
277
|
+
proof run 2/2 features/items.feature:57 counting the items (control in count-off)
|
|
278
|
+
...
|
|
279
|
+
environment count-on
|
|
280
|
+
...
|
|
281
|
+
scenario 16/16 features/items.feature:57 counting the items
|
|
282
|
+
step 1/4 passed 0.0s an item named "chair" exists
|
|
283
|
+
step 2/4 passed 0.0s I request the item count
|
|
284
|
+
step 3/4 passed 0.0s the response status is 200
|
|
285
|
+
step 4/4 passed 0.0s the response body has a count of at least 1
|
|
286
|
+
...
|
|
287
|
+
15 scenarios: 15 passed, 0 failed (2s)
|
|
288
|
+
2 control runs
|
|
289
|
+
criteria: 7 held, 1 proven, 0 failed
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
Each environment opens with three lines, cut above after the first:
|
|
293
|
+
`environment count-off`, `world count-off: serve started:` with the
|
|
294
|
+
command and the ready URL it waits for, then `world count-off: serve
|
|
295
|
+
0.1s, http://localhost:<port>` with the path of the world's `program.log`,
|
|
296
|
+
which holds what the server printed. The first version's
|
|
297
|
+
`repeated-scenario-prefix` note is gone: the two scenarios that create an
|
|
298
|
+
item no longer begin with the same line.
|
|
299
|
+
|
|
300
|
+
Scenario 8 is `counting the items` in `count-off`, where the endpoint
|
|
301
|
+
is not there: a control. Its Then broke at line 60, so the run ran it
|
|
302
|
+
once more (`proof run 2/2`), and it broke at the same line again. That
|
|
303
|
+
is what `proven` means: the scenario fails where the count does not
|
|
304
|
+
exist, so its pass in `count-on` is the count's doing. The count line
|
|
305
|
+
counts the 15 executions of required cells, the line under it the
|
|
306
|
+
control's 2 runs, and the summary opens with the table:
|
|
307
|
+
|
|
308
|
+
```text
|
|
309
|
+
# nukadoko run passed: 8 criteria in 2 environments, 7 held, 1 proven
|
|
310
|
+
|
|
311
|
+
| verdict | criterion | head count-off (item_count: false) | head count-on (item_count: true) |
|
|
312
|
+
| --- | --- | --- | --- |
|
|
313
|
+
| held | `features/items.feature:10` creating an item | pass | pass |
|
|
314
|
+
| held | `features/items.feature:19` reading an item back | pass | pass |
|
|
315
|
+
| held | `features/items.feature:25` an unknown id | pass | pass |
|
|
316
|
+
| held | `features/items.feature:46` a bad request body: not json answers 400 | pass | pass |
|
|
317
|
+
| held | `features/items.feature:47` a bad request body: {} answers 422 | pass | pass |
|
|
318
|
+
| held | `features/items.feature:48` a bad request body: {"name":""} answers 422 | pass | pass |
|
|
319
|
+
| held | `features/items.feature:50` the list holds what was created | pass | pass |
|
|
320
|
+
| proven | `features/items.feature:57` counting the items `@with:item_count` | fail@60 (control, 2 runs) | pass |
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
## Decisions
|
|
324
|
+
|
|
325
|
+
| Date | Decision | Chosen | Why | Became |
|
|
326
|
+
| --- | --- | --- | --- | --- |
|
|
327
|
+
| 2026-10-16 | Fixture scope for a server that holds state | per scenario | with `scope: "process"`, two scenarios read another scenario's items | S8 |
|
|
328
|
+
| 2026-10-16 | One request step per endpoint, or one `I send {method} {path}` | one per sentence the reviewer reads | the sentence names what a user does; the cost is a longer `from` list on each Then | Shapes: an HTTP API |
|
|
329
|
+
| 2026-10-16 | A path in a pattern | `\/items` | `/` is alternative text in a Cucumber Expression | Shapes: an HTTP API |
|
|
330
|
+
| 2026-10-16 | How the Outline rows are told apart | `<body>` and `<status>` in the name | the summary listed one name three times | S7 |
|
|
331
|
+
| 2026-10-16 | The whole body against a docstring, or one claim per field | the whole body | the ticket names the body's fields; a scenario per field would repeat the request | none |
|
|
332
|
+
| 2026-10-17 | Acting on `repeated-scenario-prefix` | not acted on | the shared Given writes state the scenario reads | S8 |
|
|
333
|
+
| 2026-10-17 | `mutates` on the POST steps | the default `true`, no go-ahead | they change the API's state, but only on the server the fixture started | SKILL.md "Before the first command" |
|
|
334
|
+
| 2026-10-24 | Where the API server runs | `nukadoko.program.ts`, one server for the run | the program file is how nukadoko starts a program, and its `program.log` and run.json's `worlds` say which program answered; a fixture that starts one in-process says neither | S8 |
|
|
335
|
+
| 2026-10-24 | Expected bodies against a shared server | claims on what the scenario created: the name it sent, an id of at least 1, the body its Given returned | the exact bodies broke as soon as an earlier scenario had created an item (measured above) | S8 |
|
|
336
|
+
| 2026-10-24 | The unknown id | `0` | the API numbers items from 1, so no run reaches it; `42` exists once a run, or `--repeat`, has created 42 items | none |
|
|
337
|
+
| 2026-10-24 | A criterion behind a switch | two environments, `count-off` and `count-on`, with `conditions`, and `@with:item_count` on the scenario | one run shows the scenario breaking where the switch is off, a control that proves it; a scenario that only ran with the switch on would say nothing about whether it notices the count | none |
|
|
338
|
+
| 2026-10-24 | How the switch follows its side | `ITEM_COUNT: "{condition.item_count}"` in `env` | `conditions` decide which cell counts, and nukadoko does not check them against the program; with `ITEM_COUNT: "1"` written apart from them, an edit to one and not the other makes a cell count for a side its server is not on | none |
|
|
339
|
+
| 2026-10-24 | How the body compares with the docstring | `args` parses the docstring, and one `equal` claim compares the two values | key order and spacing in the docstring do not count; the claim record keeps both values | none |
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
# Worked example: a stateful workflow
|
|
2
|
+
|
|
3
|
+
A finished project for a sign-up flow whose steps call the module under
|
|
4
|
+
test directly, built with nukadoko 0.16.1 on Node 24.22.0, with its Thens
|
|
5
|
+
moved to claims in the release after 0.21.0. Every output
|
|
6
|
+
block below is copied from a real run of that project, which is
|
|
7
|
+
`examples/acceptance/workflow/` in the nukadoko repository; CI runs it.
|
|
8
|
+
The rules it follows are in `../scenario-rules.md`.
|
|
9
|
+
|
|
10
|
+
## The ticket
|
|
11
|
+
|
|
12
|
+
A registration issues a confirmation link, and sign-in works only after
|
|
13
|
+
the link is opened. An email can be registered once. A password shorter
|
|
14
|
+
than 8 characters is refused. A wrong password is refused with the same
|
|
15
|
+
message as an unknown email.
|
|
16
|
+
|
|
17
|
+
## The feature
|
|
18
|
+
|
|
19
|
+
`features/signup.feature`. Each refusal reason is the exact text the
|
|
20
|
+
ticket's owner agreed to; a reason the ticket did not give was asked for,
|
|
21
|
+
not read off the program.
|
|
22
|
+
|
|
23
|
+
```gherkin
|
|
24
|
+
Feature: sign-up
|
|
25
|
+
|
|
26
|
+
Acceptance criteria (from the request):
|
|
27
|
+
- A registration issues a confirmation link; sign-in works only after the link is opened
|
|
28
|
+
- An email can be registered once
|
|
29
|
+
- A password shorter than 8 characters is refused
|
|
30
|
+
- A wrong password is refused with the same message as an unknown email
|
|
31
|
+
|
|
32
|
+
Scenario: sign in after confirming
|
|
33
|
+
Given a registration for "ada@example.com" with password "correct horse" is submitted
|
|
34
|
+
And the confirmation link is opened
|
|
35
|
+
When "ada@example.com" signs in with password "correct horse"
|
|
36
|
+
Then the sign-in is accepted
|
|
37
|
+
|
|
38
|
+
Scenario: sign in before confirming
|
|
39
|
+
Given a registration for "ada@example.com" with password "correct horse" is submitted
|
|
40
|
+
When "ada@example.com" signs in with password "correct horse"
|
|
41
|
+
Then the sign-in is refused because "email not confirmed"
|
|
42
|
+
|
|
43
|
+
Scenario: the same email twice
|
|
44
|
+
Given a registration for "ada@example.com" with password "correct horse" is submitted
|
|
45
|
+
When a registration for "ada@example.com" with password "other secret" is submitted
|
|
46
|
+
Then the registration is refused because "email already registered"
|
|
47
|
+
|
|
48
|
+
Scenario: a short password
|
|
49
|
+
When a registration for "ada@example.com" with password "short" is submitted
|
|
50
|
+
Then the registration is refused because "password shorter than 8 characters"
|
|
51
|
+
|
|
52
|
+
Scenario: a wrong password after confirming
|
|
53
|
+
Given a registration for "ada@example.com" with password "correct horse" is submitted
|
|
54
|
+
And the confirmation link is opened
|
|
55
|
+
When "ada@example.com" signs in with password "wrong horse"
|
|
56
|
+
Then the sign-in is refused because "unknown email or wrong password"
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## The steps and the fixture
|
|
60
|
+
|
|
61
|
+
- `store` (a config fixture, scoped per scenario): a new, empty user store.
|
|
62
|
+
- `register` (Given in four scenarios, When in two): submits a
|
|
63
|
+
registration and returns `outcome` (`"accepted"` or `"refused"`),
|
|
64
|
+
`token`, and `reason`. It does not throw on a refusal, so a Then can
|
|
65
|
+
claim the reason (S6, S10).
|
|
66
|
+
- `confirm` (Given): opens the link, reading `token` from `register`
|
|
67
|
+
through `from`.
|
|
68
|
+
- `sign-in` (When): returns `outcome` and `reason`, and does not throw on
|
|
69
|
+
a refusal.
|
|
70
|
+
- `sign-in-is-accepted`, `sign-in-is-refused`,
|
|
71
|
+
`registration-is-refused` (Then): read the outcome through `from` and
|
|
72
|
+
declare claims on it. The word `accepted` or `refused` in the sentence
|
|
73
|
+
states the outcome, so a `literal` claim may name it; the reason is a
|
|
74
|
+
capture.
|
|
75
|
+
|
|
76
|
+
`features/steps/register.ts`:
|
|
77
|
+
|
|
78
|
+
```ts
|
|
79
|
+
import { defineStep, z } from "nukadoko";
|
|
80
|
+
|
|
81
|
+
export default defineStep({
|
|
82
|
+
description: "Submit a registration; returns the outcome, never throws on refusal",
|
|
83
|
+
pattern: "a registration for {email:string} with password {password:string} is submitted",
|
|
84
|
+
args: z.object({
|
|
85
|
+
email: z.string().describe("The email registered"),
|
|
86
|
+
password: z.string().describe("The password chosen"),
|
|
87
|
+
}),
|
|
88
|
+
returns: z.object({
|
|
89
|
+
outcome: z.enum(["accepted", "refused"]).describe("Whether the registration was accepted or refused"),
|
|
90
|
+
token: z.string().nullable().describe("The confirmation token issued, when accepted"),
|
|
91
|
+
reason: z.string().nullable().describe("Why it was refused, when refused"),
|
|
92
|
+
}),
|
|
93
|
+
run({ store }, { email, password }) {
|
|
94
|
+
const r = store.register(email, password);
|
|
95
|
+
return r.ok
|
|
96
|
+
? { outcome: "accepted" as const, token: r.token, reason: null }
|
|
97
|
+
: { outcome: "refused" as const, token: null, reason: r.reason };
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
`features/steps/registration-is-refused.ts`:
|
|
103
|
+
|
|
104
|
+
```ts
|
|
105
|
+
import { defineStep, z } from "nukadoko";
|
|
106
|
+
import register from "./register.ts";
|
|
107
|
+
|
|
108
|
+
export default defineStep({
|
|
109
|
+
description: "The last registration was refused with exactly this reason",
|
|
110
|
+
pattern: "the registration is refused because {expected:string}",
|
|
111
|
+
args: z.object({
|
|
112
|
+
expected: z.string().describe("The expected reason"),
|
|
113
|
+
outcome: register.returns.shape.outcome,
|
|
114
|
+
reason: register.returns.shape.reason,
|
|
115
|
+
}),
|
|
116
|
+
from: { outcome: [register, "outcome"], reason: [register, "reason"] },
|
|
117
|
+
claims: [
|
|
118
|
+
{ actual: "outcome", compare: "equal", expected: { literal: "refused" } },
|
|
119
|
+
{ actual: "reason", compare: "equal", expected: "expected" },
|
|
120
|
+
],
|
|
121
|
+
});
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## The commands, in order
|
|
125
|
+
|
|
126
|
+
```
|
|
127
|
+
$ npx nuka check
|
|
128
|
+
ok: no issues found
|
|
129
|
+
$ npx nuka run
|
|
130
|
+
...
|
|
131
|
+
scenario 3/5 features/signup.feature:20 the same email twice
|
|
132
|
+
step 1/3 passed 0.0s a registration for "ada@example.com" with password "correct horse" is submitted
|
|
133
|
+
step 2/3 passed 0.0s a registration for "ada@example.com" with password "other secret" is submitted
|
|
134
|
+
step 3/3 passed 0.0s the registration is refused because "email already registered"
|
|
135
|
+
...
|
|
136
|
+
5 scenarios: 5 passed, 0 failed (0s)
|
|
137
|
+
note repeated-scenario-prefix features/signup.feature 2 scenarios begin with the same 2 steps, which took 0 seconds across them, 11% of this run's summed scenario time. The shared steps: "a registration for "ada@example.com" with password "correct horse" is submitted", "the confirmation link is opened". "a registration for "ada@example.com" with password "correct horse" is submitted" does not declare mutates: false, so a later scenario may read what this opening writes: a "process"-scope fixture would share that state between scenarios. A Background keeps the shared steps in one place and still runs them for each scenario.
|
|
138
|
+
fix: No change is necessary. A Background can hold the shared steps. A process-scope fixture fits only an opening whose steps all declare mutates: false.
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
`nuka run` reported one note, and it was not acted on.
|
|
142
|
+
|
|
143
|
+
In "the same email twice", `register` runs twice, and the Then reads the
|
|
144
|
+
second result. A probe with two registrations and then `When the
|
|
145
|
+
confirmation link is opened` showed which token `from` picked, read from
|
|
146
|
+
the step records:
|
|
147
|
+
|
|
148
|
+
```
|
|
149
|
+
register {"email":"a@example.com","password":"correct horse"} {"outcome":"accepted","token":"tok-1","reason":null}
|
|
150
|
+
register {"email":"b@example.com","password":"correct horse"} {"outcome":"accepted","token":"tok-2","reason":null}
|
|
151
|
+
confirm {"token":"tok-2"} {"email":"b@example.com"}
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
Four scenarios also share the registration line alone. The note names
|
|
155
|
+
the opening that covers the most step executions, and on a tie the
|
|
156
|
+
longer one: 2 scenarios of 2 steps against 4 of 1, so the two lines. It
|
|
157
|
+
names the same opening on every run, whatever the steps took.
|
|
158
|
+
|
|
159
|
+
Not every scenario of the file opens with these lines, so a
|
|
160
|
+
Background does not fit. Both lines write to the store the scenario then
|
|
161
|
+
reads, so a process-scope fixture does not fit either, as the note says
|
|
162
|
+
(S8).
|
|
163
|
+
|
|
164
|
+
## Decisions
|
|
165
|
+
|
|
166
|
+
| Date | Decision | Chosen | Why | Became |
|
|
167
|
+
| --- | --- | --- | --- | --- |
|
|
168
|
+
| 2026-10-16 | The same action as a Given in one scenario and the When in another | one step, `register` | the keyword says what the line does in this scenario | S10 |
|
|
169
|
+
| 2026-10-16 | A step that is refused: throw, or return the outcome | return the outcome and `reason` | a thrown refusal leaves the Then nothing to read | S6 |
|
|
170
|
+
| 2026-10-16 | A refusal reason in the sentence, or a bare `is refused` | in the sentence | the ticket gives the message, and two refusals differ only by it | S6 |
|
|
171
|
+
| 2026-10-16 | `from` when the producer ran twice | the most recent result | measured with the probe above | Shapes: the same producer twice |
|
|
172
|
+
| 2026-10-16 | Two shared Given lines: Background, or repeat them | repeat | they are not shared by every scenario of the file | Shapes: Outline or scenarios |
|
|
173
|
+
| 2026-10-24 | The outcome as a boolean `accepted`, or as the word | `outcome: "accepted" \| "refused"` | a claim may name a value only when the sentence states it, and the sentence says `accepted` or `refused`, not `true` or `false` | S1 |
|