nukadoko 0.6.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 (200) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +541 -3
  3. data/README.ja.md +20 -5
  4. data/README.md +12 -6
  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 +395 -48
  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 +1 -1
  77. data/lib/nukadoko/judgments.rb +4 -4
  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 +1148 -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 +799 -29
  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/version.rb +1 -1
  104. data/lib/nukadoko/vocabulary.rb +166 -23
  105. data/lib/nukadoko/walk.rb +2 -2
  106. data/lib/nukadoko/walk_step.rb +1 -1
  107. data/lib/nukadoko.rb +23 -0
  108. data/llms.txt +41 -34
  109. data/sig/generated/nukadoko/base.rbs +4 -4
  110. data/sig/generated/nukadoko/changed_files.rbs +42 -0
  111. data/sig/generated/nukadoko/check.rbs +147 -10
  112. data/sig/generated/nukadoko/claim_drops.rbs +135 -0
  113. data/sig/generated/nukadoko/claim_line.rbs +11 -0
  114. data/sig/generated/nukadoko/claim_rules.rbs +49 -4
  115. data/sig/generated/nukadoko/claim_sides.rbs +63 -12
  116. data/sig/generated/nukadoko/cli.rbs +80 -7
  117. data/sig/generated/nukadoko/codes.rbs +19 -4
  118. data/sig/generated/nukadoko/command.rbs +68 -1
  119. data/sig/generated/nukadoko/command_help.rbs +18 -0
  120. data/sig/generated/nukadoko/compat.rbs +392 -0
  121. data/sig/generated/nukadoko/criteria.rbs +1 -1
  122. data/sig/generated/nukadoko/definition.rbs +50 -0
  123. data/sig/generated/nukadoko/error_frames.rbs +1 -1
  124. data/sig/generated/nukadoko/events/count.rbs +69 -0
  125. data/sig/generated/nukadoko/events/counted.rbs +70 -0
  126. data/sig/generated/nukadoko/events/format.rbs +163 -0
  127. data/sig/generated/nukadoko/events/lists.rbs +47 -0
  128. data/sig/generated/nukadoko/events/path.rbs +161 -0
  129. data/sig/generated/nukadoko/events/read.rbs +109 -0
  130. data/sig/generated/nukadoko/events/reader.rbs +226 -0
  131. data/sig/generated/nukadoko/events/selection.rbs +100 -0
  132. data/sig/generated/nukadoko/events/tally.rbs +227 -0
  133. data/sig/generated/nukadoko/features.rbs +6 -4
  134. data/sig/generated/nukadoko/fixtures.rbs +67 -11
  135. data/sig/generated/nukadoko/http_recording.rbs +1 -1
  136. data/sig/generated/nukadoko/intent.rbs +132 -0
  137. data/sig/generated/nukadoko/intent_file.rbs +46 -0
  138. data/sig/generated/nukadoko/intent_view.rbs +69 -0
  139. data/sig/generated/nukadoko/judgment_file.rbs +1 -1
  140. data/sig/generated/nukadoko/judgments.rbs +1 -1
  141. data/sig/generated/nukadoko/measure_mcp.rbs +104 -0
  142. data/sig/generated/nukadoko/parts.rbs +2 -2
  143. data/sig/generated/nukadoko/path_view.rbs +105 -0
  144. data/sig/generated/nukadoko/place_rows.rbs +43 -0
  145. data/sig/generated/nukadoko/program.rbs +627 -23
  146. data/sig/generated/nukadoko/program_log.rbs +67 -0
  147. data/sig/generated/nukadoko/program_shape.rbs +147 -0
  148. data/sig/generated/nukadoko/project_fixtures.rbs +16 -3
  149. data/sig/generated/nukadoko/project_program.rbs +2 -1
  150. data/sig/generated/nukadoko/repeated_prefix.rbs +172 -0
  151. data/sig/generated/nukadoko/report_run.rbs +1 -1
  152. data/sig/generated/nukadoko/run.rbs +286 -41
  153. data/sig/generated/nukadoko/run_record.rbs +20 -12
  154. data/sig/generated/nukadoko/scaffold.rbs +3 -0
  155. data/sig/generated/nukadoko/schema.rbs +5 -0
  156. data/sig/generated/nukadoko/secrets.rbs +26 -3
  157. data/sig/generated/nukadoko/states.rbs +214 -0
  158. data/sig/generated/nukadoko/step.rbs +58 -1
  159. data/sig/generated/nukadoko/step_fixtures.rbs +39 -0
  160. data/sig/generated/nukadoko/summary.rbs +256 -2
  161. data/sig/generated/nukadoko/table.rbs +3 -2
  162. data/sig/generated/nukadoko/trace.rbs +108 -33
  163. data/sig/generated/nukadoko/tree_passes.rbs +36 -8
  164. data/sig/generated/nukadoko/underneath.rbs +141 -0
  165. data/sig/generated/nukadoko/vocabulary.rbs +45 -6
  166. data/skills/nukadoko/SKILL.md +18 -18
  167. data/skills/nukadoko/references/checking-steps.md +16 -83
  168. data/skills/nukadoko/references/diagnosing.md +6 -6
  169. data/skills/nukadoko/references/evidence.md +19 -6
  170. data/skills/nukadoko/references/exploring.md +22 -7
  171. data/skills/nukadoko/references/fixtures.md +12 -32
  172. data/skills/nukadoko/references/judgments.md +12 -0
  173. data/skills/nukadoko/references/maintenance.md +1 -1
  174. data/skills/nukadoko/references/merge-risk.md +1 -1
  175. data/skills/nukadoko/references/parts.md +46 -23
  176. data/skills/nukadoko/references/{perturbed-worlds.md → perturbed-systems.md} +30 -12
  177. data/skills/nukadoko/references/program.md +168 -169
  178. data/skills/nukadoko/references/reviewing.md +20 -20
  179. data/skills/nukadoko/references/ruby/checking-steps.md +106 -0
  180. data/skills/nukadoko/references/ruby/examples/cli.md +212 -0
  181. data/skills/nukadoko/references/ruby/fixtures.md +34 -0
  182. data/skills/nukadoko/references/ruby/program.md +112 -0
  183. data/skills/nukadoko/references/ruby/step-files.md +115 -0
  184. data/skills/nukadoko/references/running.md +34 -34
  185. data/skills/nukadoko/references/scenario-rules.md +7 -6
  186. data/skills/nukadoko/references/states.md +7 -1
  187. data/skills/nukadoko/references/step-files.md +41 -120
  188. data/skills/nukadoko/references/typescript/checking-steps.md +129 -0
  189. data/skills/nukadoko/references/{examples → typescript/examples}/cli.md +1 -1
  190. data/skills/nukadoko/references/{examples → typescript/examples}/http-api.md +6 -6
  191. data/skills/nukadoko/references/{examples → typescript/examples}/workflow.md +1 -1
  192. data/skills/nukadoko/references/typescript/fixtures.md +56 -0
  193. data/skills/nukadoko/references/typescript/program.md +111 -0
  194. data/skills/nukadoko/references/typescript/step-files.md +104 -0
  195. data/skills/nukadoko/references/verdicts.md +10 -10
  196. data/skills/nukadoko/references/writing-steps.md +67 -67
  197. data/skills/nukadoko/references/writing-the-feature.md +1 -1
  198. data/skills/nukadoko-verification/SKILL.md +13 -8
  199. metadata +103 -7
  200. data/skills/nukadoko/references/ruby.md +0 -80
