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/releasing.md ADDED
@@ -0,0 +1,237 @@
1
+ # Releasing
2
+
3
+ The npm package is the directory `typescript/`. Every `package.json`
4
+ on this page is `typescript/package.json`, and every `npm` command runs
5
+ there. The gem is `ruby/`; its own section is at the end.
6
+
7
+ nukadoko is already on npm. A release is the npm package and a git tag
8
+ whose name is `v` plus the `package.json` version. A push to `main` that
9
+ changes `package.json` runs
10
+ [`.github/workflows/publish.yml`](../.github/workflows/publish.yml). Its
11
+ `check` job reads the `package.json` version and looks for the tag
12
+ `v<version>`. When that tag already exists, as it does after a
13
+ dependency bump, the run releases nothing. Otherwise the publish job
14
+ installs the pushed commit, builds `dist/`, runs the same checks this
15
+ repository's own CI runs (including `npm run archstrict`), runs
16
+ `npm run pack-check` and the skill examples, and runs `npm publish`. npm authenticates with
17
+ GitHub Actions OIDC. Provenance is attached automatically because the repository and the
18
+ package are public. The GitHub Environment `publish` is the human
19
+ gate: the publish job waits there until it is approved.
20
+
21
+ After `npm publish` succeeds, a third job creates the tag and the
22
+ GitHub release for that version. It checks out the same commit the
23
+ publish job checked out, extracts this version's section of
24
+ `typescript/CHANGELOG.md`, and runs `gh release create --target` with the
25
+ published commit, which creates the tag `v<version>` there. Nobody
26
+ pushes that tag by hand. A release that already exists is left in
27
+ place, so a re-run of the job does not fail. The publish job's
28
+ permissions are `id-token: write` and `contents: read`.
29
+ The release job's permission is `contents: write`. That job does not
30
+ hold the npm OIDC token.
31
+
32
+ The package ships compiled JavaScript in `dist/` (the `nuka` bin is
33
+ `dist/cli.js`), plus `src/`, `docs/`, `skills/`, `CHANGELOG.md` (from `typescript/`), and
34
+ `llms.txt`. `dist/` is gitignored. The workflow builds it from the
35
+ pushed commit. `README.md`, `README.ja.md`, `LICENSE`, and
36
+ `package.json` are in the tarball because npm always packs them.
37
+
38
+ `package.json` declares `prepublishOnly`, and `.npmrc` sets
39
+ `ignore-scripts=true`, so that hook does not fire during `npm publish`.
40
+ The workflow runs `npm run build` itself. Publishing without that build
41
+ would ship whatever `dist/` happened to be there, which may be older
42
+ than `src/` or missing entirely.
43
+
44
+ The workflow stores no `NPM_TOKEN`. The repository secrets do not keep
45
+ one either. There is no token bootstrap. The package already exists, and
46
+ its Trusted Publisher is already registered.
47
+
48
+ ## One-time setup
49
+
50
+ The Environment and the trusted publisher are already configured, as of
51
+ 23 September 2026. Recreate either only when it is missing. These are
52
+ human steps. Nothing in this repository creates the Environment or
53
+ registers the trusted publisher.
54
+
55
+ 1. The GitHub repository `meganemura/nukadoko` has an Environment named
56
+ `publish` with required reviewers. The workflow job sets
57
+ `environment: publish`, so a release run waits there until a
58
+ reviewer approves it.
59
+
60
+ The run comes from the `main` branch, not from a tag. If the
61
+ Environment limits its deployment branches and tags, that list must
62
+ allow `main`. A list that allows only `v*` tags refuses the run. The
63
+ owner changes this in the repository settings, under Environments.
64
+
65
+ Registering the trusted publisher does not open a pending approval.
66
+ The approval appears only when a release run enters the Environment
67
+ `publish`.
68
+
69
+ If the Environment is missing, create it and require reviewers before
70
+ the next release. Otherwise GitHub creates it on the first run with no
71
+ required reviewers, and that run publishes as soon as the checks pass.
72
+
73
+ 2. The `nukadoko` package on npmjs.com has one GitHub Actions trusted
74
+ publisher, allowed to run `npm publish`. The fields are
75
+ case-sensitive. If the publisher is missing, add it with these
76
+ values:
77
+
78
+ - Organization or user: `meganemura`
79
+ - Repository: `nukadoko`
80
+ - Workflow filename: `publish.yml` (the filename, including `.yml`)
81
+ - Environment name: `publish`
82
+ - Allowed action: `npm publish`
83
+
84
+ A trusted publisher created after 3 September 2026 starts with
85
+ `npm stage publish` allowed. Select `npm publish` as well.
86
+ `publish.yml` runs `npm publish`.
87
+
88
+ `package.json` `repository.url` is already
89
+ `git+https://github.com/meganemura/nukadoko.git`. npm checks that URL
90
+ against the workflow repository.
91
+
92
+ 3. After OIDC publishing from Actions works, the package settings can
93
+ require two-factor authentication and disallow token publishing.
94
+ That is optional hardening. The trusted publisher keeps working.
95
+
96
+ ## Each version
97
+
98
+ 1. Move the notes under `## Unreleased` to a new version heading and
99
+ leave `## Unreleased` empty. Keep the heading shape already in
100
+ `typescript/CHANGELOG.md`: the release job extracts the section whose heading
101
+ starts with `##`, the version, and a space. Set the same version in
102
+ `package.json` and `package-lock.json`. The workflow creates the tag
103
+ from that version. In `docs/typescript/upgrading.md` and `docs/typescript/upgrading.ja.md`, rename
104
+ the heading that ends in "to the next release" (`から次のリリースへ`
105
+ in Japanese) so it names this version, for example `0.14.1 to 0.15.0`.
106
+ Then run `git grep -n "<old heading text>"` once for each language and
107
+ change every quote of the old heading to the new one. A bullet that sends
108
+ the reader to that section quotes its heading, and
109
+ `tests/docs-cli-names.test.ts` fails on a quoted heading that the file no
110
+ longer has.
111
+
112
+ 2. Run `npm run archstrict && npm run typecheck && npm test && npm run selftest && npm run pack-check && npm run skill-examples`.
113
+ `pack-check` installs the real tarball into a throwaway project
114
+ outside this repository and drives the CLI there. That is what catches
115
+ a `bin` that depends on a package this repository only lists as a
116
+ devDependency, and a `dist/` that does not match `src/`.
117
+ `skill-examples` installs the same tarball into a copy of each project
118
+ under `examples/acceptance/`, runs `nuka check` and `nuka run` there,
119
+ and compares the output with the transcripts in
120
+ `skills/nukadoko/references/typescript/examples/`.
121
+
122
+ 3. When `skills/` changed since the previous tag
123
+ (`git diff --stat v<previous>..HEAD -- skills/` prints a line), run one
124
+ skill eval by hand. Pick one worked example under
125
+ `skills/nukadoko/references/typescript/examples/`. In a scratch project, put
126
+ that example's program (`src/` of its project under
127
+ `examples/acceptance/`) and install this checkout's tarball. Delete
128
+ that example's Markdown file from the installed skill, under
129
+ `node_modules/nukadoko/skills/nukadoko/references/typescript/examples/`, and
130
+ give the agent no other copy of it. Give the agent the
131
+ example's "The ticket" section and ask it to write and run the
132
+ scenarios. Score the feature it writes against each rule, S1 to S12, of
133
+ `skills/nukadoko/references/scenario-rules.md`: met, not met, or
134
+ not applicable. Put the table, the example's name, and the model
135
+ under this version's heading in `typescript/CHANGELOG.md`, so the release notes
136
+ carry it. A rule that is not met is a finding for the skill, not a
137
+ gate on this release: the eval is one run of one model, and a second
138
+ run can score differently.
139
+
140
+ 4. Commit the version bump, the changelog, and the upgrading headings
141
+ together as `chore: release <version>`. Land that commit on `main`
142
+ through the `queue` branch. Its arrival on `main` starts the
143
+ workflow. Do not push a `v*` tag by hand: the workflow creates it.
144
+ This publish is `publish.yml` only. Do not run `npm publish` from a
145
+ checkout.
146
+
147
+ 5. Approve the `publish` Environment when that Actions run asks for it.
148
+ The pending approval is that run entering the Environment. The
149
+ workflow uses Node 24 on `ubuntu-latest` with the npm registry URL
150
+ set. It requires npm 11.5.1 or newer, the release that can exchange a
151
+ GitHub OIDC token for a publish. It runs `npm ci --ignore-scripts`
152
+ and `npm run archstrict` (that check reads source, so it needs
153
+ neither the build nor a browser), installs Playwright's Chromium
154
+ (the suite launches it, and `npm ci` never does), `npm run build`,
155
+ `npm run typecheck`, `npm test`, `npm run selftest`,
156
+ `npm run pack-check`, and `node scripts/skill-examples.ts`, then refuses the run if any tracked file
157
+ changed. `dist/` is gitignored, so the new build
158
+ output is expected and is what gets packed. Then it runs
159
+ `npm publish`. Actions are pinned to a full-length commit SHA, written
160
+ `uses: action@<40-hex> # vX.Y.Z`, the same way `ci.yml` is. This
161
+ repository has `sha_pinning_required` enabled, so a tag would be
162
+ refused before the job ran. The package `engines` field stays
163
+ `^22.18.0 || >=23.6.0`. Node 24 is the publish job, not a new
164
+ requirement for people running `nuka`.
165
+
166
+ 6. The workflow's `release` job creates the GitHub release after
167
+ `npm publish`. It reads `typescript/CHANGELOG.md` from the commit the publish
168
+ job checked out. `--notes-file CHANGELOG.md` would paste every
169
+ version's notes, so the job extracts only the section whose heading
170
+ starts with `##` plus that version and a space, then runs
171
+ `gh release create` with `--target` set to the published commit.
172
+ That call creates the tag `v<version>` and the release. Creating
173
+ both is that job.
174
+
175
+ ## The Ruby gem
176
+
177
+ `ruby/` is the gem `nukadoko`, a separate package with its own version
178
+ (`ruby/lib/nukadoko/version.rb`) and its own changelog
179
+ (`ruby/CHANGELOG.md`). The two packages release independently: both
180
+ engines pass the same `conformance/` cases, so their versions do not
181
+ need to match. A push to `main` that changes `ruby/lib/nukadoko/version.rb`
182
+ runs [`.github/workflows/release-gem.yml`](../.github/workflows/release-gem.yml);
183
+ `publish.yml` does not run, because `package.json` did not change.
184
+
185
+ The workflow has the same shape as `publish.yml`. Its `check` job reads
186
+ the gem version and looks for the tag `ruby-v<version>`, and it reads
187
+ that version's section of `ruby/CHANGELOG.md`, whose heading starts with
188
+ `## [<version>]`. The `test` job runs the checks of `ci.yml`'s
189
+ `ruby-engine` job. The `publish` job waits for the GitHub Environment
190
+ `rubygems`, builds the gem, exchanges the GitHub OIDC token for a
191
+ RubyGems credential, and runs `gem push`. The `release` job then creates
192
+ the tag `ruby-v<version>` and a GitHub release that is not marked as
193
+ the latest, so the npm package's release stays the latest one. The
194
+ `ruby-` prefix keeps the gem's tags apart from the npm package's `v*`
195
+ tags. Nobody pushes either tag by hand.
196
+
197
+ ### One-time setup for the gem
198
+
199
+ These are human steps, done once.
200
+
201
+ 0. Allow the one action the Ruby workflows use that is not GitHub's own,
202
+ `ruby/setup-ruby@*`, under Settings, Actions, General, Actions
203
+ permissions.
204
+ This repository allows only the actions it names, and a workflow that
205
+ uses any other action fails before its first job starts
206
+ (`startup_failure`), which a re-run cannot fix: a new push starts it
207
+ again.
208
+ 1. Create the GitHub Environment `rubygems` in `meganemura/nukadoko`, with
209
+ required reviewers, and allow deployments from `main`.
210
+ 2. On rubygems.org, add a pending trusted publisher (the gem does not
211
+ exist yet), at https://rubygems.org/profile/oidc/pending_trusted_publishers:
212
+ - Gem name: `nukadoko`
213
+ - Repository owner: `meganemura`
214
+ - Repository name: `nukadoko`
215
+ - Workflow filename: `release-gem.yml`
216
+ - Environment: `rubygems`
217
+ - Workflow repository owner and name: leave both empty (the workflow is
218
+ in this repository, not a reusable workflow elsewhere).
219
+
220
+ After the first push the pending publisher becomes the gem's trusted
221
+ publisher.
222
+ 3. Publish the first version from Actions, not from a push: run
223
+ `release-gem.yml` on `main` with the input `rubygems-owner` set to the
224
+ numeric account id shown on the Pending Trusted Publishers page
225
+ (meganemura's is `70209`). RubyGems creates a new gem only when the
226
+ token exchange names the account that will own it. Every later
227
+ version is a push and needs no input.
228
+
229
+ ### Each gem version
230
+
231
+ 1. In `ruby/CHANGELOG.md`, move the notes under `## [Unreleased]` to a
232
+ new `## [<version>]` heading. Set the same version in
233
+ `ruby/lib/nukadoko/version.rb`, and run `bundle install` in `ruby/` so
234
+ `Gemfile.lock` names it.
235
+ 2. Commit both as `chore: release the gem <version>` and land the commit
236
+ on `main` through `queue`.
237
+ 3. Approve the `rubygems` Environment when the run asks for it.
@@ -0,0 +1,302 @@
1
+ # Ruby エンジン
2
+
3
+ > 原文は reference.md。
4
+
5
+ `nukadoko` gem で step、fixture、config をどう書くかをまとめます。
6
+ feature ファイル、claim、run、record の意味はどちらのエンジンでも同じで、[spec](../spec.ja.md) に一度だけ書いてあります。
7
+ [TypeScript エンジンのページ](../typescript/reference.ja.md) は同じ見出しを同じ順に並べているので、2 つを並べて読めます。
8
+
9
+ ## インストールとコマンド
10
+
11
+ Ruby 3.4 以降が要ります。
12
+ テスト対象のプロジェクトの Gemfile に gem を足し、`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
+ プロジェクトに `Rakefile` があれば、`init` はそこに `bundle exec nuka run` を実行する `scenarios` タスクを足します。
24
+ 人も CI も、この 1 つのコマンドを実行します。
25
+
26
+ `page` を使う step には、`playwright-ruby-client` が起動できるブラウザが要ります。
27
+
28
+ ## 設定
29
+
30
+ `nuka init` は `nukadoko.config.rb` を書きます。
31
+ このファイルは `Nukadoko.config(...)` をキーワード引数で呼び、オプションの名前は TypeScript の config と同じです。
32
+ `program` とプロジェクトの fixture はこのページの下にあります。
33
+ `envFiles:` と `secrets:` は `env` fixture のため、`browser:` はブラウザの起動オプション、`stepTimeout:` は step が動いてよい時間(ミリ秒、既定は 20 分)、`parameterTypes:` は文の途中で値を読む parameter type のためのものです。
34
+
35
+ ```ruby
36
+ Nukadoko.config(parameterTypes: [{ name: "priority", regexp: /高|低/, transformer: ->(s) { s == "高" ? "high" : "low" } }])
37
+ ```
38
+
39
+ ## step を定義する
40
+
41
+ `features/steps/` の下に、1 ファイルに 1 つの step を snake_case の名前で置きます。
42
+ step の名前は、ファイル名の `_` を `-` にしたものです(`an_item_exists.rb` は `an-item-exists`)。
43
+ ファイルは、名前を CamelCase にしたクラスを `Nukadoko::Step` を継承して定義します。
44
+
45
+ ```ruby
46
+ class AnItemExists < Nukadoko::Step
47
+ description "Create an item through the API so a later step can read it"
48
+ pattern "an item named {name:string} exists"
49
+ args { string :name, "The item's name" }
50
+ returns do
51
+ number :id, "The id the API assigned"
52
+ object :body, "The item as the API answered it" do
53
+ number :id
54
+ string :name
55
+ end
56
+ end
57
+
58
+ def run(baseURL:, args:)
59
+ res = Net::HTTP.post(URI("#{baseURL}/items"), JSON.generate(name: args.name))
60
+ raise %(creating "#{args.name}": status #{res.code.to_i}, not 201) unless res.code.to_i == 201
61
+
62
+ item = JSON.parse(res.body)
63
+ { id: item["id"], body: item }
64
+ end
65
+ end
66
+ ```
67
+
68
+ `mutates false` は、何も変えない step であることを宣言します。
69
+ `patterns` は `pattern` のあとに同じ step の別の言い方を足します。
70
+ どの言い方も同じキーをキャプチャしなければなりません(そうでなければ `alias-key-mismatch`)。
71
+ `timeout 5000` は step 自身の `run` か `observe` の時間をミリ秒で区切ります。
72
+ 過ぎると `run_command` がまだ動かしているプログラムも止まり、step は `error.kind` が `timeout` で失敗します。
73
+ 指定がなければ config の `stepTimeout` が効きます。
74
+
75
+ ```ruby
76
+ class ItemCount < Nukadoko::Step
77
+ description "Count the items the API lists"
78
+ pattern "I count the items"
79
+ patterns "the items are counted"
80
+ timeout 5000
81
+ # ...
82
+ end
83
+ ```
84
+
85
+ `requires` は行の前に成り立っている必要がある state、`gives` は行のあとに成り立つ state、`ends` は行のあとに成り立たなくなる state を名指します。
86
+ エントリは名前か、名前と、持ち主を区別する値を持つ args のキーの組です(`requires ["signed-in", :person]`)。
87
+ `nuka check` は各 scenario をこれに沿ってたどり、state なしでしか着けない行に `state-missing` を報告します。
88
+ `nuka run` はその scenario を、どの step も動かす前に断ります。
89
+ 何を宣言するかは spec の「States」に書いてあります。
90
+
91
+ `features/steps/` の下の `*.rb` は、`features/steps/lib/` の下の補助ファイルも含めてすべて読み込みます。
92
+ そのため、ファイル名どおりの名前の補助モジュールは、`require` なしでどの step からも使えます。
93
+
94
+ ## フィールドとスキーマ
95
+
96
+ `args` と `returns` は、フィールドを並べたブロックを受け取ります。
97
+ フィールドは `string`、`number`、`integer`、`boolean`、`object`、`array`、`unknown`、`table` と、リストの `strings`、`numbers`、`integers` です。
98
+ nil を許すフィールドには `null: true`、キーがなくてもよいフィールドには `optional: true`、キーがないときに読む値には `default:` を付けます。
99
+ `enum :outcome, %w[accepted refused]` は、その語だけを許します。
100
+ `min:`、`max:`、`positive: true`、`negative: true` は、数の値、文字列の長さ、配列の要素数を、zod と同じメッセージで制限します。
101
+ `nuka describe` は、各スキーマを TypeScript エンジンと同じ JSON Schema で出します。
102
+
103
+ ## キャプチャ、テーブル、doc string
104
+
105
+ pattern の `{key:type}` は、args のキー `key` を埋めます。
106
+ データテーブルは `table` のキーに、doc string は `string` として、そのキーに届きます。
107
+
108
+ ```ruby
109
+ args { table :todos, "The data table's rows, one todo per row, the title in the first cell" }
110
+ ```
111
+
112
+ ## Claims
113
+
114
+ Then の step は、`run` の代わりに `claims` と、system を読む `observe` を宣言します。
115
+ 各 claim は nukadoko が判定します([spec](../spec.ja.md#claims) の「Claims」)。
116
+ claim が比べる args のキーは、`observe` には渡りません。
117
+
118
+ `files written: { of: RunBuild, change: "added", under: "src" }` は、前の step のコマンドが加えた、変えた、消したパスを名指しします。
119
+ claim はそのキーを実際の値として読みます([spec](../spec.ja.md) の「前の step が変えたファイル」)。
120
+ 一覧はその step の record から、その step が走らせた各 `Nukadoko.run_command` から作られ、`run` が返したものからは作られません。
121
+
122
+ `events writes: { of: PlaceScore, count: { kind: "db", op: %w[insert update delete other], committed: true } }` は、前の step の実行イベントを数え、claim はそのキーを実際の値として読みます([spec](../spec.ja.md) の「実行イベントの数についての claim」)。
123
+ 数え方の値は、`table: { sentence: "table" }` のように文から取れます。
124
+ `count` の隣に `service: "billing"` を書いたキーはそのサービスの行だけを数え、サービスを名指さないキーはすべてのサービスの行を数えます。
125
+ step は claim を判定する前にその step の trace の行を読み、読んだものを record の `events_read` に残します。
126
+
127
+ ## 連鎖(`from`)
128
+
129
+ `from id: [StartJob, :id]` は、`StartJob` という step がこの scenario で先に返した値で `id` を埋めます。
130
+ `field :id, StartJob.returns[:id]` で、返す側のフィールドをそのキーに使い回せます。
131
+
132
+ ## Parts
133
+
134
+ `parts [CreateTodo, CompleteById]` は `run` が呼んでよい step を並べ、`call.(CreateTodo, title: args.title)` はその 1 つを args と returns を検査しながら実行します([spec](../spec.ja.md#parts) の「Parts」)。
135
+
136
+ ```ruby
137
+ parts [CreateTodo, CompleteById]
138
+
139
+ def run(call:, args:)
140
+ created = call.(CreateTodo, title: args.title)
141
+ completed = call.(CompleteById, id: created.id)
142
+ { id: completed.id, done: completed.done }
143
+ end
144
+ ```
145
+
146
+ ## Fixtures
147
+
148
+ config の `Nukadoko.fixture` で、プロジェクトの fixture を足します。
149
+ ブロックが値を渡して `use` を呼び、そのあとが後片付けです。
150
+ 必要な fixture はキーワード引数で挙げ、組み込みと同じ名前の fixture は、すべての step でその組み込みに置き換わります。
151
+ `scope: :process` は、1 つの environment の run 全体で 1 つの値を使い続けます。
152
+ `use` はスコープがどう終わったかを `"passed"` か `"failed"` で返すので、後片付けで失敗の跡を残せます。
153
+ 後片付けが例外を出すと `fixture-teardown-failed` の警告になり、scenario の結果は変わりません。
154
+ scenario の記録は、そのエラーを `teardown_errors` に残します。
155
+
156
+ ```ruby
157
+ Nukadoko.fixture(:page) do |use, page:|
158
+ page.add_init_script(script: "window.wrapped = 'by the project'")
159
+ use.(page)
160
+ end
161
+ ```
162
+
163
+ MCP のクライアントを作る fixture は、その transport を `Nukadoko.measure_mcp` に通します。
164
+ すると step が送るそれぞれの呼び出しが step の `mcp.jsonl` の 1 行になり、step の trace context を運びます(docs/spec.ja.md「MCP の呼び出し」)。
165
+
166
+ ```ruby
167
+ Nukadoko.fixture(:notes) do |use, base_url:|
168
+ transport = Nukadoko.measure_mcp(MCP::Client::HTTP.new(url: "#{base_url}/mcp"))
169
+ client = MCP::Client.new(transport: transport)
170
+ client.connect
171
+ use.(client)
172
+ transport.close
173
+ end
174
+ ```
175
+
176
+ ## Context
177
+
178
+ `run` と `observe` のキーワード引数が、step の必要とする fixture です。
179
+ 名前は `page`、`context`、`page_as`、`request`、`env`、`require_env`、`base_url`、`services`、`setup_result`、`scratch`、`section`、`poll`、`evidence`、`result_of`、`call` です。
180
+ `baseURL`、`requireEnv`、`pageAs`、`setupResult`、`resultOf` と TypeScript の名前で書いても、同じ fixture に届きます。
181
+ `nuka check` は本体を呼ばずに `Method#parameters` でこれを読みます([spec](../spec.ja.md#context-api) の「Context API」)。
182
+ `scratch.dir` は新しいディレクトリで、scenario が終わると消えます。
183
+ `Nukadoko.run_command` はプログラムを実行し、それを step record に残します。
184
+ その `timeout:` の単位は秒で、step の `timeout` と `poll` の `timeout_ms` がミリ秒なのとは違います。
185
+ `timeout: 120` は 2 分です。
186
+ 止めた実行には終了コードがないので、`Timeout::Error` を投げます。
187
+
188
+ ## ポーリングと待ち
189
+
190
+ Then の step の `poll timeout_ms: 3000, settled: [...]` は、続けて 2 回読んだ値ですべての claim が成り立つか、時間が切れるまで、`observe` を読み直します。
191
+
192
+ ## プログラム
193
+
194
+ テスト対象のプログラムは config の `program:` で、プログラムの起動のしかたを返す lambda です。
195
+
196
+ ```ruby
197
+ Nukadoko.config(
198
+ program: -> { { serve: { command: "bin/rails server -p {port}", ready: "/up" } } },
199
+ )
200
+ ```
201
+
202
+ フィールドは [spec](../spec.ja.md#テスト対象のプログラム) の「テスト対象のプログラム」にあります。
203
+ `serve` は `command`、`port`(既定の `"auto"` か、まだ何も応答しない番号)、`ready`(既定は `/`)、`timeout_ms`(既定は 60000)を取ります。
204
+ `ready` が `timeout_ms` のうちに 2xx を返した時点で、system の準備ができたとみなします。
205
+ コマンドは単語の Array か、空白で分ける String です。
206
+ どちらもシェルを通さないので、シェルが要るプログラムは `["sh", "-c", "..."]` と書きます。
207
+ プログラムが知らないキーは止めます。
208
+ TypeScript エンジンが読んでこのエンジンがまだ読まないキー(下)も止めます。
209
+ プログラムが起動しなかった system ではシナリオを 1 つも走らせず、実行は `program-start-failed` と system の `program.log` の終わりを示して失敗します。
210
+
211
+ system は TypeScript エンジンと同じ順に段階を進みます。
212
+ `build`(実行ごとに tree ごと 1 回、どの system よりも前に走るコマンド)、`prepare`(system ごと 1 回、その env とプレースホルダで走るコマンド)、次に `serve` か `url`(nukadoko が起動しないプログラムの URL か、それを返す lambda)、最後に `setup`(system を受け取る lambda で、`name`、`root`、`dir`、`tree`、`url`、`port`、`env`、`services`、`conditions` を持つ)です。
213
+ `setup` が返すものは JSON の値でなければならず、すべての step がそれを `setup_result` fixture として読みます。
214
+ symbol のキーを持つ hash は、文字列のキーで読み返されます。
215
+ プログラムが `stepsReach: "url"` を宣言した system の step は、サービスの URL でだけプログラムに届くので、そこでは `Nukadoko.run_command` が `Nukadoko::CommandRefused` を投げます([spec](../spec.ja.md#steps-reachstep-が届く範囲) の「Steps reach(step が届く範囲)」)。
216
+ コマンドは `{ command:, timeout_ms: }` とも書けます。
217
+ `setup` と `url` の lambda も、`timeout_ms` 付きの `{ run: }` と `{ resolve: }` で書けます。
218
+ 失敗した段階や制限時間を過ぎた段階は system を止め、その段階の名前を示します。
219
+ environment は `policy: "read-only"` を取り、mutates を宣言する step をすべて失敗にします。
220
+ `version:` は String を返す lambda で、その値は run.json とすべての記録に `target_version` として入ります。
221
+ system に値がないプレースホルダ(`serve` も `url` もない system の `{port}`、`build` の `{root}` 以外)は、`nuka check` で `program-placeholder-unfilled` になります。
222
+ `{system}` の以前の名前である `{world}` は、`program-placeholder-renamed` になります。
223
+
224
+ nukadoko が起動する system のサービスのうち `{events}` を名指すものは、run ディレクトリの外に空のファイルを 1 つずつもらい、プログラムはそこに実行イベントを書き足します。
225
+ 各 step の各サービスの行は record の隣に残り、`observed.events` の `services` にサービスごとに 1 つずつまとめられます。
226
+ system が止まると、redact した各サービスの写しがそのサービスの `program.log` の隣に入ります([spec](../spec.ja.md) の「実行イベント」)。
227
+
228
+ ## Compat steps(移行の扉)
229
+
230
+ cucumber-ruby のスイートは、step 定義とサポートファイルをそのままにして取り込めます。
231
+ `features/` の下の `.rb` ファイルはすべて、cucumber-ruby と同じ順に読み込まれます。
232
+ `features/support/env.rb`、`features/support/` の残り、そのほかのファイルの順です。
233
+ `Given`、`When`、`Then`、`And`、`But`、`Before`、`After`、`AfterStep`、`BeforeAll`、`AfterAll`、`World`、`ParameterType` は、cucumber-ruby と同じくトップレベルにあります。
234
+ 型付き step のファイルも並んで読み込まれるので、1 つのシナリオで両方を使えます。
235
+
236
+ ```ruby
237
+ World(BasketHelpers)
238
+
239
+ Before("@tagged") do
240
+ @tagged = true
241
+ end
242
+
243
+ When("I add {int} apples") do |count|
244
+ count.times { @basket << "apple" }
245
+ end
246
+
247
+ When("I add these fruits:") do |table|
248
+ table.hashes.each { |row| row["count"].to_i.times { @basket << row["name"] } }
249
+ end
250
+ ```
251
+
252
+ - compat step の名前はパターンで、`compat: <pattern>` です。
253
+ Regexp のパターンは `/.../` と書きます。
254
+ 文字列は cucumber expression で、型付き step と同じ parameter type を読みます。
255
+ step はオプションを取らず、オプションの Hash はファイルの読み込みで拒否されます。
256
+ `nuka steps` は `compat` として並べ、`nuka describe` は契約がないと言い、`nuka do` は拒否します(`compat-step-not-runnable`)。
257
+ 1 つだけ動かすには `Nukadoko::Step` に昇格させます。
258
+ - ブロックは、マッチした値を順に受け取り、そのあと行のテーブルか doc string を受け取ります。
259
+ マッチで埋まらない引数があるブロックは、cucumber-ruby と同じく step を失敗させます。
260
+ テーブルは `DataTable` で、`raw`、`rows`、`hashes`、`symbolic_hashes`、`rows_hash`、`transpose`、`cells_rows` があります。
261
+ `diff!`、`map_headers!`、`map_column!` は、中途半端に動かさず拒否します。
262
+ step record は、テーブルを生の行のまま残します。
263
+ - シナリオごとに World が 1 つあり、そのhookと compat step が共有します。
264
+ `World(Module)` はモジュールを混ぜ込み、`World { MySystem.new }` はオブジェクトを作ります。
265
+ 名前空間つきの `World` は拒否します。
266
+ インスタンス変数には包むアクセサがないので、このエンジンは World の読み書きを計測しません。
267
+ そのため compat step の record に `world` はありません。
268
+ - `step "text"` は、同じ World の上で別の compat step を動かします。
269
+ その中身は、呼んだ step の record に入ります。
270
+ Gherkin のテキストを渡す `steps` と `skip_this_scenario` は拒否します。
271
+ nukadoko には pending という結果がないので、`pending` はエラーの種類 `unsupported` で step を失敗させます。
272
+ `log` と `attach` は step record の `attachments` に入ります。
273
+ - `open_page` と `open_request` は nukadoko が計測するページとリクエストを返すので、トレース、スクリーンショット、リクエストはその step のものになります。
274
+ 使えるのは step の中だけです。
275
+ glueが自分で始めた Capybara の `page` は、トレースなしで動きます。
276
+ - `Before` と `After` はシナリオ(`name`、`source_tag_names`、`location`、`status`、`failed?`、`passed?`)を受け取り、`AfterStep` は step の結果とその行を受け取ります。
277
+ hookのタグは `@tag` か `not @tag` で、1 つのhookが挙げるタグはすべて成り立つ必要があります。
278
+ それより広い式はエラー `unsupported-hook-tag-expression` です。
279
+ 失敗した `Before` は、あとの `Before` hookを止め、すべての step を飛ばします。
280
+ `After` は逆順に、失敗のあとでも動きます。
281
+ `AfterStep` は始まった step のあとに毎回動き、その失敗は step 自身の失敗と同じくシナリオを止めます。
282
+ hookを 1 回動かすごとに、シナリオの record の `hooks` に 1 項目入ります。
283
+ hookはページを開きません。
284
+ - `BeforeAll` と `AfterAll` は、環境ごとの 1 周に 1 回、World なしで、`--concurrency` のワーカーが fork する元のプロセスで動きます。
285
+ 失敗はfinding `hook-failed` になり、失敗した `BeforeAll` のあとはシナリオを 1 つも動かしません。
286
+ - `Around`、`InstallPlugin`、`AfterConfiguration` は、ファイルの読み込みで拒否します。
287
+ 例外を出したファイルは `step-file-import-failed` で、ほかのファイルは読み込まれます。
288
+ - compat step は例外を出すかどうかで判定するので、Then の位置にあれば警告 `then-compat-step` になり、run.json はそのシナリオに `judged_by: "compat"` を付けます。
289
+
290
+ ## 型とツール
291
+
292
+ `nuka sig` は、各 step の args と returns の RBS を `sig/nukadoko/steps.rbs` に書きます。
293
+ Steep を使うと、宣言していない args のキーを読む本体や、違う形を返す本体がエラーになります。
294
+
295
+ ## このエンジンにないもの
296
+
297
+ TypeScript エンジンにあって、このエンジンにまだないものです。
298
+ spec では、その例に `<!-- engine: typescript -->` を付けています。
299
+
300
+ - Playwright Test からの扉。
301
+ JavaScript のスイートを取り込むものなので、TypeScript エンジンのものです([doors.ja.md](../typescript/doors.ja.md))。
302
+ 上の compat の扉は、TypeScript エンジンの cucumber-js からの扉を、このエンジンの形にしたものです。