nukadoko 0.5.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (203) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +553 -3
  3. data/README.ja.md +22 -6
  4. data/README.md +13 -7
  5. data/docs/ci.ja.md +542 -0
  6. data/docs/ci.md +635 -0
  7. data/docs/commands.ja.md +1524 -0
  8. data/docs/commands.md +1281 -0
  9. data/docs/engines.json +19 -0
  10. data/docs/execution-events.ja.md +336 -0
  11. data/docs/execution-events.md +423 -0
  12. data/docs/glossary.json +1348 -0
  13. data/docs/guide.ja.md +733 -0
  14. data/docs/guide.md +815 -0
  15. data/docs/intent.ja.md +133 -0
  16. data/docs/intent.md +156 -0
  17. data/docs/layout.ja.md +442 -0
  18. data/docs/layout.md +399 -0
  19. data/docs/releasing.ja.md +186 -0
  20. data/docs/releasing.md +237 -0
  21. data/docs/ruby/reference.ja.md +302 -0
  22. data/docs/ruby/reference.md +368 -0
  23. data/docs/spec.ja.md +8916 -0
  24. data/docs/spec.md +11250 -0
  25. data/docs/tutorial.ja.md +451 -0
  26. data/docs/tutorial.md +458 -0
  27. data/docs/typescript/adopting.ja.md +231 -0
  28. data/docs/typescript/adopting.md +251 -0
  29. data/docs/typescript/doors.ja.md +301 -0
  30. data/docs/typescript/doors.md +329 -0
  31. data/docs/typescript/migration-playwright-test.ja.md +189 -0
  32. data/docs/typescript/migration-playwright-test.md +212 -0
  33. data/docs/typescript/migration.ja.md +391 -0
  34. data/docs/typescript/migration.md +505 -0
  35. data/docs/typescript/reference.ja.md +176 -0
  36. data/docs/typescript/reference.md +197 -0
  37. data/docs/typescript/upgrading.ja.md +1774 -0
  38. data/docs/typescript/upgrading.md +2224 -0
  39. data/docs/web-app.ja.md +627 -0
  40. data/docs/web-app.md +659 -0
  41. data/docs/writing-scenarios.ja.md +544 -0
  42. data/docs/writing-scenarios.md +563 -0
  43. data/lib/nukadoko/base.rb +12 -5
  44. data/lib/nukadoko/changed_files.rb +95 -0
  45. data/lib/nukadoko/check.rb +459 -51
  46. data/lib/nukadoko/claim_drops.rb +271 -0
  47. data/lib/nukadoko/claim_line.rb +24 -4
  48. data/lib/nukadoko/claim_rules.rb +143 -1
  49. data/lib/nukadoko/claim_sides.rb +157 -9
  50. data/lib/nukadoko/cli.rb +403 -50
  51. data/lib/nukadoko/codes.json +246 -21
  52. data/lib/nukadoko/codes.rb +21 -4
  53. data/lib/nukadoko/command.rb +120 -13
  54. data/lib/nukadoko/command_help.rb +128 -0
  55. data/lib/nukadoko/compat.rb +469 -0
  56. data/lib/nukadoko/criteria.rb +1 -1
  57. data/lib/nukadoko/definition.rb +157 -7
  58. data/lib/nukadoko/error_frames.rb +6 -3
  59. data/lib/nukadoko/events/count.rb +146 -0
  60. data/lib/nukadoko/events/counted.rb +114 -0
  61. data/lib/nukadoko/events/format.rb +257 -0
  62. data/lib/nukadoko/events/lists.rb +154 -0
  63. data/lib/nukadoko/events/path.rb +285 -0
  64. data/lib/nukadoko/events/read.rb +284 -0
  65. data/lib/nukadoko/events/reader.rb +490 -0
  66. data/lib/nukadoko/events/selection.rb +252 -0
  67. data/lib/nukadoko/events/tally.rb +438 -0
  68. data/lib/nukadoko/features.rb +2 -2
  69. data/lib/nukadoko/fixtures.rb +160 -35
  70. data/lib/nukadoko/http_recording.rb +6 -2
  71. data/lib/nukadoko/intent.rb +364 -0
  72. data/lib/nukadoko/intent_file.rb +81 -0
  73. data/lib/nukadoko/intent_view.rb +190 -0
  74. data/lib/nukadoko/js_json.rb +2 -1
  75. data/lib/nukadoko/judge.rb +2 -2
  76. data/lib/nukadoko/judgment_file.rb +22 -1
  77. data/lib/nukadoko/judgments.rb +33 -3
  78. data/lib/nukadoko/measure_mcp.rb +202 -0
  79. data/lib/nukadoko/parts.rb +8 -2
  80. data/lib/nukadoko/path_view.rb +252 -0
  81. data/lib/nukadoko/place_rows.rb +161 -0
  82. data/lib/nukadoko/program.rb +1265 -51
  83. data/lib/nukadoko/program_log.rb +122 -0
  84. data/lib/nukadoko/program_shape.rb +385 -0
  85. data/lib/nukadoko/project_fixtures.rb +43 -10
  86. data/lib/nukadoko/project_program.rb +5 -4
  87. data/lib/nukadoko/repeated_prefix.rb +310 -0
  88. data/lib/nukadoko/report_run.rb +3 -3
  89. data/lib/nukadoko/run.rb +1156 -159
  90. data/lib/nukadoko/run_record.rb +70 -46
  91. data/lib/nukadoko/scaffold.rb +24 -6
  92. data/lib/nukadoko/schema.rb +15 -2
  93. data/lib/nukadoko/secrets.rb +55 -5
  94. data/lib/nukadoko/states.rb +478 -0
  95. data/lib/nukadoko/step.rb +71 -2
  96. data/lib/nukadoko/step_fixtures.rb +52 -3
  97. data/lib/nukadoko/summary.rb +803 -30
  98. data/lib/nukadoko/table.rb +4 -2
  99. data/lib/nukadoko/text_fit.rb +20 -7
  100. data/lib/nukadoko/trace.rb +152 -45
  101. data/lib/nukadoko/tree_passes.rb +95 -33
  102. data/lib/nukadoko/underneath.rb +311 -0
  103. data/lib/nukadoko/verdict.rb +18 -1
  104. data/lib/nukadoko/version.rb +1 -1
  105. data/lib/nukadoko/vocabulary.rb +166 -23
  106. data/lib/nukadoko/walk.rb +2 -2
  107. data/lib/nukadoko/walk_step.rb +1 -1
  108. data/lib/nukadoko.rb +23 -0
  109. data/llms.txt +42 -35
  110. data/sig/generated/nukadoko/base.rbs +4 -4
  111. data/sig/generated/nukadoko/changed_files.rbs +42 -0
  112. data/sig/generated/nukadoko/check.rbs +147 -10
  113. data/sig/generated/nukadoko/claim_drops.rbs +135 -0
  114. data/sig/generated/nukadoko/claim_line.rbs +11 -0
  115. data/sig/generated/nukadoko/claim_rules.rbs +49 -4
  116. data/sig/generated/nukadoko/claim_sides.rbs +63 -12
  117. data/sig/generated/nukadoko/cli.rbs +80 -7
  118. data/sig/generated/nukadoko/codes.rbs +19 -4
  119. data/sig/generated/nukadoko/command.rbs +68 -1
  120. data/sig/generated/nukadoko/command_help.rbs +18 -0
  121. data/sig/generated/nukadoko/compat.rbs +392 -0
  122. data/sig/generated/nukadoko/criteria.rbs +1 -1
  123. data/sig/generated/nukadoko/definition.rbs +50 -0
  124. data/sig/generated/nukadoko/error_frames.rbs +1 -1
  125. data/sig/generated/nukadoko/events/count.rbs +69 -0
  126. data/sig/generated/nukadoko/events/counted.rbs +70 -0
  127. data/sig/generated/nukadoko/events/format.rbs +163 -0
  128. data/sig/generated/nukadoko/events/lists.rbs +47 -0
  129. data/sig/generated/nukadoko/events/path.rbs +161 -0
  130. data/sig/generated/nukadoko/events/read.rbs +109 -0
  131. data/sig/generated/nukadoko/events/reader.rbs +226 -0
  132. data/sig/generated/nukadoko/events/selection.rbs +100 -0
  133. data/sig/generated/nukadoko/events/tally.rbs +227 -0
  134. data/sig/generated/nukadoko/features.rbs +6 -4
  135. data/sig/generated/nukadoko/fixtures.rbs +67 -11
  136. data/sig/generated/nukadoko/http_recording.rbs +1 -1
  137. data/sig/generated/nukadoko/intent.rbs +132 -0
  138. data/sig/generated/nukadoko/intent_file.rbs +46 -0
  139. data/sig/generated/nukadoko/intent_view.rbs +69 -0
  140. data/sig/generated/nukadoko/judgment_file.rbs +7 -1
  141. data/sig/generated/nukadoko/judgments.rbs +10 -0
  142. data/sig/generated/nukadoko/measure_mcp.rbs +104 -0
  143. data/sig/generated/nukadoko/parts.rbs +2 -2
  144. data/sig/generated/nukadoko/path_view.rbs +105 -0
  145. data/sig/generated/nukadoko/place_rows.rbs +43 -0
  146. data/sig/generated/nukadoko/program.rbs +627 -23
  147. data/sig/generated/nukadoko/program_log.rbs +67 -0
  148. data/sig/generated/nukadoko/program_shape.rbs +147 -0
  149. data/sig/generated/nukadoko/project_fixtures.rbs +16 -3
  150. data/sig/generated/nukadoko/project_program.rbs +2 -1
  151. data/sig/generated/nukadoko/repeated_prefix.rbs +172 -0
  152. data/sig/generated/nukadoko/report_run.rbs +1 -1
  153. data/sig/generated/nukadoko/run.rbs +286 -41
  154. data/sig/generated/nukadoko/run_record.rbs +20 -12
  155. data/sig/generated/nukadoko/scaffold.rbs +3 -0
  156. data/sig/generated/nukadoko/schema.rbs +5 -0
  157. data/sig/generated/nukadoko/secrets.rbs +26 -3
  158. data/sig/generated/nukadoko/states.rbs +214 -0
  159. data/sig/generated/nukadoko/step.rbs +58 -1
  160. data/sig/generated/nukadoko/step_fixtures.rbs +39 -0
  161. data/sig/generated/nukadoko/summary.rbs +256 -2
  162. data/sig/generated/nukadoko/table.rbs +3 -2
  163. data/sig/generated/nukadoko/trace.rbs +108 -33
  164. data/sig/generated/nukadoko/tree_passes.rbs +36 -8
  165. data/sig/generated/nukadoko/underneath.rbs +141 -0
  166. data/sig/generated/nukadoko/verdict.rbs +8 -0
  167. data/sig/generated/nukadoko/vocabulary.rbs +45 -6
  168. data/skills/nukadoko/SKILL.md +18 -18
  169. data/skills/nukadoko/references/checking-steps.md +16 -83
  170. data/skills/nukadoko/references/diagnosing.md +6 -6
  171. data/skills/nukadoko/references/done.md +22 -0
  172. data/skills/nukadoko/references/evidence.md +19 -6
  173. data/skills/nukadoko/references/exploring.md +22 -7
  174. data/skills/nukadoko/references/fixtures.md +12 -32
  175. data/skills/nukadoko/references/judgments.md +18 -0
  176. data/skills/nukadoko/references/maintenance.md +1 -1
  177. data/skills/nukadoko/references/merge-risk.md +1 -1
  178. data/skills/nukadoko/references/parts.md +46 -23
  179. data/skills/nukadoko/references/{perturbed-worlds.md → perturbed-systems.md} +30 -12
  180. data/skills/nukadoko/references/program.md +168 -169
  181. data/skills/nukadoko/references/reviewing.md +20 -20
  182. data/skills/nukadoko/references/ruby/checking-steps.md +106 -0
  183. data/skills/nukadoko/references/ruby/examples/cli.md +212 -0
  184. data/skills/nukadoko/references/ruby/fixtures.md +34 -0
  185. data/skills/nukadoko/references/ruby/program.md +112 -0
  186. data/skills/nukadoko/references/ruby/step-files.md +115 -0
  187. data/skills/nukadoko/references/running.md +34 -34
  188. data/skills/nukadoko/references/scenario-rules.md +7 -6
  189. data/skills/nukadoko/references/states.md +7 -1
  190. data/skills/nukadoko/references/step-files.md +41 -120
  191. data/skills/nukadoko/references/typescript/checking-steps.md +129 -0
  192. data/skills/nukadoko/references/{examples → typescript/examples}/cli.md +1 -1
  193. data/skills/nukadoko/references/{examples → typescript/examples}/http-api.md +6 -6
  194. data/skills/nukadoko/references/{examples → typescript/examples}/workflow.md +1 -1
  195. data/skills/nukadoko/references/typescript/fixtures.md +56 -0
  196. data/skills/nukadoko/references/typescript/program.md +111 -0
  197. data/skills/nukadoko/references/typescript/step-files.md +104 -0
  198. data/skills/nukadoko/references/verdicts.md +10 -10
  199. data/skills/nukadoko/references/writing-steps.md +67 -67
  200. data/skills/nukadoko/references/writing-the-feature.md +1 -1
  201. data/skills/nukadoko-verification/SKILL.md +13 -8
  202. metadata +103 -7
  203. data/skills/nukadoko/references/ruby.md +0 -80