data/docs/tutorial.md ADDED
@@ -0,0 +1,458 @@
1
+ # Your first scenario
2
+
3
+ This tutorial starts in an empty directory and ends with a scenario that
4
+ runs green. It works for a Ruby project and for a TypeScript project. Where
5
+ the two engines differ, the tutorial shows each one under its own label.
6
+
7
+ ## What you will build
8
+
9
+ You will test `greet`, a small command line program. `greet Ada` prints
10
+ `Hello, Ada!` and exits with 0. `greet` with no name prints
11
+ `greet: a name is required` to stderr and exits with 1.
12
+
13
+ You will write two scenarios, one for each case. A scenario is a list of
14
+ lines in a feature file. A step is the code behind one line. A step can
15
+ run the program, or it can make claims. A claim compares a value that the
16
+ run measured with a value that the line gives, and nukadoko checks it.
17
+ The sections below go in order: install, write, check, scaffold, run,
18
+ read the records, break a claim, and clean up.
19
+
20
+ You need one of these:
21
+
22
+ - Ruby 3.4 or later, with Bundler.
23
+ - Node 22.18 or later on the 22 line, or Node 23.6 or later.
24
+
25
+ Every output block below is copied from a real run in an empty directory,
26
+ with nukadoko 0.29.0 (npm) and 0.6.0 (gem). Run IDs, times, and
27
+ temporary paths differ on your machine.
28
+
29
+ ## Install
30
+
31
+ Make a new, empty directory and go into it.
32
+
33
+ In a Ruby project, add nukadoko to the `test` group of a `Gemfile`, then
34
+ install it:
35
+
36
+ <!-- engine: ruby -->
37
+ ```ruby
38
+ source "https://rubygems.org"
39
+
40
+ gem "nukadoko", group: :test
41
+ ```
42
+
43
+ <!-- engine: ruby -->
44
+ ```sh
45
+ bundle install
46
+ ```
47
+
48
+ In a TypeScript project, make a `package.json` with `"type": "module"`,
49
+ then install nukadoko as a devDependency, pinned to one exact version:
50
+
51
+ <!-- engine: typescript -->
52
+ ```sh
53
+ npm init -y
54
+ npm pkg set type=module
55
+ npm install -D -E nukadoko
56
+ ```
57
+
58
+ In this guide, `nuka` means the launcher of your engine. Each command
59
+ `nuka <arguments>` below is one of these in a real project:
60
+
61
+ <!-- engine: ruby -->
62
+ ```sh
63
+ bundle exec nuka init
64
+ ```
65
+
66
+ <!-- engine: typescript -->
67
+ ```sh
68
+ npx nuka init
69
+ ```
70
+
71
+ The next section runs this command. If you add nukadoko to a TypeScript
72
+ project that already has code and tests, read
73
+ [Adding nukadoko to an existing project](typescript/adopting.md)
74
+ after this tutorial.
75
+
76
+ ## Run nuka init
77
+
78
+ Run `nuka init` in the project directory. It writes a configuration file
79
+ and the `features/steps/` directory. It adds `.nukadoko/` and the `.env`
80
+ entries (`.env`, `.env.*`, and `!.env.example`) to `.gitignore`. The two
81
+ engines print different lines.
82
+
83
+ In a Ruby project:
84
+
85
+ <!-- engine: ruby -->
86
+ ```text
87
+ next: read <gem directory>/llms.txt, written for an agent: the loop, every command, and every finding code; its Ruby section is how a Ruby step is written
88
+ nukadoko.config.rb
89
+ features/steps
90
+ .gitignore
91
+ ```
92
+
93
+ The `next:` line names a file inside the installed gem. In a TypeScript
94
+ project:
95
+
96
+ <!-- engine: typescript -->
97
+ ```text
98
+ nukadoko.config.ts
99
+ features/steps
100
+ .gitignore
101
+ package.json
102
+ next: read node_modules/nukadoko/llms.txt, written for an agent: the loop, every command, and every finding code
103
+ ```
104
+
105
+ In a TypeScript project, `nuka init` also adds a `test:scenarios` script
106
+ to `package.json`.
107
+
108
+ The configuration file holds the settings of the project, for example a
109
+ program to start before the scenarios run. For now it holds an empty
110
+ configuration and a comment that points to the list of keys. This CLI
111
+ project needs no settings. [Project layout](layout.md)
112
+ tells where each file goes.
113
+
114
+ ## Write the program and the feature
115
+
116
+ Write the program under test first. A Ruby reader writes `src/greet.rb`,
117
+ and a TypeScript reader writes `src/greet.ts`:
118
+
119
+ ```ruby
120
+ # greet: print a greeting for the name given as the first argument.
121
+ name = ARGV[0]
122
+ if name.nil? || name.empty?
123
+ warn "greet: a name is required"
124
+ exit 1
125
+ end
126
+ puts "Hello, #{name}!"
127
+ ```
128
+
129
+ ```ts
130
+ // greet: print a greeting for the name given as the first argument.
131
+ const name = process.argv[2];
132
+ if (!name) {
133
+ process.stderr.write("greet: a name is required\n");
134
+ process.exit(1);
135
+ }
136
+ process.stdout.write(`Hello, ${name}!\n`);
137
+ ```
138
+
139
+ Then write `features/greet.feature`. This file is the same for both
140
+ engines:
141
+
142
+ ```gherkin
143
+ Feature: greet says hello
144
+
145
+ Scenario: greets by name
146
+ When I run greet with "Ada"
147
+ Then it exits with 0
148
+ And the output is "Hello, Ada!"
149
+
150
+ Scenario: no name is an error
151
+ When I run greet with ""
152
+ Then it exits with 1
153
+ And the error says "greet: a name is required"
154
+ ```
155
+
156
+ Each scenario has one `When` line that acts and two `Then` lines that
157
+ make claims about the result.
158
+
159
+ ## Check it
160
+
161
+ Run `nuka check`. It reads the feature files and the step files, and it
162
+ runs nothing. It prints six findings, one for each step line. Both
163
+ engines print the same text. These are the first two, and the other four
164
+ have the same shape:
165
+
166
+ ```text
167
+ error undefined-step features/greet.feature:4 No step definition matches "I run greet with "Ada""
168
+ do: nuka scaffold --feature features/greet.feature
169
+ error undefined-step features/greet.feature:5 No step definition matches "it exits with 0"
170
+ do: nuka scaffold --feature features/greet.feature
171
+ ```
172
+
173
+ The command exits with 1. Each finding has a severity, a code, a place,
174
+ and a message. The `do:` line under it is a command that fixes it.
175
+
176
+ Do not run the `do:` command here. It writes one stub for each step that
177
+ the lines need: four stubs for six lines. A stub has a pattern and a body
178
+ that raises "not implemented", so you must replace each body by hand. The
179
+ next section writes complete steps with other names in place of the
180
+ stubs. If you ran the `do:` command, delete the four stub files in
181
+ `features/steps/` first, because two steps with the same pattern make
182
+ `nuka check` fail.
183
+
184
+ ## Scaffold the steps
185
+
186
+ Run these four commands. The first command names the program, so it is
187
+ different in each engine:
188
+
189
+ <!-- engine: ruby -->
190
+ ```sh
191
+ nuka scaffold run-greet --pattern "I run greet with {name:string}" --command src/greet.rb --argv name
192
+ ```
193
+
194
+ <!-- engine: typescript -->
195
+ ```sh
196
+ nuka scaffold run-greet --pattern "I run greet with {name:string}" --command src/greet.ts --argv name
197
+ ```
198
+
199
+ The other three commands are the same in both engines:
200
+
201
+ ```sh
202
+ nuka scaffold exits-with --pattern "it exits with {code:int}" --then --from run-greet.exitCode
203
+ nuka scaffold output-is --pattern "the output is {text:string}" --then --from run-greet.stdout
204
+ nuka scaffold error-says --pattern "the error says {text:string}" --then --from run-greet.stderr
205
+ ```
206
+
207
+ Each command prints the path of the file it wrote, for example
208
+ `features/steps/run_greet.rb` or `features/steps/run-greet.ts`.
209
+
210
+ - `--command <entry point>` writes a step that runs the program in a new,
211
+ empty scratch directory and returns `exitCode`, `stdout`, and `stderr`.
212
+ - `--argv <key>` splits the capture with that name on whitespace into the
213
+ program's arguments.
214
+ - `--then` writes a step for a `Then` line: it makes claims and runs no
215
+ code of its own.
216
+ - `--from <step>.<key>` fills an argument from a value that an earlier step
217
+ returned. With `--then` and one capture, the claim compares the two.
218
+
219
+ The first command writes `run-greet`, the step that runs `greet`.
220
+ The third command writes `output-is`, shown below. It has no code that
221
+ asserts. It declares one claim: the `stdout` of `run-greet`, read as
222
+ text, is equal to the `text` capture of the line.
223
+
224
+ ```ruby
225
+ # frozen_string_literal: true
226
+
227
+ class OutputIs < Nukadoko::Step
228
+ description "TODO: describe output-is"
229
+ pattern "the output is {text:string}"
230
+ # Give each field a description: `nuka describe` shows it to whoever picks this step.
231
+ args do
232
+ string :text
233
+ field :stdout, RunGreet.returns[:stdout]
234
+ end
235
+ from stdout: [RunGreet, :stdout]
236
+ # The program ends its output with a newline that the feature line does not show.
237
+ claims [{ actual: "stdout", view: "text", compare: "equal", expected: "text" }]
238
+ end
239
+ ```
240
+
241
+ ```ts
242
+ import { defineStep, z } from "nukadoko";
243
+ import runGreet from "./run-greet.ts";
244
+
245
+ export default defineStep({
246
+ description: "TODO: describe output-is",
247
+ pattern: "the output is {text:string}",
248
+ // Give each field a .describe(): `nuka describe` shows it to whoever picks this step.
249
+ args: z.object({
250
+ text: z.string(),
251
+ stdout: runGreet.returns.shape.stdout,
252
+ }),
253
+ from: {
254
+ stdout: [runGreet, "stdout"],
255
+ },
256
+ // The program ends its output with a newline that the feature line does not show.
257
+ claims: [{ actual: "stdout", view: "text", compare: "equal", expected: "text" }],
258
+ });
259
+ ```
260
+
261
+ The `text` view removes the whitespace at the end of the value, including
262
+ the final newline. So `"Hello, Ada!\n"` is equal to `"Hello, Ada!"`. For
263
+ the full set of claim fields, read [Claims](spec.md#claims). For `from`,
264
+ read [Chaining steps](spec.md#chaining-steps).
265
+
266
+ ## Run it
267
+
268
+ Run `nuka run`. It checks the steps again, then runs every scenario:
269
+
270
+ ```text
271
+ scenario 1/2 features/greet.feature:3 greets by name
272
+ step 1/3 passed 0.1s I run greet with "Ada"
273
+ step 2/3 passed 0.0s it exits with 0
274
+ step 3/3 passed 0.0s the output is "Hello, Ada!"
275
+ scenario 2/2 features/greet.feature:8 no name is an error
276
+ step 1/3 passed 0.1s I run greet with ""
277
+ step 2/3 passed 0.0s it exits with 1
278
+ step 3/3 passed 0.0s the error says "greet: a name is required"
279
+ steps .nukadoko/runs/run-20261203-225738-vv3x/steps/ 6
280
+ summary .nukadoko/runs/run-20261203-225738-vv3x/summary.md
281
+ run .nukadoko/runs/run-20261203-225738-vv3x/run.json
282
+ 2 scenarios: 2 passed, 0 failed (0s)
283
+ ```
284
+
285
+ The command exits with 0. A `scenario` line gives the place and the name
286
+ of a scenario. A `step` line gives the status, the duration, and the text
287
+ of a feature line. The `steps`, `summary`, and `run` lines give the paths
288
+ of the run's records, and the last line gives the totals.
289
+
290
+ ## Read what the run left
291
+
292
+ Each run writes one directory, `.nukadoko/runs/<run_id>/`. The
293
+ `.gitignore` that `nuka init` wrote keeps it out of git. `run.json` is
294
+ the record of the whole run, for a program to read. `summary.md` is the
295
+ same run, for a person to read, for example on a pull request. `steps/`
296
+ holds one directory for each step that ran, with its `record.json` and
297
+ the files the step produced. [The state directory](layout.md#the-state-directory)
298
+ gives the full list.
299
+
300
+ This is the start of `summary.md`:
301
+
302
+ ```text
303
+ <!-- nukadoko:run -->
304
+ # nukadoko run passed: 2 criteria, 2 held
305
+
306
+ | verdict | criterion | head default |
307
+ | --- | --- | --- |
308
+ | held | `features/greet.feature:3` greets by name | pass |
309
+ | held | `features/greet.feature:8` no name is an error | pass |
310
+
311
+ - commit: unknown (no git state was readable when the run started)
312
+ - environment: default
313
+ - browser: none launched
314
+ - selection: full
315
+ - nukadoko: 0.29.0
316
+ - run: run-20261203-225738-vv3x
317
+ - started 2026-12-03T22:57:37.878Z, finished 2026-12-03T22:57:38.297Z (0s)
318
+ ```
319
+
320
+ The `nukadoko` line gives the version of the engine. This excerpt is from
321
+ a TypeScript project, and in a Ruby project the line shows the gem
322
+ version, for example `0.6.0`. The `commit` line is `unknown` because the
323
+ tutorial directory is not a git repository. In a git repository, the line
324
+ names the commit that ran. For every field of each record, read
325
+ [Records](spec.md#records).
326
+
327
+ ## Make it fail on purpose
328
+
329
+ Change the expected text in `features/greet.feature`. On line 6, replace
330
+ `"Hello, Ada!"` with `"Hello, Ada."`. Then run only the first scenario.
331
+ Give the feature file and the line of the scenario:
332
+
333
+ ```sh
334
+ nuka run features/greet.feature:3
335
+ ```
336
+
337
+ ```text
338
+ scenario 1/1 features/greet.feature:3 greets by name
339
+ step 1/3 passed 0.1s I run greet with "Ada"
340
+ step 2/3 passed 0.0s it exits with 0
341
+ step 3/3 failed 0.0s the output is "Hello, Ada."
342
+ claim broken: "Hello, Ada!" (from:run-greet@4.stdout as text) equal "Hello, Ada." (sentence:text)
343
+ record .nukadoko/runs/run-20261203-225756-dbl4/steps/step-20261203-225756-6w9w
344
+ steps .nukadoko/runs/run-20261203-225756-dbl4/steps/ 3
345
+ summary .nukadoko/runs/run-20261203-225756-dbl4/summary.md
346
+ run .nukadoko/runs/run-20261203-225756-dbl4/run.json
347
+ 1 scenario: 0 passed, 1 failed (0s)
348
+ failed scenario-failed features/greet.feature:3 greets by name: claim broken: "Hello, Ada!" (from:run-greet@4.stdout as text) equal "Hello, Ada." (sentence:text)
349
+ do: nuka run features/greet.feature:3
350
+ ```
351
+
352
+ The command exits with 1. The `claim broken` line shows the actual value
353
+ on the left and the expected value on the right. The `record` line names
354
+ the step record of the failed step. The last two lines are a finding with
355
+ a `do:` line, the command that runs this scenario again.
356
+
357
+ Now put `"Hello, Ada!"` back on line 6 and run the same command again. The
358
+ last line is `1 scenario: 1 passed, 0 failed (0s)`.
359
+
360
+ ## Clean up the notes
361
+
362
+ The run is green, but `nuka check` still prints seven notes in each
363
+ engine, and exits with 0. A `step-description-todo` note names a step
364
+ that still has the `TODO` description of the scaffold. A
365
+ `schema-field-undescribed` note names a step that has a field with no
366
+ description. In a Ruby project, these are the two notes about
367
+ `output-is`. The TypeScript notes have the same two codes, and they name
368
+ the fields `args.text` and `args.stdout`.
369
+
370
+ <!-- engine: ruby -->
371
+ ```text
372
+ note step-description-todo features/steps/output_is.rb Step "output-is" still has the description nuka scaffold wrote ("TODO: describe output-is"); nuka steps and nuka describe show it to whoever picks a step, so say what the step does.
373
+ fix: Replace the description with one sentence that says what the step does.
374
+ note schema-field-undescribed features/steps/output_is.rb Step "output-is" has schema fields with no description: text, stdout
375
+ fix: Give each field a description, so nuka steps and an agent can say what it means.
376
+ ```
377
+
378
+ Edit the four step files. In the three `Then` steps, replace the `TODO`
379
+ description with one sentence. In all four steps, give each field a
380
+ description, and remove the comments that ask for one. A field that
381
+ `from` copies from `run-greet` gets its description from there. These are
382
+ the `returns` fields of `run-greet` after the edits:
383
+
384
+ ```ruby
385
+ returns do
386
+ number :exitCode, "The process exit code", null: true
387
+ string :stdout, "Everything greet wrote to stdout"
388
+ string :stderr, "Everything greet wrote to stderr"
389
+ end
390
+ ```
391
+
392
+ ```ts
393
+ returns: z.object({
394
+ exitCode: z.number().nullable().describe("The process exit code"),
395
+ stdout: z.string().describe("Everything greet wrote to stdout"),
396
+ stderr: z.string().describe("Everything greet wrote to stderr"),
397
+ }),
398
+ ```
399
+
400
+ This is `exits-with` after the edits:
401
+
402
+ ```ruby
403
+ class ExitsWith < Nukadoko::Step
404
+ description "The exit code of the greet run is exactly this"
405
+ pattern "it exits with {code:int}"
406
+ args do
407
+ number :code, "The expected exit code"
408
+ field :exitCode, RunGreet.returns[:exitCode]
409
+ end
410
+ from exitCode: [RunGreet, :exitCode]
411
+ claims [{ actual: "exitCode", compare: "equal", expected: "code" }]
412
+ end
413
+ ```
414
+
415
+ ```ts
416
+ import { defineStep, z } from "nukadoko";
417
+ import runGreet from "./run-greet.ts";
418
+
419
+ export default defineStep({
420
+ description: "The exit code of the greet run is exactly this",
421
+ pattern: "it exits with {code:int}",
422
+ args: z.object({
423
+ code: z.number().describe("The expected exit code"),
424
+ exitCode: runGreet.returns.shape.exitCode,
425
+ }),
426
+ from: {
427
+ exitCode: [runGreet, "exitCode"],
428
+ },
429
+ claims: [{ actual: "exitCode", compare: "equal", expected: "code" }],
430
+ });
431
+ ```
432
+
433
+ The notes do not ask about `mutates`. `run-greet` only runs the program,
434
+ so you can set it to `false` (`mutates false` in Ruby), and
435
+ [A step's contract](writing-scenarios.md#a-steps-contract) explains when
436
+ a step that changes the system a later scenario reads must keep `true`.
437
+ Then run `nuka check` again:
438
+
439
+ ```text
440
+ ok: no issues found
441
+ ```
442
+
443
+ Run `nuka run` again, and both scenarios pass.
444
+
445
+ ## Where to go next
446
+
447
+ - [Writing scenarios](writing-scenarios.md): how to word feature lines and
448
+ claims for more than one program.
449
+ - [Testing a web app](web-app.md): how to test a server: an HTTP API, a
450
+ page in a browser, or a Rails app.
451
+ - [Project layout](layout.md): where each file of a nukadoko project goes.
452
+ - [Commands](commands.md): every `nuka` command and its options.
453
+ - [Ruby reference](ruby/reference.md) and
454
+ [TypeScript reference](typescript/reference.md): how a step is written
455
+ in each engine.
456
+ - [CI](ci.md): how to run the scenarios on every pull request.
457
+
458
+ [Japanese](tutorial.ja.md)
@@ -0,0 +1,231 @@
1
+ # 既存のプロジェクトに nukadoko を導入する
2
+
3
+ > 原文は adopting.md。
4
+ > 相違があれば原文が正。
5
+
6
+ このガイドは、コードとユニットテストをすでに持つプロジェクトを、最初の scenario が green になり、CI で走り、pull request に run サマリが載るところまで進めます。
7
+ Node のプロジェクトを前提にしています。
8
+ `package.json` のないリポジトリは、[Setup details](../guide.ja.md#setup-details) の注記から始めてください。
9
+
10
+ 各手順は、実行するコマンドと、それが書くものを示します。
11
+ 以下の出力は、パックしたパッケージを scratch プロジェクトで実際に実行して写したものです。
12
+ そのプロジェクトの CLI `src/cli.ts` は `Hello, <name>!` を出力します。
13
+ README は同じプロジェクトを、すべてのファイルを全文で示しながらたどります。
14
+ [Beside your unit tests](../../README.ja.md#beside-your-unit-tests) を参照してください。
15
+
16
+ ## 1. nukadoko をインストールする
17
+
18
+ Node 22 系なら 22.18 以降、それ以外は 23.6 以降が必要です。
19
+ nukadoko を devDependency として、1 つの版に厳密に固定してインストールします:
20
+
21
+ ```sh
22
+ npm install -D -E nukadoko
23
+ ```
24
+
25
+ `-E` を付けると、caret の範囲ではなく `"nukadoko": "0.17.0"` が書かれます。
26
+ nukadoko が 0.x のあいだは、どのリリースでも公開 API が変わりえます。
27
+ 新しい版へは意図して移り、そのときは [docs/typescript/upgrading.ja.md](upgrading.ja.md) を読んでください。
28
+
29
+ `page` か `request` を使う step には Playwright が必要です。
30
+ CLI のプロジェクトには要りません。
31
+ 追加するときは [Install](../../README.ja.md#install) に従ってください。
32
+
33
+ ## 2. `nuka init` を実行する
34
+
35
+ プロジェクトの `package.json` があるディレクトリで実行します:
36
+
37
+ ```sh
38
+ npx nuka init
39
+ ```
40
+
41
+ ```text
42
+ nukadoko.config.ts
43
+ features/steps
44
+ .gitignore
45
+ package.json
46
+ tsconfig.json
47
+ next: read node_modules/nukadoko/llms.txt, written for an agent: the loop, every command, and every finding code
48
+ ```
49
+
50
+ `init` は `nukadoko.config.ts` と `features/steps/` を書き、3 つのファイルに行を追加します:
51
+
52
+ - `.gitignore` に `.nukadoko/`(state ディレクトリ)と、`.env`、`.env.*`、`!.env.example` を追加します。
53
+ - `package.json` に `"test:scenarios": "nuka run"` を追加します。
54
+ 人も CI も、この 1 つのコマンドを実行します。
55
+ - `tsconfig.json` の `include` が `features/**/*` と config ファイルを含んでいなければ、それらを追加します。
56
+ `compilerOptions` が `rewriteRelativeImportExtensions` と `allowImportingTsExtensions` のどちらも書いていなければ、`"rewriteRelativeImportExtensions": true` も追加します。
57
+
58
+ オプションのフラグはここで決めてください。
59
+ `nukadoko.config.ts` ができたあとは、`nuka init` はもう一度の実行を拒否します。
60
+
61
+ - `--allure` は `allurerc.mjs` を書きます。
62
+ これは失敗を Allure のカテゴリに振り分けます。
63
+ 付けなかった場合は、[examples/allure/allurerc.mjs](https://github.com/meganemura/nukadoko/blob/main/typescript/examples/allure/allurerc.mjs) を手でコピーします。
64
+
65
+ HTTP を提供するテスト対象のプログラムは、同じファイルに `program` として書きます。
66
+ `nuka init` はこのファイルを書きません。
67
+ [Web アプリをテストする](../web-app.ja.md) を参照してください。
68
+
69
+ CommonJS のプロジェクト(`"type": "module"` がないもの)では、代わりに `nukadoko.config.mts` が書かれ、`nuka scaffold` は step ファイルを `.mts` で書きます。
70
+ package.json に `"type"` がまったくなければ、`.ts` の step ファイルもそこで動きますが、読み込むたびに Node が `MODULE_TYPELESS_PACKAGE_JSON` の警告を出します。
71
+ `"type": "commonjs"` のもとでは `.ts` の step ファイルは import できず、`nuka check` は `step-file-import-failed` として報告します。
72
+
73
+ ## 3. 最初の feature を書く
74
+
75
+ 誰かが求めた振る舞いを 1 つ選び、その人の言葉で scenario を 1 つ書きます。
76
+ `features/greet.feature` として保存します:
77
+
78
+ ```gherkin
79
+ Feature: greet
80
+
81
+ Scenario: greets by name
82
+ When I run greet with "Ada"
83
+ Then the output says "Hello, Ada!"
84
+ ```
85
+
86
+ ## 4. 検査し、足りない step を scaffold する
87
+
88
+ `nuka check` はすべての feature ファイルと step ファイルを読み、何も実行しません:
89
+
90
+ ```sh
91
+ npx nuka check
92
+ ```
93
+
94
+ ```text
95
+ error undefined-step features/greet.feature:4 No step definition matches "I run greet with "Ada""
96
+ do: nuka scaffold --feature features/greet.feature
97
+ error undefined-step features/greet.feature:5 No step definition matches "the output says "Hello, Ada!""
98
+ do: nuka scaffold --feature features/greet.feature
99
+ ```
100
+
101
+ `do:` の行を実行します。
102
+ どの step にも一致しない行ごとに stub を 1 つ書き、各 stub をオプションを足して書き直すコマンドを出力します:
103
+
104
+ ```sh
105
+ npx nuka scaffold --feature features/greet.feature
106
+ ```
107
+
108
+ ```text
109
+ features/steps/i-run-greet-with.ts
110
+ features/steps/the-output-says.ts
111
+ next: redo a stub in place with its line below, adding --command, --request, --from, or --description; --replace overwrites the stub while nobody has edited it:
112
+ nuka scaffold i-run-greet-with --pattern 'I run greet with {value:string}' --replace
113
+ nuka scaffold the-output-says --pattern 'the output says {value:string}' --then --replace
114
+ ```
115
+
116
+ stub は、中身を書くまで `not implemented` を投げます。
117
+ よくある形なら、編集する代わりにオプションを付けて書き直します:
118
+
119
+ - `--command <entry point>` は、プログラムを空のディレクトリで実行し、`exitCode`、`stdout`、`stderr` を返す When の step を作ります。
120
+ - `--request "<METHOD> <path>"` は、HTTP request を 1 つ送り、`status` と `body` を返す When の step を作ります。
121
+ - `--then --from <step>.<key>` は、claim を 1 つ持つ Then の step を作ります。
122
+ その claim は、前の step が返した値をその行のキャプチャと比べます。
123
+
124
+ pattern のキャプチャは、中身を表す名前に変えます:
125
+
126
+ ```sh
127
+ npx nuka scaffold i-run-greet-with --pattern 'I run greet with {name:string}' --command src/cli.ts --description "Run greet in an empty scratch directory" --replace
128
+ npx nuka scaffold the-output-says --pattern 'the output says {text:string}' --then --from i-run-greet-with.stdout --description "greet printed exactly this line" --replace
129
+ npx nuka check
130
+ ```
131
+
132
+ ```text
133
+ ok: no issues found
134
+ ```
135
+
136
+ `--command` はエントリポイントを `node` で実行します。
137
+ `.ts` ファイルどうしが `.js` の名前で import し合うプロジェクトでは、ビルド済みのプログラムを指定します(たとえば `--command dist/cli.js`)。
138
+ 理由は README の [Beside your unit tests](../../README.ja.md#beside-your-unit-tests) にあります。
139
+ どのオプションにも当てはまらない step は、`run` を自分で書きます。
140
+ すでにある語彙は `nuka steps` と `nuka describe <name>` で確認できます。
141
+
142
+ ## 5. 実行する
143
+
144
+ ```sh
145
+ npm run test:scenarios
146
+ ```
147
+
148
+ npm の最初の行は、パッケージの名前とバージョンを名指します。
149
+
150
+ ```text
151
+ > <name>@<version> test:scenarios
152
+ > nuka run
153
+
154
+ scenario 1/1 features/greet.feature:3 greets by name
155
+ step 1/2 passed 0.1s I run greet with "Ada"
156
+ step 2/2 passed 0.0s the output says "Hello, Ada!"
157
+ steps .nukadoko/runs/run-20261018-232314-j5x1/steps/ 2
158
+ summary .nukadoko/runs/run-20261018-232314-j5x1/summary.md
159
+ run .nukadoko/runs/run-20261018-232314-j5x1/run.json
160
+ 1 scenario: 1 passed, 0 failed (0s)
161
+ ```
162
+
163
+ `nuka run` は先に `nuka check` を実行し、エラーがあれば止まります。
164
+ scenario が失敗すると、stderr にその step、エラー、step record、そしてその scenario だけを再実行する `nuka run features/greet.feature:3` のような `do:` の行が出ます。
165
+
166
+ `nuka run --env <name>` は、`nukadoko.config.ts` のプログラムの `environments` が名付けた environment に対して実行します。
167
+ 各 environment は自分の `url` または `serve`、`envFiles`、`policy` を持ちます。
168
+ `policy: "read-only"` の environment は、`mutates: true` と宣言された step を実行前にすべて拒否します。
169
+ `--command` の scaffold は `mutates: true` を書くので、プログラムが scratch ディレクトリの外を何も変えないなら `false` にします。
170
+ [docs/spec.ja.md](../spec.ja.md#テスト対象のプログラム) の「テスト対象のプログラム」と「Environment、secret」を参照してください。
171
+
172
+ ## 6. run ディレクトリを読む
173
+
174
+ `nuka run` は毎回、`.nukadoko/runs/` の下にディレクトリを 1 つ書きます:
175
+
176
+ - `run.json` は run の結果です。
177
+ 断定、件数、そして各 scenario の record と再実行のコマンドを持ちます。
178
+ - `summary.md` は Markdown の run サマリです。
179
+ GitHub Actions では、ジョブのサマリページにも載ります。
180
+ - `steps/<id>/record.json` は step record 1 つです。
181
+ 引数とその出所、バリデーション済みの結果、そしてツールが観測したもの(`runCommand` が起動したプロセス、step が送ったリクエスト、step が変えたファイル、見えたが計測できなかった操作)を持ちます。
182
+ evidence のファイル(trace、スクリーンショット、`http.jsonl`)はその隣に置かれます。
183
+ - `scenarios/<id>/` は、scenario が自分の evidence を書いたときにだけ、それを持ちます。
184
+ - `sources.json` は run が読んだ feature のテキストで、`exports` はこの run から `nuka report` が `.nukadoko/export/` の下に書いたファイルの一覧です。
185
+ retention は run と一緒にそれらを消します。
186
+ ほかの場所に書いたレポートは一覧に入りません。
187
+
188
+ 既定では、nukadoko は新しいほうから 20 個の run を残します(`retention.runs`)。
189
+ `nuka clean` はそれらを消します。
190
+ `.nukadoko/` はコミットしないでください。
191
+ trace とスクリーンショットは redact されません。
192
+ 全体の構成は [docs/spec.ja.md](../spec.ja.md#state-directory) の「State directory」にあります。
193
+
194
+ ## 7. `nuka report` でレポートを描き出す
195
+
196
+ `nuka report` は、終わった run をその run ディレクトリだけから描き出します。
197
+ run ディレクトリを指定しなければ、最新の run を使います。
198
+
199
+ ```sh
200
+ npx nuka report --format markdown # the run summary, on stdout
201
+ npx nuka report --format allure # .nukadoko/export/allure-results/
202
+ npx nuka report --format messages --out messages.ndjson # a cucumber-messages stream
203
+ ```
204
+
205
+ Allure results をレポートにするには Allure 3 の CLI が要ります。
206
+ そのコマンドと、各コマンドに `--output` を付ける理由は [Reports fill themselves](../guide.ja.md#reports-fill-themselves) にあります。
207
+
208
+ ## 8. CI に加える
209
+
210
+ CLI か API のプロジェクトは、ユニットテストのあとに step を 1 つ足します:
211
+
212
+ ```yaml
213
+ - run: npm run test:scenarios
214
+ ```
215
+
216
+ workflow の全体、ブラウザを使う場合、run ディレクトリのアップロードと pull request への run サマリの投稿は [docs/ci.ja.md](../ci.ja.md) にあります。
217
+
218
+ `features/`、`nukadoko.config.ts`、そして `package.json`、`tsconfig.json`、`.gitignore` の変更をコミットします。
219
+
220
+ ## 次に読むもの
221
+
222
+ - coding agent は nukadoko の skill([skills/nukadoko/SKILL.md](../../skills/nukadoko/SKILL.md))を読み込みます。
223
+ `nuka skill path` は、インストールした版の `skills/` ディレクトリを出力し、そこにそのコピーがあります。
224
+ - cucumber-js のスイートを持つプロジェクトは、import を 1 つ切り替えて取り込みます。
225
+ [docs/typescript/migration.ja.md](migration.ja.md) を参照してください。
226
+ - 何かが実行される前に `nuka check` が捕まえるもの: [Wrong before it runs](../../README.ja.md#wrong-before-it-runs)。
227
+ - すべてのコマンド、config のキー、record のフィールド: [docs/spec.ja.md](../spec.ja.md)。
228
+
229
+ ---
230
+
231
+ [English](adopting.md)