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/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  The Ruby engine of [nukadoko](../README.md): typed step contracts for Gherkin, written in Ruby, so a scenario can be told wrong before it runs.
4
4
  It reads the same feature files as the TypeScript engine and must judge them the same way; the cases in [`../conformance/`](../conformance/README.md) hold it to that.
5
5
 
6
- Status: it passes every scenario under `conformance/engine/`, which runs each `nuka` command against both engines, and the ten cases in `conformance/`: HTTP steps, browser steps, command-line steps, fixtures a project defines, steps made of parts, polling Then steps, `from`, docstrings, Scenario Outlines, environments with conditions, controls with proof runs, and the verdict table. It runs `--base`, `--step`, `nuka do`, `nuka scaffold`, and `nuka init`. `nuka check` reports the pattern, position, tag, outline, `from` order, fixture, and parse findings the TypeScript engine reports, and its notes on unbound steps, unused fixtures, unused `from` keys, and scaffold descriptions. Some of what the TypeScript engine does is not here yet, such as `nuka init --allure`.
6
+ Status: it passes every scenario under `conformance/engine/`, which runs each `nuka` command against both engines, and the ten cases in `conformance/`: HTTP steps, browser steps, command-line steps, fixtures a project defines, steps made of parts, polling Then steps, `from`, docstrings, Scenario Outlines, environments with conditions, controls with proof runs, and the verdict table. It runs `--base`, `--step`, `nuka do`, `nuka scaffold`, and `nuka init`. `nuka check` reports the pattern, position, tag, outline, `from` order, fixture, and parse findings the TypeScript engine reports, and its notes on unbound steps, unused fixtures, unused `from` keys, and scaffold descriptions. Some of what the TypeScript engine does is not here yet; the Ruby section of [llms.txt](../llms.txt) lists it.
7
7
 
8
8
  ## Install
9
9
 
@@ -13,6 +13,8 @@ Add it to the Gemfile of the project under test. It needs Ruby 3.4 or later.
13
13
  gem "nukadoko", group: :test