@@ -0,0 +1,368 @@
1
+ # The Ruby engine
2
+
3
+ How a step, a fixture, and a config are written for the `nukadoko` gem.
4
+ What a feature file, a claim, a run, and a record mean is the same in both
5
+ engines, and [the spec](../spec.md) says it once. The
6
+ [TypeScript engine's page](../typescript/reference.md) has the same
7
+ headings in the same order, so the two can be read side by side.
8
+
9
+ ## Install and command
10
+
11
+ Ruby 3.4 or later. Add the gem to the Gemfile of the project under test,
12
+ and run it with `bundle exec nuka`:
13
+
14
+ ```ruby
15
+ gem "nukadoko", group: :test
16
+ ```
17
+
18
+ ```sh
19
+ bundle install
20
+ bundle exec nuka init
21
+ ```
22
+
23
+ When the project has a `Rakefile`, `init` adds a `scenarios` task to it
24
+ that runs `bundle exec nuka run`, the one command a person or CI runs.
25
+
26
+ A step that uses `page` needs a browser that `playwright-ruby-client`
27
+ can launch.
28
+
29
+ ## Configuration
30
+
31
+ `nuka init` writes `nukadoko.config.rb`, which calls
32
+ `Nukadoko.config(...)` with the options as keywords, under the same names
33
+ as the TypeScript config: `program` and project fixtures below,
34
+ `envFiles:` and `secrets:` for the `env` fixture, `browser:` for the
35
+ browser's launch options, `stepTimeout:` for how long a step may run
36
+ (in milliseconds, twenty minutes by default), and `parameterTypes:` for a
37
+ parameter type read inside a sentence:
38
+
39
+ ```ruby
40
+ Nukadoko.config(parameterTypes: [{ name: "priority", regexp: /高|低/, transformer: ->(s) { s == "高" ? "high" : "low" } }])
41
+ ```
42
+
43
+ ## Defining a step
44
+
45
+ One step per file under `features/steps/`, named in snake_case; the file
46
+ name is the step name with hyphens (`an_item_exists.rb` is
47
+ `an-item-exists`). The file defines a class of the CamelCase name that
48
+ inherits `Nukadoko::Step`:
49
+
50
+ ```ruby
51
+ class AnItemExists < Nukadoko::Step
52
+ description "Create an item through the API so a later step can read it"
53
+ pattern "an item named {name:string} exists"
54
+ args { string :name, "The item's name" }
55
+ returns do
56
+ number :id, "The id the API assigned"
57
+ object :body, "The item as the API answered it" do
58
+ number :id
59
+ string :name
60
+ end
61
+ end
62
+
63
+ def run(baseURL:, args:)
64
+ res = Net::HTTP.post(URI("#{baseURL}/items"), JSON.generate(name: args.name))
65
+ raise %(creating "#{args.name}": status #{res.code.to_i}, not 201) unless res.code.to_i == 201
66
+
67
+ item = JSON.parse(res.body)
68
+ { id: item["id"], body: item }
69
+ end
70
+ end
71
+ ```
72
+
73
+ `mutates false` declares a step that changes nothing. `patterns` adds
74
+ more wordings of the same step after `pattern`, and every wording must
75
+ capture the same keys (`alias-key-mismatch` otherwise). `timeout 5000`
76
+ bounds the step's own `run` or `observe` in milliseconds; past it a
77
+ program `run_command` still runs for the step is stopped, the
78
+ step fails with `error.kind` `timeout`, and without it the config's
79
+ `stepTimeout` applies.
80
+
81
+ ```ruby
82
+ class ItemCount < Nukadoko::Step
83
+ description "Count the items the API lists"
84
+ pattern "I count the items"
85
+ patterns "the items are counted"
86
+ timeout 5000
87
+ # ...
88
+ end
89
+ ```
90
+
91
+ `requires`, `gives`, and `ends` name the states a line needs held, leaves
92
+ held, and leaves not held: a name, or a name and the args key whose value
93
+ tells one holder from another (`requires ["signed-in", :person]`). `nuka
94
+ check` walks each scenario through them and reports `state-missing` at a
95
+ line that can only run without its state, and `nuka run` refuses that
96
+ scenario before any step runs. The spec's "States" says what to declare.
97
+
98
+ Every `*.rb` file
99
+ under `features/steps/` is loaded, a helper under `features/steps/lib/`
100
+ too, so a helper module named after its file can be used from any step
101
+ without a `require`.
102
+
103
+ ## Fields and schemas
104
+
105
+ `args` and `returns` take a block of fields: `string`, `number`,
106
+ `integer`, `boolean`, `object`, `array`, `unknown`, and the lists
107
+ `strings`, `numbers`, and `integers`. A field takes `null: true` when nil
108
+ is allowed, `optional: true` when the key may be absent, and `default:`
109
+ for the value an absent key reads as. `enum :outcome, %w[accepted refused]`
110
+ allows only those words. `min:`, `max:`, `positive: true`, and
111
+ `negative: true` bound a number's value, a string's length, and an
112
+ array's item count, with zod's messages. `nuka describe` prints each
113
+ schema as the same JSON Schema the TypeScript engine prints.
114
+
115
+ ## Captures, tables, and doc strings
116
+
117
+ Each `{key:type}` in the pattern fills the args key `key`. A data table
118
+ reaches its key through `table`, and a doc string as a `string`:
119
+
120
+ ```ruby
121
+ args { table :todos, "The data table's rows, one todo per row, the title in the first cell" }
122
+ ```
123
+
124
+ ## Claims
125
+
126
+ A Then step declares `claims` and an `observe` that reads the system, in
127
+ place of `run`. nukadoko judges each claim ("Claims" in
128
+ [the spec](../spec.md#claims)). `observe` does not receive an args key
129
+ that a claim compares with.
130
+
131
+ `files written: { of: RunBuild, change: "added", under: "src" }` names
132
+ the paths the commands of an earlier step added, changed, or removed,
133
+ and a claim reads the key as its actual ("Files an earlier step
134
+ changed" in [the spec](../spec.md#files-an-earlier-step-changed)). The
135
+ list comes from that step's record, from each `Nukadoko.run_command` it
136
+ ran, never from what its `run` returned.
137
+
138
+ `events writes: { of: PlaceScore, count: { kind: "db", op: %w[insert
139
+ update delete other], committed: true } }` counts the execution events of
140
+ an earlier step, and a claim reads the key as its actual ("A claim on a
141
+ count of events" in [the spec](../spec.md#a-claim-on-a-count-of-events)).
142
+ A value of the count can come from the sentence, `table: { sentence:
143
+ "table" }`. A key with `service: "billing"` beside its `count` counts
144
+ that one service's lines, and one that names no service counts every
145
+ service's. The step reads the lines of that step's trace before it
146
+ judges its claims, and keeps each reading in its record's `events_read`.
147
+
148
+ ## Chaining (`from`)
149
+
150
+ `from id: [StartJob, :id]` fills `id` with what the step `StartJob`
151
+ returned earlier in the scenario. `field :id, StartJob.returns[:id]`
152
+ reuses the producer's field for the key.
153
+
154
+ ## Parts
155
+
156
+ `parts [CreateTodo, CompleteById]` lists the steps `run` may call, and
157
+ `call.(CreateTodo, title: args.title)` runs one with its args and returns
158
+ checked ("Parts" in [the spec](../spec.md#parts)):
159
+
160
+ ```ruby
161
+ parts [CreateTodo, CompleteById]
162
+
163
+ def run(call:, args:)
164
+ created = call.(CreateTodo, title: args.title)
165
+ completed = call.(CompleteById, id: created.id)
166
+ { id: completed.id, done: completed.done }
167
+ end
168
+ ```
169
+
170
+ ## Fixtures
171
+
172
+ `Nukadoko.fixture` in the config adds a project fixture. The block calls
173
+ `use` with the value, and what follows is its teardown. A keyword
174
+ argument names a fixture it needs, and a fixture named like a builtin
175
+ replaces it for every step. `scope: :process` keeps one value for the
176
+ whole run of an environment. `use` returns how the scope ended,
177
+ `"passed"` or `"failed"`, so a teardown can keep what a failure left. A
178
+ teardown that raises is a `fixture-teardown-failed` warning, and the
179
+ scenario keeps its status; the scenario record keeps the error in
180
+ `teardown_errors`:
181
+
182
+ ```ruby
183
+ Nukadoko.fixture(:page) do |use, page:|
184
+ page.add_init_script(script: "window.wrapped = 'by the project'")
185
+ use.(page)
186
+ end
187
+ ```
188
+
189
+ A fixture that makes an MCP client passes its transport through
190
+ `Nukadoko.measure_mcp`, so each call a step sends is a line of the step's
191
+ `mcp.jsonl` and carries the step's trace context (docs/spec.md "MCP
192
+ calls"):
193
+
194
+ ```ruby
195
+ Nukadoko.fixture(:notes) do |use, base_url:|
196
+ transport = Nukadoko.measure_mcp(MCP::Client::HTTP.new(url: "#{base_url}/mcp"))
197
+ client = MCP::Client.new(transport: transport)
198
+ client.connect
199
+ use.(client)
200
+ transport.close
201
+ end
202
+ ```
203
+
204
+ ## Context
205
+
206
+ The keyword arguments of `run` and `observe` are the fixtures the step
207
+ needs: `page`, `context`, `page_as`, `request`, `env`, `require_env`,
208
+ `base_url`, `services`, `setup_result`, `scratch`, `section`, `poll`,
209
+ `evidence`,
210
+ `result_of`, and `call`. `baseURL`, `requireEnv`, `pageAs`, `setupResult`, and `resultOf` reach the same
211
+ fixtures under the TypeScript names. `nuka check` reads them with
212
+ `Method#parameters`, without calling the body ("Context API" in
213
+ [the spec](../spec.md#context-api)). `scratch.dir` is a fresh directory,
214
+ removed when the scenario ends. `Nukadoko.run_command` runs a program and
215
+ records it in the step record. Its `timeout:` is in seconds, unlike the
216
+ step's `timeout` and `poll`'s `timeout_ms`, which are milliseconds:
217
+ `timeout: 120` is two minutes. A run it stops has no exit code, so it
218
+ raises `Timeout::Error`.
219
+
220
+ ## Polling and waiting
221
+
222
+ `poll timeout_ms: 3000, settled: [...]` on a Then step reads `observe`
223
+ again until every claim holds on two readings in a row, or the time runs
224
+ out.
225
+
226
+ ## Program
227
+
228
+ The program under test is `program:` in the config, a lambda that
229
+ returns how the program starts:
230
+
231
+ ```ruby
232
+ Nukadoko.config(
233
+ program: -> { { serve: { command: "bin/rails server -p {port}", ready: "/up" } } },
234
+ )
235
+ ```
236
+
237
+ Its fields are under "Program" in [the spec](../spec.md#program).
238
+ `serve` takes `command`, `port` (`"auto"`, the default, or a number
239
+ nothing answers on yet), `ready` (default `/`), and `timeout_ms`
240
+ (default 60000): the system is ready once `ready` answers 2xx within
241
+ `timeout_ms`. A command is an Array of words, or a String split on
242
+ whitespace; neither goes through a shell, so a program that needs one
243
+ writes `["sh", "-c", "..."]`. A key the program does not know is
244
+ refused, and so is a key the TypeScript engine reads and this one does
245
+ not yet (below). A system whose program does not start runs none of its
246
+ scenarios, and the run fails with `program-start-failed` and the end
247
+ of the system's `program.log`.
248
+
249
+ A system goes through the phases in the TypeScript engine's order:
250
+ `build` (commands run once per tree per run, before any system), `prepare`
251
+ (commands run once per system, with its env and placeholders), then
252
+ `serve` or `url` (a URL, or a lambda that returns one, for a program
253
+ nukadoko does not start), then `setup` (a lambda that receives the system:
254
+ `name`, `root`, `dir`, `tree`, `url`, `port`, `env`, `services`, and
255
+ `conditions`). What `setup` returns has to be a JSON value, and every
256
+ step reads it as the `setup_result` fixture; a hash with symbol keys is
257
+ read back with string keys. A step in a system whose program declares
258
+ `stepsReach: "url"` reaches the program only at a service URL, so
259
+ `Nukadoko.run_command` raises `Nukadoko::CommandRefused` there
260
+ ("Steps reach" in [the spec](../spec.md#steps-reach)). A command may
261
+ be `{ command:, timeout_ms: }`, and `setup` and a `url` lambda may be
262
+ `{ run: }` or `{ resolve: }` with a `timeout_ms`. A phase that fails, or
263
+ runs past its limit, stops the system and names itself. An environment
264
+ takes `policy: "read-only"`, which fails every step that declares it
265
+ mutates, and `version:`, a lambda whose String goes into run.json and
266
+ every record as `target_version`. A placeholder a system has no value for
267
+ (`{port}` in a system with neither `serve` nor `url`, anything but
268
+ `{root}` in `build`) is `program-placeholder-unfilled` in `nuka check`,
269
+ and `{world}`, what `{system}` was called before, is
270
+ `program-placeholder-renamed`.
271
+
272
+ Each service of a served system that names `{events}` gets an empty file
273
+ outside the run directory, which the program appends its execution events
274
+ to. Each step's lines of each service are kept beside its record and
275
+ summed up in its `observed.events`, one entry per service under
276
+ `services`, and each service's redacted copy goes beside its
277
+ `program.log` once the system stops ([spec](../spec.md), "Execution
278
+ events").
279
+
280
+ ## Compat steps (the migration door)
281
+
282
+ A cucumber-ruby suite comes in with its step definitions and support files
283
+ as they are. Every `.rb` file under `features/` loads in cucumber-ruby's
284
+ order: `features/support/env.rb`, the rest of `features/support/`, then the
285
+ other files. `Given`, `When`, `Then`, `And`, `But`, `Before`, `After`,
286
+ `AfterStep`, `BeforeAll`, `AfterAll`, `World`, and `ParameterType` are at
287
+ the top level, as cucumber-ruby defines them. Typed step files load beside
288
+ them, so one scenario can bind both kinds.
289
+
290
+ ```ruby
291
+ World(BasketHelpers)
292
+
293
+ Before("@tagged") do
294
+ @tagged = true
295
+ end
296
+
297
+ When("I add {int} apples") do |count|
298
+ count.times { @basket << "apple" }
299
+ end
300
+
301
+ When("I add these fruits:") do |table|
302
+ table.hashes.each { |row| row["count"].to_i.times { @basket << row["name"] } }
303
+ end
304
+ ```
305
+
306
+ - A compat step is named by its pattern, `compat: <pattern>`, and a Regexp
307
+ pattern is written `/.../`. A string is a cucumber expression and reads
308
+ the same parameter types as typed steps. A step takes no options, and an
309
+ options hash is refused when the file loads. `nuka steps` lists the step
310
+ as `compat`, `nuka describe` says it has no contract, and `nuka do`
311
+ refuses it (`compat-step-not-runnable`): promote it to a `Nukadoko::Step`
312
+ to run it alone.
313
+ - The block gets the matched values in order, then the line's table or doc
314
+ string. A block whose parameters the match does not fill fails the step,
315
+ as cucumber-ruby fails it. A table is a `DataTable` with `raw`, `rows`,
316
+ `hashes`, `symbolic_hashes`, `rows_hash`, `transpose`, and `cells_rows`.
317
+ `diff!`, `map_headers!`, and `map_column!` are refused, never half done.
318
+ The step record keeps the table as its raw rows.
319
+ - Each scenario gets one World, which its hooks and compat steps share.
320
+ `World(Module)` mixes a module in, and `World { MySystem.new }` builds the
321
+ object. A namespaced `World` is refused. The engine does not measure the
322
+ World's reads and writes: an instance variable has no accessor to wrap,
323
+ so a compat step record has no `world`.
324
+ - `step "text"` runs another compat step on the same World, inside the
325
+ record of the step that called it. `steps` with Gherkin text and
326
+ `skip_this_scenario` are refused. `pending` fails the step with the
327
+ error kind `unsupported`, since nukadoko has no pending outcome. `log`
328
+ and `attach` go into the step record's `attachments`.
329
+ - `open_page` and `open_request` return the page and the request nukadoko
330
+ measures, so their trace, screenshots, and requests are the step's. They
331
+ work inside a step only. A Capybara `page` the glue starts itself runs,
332
+ with no trace.
333
+ - `Before` and `After` get the scenario (`name`, `source_tag_names`,
334
+ `location`, `status`, `failed?`, `passed?`), and `AfterStep` gets the
335
+ step's result and its line. A hook's tags are `@tag` or `not @tag`, and
336
+ all the tags one hook names must hold; anything wider is the error
337
+ `unsupported-hook-tag-expression`. A `Before` that fails stops the
338
+ `Before` hooks after it and skips every step. `After` runs in reverse
339
+ order, after a failure too. `AfterStep` runs after each step that began,
340
+ and its failure stops the scenario as the step's own would. Each run of
341
+ a hook is an entry in the scenario record's `hooks`, and a hook opens no
342
+ page.
343
+ - `BeforeAll` and `AfterAll` run once for each environment's pass, with no
344
+ World, in the process the workers of `--concurrency` fork from. A failure
345
+ is the finding `hook-failed`, and a `BeforeAll` that failed plays no
346
+ scenario.
347
+ - `Around`, `InstallPlugin`, and `AfterConfiguration` are refused when the
348
+ file loads. A file that raises is `step-file-import-failed`, and the other
349
+ files still load.
350
+ - A compat step judges by raising or not, so one in Then position is the
351
+ warning `then-compat-step`, and run.json gives the scenario
352
+ `judged_by: "compat"`.
353
+
354
+ ## Types and tooling
355
+
356
+ `nuka sig` writes `sig/nukadoko/steps.rbs`, the RBS of each step's args
357
+ and returns. With Steep, a body that reads an undeclared args key or
358
+ returns the wrong shape is an error.
359
+
360
+ ## Not in this engine
361
+
362
+ What the TypeScript engine has and this one does not yet. The spec marks
363
+ each of its examples with `<!-- engine: typescript -->`.
364
+
365
+ - The door from Playwright Test. It brings a JavaScript suite in, so it is
366
+ the TypeScript engine's ([doors.md](../typescript/doors.md)). The compat
367
+ door above is this engine's form of the TypeScript engine's door from
368
+ cucumber-js.