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,329 @@
1
+ # Bringing an existing suite in
2
+
3
+ The two doors through which an existing JavaScript suite comes into the
4
+ TypeScript engine: its cucumber-js step definitions, run as they are, and a
5
+ Playwright Test suite that shares its code with typed steps. Moving a suite
6
+ across step by step is [migration.md](migration.md) for the first door and
7
+ [migration-playwright-test.md](migration-playwright-test.md) for the second.
8
+ The Ruby engine has a compat door of its own, for a cucumber-ruby suite
9
+ ([reference.md](../ruby/reference.md)), and no door from Playwright Test.
10
+
11
+ ## Compat steps (the migration door)
12
+
13
+ An existing Cucumber and Playwright suite can adopt nukadoko by changing
14
+ one import:
15
+
16
+ ```ts
17
+ // before: import { Given, When, Then } from "@cucumber/cucumber";
18
+ import { Given, When, Then } from "nukadoko/compat";
19
+ ```
20
+
21
+ - Compat steps keep their existing pattern syntax and World (`this`). The
22
+ nukadoko harness provides and manages `page` and `request`. Custom World
23
+ classes use `setWorldConstructor` to extend the nukadoko base. A throw
24
+ while that World is constructed fails that one scenario: stderr gets one
25
+ setup line, the scenario record is failed and cites no step record, later
26
+ scenarios in the run still execute, and the messages export is finalized.
27
+ The API
28
+ supports the commonly used subset: Given, When, Then, World, Before,
29
+ After, and AfterStep. New demand determines when this subset grows.
30
+ - `Given`, `When`, and `Then` are three names for one registration
31
+ operation. A keyword has no meaning during registration. As in Cucumber,
32
+ the scenario position determines its meaning at run time. A pattern can
33
+ be a plain cucumber-expression string or a RegExp. Compat strings do not
34
+ require named captures because that rule belongs to typed steps. RegExp
35
+ support admits legacy glue that uses regular expressions. Compat accepts
36
+ both cucumber-js call forms: `Given(pattern, fn)` and
37
+ `Given(pattern, { timeout }, fn)`. It applies the specified timeout and
38
+ throws on an unknown option key. Discovery imports each file and assigns
39
+ its registrations to that file. The pattern text identifies a compat
40
+ step. `nuka steps` lists its kind, and `nuka describe` shows that it has
41
+ no contract. `nuka do` refuses the compat step by name. Promotion to
42
+ `defineStep` enables single-step execution.
43
+ - `defineParameterType` in compat code and `config.parameterTypes` use one
44
+ registry. Moving a registration to the config does not change pattern
45
+ matching, so a team can make this move early. A registration that sets
46
+ `preferForRegexpMatch` is the exception (below). The config is their
47
+ final location. A transformer's `this` is that scenario's World, the
48
+ same object the step and its hooks run against. A Promise the
49
+ transformer returns is awaited before the step runs. This holds for a
50
+ string pattern and a RegExp pattern alike. `preferForRegexpMatch` on a
51
+ compat registration picks the type for a RegExp group that several types
52
+ match, as in cucumber-js. `config.parameterTypes` has no such key, so a
53
+ registration that sets it stays in compat code while a RegExp step
54
+ relies on it. Moved to config with the key, it is a config error; moved
55
+ without it, a RegExp group that two types match fails again. Two types
56
+ that prefer one regexp, or a type that prefers a built-in type's regexp
57
+ such as `{int}`'s, are a `parameter-type-invalid` error.
58
+ - Execution supports two forms. Glue that starts its own Playwright
59
+ continues to work, with no trace and no page log. A World subclass assigns that
60
+ page and request with `this.page = ...` and `this.request = ...`, and
61
+ the getter returns the assigned value ahead of anything `openPage()` or
62
+ `openRequest()` stored. The assigned page gets no trace or screenshot;
63
+ a request a step sends through the assigned request context is still a
64
+ `node:http` or `node:https` line in http.jsonl (see docs/spec.md "Records"). `await
65
+ this.openPage()` and `await this.openRequest()` return the measured
66
+ page and request from the harness. With no assignment, reading
67
+ `this.page` or `this.request` before the matching opener has resolved
68
+ throws. Typed steps in a mixed scenario share the same context and
69
+ cookies. Tables use a small, dependency-free `DataTable` with
70
+ raw/rows/hashes/rowsHash/transpose. This preserves glue that calls
71
+ `table.hashes()` after the import change. Docstrings remain plain strings.
72
+ Before and After hooks support all three cucumber-js forms:
73
+ `Before(fn)`, `Before({ tags }, fn)`, and `Before("@tag", fn)`. They
74
+ also accept `{ name }` beside `tags` and `timeout`. The string is stored
75
+ on the registration and, when it is non-empty, on that invocation's
76
+ `hooks` entry. Allure fixture names, run summary rows, trace chunk
77
+ titles, and hook failure messages use it as the title. It does not change
78
+ which scenarios the hook runs for, its timeout, or its order. `AfterStep`
79
+ does not accept `name`: cucumber-js step-hook options have no such field.
80
+ They receive Cucumber's hook parameter. A hook can filter only on `@tag` or
81
+ `not @tag`. More complex expressions fail explicitly to prevent a silent
82
+ mismatch. Hooks appear in the scenario record's `hooks` array and do not
83
+ create step records. Their network traffic remains outside all step
84
+ boundaries. The http.jsonl lines remain scenario-wide and do not
85
+ identify one hook invocation. Playwright traces
86
+ use a narrower boundary. Each Before, After, or AfterStep invocation that
87
+ uses `this.openPage()` gets a separate trace chunk and `actions` list in
88
+ its `hooks` entry. The entry has `trace`, `actions`, and `truncated`, which
89
+ use the shape of a step record (see docs/spec.md "Records"). Each chunk is separate
90
+ from step chunks and sibling hook chunks. A hook has no fixture bag for
91
+ `section` or `poll`, so its entry has no `sections` or `polls`. Only the
92
+ `actions` read from the trace chunk are available. `AfterStep` supports
93
+ the same three registration forms and tag filters. Before and After
94
+ bracket a scenario, while AfterStep runs after each pickle step that
95
+ executed. It does not run for a step skipped after an earlier failure
96
+ because that step never began. This is also the rule for a hook whose tag
97
+ does not match. Each `AfterStep` entry has `step_index`, the zero-based
98
+ index of the executed step in that record's `steps` array. Allure and
99
+ cucumber-messages preserve this index. The hook parameter's
100
+ `result.status` uses the `TestStepResultStatus` strings from
101
+ `@cucumber/messages`. `nukadoko/compat` re-exports the same enum as
102
+ `Status`, so `result.status === Status.FAILED` imports and compares
103
+ correctly. `After` and `AfterStep` also receive `result.duration`,
104
+ cucumber's `Duration` (seconds and nanos) for the step whose outcome
105
+ `result` describes, measured from that step's own start and finish.
106
+ When that outcome is a failure, `result.message` is the failure text
107
+ the executor already recorded, and `error` is the thrown value when
108
+ the failure was a throw. `Before` receives neither `result` nor
109
+ `error`. `error` is present on `After` and `AfterStep` even when the
110
+ step passed, and the value is `undefined` then, because cucumber-js
111
+ assigns the key whenever it assigns `result`. `AfterStep` also
112
+ receives `pickleStep`, the pickle step that just ran, and
113
+ `testStepId`, that step's step record id. The id is the same kind of
114
+ stand-in `testCaseStartedId` already is: a real stable id the
115
+ executor holds, not the id the cucumber-messages stream assigns
116
+ later. `SKIPPED` matches in one place: the `After` hooks of a scenario
117
+ a walk stopped, whose steps did not all run (see docs/spec.md "A walk with a
118
+ person"). The other members, `PENDING`, `UNDEFINED`, and `AMBIGUOUS`,
119
+ cannot match. Nukadoko has no corresponding concept for a hook result.
120
+ Migrated glue never takes a branch that compares these values, and
121
+ this behavior is not a compat gap. `BeforeAll` and `AfterAll`
122
+ bracket the full run. They accept `{ timeout }` and `{ name }`. They
123
+ reject `tags` and `on`. `on` would choose which process runs the hook,
124
+ and nukadoko does not offer that choice. A non-empty `name` is the title
125
+ in their failure messages. They have no World, and do not run
126
+ when no scenario is selected. They report through the exit code because
127
+ they do not belong to a scenario record. `setDefaultTimeout` sets the
128
+ default for items without a specific timeout. A negative value means no
129
+ timeout, matching cucumber-js: `setDefaultTimeout(-1)` and a step or hook
130
+ `{ timeout: -1 }` turn the limit off, and zero still times out. If the
131
+ glue does not call it, or calls it with a negative value, steps have no
132
+ time limit. This avoids applying Cucumber's five-second limit to a slow
133
+ suite only because the suite migrated.
134
+ - Nukadoko always measures the World. Each compat step record lists the
135
+ World keys that the step read and wrote, in access order. This exposes
136
+ data flow through `this.foo`. Measurement covers the bag's own data
137
+ properties. By construction, it does not include `#private` state.
138
+ `defineWorld({ key: zodSchema })` enables validation for individual keys.
139
+ A write that fails its schema fails the step and does not appear as a
140
+ write. `class MyWorld extends defineWorld({...})` adds a type to `this`.
141
+ Cucumber reserves `attach`, `log`, `link`, and `parameters`. These keys
142
+ cannot be measured or declared, and an overwrite causes an error.
143
+ `parameters` is `worldParameters` from config, and the default is `{}`.
144
+ `page` and `request` are harness getters, not bag fields. `defineWorld`
145
+ refuses either name when the step file is imported. `nuka check` reports
146
+ that refusal as `step-file-import-failed`, and `nuka run` stops with the
147
+ same message. The message names the field. A subclass can still assign
148
+ them. `await this.openPage()` and `await this.openRequest()` still return
149
+ the harness objects.
150
+ - `this.attach` and `this.link` follow cucumber-js. `attach` takes a
151
+ string, a `Buffer` or `Uint8Array`, or a readable stream. A media type
152
+ that starts with `base64:` means the string is base64, and the file is
153
+ the decoded bytes. The second argument is that media type, or
154
+ `{ mediaType, fileName }`. `fileName`, when present, is the file written
155
+ under the step record. A missing media type is `text/plain` for a string
156
+ or a buffer. A stream returns a promise the step has to await, and a
157
+ stream with no media type throws, because the bytes are not known until
158
+ the stream ends and the type was never given. `link` takes one URL or
159
+ several. Each argument is its own declared link, with no display name.
160
+ - The harness owns the browser and request objects. Therefore, compat steps
161
+ get measured step records without code changes. These records contain the
162
+ status, timing, trace, screenshots, and HTTP log.
163
+ - Compat steps lack typed contracts, a validated `result` in the step
164
+ record, and single-step CLI execution. A team can add these properties
165
+ one step at a time by promoting a frequently used step to `defineStep`.
166
+ - An audit measured the width of this door. It inspected the glue text of
167
+ eight public cucumber-js suites without running them. At that time, none
168
+ worked after only the import change. Fixes for the observed blockers have
169
+ since brought two suites to a state where compat rejects none of their
170
+ glue. [docs/typescript/migration.md](migration.md) lists the remaining requirements.
171
+ The audit established a rule: unsupported compat behavior must fail
172
+ during import or the first run. A migrating team can respond to an
173
+ explicit failure, but it cannot see a silent behavior change. A silent
174
+ change costs more trust than a missing feature costs time. Import
175
+ failures and the findings below meet this rule. Some value-level
176
+ differences remain. They do not fail, so [docs/typescript/migration.md](migration.md)
177
+ "Known limits" lists each measured one.
178
+ - Explicit failures divide into static findings and failures that require
179
+ step execution. `nuka check` reports only static findings.
180
+ **`nuka check` can report these failures**: a step file that throws during
181
+ import becomes a `step-file-import-failed` error. Causes include a value
182
+ import that `nukadoko/compat` does not export, a CommonJS `require` in ESM
183
+ glue, and a deep subpath import. A hook tag expression more complex than
184
+ one `@tag` or `not @tag` becomes an
185
+ `unsupported-hook-tag-expression` error. The file text establishes both
186
+ failures before execution. Two additional findings describe the area
187
+ that discovery scans:
188
+ `step-file-unsupported-extension` reports a `.cjs` or `.cts` file under
189
+ `featuresDir` (see docs/spec.md "Typed steps" for the import rule).
190
+ `no-step-files-found` reports a scan that found no candidate files. Each
191
+ finding identifies what discovery inspected, so that a reader can verify
192
+ the finding; the `pattern-unbound` note names its scanned directories for
193
+ the same reason.
194
+ An `undefined-step` finding can also identify a missing pair of quotes.
195
+ The finding applies when one registered pattern fits the same position and
196
+ all its captures are `{...:string}` parameters. It names the step and
197
+ pattern and gives the rewritten Gherkin line. It stays silent when two or
198
+ more patterns can explain the line, because that choice belongs to the
199
+ author.
200
+ **`nuka check` can also report a done callback**, as
201
+ `done-callback-arity`. A compat hook is over the limit when Before, After,
202
+ or AfterStep declares two or more parameters, or when BeforeAll or AfterAll
203
+ declares one or more. A matched compat step is over the limit when its
204
+ function declares more parameters than the line's captures plus a table or
205
+ docstring. That count is known from the function and the matched line, so
206
+ the finding can only end one way. An unmatched step stays silent, because
207
+ the capture count comes from the line that selected it.
208
+ **Only `nuka run` can report these failures**: a step or hook returns
209
+ `"pending"` or `"skipped"`. Those values depend on what the function does
210
+ during execution. Import analysis cannot identify them. **The following case is not a gap**: esbuild removes a
211
+ name that appears only in a type annotation or an unused import before
212
+ nukadoko imports the file. The import does not occur at run time, and the
213
+ glue runs as compiled. `tsc` still resolves the name against compat
214
+ exports. A missing name is therefore a compile error. The audit found
215
+ `IWorldOptions` and `ITestCaseHookParameter` in this category. Exporting
216
+ them prevents a user typecheck failure even though `nuka` cannot observe
217
+ that failure during a run.
218
+ - A permanent design rule applies to all migration work. A working compat
219
+ asset must continue to work after a team adopts nukadoko or moves another
220
+ asset to typed steps. A transition can place related definitions in two
221
+ locations. Examples include parameter types in support code and the
222
+ config, or a World bag beside typed results. Both locations must share one
223
+ mechanism. `nuka check` must expose the split. Each migration step must
224
+ preserve semantics so a team can make it early and safely. A team must
225
+ also be able to restore the original import.
226
+ - [docs/typescript/migration.md](migration.md) gives a step-by-step procedure for an
227
+ existing cucumber-js and Playwright suite. [docs/typescript/upgrading.md](upgrading.md)
228
+ explains how to move an existing nukadoko project to a newer release.
229
+
230
+ ## The second door: a Playwright Test suite
231
+
232
+ The first door serves a suite built on cucumber-js by changing an import.
233
+ A suite written directly for Playwright Test has no such import. Its tests
234
+ use `test("...", async ({ page }) => {...})`, with no glue layer to
235
+ redirect. This suite requires a different migration method.
236
+
237
+ [docs/typescript/migration-playwright-test.md](migration-playwright-test.md) gives the
238
+ step-by-step procedure for this door. `docs/typescript/migration.md` covers the first
239
+ door. The documents serve different readers because a Playwright Test suite
240
+ has no compat steps, World, or Cucumber hooks.
241
+
242
+ **Share the implementation.** Move an operation from a spec file to a plain
243
+ async function. The function accepts only Playwright objects. Both the spec
244
+ and a typed step's `run` call this function. Each runner loads only its own
245
+ files.
246
+
247
+ ```
248
+ e2e/cart.spec.ts ──▶ features/steps/lib/cart.ts ◀── features/steps/add-item.ts
249
+ (Playwright) (plain functions) (nukadoko)
250
+ ```
251
+
252
+ The arrows intentionally point one way. The Playwright suite does not
253
+ import nukadoko. After the move, it still depends only on Playwright and a
254
+ function in its repository. To reverse the compat migration, restore an
255
+ import. To reverse this migration, delete the feature files and steps. The
256
+ Playwright suite remains unchanged because its dependencies never include
257
+ nukadoko.
258
+
259
+ The shared API shape makes this arrangement work. `page`, `context`,
260
+ `request`, and `baseURL` are Playwright objects on both sides (see docs/spec.md "Context
261
+ API"). Both callers can use a function that accepts these objects. No
262
+ adapter, wrapper, or re-export is necessary.
263
+
264
+ Do not share anything above this API boundary. A spec must not call
265
+ `step.run(bag, args)` directly. Such a call works only while the step uses
266
+ Playwright fixture names. It fails when the step uses `call`, `section`,
267
+ `resultOf`, or `requireEnv`. These fixtures provide much of the value of a
268
+ typed step. A spec also cannot share the fixture map because of the typing
269
+ constraint described in "Fixtures."
270
+
271
+ Place the contract in the shared unit. A step's `args` and `returns` are
272
+ plain zod schemas. The function file can export them, and the step can
273
+ declare them:
274
+
275
+ ```ts
276
+ // features/steps/lib/cart.ts
277
+ export const openCartReturns = z.object({ id: z.string() });
278
+ export async function openCart(request: APIRequestContext) { ... }
279
+
280
+ // features/steps/open-cart.ts
281
+ export default defineStep({ returns: openCartReturns, run: ({ request }) => openCart(request) });
282
+ ```
283
+
284
+ The spec and step import one definition, which keeps their shapes aligned.
285
+ The shared file depends only on Playwright and zod, so the dependency
286
+ direction stays unchanged.
287
+
288
+ This migration opens both nukadoko paths. `nuka run` fixes a path in a
289
+ feature file, and `nuka do` runs each step alone. Operations that the
290
+ existing suite already trusts become the vocabulary that an agent uses for
291
+ exploration (see docs/spec.md "Single steps").
292
+
293
+ Both trees can exist in one repository. A team can put them side by side.
294
+ Alternatively, it can put `featuresDir` *inside* the directory that already
295
+ contains the specs. The second arrangement requires less movement when the
296
+ Playwright suite is the primary asset.
297
+
298
+ ```
299
+ e2e/
300
+ cart.spec.ts <- Playwright finds this
301
+ lib/cart.ts <- shared, owned by neither runner
302
+ nukadoko/ <- featuresDir
303
+ cart.feature
304
+ steps/add-item.ts <- Playwright does not find this
305
+ ```
306
+
307
+ Each runner loads only recognized files. Playwright collects files that
308
+ match its `testMatch`. A step file named after its step does not match.
309
+ Discovery imports each `.ts`, `.mts`, `.js`, or `.mjs` file under
310
+ `featuresDir`. A spec outside that directory is outside the discovery
311
+ area. These naming and placement rules do not conflict.
312
+
313
+ Nukadoko reports two incorrect arrangements explicitly.
314
+
315
+ Discovery imports a spec **inside** `featuresDir`. Playwright's `test()`
316
+ then refuses to run outside the Playwright runner, so the import fails.
317
+ `nuka check` identifies the file and includes the Playwright message.
318
+ `run` and `do` refuse execution as they do for other broken glue.
319
+
320
+ A step file **named like a spec** causes a different conflict. The file
321
+ basename defines the step name. Therefore, `open-cart.spec.ts` defines a
322
+ second step named `open-cart.spec` with the first step's pattern.
323
+ `nuka check` reports `ambiguous-step` and identifies both steps. The error
324
+ is one pattern that matches multiple steps. Rename the file to fix it.
325
+
326
+ In both arrangements, place the shared file outside `featuresDir`.
327
+ Discovery could import it without harm because the module defines no step.
328
+ However, its location shows that the existing suite owns it.
329
+
@@ -0,0 +1,189 @@
1
+ # 第二の扉: Playwright Test のスイート
2
+
3
+ > 原文は migration-playwright-test.md。
4
+ > 相違があれば原文が正。
5
+
6
+ まだ cucumber-js も Gherkin も使っていないプロジェクト向けです。
7
+ Playwright Test に対して直接書かれたスイートには、差し替える import そのものがありません: そのテストは `test("...", async ({ page }) => {...})` であり、リダイレクトする glue レイヤーもありません。
8
+ [docs/typescript/migration.ja.md](migration.ja.md) はもう一方の扉、cucumber-js から始まる扉を扱っています。
9
+ そちらがあなたのスイートでなければ、ここから始めてください。
10
+
11
+ nukadoko 自身のインストールと設定は、どちらの扉を使っても同じであり、その手順のどこにも cucumber 固有のものはありません。
12
+ パッケージをインストールし、プロジェクトルートから `nuka init` を実行してください。
13
+ `nuka init` は `nukadoko.config.ts` を書きます。
14
+ CommonJS のプロジェクト(`package.json` に `"type": "module"` が無い場合で、既存のスイートはこうなっていることもあります)では `nukadoko.config.mts` を書きます。
15
+ feature が `features/` に無いときは、そこに `featuresDir` を足してください:
16
+
17
+ ```ts
18
+ import { defineConfig } from "nukadoko";
19
+
20
+ export default defineConfig({
21
+ featuresDir: "features",
22
+ });
23
+ ```
24
+
25
+ テスト対象のアプリは、同じファイルに `program` として書きます。
26
+ 起動の仕方か、すでに動いているアプリの URL です。
27
+
28
+ ```ts
29
+ import { defineConfig } from "nukadoko";
30
+
31
+ export default defineConfig({
32
+ program: () => ({
33
+ serve: { command: "npm start", ready: "/" }, // the command webServer runs
34
+ env: { PORT: "{port}" },
35
+ }),
36
+ });
37
+ ```
38
+
39
+ その CommonJS の場合、step ファイルも同じ `.mts` 拡張子にする必要があります。
40
+ `"type": "commonjs"` では、Node はふつうの `.ts` ファイルを CommonJS として読み、nukadoko は ESM 専用だからです。
41
+ `"type"` が無い場合、Node は `.ts` ファイルを解析し直してから読み込み、読み込むたびに `MODULE_TYPELESS_PACKAGE_JSON` の警告を出します。
42
+ `nuka init` はそれを stderr で伝えます。
43
+
44
+ `nuka run` も `nuka do` も `playwright.config.ts` を一切読まないため、その `webServer` フィールドと `use.baseURL` は nukadoko にとって意味を持ちません。
45
+ `webServer` の役目は、プログラムの `serve` が果たします。
46
+ nukadoko は専用の空いているポートでアプリを起動し、`ready` が答えるまで待ち、その URL を `page` と `request` の base URL にします。
47
+ 同じコマンドを両方のファイルに書くことになります。
48
+ ここではその重複を解消しません。
49
+ 2 つの設定が今そういう関係にある、というだけです。
50
+
51
+ ## 共有するのは runner ではなく実装
52
+
53
+ 既存のスイートには差し替える import がないため、この扉は別のやり方で動きます。
54
+ ある操作が spec ファイルの外に移り、Playwright 自身のオブジェクトだけを受け取る、ただの非同期関数になります。
55
+ spec はそれを呼びます。
56
+ 型付き step の `run` もそれを呼びます。
57
+ どちらの runner も、もう一方のファイルを読み込むことは決してありません。
58
+
59
+ ```
60
+ e2e/cart.spec.ts ──▶ e2e/lib/cart.ts ◀── features/steps/add-item.ts
61
+ (Playwright) (plain functions) (nukadoko)
62
+ ```
63
+
64
+ 矢印は意図的に一方向です。
65
+ Playwright のスイートは nukadoko を一切 import しないため、この移動のあとにそれが依存するものは、移動の前に依存していたものとまったく同じです: Playwright と、自分自身のリポジトリにある関数です。
66
+ そのため、この扉の戻り道は compat の扉の戻り道より強力です。
67
+ compat の扉を戻すとは import を元に戻すことであり、この扉を戻すとは feature ファイルと step ファイルを削除することです。
68
+ 削除したあとのスイートが無傷のままなのは、そこが使うものがどれも nukadoko の存在を一度も知らなかったからです。
69
+
70
+ 共有を成立させているのは約束ではなく形です: `page`、`context`、`request`、`baseURL` はどちら側でも Playwright 自身のオブジェクトであり(docs/spec.ja.md の「Context API」を参照)、それらに対して書かれた関数はすでにどちらからも呼び出せます。
71
+ 何も変換されず、ラップされず、re-export もされません。
72
+
73
+ ## あえて共有しないもの
74
+
75
+ 意図的に共有しないのは、その一線より上にあるものすべてです。
76
+ spec は `step.run(bag, args)` を直接呼んではいけません。
77
+ これは誘惑的に見えますが、成り立つのはその step が Playwright だけの名前を分割代入している間だけです: その step が `call`、`section`、`resultOf`、`requireEnv` のどれかに手を伸ばした瞬間に壊れ、それはその step が持つ価値を持ち始める瞬間でもあります。
78
+ fixture map も同じく共有できません。
79
+ その型づけ上の理由は docs/spec.ja.md の「Fixtures」がすでに挙げています。
80
+
81
+ ## 契約は両側とも 1 つ
82
+
83
+ 契約は、その一線より上にではなく共有ユニットの側に置くことができ、そう置くべきです。
84
+ step の `args` と `returns` はただの zod スキーマなので、その関数自身のファイルがそれらを export し、step 側はそれを宣言できます:
85
+
86
+ ```ts
87
+ // e2e/lib/cart.ts
88
+ export const openCartReturns = z.object({ id: z.string() });
89
+ export async function openCart(request: APIRequestContext) { ... }
90
+
91
+ // features/steps/open-cart.ts
92
+ export default defineStep({
93
+ patterns: ["a cart is opened"],
94
+ description: "Open a new cart",
95
+ args: z.object({}),
96
+ returns: openCartReturns,
97
+ run: ({ request }) => openCart(request),
98
+ });
99
+ ```
100
+
101
+ 定義は 1 つだけで、両方の住まいからそれを import するので、spec と step が形について食い違う方向へずれることはありません。
102
+ 共有ファイルが依存するのはあくまで Playwright と zod だけなので、上の矢印は変わりません。
103
+
104
+ ## 値の出どころを名指す: `from`
105
+
106
+ `from` は、pattern がキャプチャしなかった args キーの値がどこから来るかを宣言します(docs/spec.ja.md の「step の連鎖」を参照)。
107
+ 上流の step と、その step の `returns` のどのキーを読むかです。
108
+
109
+ ```ts
110
+ // e2e/lib/cart.ts (continuing the file above)
111
+ export const addItemArgs = z.object({ cartId: z.string(), sku: z.string() });
112
+ export const addItemReturns = z.object({ itemId: z.string(), cartId: z.string(), sku: z.string() });
113
+ export async function addItem(request: APIRequestContext, cartId: string, sku: string) { ... }
114
+
115
+ // features/steps/add-item.ts
116
+ import openCartStep from "./open-cart.ts";
117
+
118
+ export default defineStep({
119
+ patterns: ["item {sku:string} is added to the cart"],
120
+ description: "Add one item to the cart opened earlier in this scenario",
121
+ args: addItemArgs,
122
+ returns: addItemReturns,
123
+ from: { cartId: [openCartStep, "id"] },
124
+ run: ({ request }, args) => addItem(request, args.cartId, args.sku),
125
+ });
126
+ ```
127
+
128
+ `from` は、上流の step を import することでそれを名指します。
129
+ 値が他のどのモジュールに入るときとも同じやり方です。
130
+ 上の `openCartStep` は `open-cart.ts` 自身の default export です。
131
+ `from` の値は常に `[<step>, "<キー>"]` です。
132
+ 値を生み出す step と、その step 自身の `returns` のどのキーを読むかの組です。
133
+ キャプチャにも自分自身の名前が要ります。
134
+ `{sku:string}` であり、cucumber の裸の `{string}` ではありません。
135
+ `nuka check` は名前のない形を `unnamed-capture` として拒否します。
136
+ `from` はどのキャプチャも届かなかったキーを埋めるものです。
137
+
138
+ これは `use` が必要とするものでもあります。
139
+ `nuka do --use <record-id>` は、先行する step record の結果から step の `from` キーを埋めます。
140
+ 上流の step を名指す `from` エントリを持たない step には `use` が埋めるものが何もなく、黙って無視されるのではなく拒否されます。
141
+
142
+ ## 1 つのリポジトリに 2 つの木
143
+
144
+ nukadoko 自身の 2 つの経路がどちらも同時に開き、それこそが書き直すのではなくここから入る意味です。
145
+ `nuka run` は feature ファイルの中に経路を固定し、`nuka do` はそのどの step も単独で実行できるので、既存のスイートがすでに信頼している同じ操作が、agent が探索するときの語彙になります(参照: docs/spec.ja.md の「単体 step」)。
146
+
147
+ 2 つの木は 1 つのリポジトリに同居でき、どちらの配置でも動きます。
148
+ 並べて置くのが分かりやすい方です。
149
+ もう一方は名指す価値があります。
150
+ Playwright のスイートを資産とするチームにとって要求が小さいからです: `featuresDir` を、spec がすでに住んでいるディレクトリの内側に置きます。
151
+
152
+ ```
153
+ e2e/
154
+ cart.spec.ts <- Playwright finds this
155
+ lib/cart.ts <- shared, owned by neither runner
156
+ nukadoko/ <- featuresDir
157
+ cart.feature
158
+ steps/add-item.ts <- Playwright does not find this
159
+ ```
160
+
161
+ これが成り立つのは、それぞれの runner が自分の認識するものしか読み込まないからです。
162
+ Playwright は自分自身の `testMatch` にマッチするファイルを集めますが、自分が定義する step にちなんで名付けられた step ファイルがそれにマッチすることは決してありません。
163
+ discovery は `featuresDir` の下にある `.ts`/`.mts`/`.js`/`.mjs` をすべて import しますが、その外に留まる spec がそこに含まれることは決してありません。
164
+ この 2 つの規則は命名と配置についてのものであり、互いに衝突しません。
165
+
166
+ 間違え方は 2 つあり、どちらも黙っては終わらず捕まります。
167
+ `featuresDir` の内側にある spec は discovery に import されますが、Playwright の `test()` は自分自身の runner の外から呼ばれることを拒否するので、そのファイルは import に失敗します。
168
+ `nuka check` はこれを、docs/typescript/migration.ja.md で名指されているのと同じ `step-file-import-failed` のコードで報告し、今回は Playwright 自身のエラーメッセージを運びます。
169
+ `run`/`do` も、他の壊れた glue に対してとまったく同じように、実行そのものを拒否します。
170
+ spec のように名付けられた step ファイルは、また別の形でぶつかります。
171
+ step の名前はそのファイルの basename なので、`open-cart.spec.ts` は最初の step と同じ pattern を持つ、`open-cart.spec` という 2 つ目の step を定義してしまい、`nuka check` はその両方を名指しして `ambiguous-step` を報告します。
172
+ 1 つの pattern が 2 つ以上の step にマッチしていることがそのエラーであり、直すのはファイル名です。
173
+
174
+ 共有ファイルは、どちらの配置でも `featuresDir` の外に属します。
175
+ discovery がそれを import しても害はありません。
176
+ step を 1 つも定義しないモジュールは単に語彙ではないからです。
177
+ それでも配置は誰がそれを所有するかを語っており、所有するのは既存のスイートです。
178
+
179
+ 最初に 1 つ確かめることがあります。
180
+ nukadoko は `playwright` を、キャレットの範囲を持つ optional な peer dependency として宣言しています(`npm view nukadoko peerDependencies` でどの範囲かが分かります)。
181
+ nukadoko はプロジェクト自身の Playwright を使うので、コピーも、ブラウザのダウンロードも、`Page` の型も 1 つです。
182
+ プロジェクト自身の `playwright` がその範囲の外にあるあいだは、npm は nukadoko のインストールを拒否します(`ERESOLVE`)。
183
+ プロジェクトの Playwright をその範囲まで上げるか、範囲がプロジェクトの版を含む nukadoko に上げてください。
184
+
185
+ ## 戻り道
186
+
187
+ feature ファイルと step ファイルを削除すれば、Playwright のスイートは無傷のままです。
188
+ これは「共有するのは runner ではなく実装」で述べたのと同じ約束です。
189
+ 使っているものが nukadoko を一度も import していないからです。