14
14
  ```
15
15
 
16
+ **nukadoko 0.7.0 and later** bundle the skills and offer [Rails Hyperdrive](https://github.com/rails-hyperdrive/rails-hyperdrive) companion installation. For Rails apps bundling nukadoko, `bin/rails hyperdrive:init` installs them to `.claude/skills/nukadoko/SKILL.md` and `.claude/skills/nukadoko-verification/SKILL.md`.
17
+
16
18
  ## A step
17
19
 
18
20
  One step per file under `features/steps/`. The file name is the step name (`add_todo.rb` is `add-todo`).
@@ -43,13 +45,14 @@ end
43
45
  - `context` is the browser context `page` belongs to. `page_as.("aki", { javaScriptEnabled: false })` gives the page of a browser context of its own for the name, so a second person in the scenario keeps cookies of their own. A later call for the name gets the same page. Each step that calls it keeps `trace.aki.zip`, and the scenario ends with `final.aki.png`.
44
46
  - `section.("label")` marks a stage the body reached, in the record's `sections`. `poll.(description: "the order", timeout: 30_000, interval: 500) { value or nil }` calls the block until it gives a value, raises `Nukadoko::PollTimeoutError` when the time runs out, and keeps each call in `polls`. `evidence.attach(name, body)` writes a file into the step's own directory, and `evidence.path(name)` gives a path there to write to; the record lists both in `evidence.attachments`. `result_of.(MakeTotal)` reads what an earlier step of the scenario last returned, or nil.
45
47
  - `base_url:`, `require_env:`, `page_as:`, and `result_of:` are the snake_case names of `baseURL`, `requireEnv`, `pageAs`, and `resultOf`, so a body passes RuboCop's naming cops. Either name reaches the same fixture. `require_env.("KEY")` raises when the key is missing or empty, and the record lists each key asked for in `required_env`.
46
- - A Then step declares `claims` and an `observe` that reads the world. nukadoko judges the claims. `observe` does not receive an args key that a claim compares with.
48
+ - A Then step declares `claims` and an `observe` that reads the system. nukadoko judges the claims. `observe` does not receive an args key that a claim compares with.
47
49
 
48
50
  ## Commands
49
51
 
50
52
  - `nuka init` writes `nukadoko.config.rb`, the empty `features/steps/`, and the `.gitignore` entries for `.nukadoko/` and `.env` files. A Rakefile with no `scenarios` task gets one that runs `bundle exec nuka run`, so people and CI run `rake scenarios`. It refuses when the config file exists.
51
- - `nuka check [--json]` reports what is wrong before anything runs.
52
- - `nuka run [<feature[:line]|dir>...] [--tag <expression>]... [--env <name>]... [--order file|shuffled[:<seed>]] [--repeat <n>] [--concurrency <n>] [--proof-runs <n>] [--step] [--records] [--json] [--no-check]` starts the program in each selected world, runs the selected scenarios, and writes a record per step under `.nukadoko/runs/`. With no target it runs `features/`. `--order shuffled` plays the files, then each file's scenarios, in an order a seed names, the same order the TypeScript engine plays for that seed. `--repeat` plays the selection that many times, `--concurrency` spreads whole feature files over that many worker processes (a file tagged `@nukadoko:serial` on its Feature line runs alone, after them), `--proof-runs` sets how many times each control runs, and `--records` writes each scenario record to stdout as it ends.
53
+ - `nuka <command> --help` prints the command's usage, what it is for, and the flags it reads.
54
+ - `nuka check [--json] [--fail-on <code>]... [--env <name>]...` reports what is wrong before anything runs. `--fail-on` makes a finding of that code fail the check, a note included, and `nuka check --codes` lists every code with its meaning.
55
+ - `nuka run [<feature[:line]|dir>...] [--tag <expression>]... [--env <name>]... [--order file|shuffled[:<seed>]] [--repeat <n>] [--concurrency <n>] [--proof-runs <n>] [--step] [--records] [--json] [--no-check]` starts the program in each selected system, runs the selected scenarios, and writes a record per step under `.nukadoko/runs/`. With no target it runs `features/`. `--order shuffled` plays the files, then each file's scenarios, in an order a seed names, the same order the TypeScript engine plays for that seed. `--repeat` plays the selection that many times, `--concurrency` spreads whole feature files over that many worker processes (a file tagged `@nukadoko:serial` on its Feature line runs alone, after them), `--proof-runs` sets how many times each control runs, and `--records` writes each scenario record to stdout as it ends.
53
56
  - `nuka verdict [--json] [--trailer]` says whether the newest run judged the working tree as it is now and left nothing red. It never starts a run. `--trailer` prints one git trailer line that stamps a commit with that answer, and exits 0.
54
57
  - `nuka judge <feature>:<line> [--run <id>] [--json]` shows the values a run read for a criterion whose Then asks for a judgment (a `judged-as` claim). With `--meets` or `--misses`, `--by <who>`, and `--because <one sentence>` it records a judgment of them in `judgments/<feature>.json`, which the next run reads the criterion against.
55
58
  - `nuka report [run] --format markdown|messages|allure [--out <path>] [--json]` renders a run again from its run directory alone, the newest run when none is named. `markdown` is its `summary.md`. `messages` is a cucumber-messages stream, one envelope per line, so a formatter or a JUnit step that reads cucumber's protocol keeps working: a claim step's claims and each criterion's verdict ride as attachments. `allure` is a directory of Allure results, `.nukadoko/export/allure-results` unless `--out` names another: one result per execution, each claim a child step of its Then, with the history id the TypeScript engine's results of the same scenario carry.
@@ -59,9 +62,10 @@ end
59
62
  - `nuka do <step> [--args <json>] [--use <step-id>]...` runs one step outside any scenario and prints its step record. `--use` fills the step's `from` args from an earlier record, of a `do` or of a run.
60
63
  - `nuka scaffold <name> [--pattern <p>] [--then] [--description <text>] [--replace]` writes `features/steps/<name>.rb`, a step whose body raises `not implemented` until someone writes it. `nuka scaffold --feature <path>` writes one for each line no step matches, its pattern read from the line. `--command <entry point>` writes a step that runs the program under Ruby in a scratch directory and returns `exitCode`, `stdout`, and `stderr` (`--cwd <key>` runs it in the directory an args key holds, and `--argv <key>` splits one capture into its arguments). For an executable a gem installs, `bundle binstubs <gem>` writes `bin/<name>`, an entry point `--command` can run. `--request "<METHOD> <path>"` writes a step that sends one request and returns `status` and `body` (`--body <key>` sends that args key). `--from <step>.<key>` fills an args key from an earlier step's returns; with `--then` and one capture, the claim compares the two, so the step needs no edit.
61
64
  - Browser launch options go in `nukadoko.config.rb`, as `Nukadoko.config(browser: { executablePath: "..." })`. A step that names `page` gets a browser context of its own for each scenario; each step record holds the requests the page sent and a trace of the step.
62
- - A step that names `scratch` gets `scratch.dir`, a fresh directory that is removed when the scenario ends, and `scratch.copy(source)`, one that holds a copy of a file or directory of the project. A body that names no `args:` keyword is called without them. `Nukadoko.run_command(command, args, cwd:, env:, input:, timeout:, redact:)` runs a program and returns `{ exitCode:, signal:, stdout:, stderr: }`; the step record lists each run, with each `redact:` value the step holds written as `{{secret.NAME}}`. The program inherits nuka's environment, which under `bundle exec` names nuka's Gemfile; `unbundled: true` runs it with the environment from before Bundler, for a command in another Ruby project such as `bin/rails runner`.
63
- - `Nukadoko.config(envFiles: [".env"])` loads env files into the `env` fixture, and an environment of the config's `program:` adds its own `envFiles:` after them. A file git does not track, or one that differs from HEAD, is a secret source: each of its values four characters or longer is written as `{{secret.NAME}}` in every step record, `http.jsonl`, and what `nuka do` prints, and what a step prints reaches stderr with them redacted. `secrets: { public: [...], redact: [...] }` keeps one such key plain, or redacts one key of a tracked file. `nuka check` warns about a missing file, a line it skipped, and a `secrets` key no file defines, and never prints a value.
65
+ - A step that names `scratch` gets `scratch.dir`, a fresh directory that is removed when the scenario ends, and `scratch.copy(source)`, one that holds a copy of a file or directory of the project. A body that names no `args:` keyword is called without them. `Nukadoko.run_command(command, args, cwd:, env:, input:, timeout:, redact:)` runs a program and returns `{ exitCode:, signal:, stdout:, stderr: }`; the step record lists each run, with each `redact:` value the step holds written as `{{secret.NAME}}`. Its `timeout:` is in seconds, unlike the step's `timeout` and `poll`'s `timeout_ms`, which are milliseconds; a run it stops raises `Timeout::Error`, since it has no exit code. The program inherits nuka's environment, which under `bundle exec` names nuka's Gemfile; `unbundled: true` runs it with the environment from before Bundler, for a command in another Ruby project such as `bin/rails runner`.
66
+ - `Nukadoko.config(envFiles: [".env"])` loads env files into the `env` fixture, and an environment of the config's `program:` adds its own `envFiles:` after them. A file git does not track, or one that differs from HEAD, is a secret source: each of its values four characters or longer is written as `{{secret.NAME}}` in every step record, `http.jsonl`, the system's `program.log`, and what `nuka do` prints, and what a step prints reaches stderr with them redacted. `secrets: { public: [...], redact: [...] }` keeps one such key plain, or redacts one key of a tracked file. `nuka check` warns about a missing file, a line it skipped, and a `secrets` key no file defines, and never prints a value.
64
67
  - `Nukadoko.config(parameterTypes: [{ name: "priority", regexp: /高|低/, transformer: ->(s) { s == "高" ? "high" : "low" } }])` registers a parameter type, as `parameterTypes` does in the TypeScript config, so `{p:priority}` reads a value inside a sentence with no spaces around it. The regexp is a Ruby Regexp or a string, and the transformer, which may be left out, is given the groups the regexp captured. `nuka check` reports a type that takes a built-in name, one no pattern names, and a claim that compares with a capture a transformer rewrote.
68
+ - A cucumber-ruby suite comes in as it is: its step definitions and `features/support/` files load in cucumber-ruby's order, with `Given`, `When`, `Then`, `Before`, `After`, `AfterStep`, `BeforeAll`, `AfterAll`, `World`, and `ParameterType` at the top level. Each line a compat step binds runs with a step record of its own, named `compat: <pattern>`, and each step can move to a `Nukadoko::Step` on its own. A compat step has no contract, so `nuka check` warns of one in Then position (`then-compat-step`). [docs/ruby/reference.md](../docs/ruby/reference.md#compat-steps-the-migration-door) lists what the door takes and what it refuses.
65
69
  - A project fixture goes in `nukadoko.config.rb`. The block calls `use` with the value, and what follows is the teardown: `Nukadoko.fixture(:store) { |use| use.(Store.new) }`. `scope: :process` keeps one value for the whole run of an environment. A keyword argument names what the fixture needs: another project fixture, or a builtin (such as `page`, `request`, `env`, `requireEnv`, `baseURL`, `scratch`). A fixture with a builtin's name replaces it for every step, and its own `page:` is the builtin, so it can wrap it: `Nukadoko.fixture(:page) { |use, page:| page.set_default_navigation_timeout(10_000); use.(page) }`. `nuka check` refuses a `page` override that names none of `page`, `context`, and `pageAs` (`page-override-unowned`).
66
70
  - `parts [CreateTodo, CompleteById]` declares the steps a step may run, and `call.(CreateTodo, title: args.title)` runs one, with its args and returns checked. A part needs no pattern. Each call is kept under `calls` in the calling step's record. `nuka check` reports a cycle in `parts` and a `mutates false` step whose part declares `mutates true`.
67
71
  - `poll timeout_ms: 3000` reads `observe` again, 100 ms apart, until every claim holds on two readings in a row or the time runs out. `settled:` names a state that cannot change once reached, so two settled readings in a row stop the wait for a claim that broke. Every reading is kept in the step record.
@@ -78,6 +82,8 @@ Nukadoko.config(
78
82
  )
79
83
  ```
80
84
 
85
+ The system is ready once `ready` answers 2xx within `timeout_ms` (default 60000). The command is split on whitespace and never goes through a shell; [docs/ruby/reference.md](../docs/ruby/reference.md#program) has every field.
86
+
81
87
  ## Development
82
88
 
83
89
  - `bundle install` in this directory.
data/docs/ci.ja.md ADDED
@@ -0,0 +1,542 @@
1
+ # CI で nukadoko を実行する
2
+
3
+ これはレシピであって要件ではありません。
4
+ `nuka check` と `nuka run` は普通の CLI コマンドで、すべてが保たれていれば `0` で終了し、何かが壊れた瞬間に非ゼロで終了します([README.md](../README.ja.md#running-this-in-ci) と [docs/spec.ja.md](spec.ja.md#cli-summary) の「CLI summary」を参照)。
5
+ だからどの CI システムからでも呼び出せます。
6
+ このページが埋めるのは 2 行の抜粋には書けないものです。
7
+ すなわち、丸ごと 2 つの workflow ファイル(CLI や API のプロジェクトのための 1 つの job と、ブラウザのプロジェクトの workflow)、CircleCI の config にした Ruby のブラウザの workflow、そのうち 3 行が存在する理由、そして `npx playwright test` から来たプロジェクトが自分の手で足す必要があり、`nuka run` が自分では決してやらない 4 つのことです。
8
+
9
+ ## CLI や API のプロジェクト: job は 1 つ
10
+
11
+ `nuka init` で準備したプロジェクトには、`nuka run` を実行するコマンドが既に 1 つあります。
12
+ Ruby のプロジェクトでは `Rakefile` の `scenarios` タスク、TypeScript のプロジェクトでは `package.json` の `test:scenarios` スクリプトです。
13
+ 対象を渡さない `nuka run` は `featuresDir` を実行します。
14
+ 何かを実行する前に、その scenario について `nuka check` が報告する内容を報告し、error が 1 つでもあれば何も実行せずに `2` で終了します。
15
+ 失敗した scenario があれば `1` で終了します。
16
+ この 2 つを区別する必要がある job の step は `$?` を読みます。
17
+ `2` は、実行できるようになる前に呼び出し方か suite を直すこと(不正なフラグ、不正な config、存在しない対象、`check` のエラー)を意味します。
18
+ `1` は、実行されて何かが red になったことを意味します。
19
+ そのため、step がブラウザを開かないプロジェクトでは、1 つの job がゲートのすべてです。
20
+
21
+ <!-- engine: ruby -->
22
+ ```yaml
23
+ jobs:
24
+ scenarios:
25
+ runs-on: ubuntu-latest
26
+ permissions:
27
+ contents: read
28
+ steps:
29
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
30
+ - uses: ruby/setup-ruby@b3aaceaef7e0ee231b499e7b5f49c03fc1d32199 # v1.338.0
31
+ with:
32
+ ruby-version: "3.4"
33
+ bundler-cache: true
34
+ # The Rakefile's `scenarios` task; `bundle exec nuka run` when the
35
+ # project has no such task.
36
+ - run: bundle exec rake scenarios
37
+ ```
38
+
39
+ <!-- engine: typescript -->
40
+ ```yaml
41
+ jobs:
42
+ scenarios:
43
+ runs-on: ubuntu-latest
44
+ permissions:
45
+ contents: read
46
+ steps:
47
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
48
+ - uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
49
+ with:
50
+ node-version: 24
51
+ - run: npm ci --ignore-scripts
52
+ - run: npm run test:scenarios
53
+ ```
54
+
55
+ `node-version` には nukadoko が動くどのリリースでも指定できます。
56
+ 22 系なら 22.18 以降、それ以外は 23.6 以降で、フラグなしで `.ts` ファイルを読み込めるリリースです。
57
+ これらのファイルでは長期サポートの系列である 24 を使います。
58
+ `ruby-version` には、gem が動く 3.4 以降のリリースを指定できます。
59
+ `bundler-cache: true` は `bundle install` を実行し、インストールした gem を workflow の実行をまたいでキャッシュします。
60
+
61
+ ここではブラウザも Playwright 自体もインストールしません。
62
+ Ruby の job は Node をまったく必要としません。
63
+ gem の `request` fixture は Playwright を使わずにリクエストを送るからです。
64
+ TypeScript の job では、`playwright` は nukadoko の optional な peer dependency なので、`npm ci` がそれを入れるのは、自分の `devDependencies` にそれを書いたプロジェクトだけです。
65
+ それを書いていないプロジェクトにそれを必要とする step があれば、この job はどの scenario も実行する前に、check で `playwright-missing` として止まります。
66
+
67
+ 単独の `nuka check` には、まだ 2 つの使い道があります。
68
+ 1 つは `additionalFeatureDirs` で、これを辿るのは `nuka check` だけです。
69
+ もう 1 つは、run が数秒で終わらないときにも数秒で終わらなければならないゲートです。
70
+ このゲートは run と同じ対象、つまりファイルやディレクトリ(`nuka check features/checkout`)を受け、それについて run が止まるはずの error を報告します。
71
+
72
+ ## ブラウザのプロジェクト: そのままコピーできる workflow
73
+
74
+ これは 1 つのファイル、`.github/workflows/nukadoko.yml` です。
75
+ すべての push と pull request で `nuka check` を実行し(数秒、ブラウザ不要)、それが通ったら `nuka run` を実行します(実際に実行するゲート)。
76
+ pull request では、pull request の基点に対して `nuka run --base` を実行するので、run は変更が各受け入れ基準に何をしたかを断定します。
77
+ 対象を指定しない `nuka check` は、壊れているものではなく腐りつつあるものについての注記も出力します。
78
+ 注記は、`--fail-on` がその code を名指さない限り job を失敗させません。
79
+ 2 つのコマンドを 2 つの job に分けているので、check が失敗すればブラウザをインストールする前に止まります。
80
+ `nuka run` も実行の前に自分の scenario を改めて check します。
81
+ その費用は step の discovery 1 回分で、ブラウザは要りません。
82
+
83
+ ブラウザのプロジェクトは、nukadoko がテストしているバージョンの `playwright` を自分の `devDependencies` に書きます(`npm install -D -E playwright@1.63.0`)。
84
+ nukadoko はそれを optional な peer dependency として宣言しており、インストールはしません。
85
+ すると下の `npm ci` の行がどの job でもそのパッケージを入れ、ブラウザをダウンロードするのは `run` job だけです。
86
+
87
+ Ruby のブラウザのプロジェクトにも Node が要ります。
88
+ ただし要るのは `run` job だけです。
89
+ gem は依存する `playwright-ruby-client` を通してブラウザを動かし、このクライアントは Node の `playwright` パッケージの driver を、既定では `npx playwright` で起動します。
90
+ プロジェクトは自分の `package.json` に同じバージョンの `playwright` を書きます(`package.json` の無いプロジェクトでは、同じ `npm install` がそれを書きます)。
91
+ `run` job は Node を準備してそのパッケージを入れ、Ruby エンジンが起動する唯一のブラウザである Chromium をインストールします。
92
+ `check` job に要るのは Ruby だけです。
93
+ Ruby エンジンの `nuka check` はそのパッケージを探さないからです。
94
+ Ruby エンジンは `$GITHUB_STEP_SUMMARY` に書かないので、Ruby の `run` job は最後の step で、`nuka report --format markdown` を使ってサマリをそこへ書きます。
95
+
96
+ <!-- engine: ruby -->
97
+ ```yaml
98
+ name: nukadoko
99
+
100
+ on:
101
+ push:
102
+ branches: [main]
103
+ pull_request:
104
+
105
+ jobs:
106
+ check:
107
+ runs-on: ubuntu-latest
108
+ permissions:
109
+ contents: read
110
+ steps:
111
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
112
+ - uses: ruby/setup-ruby@b3aaceaef7e0ee231b499e7b5f49c03fc1d32199 # v1.338.0
113
+ with:
114
+ ruby-version: "3.4"
115
+ bundler-cache: true
116
+ # PR gate: static, seconds, no browser and no Node. Put this on
117
+ # every PR; it can fail before anything runs. Its notes (what is
118
+ # rotting rather than what is broken) leave the exit code alone; add
119
+ # `--fail-on <code>` for each note the team has agreed to gate on.
120
+ - run: bundle exec nuka check
121
+
122
+ run:
123
+ needs: check
124
+ runs-on: ubuntu-latest
125
+ permissions:
126
+ contents: read
127
+ steps:
128
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
129
+ - uses: ruby/setup-ruby@b3aaceaef7e0ee231b499e7b5f49c03fc1d32199 # v1.338.0
130
+ with:
131
+ ruby-version: "3.4"
132
+ bundler-cache: true
133
+ # The gem drives the browser through playwright-ruby-client, which
134
+ # starts the driver of the Node `playwright` package with
135
+ # `npx playwright`. These two lines bring in Node and that package,
136
+ # at the version the project's own package.json pins.
137
+ - uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
138
+ with:
139
+ node-version: 24
140
+ - run: npm ci --ignore-scripts
141
+ # `nuka run` opens a browser; install it here, not on the `check`
142
+ # job above, which never launches one. The Ruby engine launches
143
+ # Chromium only. `--with-deps` is a Linux-runner requirement: without
144
+ # it, Playwright's own browser binary is present but missing the
145
+ # system libraries it needs to actually launch.
146
+ - run: npx playwright install --with-deps chromium
147
+ # No step starts the app under test: `nuka run` builds and starts
148
+ # it from the program in nukadoko.config.rb, on a port of its own,
149
+ # waits until its ready path answers, and stops it after the
150
+ # scenarios (docs/spec.md "Program").
151
+ # Merge/deploy gate: executes, writes step records.
152
+ - if: github.event_name != 'pull_request'
153
+ run: bundle exec nuka run features/
154
+ # On a pull request, compare with its base (docs/spec.md
155
+ # "Verdicts"). The checkout is shallow, so fetch the base's one
156
+ # commit first. The branch name goes through env, never straight
157
+ # into the script.
158
+ - if: github.event_name == 'pull_request'
159
+ env:
160
+ BASE_REF: ${{ github.base_ref }}
161
+ run: |
162
+ git fetch --no-tags --depth=1 origin "$BASE_REF:refs/remotes/origin/$BASE_REF"
163
+ bundle exec nuka run features/ --base "origin/$BASE_REF"
164
+ # The Ruby engine does not append to $GITHUB_STEP_SUMMARY, so this
165
+ # step puts the newest run's Markdown summary on this job's summary
166
+ # page, a red run's too.
167
+ - if: always()
168
+ run: bundle exec nuka report --format markdown >> "$GITHUB_STEP_SUMMARY"
169
+ ```
170
+
171
+ <!-- engine: typescript -->
172
+ ```yaml
173
+ name: nukadoko
174
+
175
+ on:
176
+ push:
177
+ branches: [main]
178
+ pull_request:
179
+
180
+ jobs:
181
+ check:
182
+ runs-on: ubuntu-latest
183
+ permissions:
184
+ contents: read
185
+ steps:
186
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
187
+ - uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
188
+ with:
189
+ node-version: 24
190
+ - run: npm ci --ignore-scripts
191
+ # PR gate: static, seconds, no browser. Put this on every PR; it can
192
+ # fail before anything runs. Its notes (what is rotting rather than
193
+ # what is broken) leave the exit code alone; add `--fail-on <code>`
194
+ # for each note the team has agreed to gate on.
195
+ - run: npx nuka check
196
+
197
+ run:
198
+ needs: check
199
+ runs-on: ubuntu-latest
200
+ permissions:
201
+ contents: read
202
+ steps:
203
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
204
+ - uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
205
+ with:
206
+ node-version: 24
207
+ - run: npm ci --ignore-scripts
208
+ # `nuka run` opens a browser; install it here, not on the `check`
209
+ # job above, which never launches one. `chromium` is
210
+ # `browserType`'s own default (docs/spec.md "Environments and
211
+ # secrets"); add `firefox`/`webkit` too if `browserType` names one
212
+ # of them. `--with-deps` is a Linux-runner requirement: without it,
213
+ # Playwright's own browser binary is present but missing the system
214
+ # libraries it needs to actually launch.
215
+ - run: npx playwright install --with-deps chromium
216
+ # No step starts the app under test: `nuka run` builds and starts
217
+ # it from the program in nukadoko.config.ts, on a port of its own, waits until its
218
+ # ready path answers, and stops it after the scenarios
219
+ # (docs/spec.md "Program"). `nuka run` never reads
220
+ # playwright.config.ts, so its `webServer` field starts nothing.
221
+ # Merge/deploy gate: executes, writes step records. Its Markdown
222
+ # run summary appears on this job's summary page by itself, since
223
+ # `nuka run` appends to $GITHUB_STEP_SUMMARY whenever it is set.
224
+ - if: github.event_name != 'pull_request'
225
+ run: npx nuka run features/
226
+ # On a pull request, compare with its base (docs/spec.md
227
+ # "Verdicts"). The checkout is shallow, so fetch the base's one
228
+ # commit first. The branch name goes through env, never straight
229
+ # into the script.
230
+ - if: github.event_name == 'pull_request'
231
+ env:
232
+ BASE_REF: ${{ github.base_ref }}
233
+ run: |
234
+ git fetch --no-tags --depth=1 origin "$BASE_REF:refs/remotes/origin/$BASE_REF"
235
+ npx nuka run features/ --base "origin/$BASE_REF"
236
+ ```
237
+
238
+ `pull_request` イベントでは、checkout はブランチと基点のブランチの先端から GitHub が作った merge コミットです。
239
+ そのため `origin/<base branch>` と比べると、pull request が変えたものをちょうど比べます。
240
+ そのような merge コミットではない checkout(手元のマシンや `push` イベントで、ブランチをそのまま checkout したもの)は、代わりに merge base と比べます。
241
+ `nuka run --base "$(git merge-base HEAD origin/main)"` です。
242
+ ブランチを始めてから先へ進んだ基点のブランチの先端と比べると、そこで足された受け入れ基準は `removed` と読まれ、そこで変わった受け入れ基準はブランチが変えたものと読まれます。
243
+ ブランチがどちらにも触れていなくても、そう読まれます。
244
+ 新しいか変わった受け入れ基準は基点のコードに対しても走り、run はそれを基点自身の config から、run ディレクトリの下の tree で build します。
245
+ 変わっていない受け入れ基準は、step が変わったとき基点の step のもとで走ります。
246
+ そのため job には基点の build に要るものが必要です。
247
+ TypeScript では、基点はこの checkout の `node_modules` からパッケージを解決します。
248
+ base や old の system を要する行だけがそこで走るので、増える時間は 1 回の build と変わった scenario、そして step ファイルが変わったときは変わっていないすべての scenario です。
249
+ fetch が無ければ、`nuka run` は `base-shallow` で拒否し、同じ `git fetch` を `do:` の行に出します。
250
+
251
+ ## 上の workflow が action を固定し、インストールスクリプトを止め、権限を絞る理由
252
+
253
+ 2026 年 8 月、広く使われている npm パッケージ群が複数、侵害されました。
254
+ 攻撃の経路は `package.json` の `preinstall` フックから始まりました。
255
+ これは `npm install` を実行した瞬間に npm が自動で実行するもので、誰もそのパッケージ自身のコードを 1 行も読まないうちに動きます。
256
+ このフックは 200 を超えるファイルパスを走査して、AWS の認証情報、GitHub の個人アクセストークン、npm のトークン、SSH 鍵を探し、見つけたものをプロジェクトの外のサーバへ送りました。
257
+ 盗んだ GitHub トークンを使って、同じ攻撃はさらに `.github/workflows/` へ workflow を注入しました。
258
+ その workflow は `toJSON(secrets)` でリポジトリのシークレットをすべて読み、その結果をビルドの artifact へ書き込むものでした。
259
+
260
+ 上の workflow の 3 行が、その経路の 3 つの部分にそれぞれ答えます。
261
+
262
+ - **`uses:` はタグではなくコミットを名指しします。**
263
+ `@v4` のようなタグは動きます。
264
+ 侵害されたメンテナのアカウントは、読み手が workflow ファイルで目にする文字列を変えないまま、そのタグを別のコードへ付け替えられます。
265
+ コミット SHA は同じようには動かないので、上の workflow は SHA を名指しています。
266
+ 上の 2 つの SHA は、この文章を書いている時点でそれぞれの action の最新リリースでもあります(`checkout` は v7.0.1、`setup-node` は v7.0.0)。
267
+ これはこのファイルが以前に使っていた `v4` の系列から 3 メジャー先で、固定をやり直すこの機会がそこへ移る潮時でした。
268
+ SHA へ固定することは、動くタグが運んでいた自動の更新と引き換えです。
269
+ ここに書かれたものは自分からピンを進めません。
270
+ 誰かが手で進めるか、そのために作られた道具に進めさせる必要があります。
271
+ Dependabot は SHA のピンを更新できます。
272
+ それはいくつかある選択肢の 1 つであって、このレシピが求めるものではありません。
273
+ Ruby の job も `ruby/setup-ruby` を同じように、このリポジトリ自身の CI が使うリリースである v1.338.0 のコミットに固定します。
274
+ - **`npm ci --ignore-scripts` は上の攻撃が使ったフックを止めます。**
275
+ このリポジトリ自身の `.npmrc` はすでに `ignore-scripts=true` を設定しているので、CI の行に無くてもこの効果はすでにここで効いています。
276
+ それでもこのフラグを行そのものに書くのは、このレシピを別のプロジェクトへコピーする読み手が持っていくのが YAML であって、このリポジトリの `.npmrc` ではないからです。
277
+ 行そのものにフラグが無ければ、そのプロジェクトはすべての依存のインストールスクリプトを既定で実行します。
278
+ それは上の攻撃が頼った、まさにその既定です。
279
+ Ruby の workflow では、Playwright の driver を入れる `run` job の `npm ci` の行が、同じ理由でこのフラグを持ちます。
280
+ - **`permissions: contents: read` は job の中のトークンにできることを絞ります。**
281
+ step が GitHub 自身のトークンで何をできるかは `permissions:` ブロックが決めるものであって、その場その場で決まるものではありません。
282
+ job レベルの `permissions: contents: read` はそのトークンをリポジトリの内容を読むことだけに絞るので、すでに侵害された step であっても、それを使ってコミットを push したり新しい workflow ファイルを書いたりはできません。
283
+ このリポジトリ自身の既定の workflow permission はすでに `read` で、リポジトリのシークレットも 0 件です。
284
+ ですが、このレシピをコピーする読み手が持っていくのは YAML であって、このリポジトリのアカウントレベルの設定ではありません。
285
+ 既定が違うリポジトリでは、同じ行をファイル自身に書き込む必要があります。
286
+
287
+ ## `npx playwright test` に対してこれが加える 4 つのこと
288
+
289
+ すでに動いている Playwright Test の CI 構成から来たチームは、上の大部分をすでに持っています。
290
+ 変わるのはこの 4 つです。
291
+
292
+ - **ブラウザのインストール行がエンジンを名指しします。**
293
+ 新しいランナー上で `npx playwright test` は `npx playwright install --with-deps` だけで済みます。
294
+ Playwright 自身が、どのブラウザをインストールするかをプロジェクト自身の `playwright.config.ts` から読むからです。
295
+ nukadoko には読み込む先の `playwright.config.ts` がありません。
296
+ 代わりに `nukadoko.config.ts` の `browserType` がエンジンを選びます(既定は `"chromium"`)。
297
+ だから上のインストールコマンドはそれを明示的に名指しています。
298
+ firefox と webkit もそれぞれ自分自身のバイナリを必要とします(docs/spec.ja.md の「Environment、secret」を参照)。
299
+ `browserType`(や、それを渡り歩く test matrix)が実際に必要とするものを足してください。
300
+ Ruby エンジンは `browserType` を読まず、Chromium だけを起動します。
301
+ だからそのインストール行は `chromium` だけを名指します。
302
+ - **テスト対象のアプリは `webServer` ではなく config のプログラムから起動します。**
303
+ `nuka run` と `nuka do` は `playwright.config.ts` を一切読みません([docs/typescript/migration-playwright-test.ja.md](typescript/migration-playwright-test.ja.md) を参照)。
304
+ だからその `webServer` フィールドは何も起動しません。
305
+ その役目はプログラムの `build`、`prepare`、`serve` が果たします。
306
+ 起動しなかったプログラムは、`page` や `request` に触れる最初の step の `ECONNREFUSED` ではなく、`program-start-failed` とログの末尾で run を失敗させます(docs/spec.ja.md の「テスト対象のプログラム」を参照)。
307
+ - **run が残すものには上限があり、それ以外にはありません。**
308
+ `nuka run` は最新 `retention.runs` 回分の run を保ち、それより古い run を毎回の run の終わりに自分で消します(docs/spec.ja.md の「成果物」を参照)。
309
+ だから永続するランナーでも、`.nukadoko/runs/` と export の出力はその回数ぶんの大きさに留まります。
310
+ 決して消さないのは、nukadoko が run ごとのファイル一覧を残すようになる前に書かれた `allure-results/` です。
311
+ GitHub がホストするランナーはジョブごとに新しい仮想マシンなので、そこでは問題になりません。
312
+ セルフホストや、それ以外の理由で永続するランナーでは、それに対して手当てが 2 つあります。
313
+ ジョブの先頭で `rm -rf .nukadoko` するか、`nuka clean`(自身の `--help` を参照)を叩くかです。
314
+ 後者は同じことをより狭く行います。
315
+
316
+ ## チームがその上に足すもの
317
+
318
+ 上の workflow がチームに委ねているものが 5 つあります。
319
+ どれも小さいものです。
320
+
321
+ - **pull request のコメントとしての run サマリ。**
322
+ ジョブのサマリページにはすでに表示されますが、レビュアーが読むのは pull request です。
323
+ 差分の中の feature と、その横のサマリを読みます。
324
+ サマリは、その commit で何が走ったかの証跡です。
325
+ 上の `--base` の run からは、pull request の基点に対して各受け入れ基準がどうなったかも分かります。
326
+ 承認をどこに記録するか(pull request のレビューなど)はチームのプロセスで、nukadoko が記録するのは証跡であり承認ではありません(docs/spec.ja.md の「レビュー」を参照)。
327
+ `nuka report --format markdown --out <path>` は最新の run の同じ Markdown をファイルに書き、もう 1 つの step がそれを投稿します。
328
+
329
+ <!-- engine: ruby -->
330
+ ```yaml
331
+ # in the `run` job, which then needs `pull-requests: write` beside
332
+ # `contents: read`, after its `nuka run` steps
333
+ - run: bundle exec nuka report --format markdown --out nukadoko-summary.md
334
+ if: always()
335
+ - name: Comment the run summary on the pull request
336
+ if: always() && github.event_name == 'pull_request' && hashFiles('nukadoko-summary.md') != ''
337
+ env:
338
+ GH_TOKEN: ${{ github.token }}
339
+ run: >-
340
+ gh pr comment ${{ github.event.pull_request.number }}
341
+ --body-file nukadoko-summary.md --edit-last --create-if-none
342
+ ```
343
+
344
+ <!-- engine: typescript -->
345
+ ```yaml
346
+ # in the `run` job, which then needs `pull-requests: write` beside
347
+ # `contents: read`, after its `nuka run` steps
348
+ - run: npx nuka report --format markdown --out nukadoko-summary.md
349
+ if: always()
350
+ - name: Comment the run summary on the pull request
351
+ if: always() && github.event_name == 'pull_request' && hashFiles('nukadoko-summary.md') != ''
352
+ env:
353
+ GH_TOKEN: ${{ github.token }}
354
+ run: >-
355
+ gh pr comment ${{ github.event.pull_request.number }}
356
+ --body-file nukadoko-summary.md --edit-last --create-if-none
357
+ ```
358
+
359
+ `if: always()` があるのは、レビュアーが最も読む必要があるのが赤い run だからです。
360
+ `--edit-last` は、push のたびにコメントを足すのではなく、前の push が残したコメントを更新します。
361
+ どのサマリも `<!-- nukadoko:run -->` という行で始まるので、ほかのコメントも投稿する step は、代わりにこの目印でこのコメントを見つけられます。
362
+ サマリは何が走ったかを名指しします。
363
+ 断定の表(受け入れ基準ごとに 1 行で、その断定と environment ごとのセルを持ちます)、コミット、environment、ブラウザ、失敗した step のエラーの 1 行目(secret はすでに伏せてあります)、そしてそれを再実行するコマンドです(docs/spec.ja.md の「Records」を参照)。
364
+ サマリの `seen` のリンクは、run のディレクトリからの相対パスです。
365
+ リンク先は、Then が読んだ各ページを claim を判定した読み取りの直後に撮ったスクリーンショット、またはページを読まない Then が送ったリクエストです。
366
+ GitHub はそれを run のディレクトリではなく自分の URL に対して解決するので、ジョブのサマリページとこのコメントでは、どこにもつながりません。
367
+ それでも各リンクの行き先は `steps/<id>/judged/page.png` のような run のディレクトリの中のパスで終わるので、レビュアーはアップロードした run のディレクトリ(次の項目)でそれを開きます。
368
+ 代償は `pull-requests: write` の権限です。
369
+ suite を走らせるジョブが pull request に書き込めるようになります。
370
+ fork からの pull request は読み取り専用のトークンを受け取るので、そこではこの step は失敗します。
371
+ fork からの pull request を受け付けるチームは、この step を別のジョブに移します。
372
+ - **build artifact としての run ディレクトリ。**
373
+ 1 回の `nuka run` が計測したものは、すべて 1 つのディレクトリ `.nukadoko/runs/<run_id>/` にあります。
374
+ `run.json`、`summary.md`、そして trace、screenshot、`http.jsonl` を持つ各 step record です(docs/spec.ja.md の「State directory」を参照)。
375
+ `run.json` の中のパスはそのディレクトリからの相対パスなので、ダウンロードした写しもランナーの上のものと同じように読めます。
376
+ `run` ジョブにもう 1 つ step を足すと、それをアップロードできます。
377
+
378
+ ```yaml
379
+ - name: Upload the run directory
380
+ if: always()
381
+ uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
382
+ with:
383
+ name: nukadoko-runs
384
+ path: .nukadoko/runs/
385
+ # `.nukadoko` starts with a dot, and upload-artifact skips every
386
+ # file inside such a directory unless this is set.
387
+ include-hidden-files: true
388
+ if-no-files-found: ignore
389
+ retention-days: 14
390
+ ```
391
+
392
+ `if: always()` があるのは、コメントの step と同じ理由です。
393
+ 誰かがダウンロードするのは赤い run です。
394
+ GitHub がホストするランナーでは、このディレクトリはこのジョブの run だけを持ちます。
395
+ 永続するランナーでは、retention が保ったすべての run を持ちます。
396
+ 展開したディレクトリの `summary.md` では、`seen` のリンクが開けます。
397
+ どれも隣にあるファイルを指すからです。
398
+ `nuka do` の record は、その外の `.nukadoko/do/` にあります。
399
+ CI のジョブは `nuka do` を走らせないからです。
400
+ trace はブラウザの cookie を持ち、screenshot は画面に出ていたものを持つので、最初のアップロードの前に誰が artifact を開いてよいかを決めてください(下の「このページが主張しないこと」を参照)。
401
+ - **run の結果に基づいて動くスクリプト。**
402
+ 失敗した scenario ごとに issue を作る step や、それらを再実行する step は、stderr ではなく `run.json` を読みます。
403
+ `nuka run features/ --json > run.json` がそれを出力し、run はどちらの場合も同じファイルを `.nukadoko/runs/<run_id>/run.json` に書きます。
404
+ その `scenarios` のエントリは、各 scenario の status と、行、status、step record、エラーを持つ step を持ち、失敗した scenario はそれを再実行する `do` コマンドを持ちます(docs/spec.ja.md の「Scenario(スクリプト化された経路)」を参照)。
405
+ その `table` は、受け入れ基準ごとの断定(`held`、`proven`、`failed`)とその理由を持ちます(docs/spec.ja.md の「断定」を参照)。
406
+ - **matrix ではなく 1 つの job で、機能のスイッチの両側。**
407
+ フラグの値ごとに同じ job を走らせていたスイート(`CHECKOUT_V2: ["", "1"]` に対する `strategy.matrix`)は、代わりに各値を config のプログラムの environment として宣言し、その側を `conditions` に名指します(docs/spec.ja.md の「断定」を参照)。
408
+ step は `nuka run features/` のままです。
409
+ `--env` の無い run がそれらの environment をそれぞれ 1 つの job の 1 回の run で走らせ、サマリの表が各 scenario を両側で示します。
410
+ `@with:checkout_v2` の tag を付けた scenario は、フラグが入っているところで必須、切れているところで対照で、そこで Then が成り立たなければ、その行は `proven` です。
411
+ 2 つの job が言えるのは、それぞれの側が green だったことです。
412
+ 1 回の run は、scenario が 2 つを見分けたことを言えます。
413
+ job は、対照が赤にすることのない `nuka run` の終了コードでゲートします。
414
+ `nuka report --format messages` から作る JUnit のレポートは対照を外すので、対照がそれを赤にすることもありません。
415
+ ただし `--base` のもとでは `unproven` や `moved` の行を失敗として示さないので、ゲートにはなりません。
416
+ Allure のレポートは、失敗した対照を `<scenario> (control)` という名前の失敗した result として、設計どおり示します。
417
+ その失敗こそが証明だからです。
418
+ - **ランナー自身の速さに合わせた `retention.runs`。**
419
+ 既定は最新 20 回の run を残します。
420
+ merge のたびと毎晩に走る永続ランナーは数日で 20 に達し、`nuka report` と `nuka do --use` は保持された run しか読みません。
421
+ 数字を決める前に、1 週間の速さを測ってください。
422
+
423
+ ## CircleCI での Ruby のプロジェクト
424
+
425
+ 上のブラウザの workflow を、`nukadoko.config.rb` に program を持つ Ruby のプロジェクトのための 1 つの `.circleci/config.yml` にしたものです。
426
+ job は 1 つです。
427
+ `nuka check` はブラウザをインストールするどの step よりも先に走り、error があれば `1` で終了して、そこで job を止めます。
428
+ `nuka run` は、scenario か受け入れ基準が失敗すると `1` で、拒否して何も実行しなかったときは `2` で終了します。
429
+ CircleCI は `0` 以外の終了で job を失敗にします。
430
+
431
+ <!-- engine: ruby -->
432
+ ```yaml
433
+ version: 2.1
434
+
435
+ jobs:
436
+ scenarios:
437
+ docker:
438
+ # cimg/ruby:3.4.13-node, named by its digest
439
+ - image: cimg/ruby@sha256:2b3e8e5d16b1e1f223977665a939b192f96b08318e201a47cd97f041d0924398
440
+ steps:
441
+ # A full clone: the default blobless clone leaves out the files of
442
+ # older commits, and `--base` builds the base commit's tree.
443
+ - checkout:
444
+ method: full
445
+ - run: bundle install
446
+ # A step reads secrets from env files only, never from the job's
447
+ # environment. `envFiles` names this file and .gitignore lists it,
448
+ # so every value in it is redacted from the records. The single
449
+ # quotes keep a `#` in a value.
450
+ - run: printf "API_KEY='%s'\n" "$API_KEY" > .env.ci
451
+ # Static, seconds, no browser: an error stops the job here.
452
+ - run: bundle exec nuka check
453
+ # playwright-ruby-client starts the driver of the Node `playwright`
454
+ # package with `npx playwright`, at the version package.json pins.
455
+ # The Ruby engine launches Chromium only.
456
+ - run: npm ci --ignore-scripts
457
+ - run: npx playwright install --with-deps chromium
458
+ # `nuka run` starts the program in nukadoko.config.rb itself. On a
459
+ # branch, it compares each criterion with where the branch left main.
460
+ - run: |
461
+ if [ "$CIRCLE_BRANCH" = main ]; then
462
+ bundle exec nuka run features/
463
+ else
464
+ git fetch --no-tags origin "main:refs/remotes/origin/main"
465
+ bundle exec nuka run features/ --base "$(git merge-base HEAD origin/main)"
466
+ fi
467
+ # store_artifacts runs after a failed step too: a red run is the one
468
+ # somebody opens.
469
+ - store_artifacts:
470
+ path: .nukadoko/runs
471
+ destination: nukadoko-runs
472
+
473
+ workflows:
474
+ nukadoko:
475
+ jobs:
476
+ - scenarios:
477
+ context: nukadoko-secrets
478
+ ```
479
+
480
+ - **image はダイジェストで名指しします。**
481
+ cimg のタグは付け替えられることがあります。
482
+ `3.4` は 2026-11-19 に新しいビルドへ移りました。
483
+ ダイジェストは動きません。
484
+ GitHub の workflow がタグではなくコミットを名指しするのと同じ理由です。
485
+ `-node` の版には、Playwright の driver が動く Node が入っています。
486
+ この config は orb を使いません。
487
+ orb はリポジトリの外から来て job の中で動くコードで、上の step はどれもそれを必要としないからです。
488
+ - **secret は context かプロジェクトの環境変数から、env file を通して渡します。**
489
+ `env` fixture はプロセスの環境変数を決して読みません([docs/spec.ja.md](spec.ja.md#environmentsecret) の「Environment、secret」を参照)。
490
+ そのため job は、step が読む値を env file に書き出します。
491
+ config がそのファイルを `Nukadoko.config(envFiles: [".env.ci"], program: ...)` のように名指しし、`.gitignore` がそれを載せます。
492
+ 無視される env file は secret の出どころなので、その中の値はすべて記録から伏せられます。
493
+ プログラムは job の環境変数をそのまま受け取ります([env](spec.ja.md#env))。
494
+ - **`--base` は merge base と比べます。**
495
+ CircleCI はブランチを merge コミットとしてではなく、そのまま checkout します。
496
+ そのため run は、上の `push` イベントのときと同じく、ブランチが `main` から分かれたコミットと比べます。
497
+ pull request の merge 先のブランチを `main` の代わりに書いてください。
498
+ - **run ディレクトリが artifact です。**
499
+ `.nukadoko/runs/<run_id>/` は、`run.json`、run サマリの `summary.md`、そして trace を持つ各 step record を持ちます。
500
+ Ruby エンジンはサマリをそこにしか書きません。
501
+ trace は伏せられません(次の節を参照)。
502
+
503
+ ## このページが主張しないこと
504
+
505
+ 上のどの workflow も、GitHub Actions の中で実際に実行してはいません。
506
+ このリポジトリの中では、それを実行する手段が無いからです。
507
+ 代わりに確かめたのは次のことです。
508
+ `npm run test:scenarios` は、本パッケージの tarball を新しくインストールした CLI のプロジェクトで、green と red の両方を実行しました。
509
+ この YAML は妥当な YAML としてパースできること、そして TypeScript の workflow にある `nuka` コマンドはすべて(上で使っているディレクトリ形式の `nuka run features/` も、1 つの feature ファイルだけでなく)、実際に `npm install` した本パッケージのコピーに対して実行したことです。
510
+ Ruby の workflow については、このリポジトリの `ruby/` ディレクトリから作った gem を Gemfile の `path:` で入れ、CLI のプロジェクトで `rake scenarios` を green と red の両方で実行し、そこに出てくる `nuka` コマンドを `--base` も含めてそれぞれ実行しました。
511
+ ブラウザの scenario も Ruby エンジンで走らせました。
512
+ `package.json` が固定した `playwright` を `npm ci --ignore-scripts` で入れたあと、driver は `npx playwright` から起動しました。
513
+ 「チームがその上に足すもの」にある pull request のコメント step も実行していません。
514
+ その `gh pr comment` のフラグは `gh` 自身のヘルプから読んだもので、実際の pull request に対して試してはいません。
515
+ `npx playwright install --with-deps chromium` は自身の `--dry-run` で確かめただけで、最後まで実行してはいません。
516
+ `--with-deps` は Linux ランナーの外では何もしないため(このリポジトリには Linux ランナーがありません)、ダウンロード自体はここでは試していません。
517
+ 上の `uses:` 行にある 2 つのコミット SHA は、GitHub 自身の API に照らして確かめました。
518
+ `repos/actions/checkout/git/ref/tags/v7.0.1` と `setup-node` の同等のエンドポイントをそれぞれ 1 回ずつ呼び、それぞれがコメントの主張どおりのコミットを名指ししていて、他の何も指していないことを確かめました。
519
+ `ruby/setup-ruby` の SHA は、`git ls-remote https://github.com/ruby/setup-ruby` で確かめました。
520
+ タグ `v1.338.0` はそのコミットを名指ししています。
521
+ これはこのリポジトリ自身の CI が使う固定先で、最新のリリースではありません。
522
+ 「チームがその上に足すもの」にある `upload-artifact` の SHA は、`git ls-remote https://github.com/actions/upload-artifact` で確かめました。
523
+ タグ `v7.0.2` はそのコミットを名指ししており、これを書いた時点で最新のリリースタグです。
524
+ そこにある `action.yml` は、この step が使う入力をすべて宣言しています。
525
+ アップロードの step そのものは実行していません。
526
+ この workflow は、実際のランナー上で green になるのを見届けたファイルとしてではなく、手を加えるための出発点として読んでください。
527
+
528
+ CircleCI の config も、CircleCI の上では実行していません。
529
+ その `run` の step は、`bash -eo pipefail` のもとで順に、Ruby 3.4.10 で、`origin` を持つ使い捨ての git リポジトリの中で実行しました。
530
+ gem は `ruby/` から作って Gemfile の `path:` で入れ、ブラウザの scenario を使いました。
531
+ `main` では、run は `0` で終了しました。
532
+ 受け入れ基準を 1 つも変えないブランチでは、`--base` の run では 2 つの受け入れ基準が成り立ち(`held`)、`0` で終了しました。
533
+ 基点がすでに通る scenario を足したブランチでは、`criterion-unproven` で `1` で終了しました。
534
+ gem は `#` を含む secret を env file から欠けずに読み、run はそれを `http.jsonl` で伏せました。
535
+ image、`checkout`、context、`store_artifacts` は試していません。
536
+ ダイジェストはタグ `3.4.13-node` について Docker Hub のレジストリから読み、`checkout` と `store_artifacts` のキーは CircleCI の設定リファレンスから読みました。
537
+
538
+ `nuka report --format allure` で Allure の出力を描き出すプロジェクトについて、ジョブの後でそれがどこへ行くかも、このページは何も言いません(run 自身は何も書きません)。
539
+ trace と screenshot は伏せられません(docs/spec.ja.md の「Environment、secret」を参照)。
540
+ 隣の `http.jsonl` は秘密を置き換えてありますが、trace はブラウザ自身の状態を cookie ごと持ち、screenshot は画面に出ていたものをそのまま持ちます。
541
+ artifact としてアップロードした run ディレクトリや `allure-results/`、チャットに貼った生成済みレポートは、そのすべてを運びます。
542
+ ランナーの中に留めるか、最初のアップロードの前に誰が開いてよいかを決めてください。