nukadoko 0.2.0 → 0.4.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 (76) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +153 -0
  3. data/README.ja.md +6 -3
  4. data/README.md +6 -3
  5. data/lib/nukadoko/aria_snapshot.rb +4 -4
  6. data/lib/nukadoko/base.rb +49 -29
  7. data/lib/nukadoko/check.rb +62 -5
  8. data/lib/nukadoko/claim_check.rb +2 -2
  9. data/lib/nukadoko/claim_rules.rb +1 -1
  10. data/lib/nukadoko/claim_sides.rb +481 -0
  11. data/lib/nukadoko/claims.rb +182 -20
  12. data/lib/nukadoko/cli.rb +24 -7
  13. data/lib/nukadoko/codes.json +20 -15
  14. data/lib/nukadoko/criteria.rb +1 -1
  15. data/lib/nukadoko/env_check.rb +1 -3
  16. data/lib/nukadoko/fixtures.rb +53 -21
  17. data/lib/nukadoko/init.rb +0 -1
  18. data/lib/nukadoko/js_json.rb +274 -0
  19. data/lib/nukadoko/js_pattern.rb +531 -0
  20. data/lib/nukadoko/parameter_types.rb +54 -0
  21. data/lib/nukadoko/parts.rb +1 -1
  22. data/lib/nukadoko/pattern.rb +112 -2
  23. data/lib/nukadoko/poll.rb +5 -3
  24. data/lib/nukadoko/program.rb +5 -5
  25. data/lib/nukadoko/project_files.rb +17 -0
  26. data/lib/nukadoko/project_program.rb +119 -0
  27. data/lib/nukadoko/run.rb +62 -17
  28. data/lib/nukadoko/run_record.rb +25 -22
  29. data/lib/nukadoko/scaffold.rb +2 -2
  30. data/lib/nukadoko/schema.rb +60 -18
  31. data/lib/nukadoko/secrets.rb +20 -4
  32. data/lib/nukadoko/spaces.rb +28 -0
  33. data/lib/nukadoko/step.rb +7 -1
  34. data/lib/nukadoko/text_fit.rb +1 -1
  35. data/lib/nukadoko/trace_actions.rb +4 -2
  36. data/lib/nukadoko/tree_passes.rb +6 -3
  37. data/lib/nukadoko/version.rb +1 -1
  38. data/lib/nukadoko.rb +26 -2
  39. data/llms.txt +20 -18
  40. data/sig/generated/nukadoko/aria_snapshot.rbs +2 -2
  41. data/sig/generated/nukadoko/base.rbs +24 -18
  42. data/sig/generated/nukadoko/check.rbs +11 -1
  43. data/sig/generated/nukadoko/claim_sides.rbs +216 -0
  44. data/sig/generated/nukadoko/claims.rbs +46 -3
  45. data/sig/generated/nukadoko/cli.rbs +1 -1
  46. data/sig/generated/nukadoko/env_check.rbs +0 -4
  47. data/sig/generated/nukadoko/fixtures.rbs +25 -2
  48. data/sig/generated/nukadoko/init.rbs +0 -2
  49. data/sig/generated/nukadoko/js_json.rbs +109 -0
  50. data/sig/generated/nukadoko/js_pattern.rbs +194 -0
  51. data/sig/generated/nukadoko/parameter_types.rbs +27 -0
  52. data/sig/generated/nukadoko/pattern.rbs +59 -1
  53. data/sig/generated/nukadoko/poll.rbs +3 -2
  54. data/sig/generated/nukadoko/program.rbs +1 -1
  55. data/sig/generated/nukadoko/project_files.rbs +19 -0
  56. data/sig/generated/nukadoko/project_program.rbs +55 -0
  57. data/sig/generated/nukadoko/run.rbs +17 -3
  58. data/sig/generated/nukadoko/run_record.rbs +5 -4
  59. data/sig/generated/nukadoko/schema.rbs +22 -4
  60. data/sig/generated/nukadoko/secrets.rbs +17 -2
  61. data/sig/generated/nukadoko/spaces.rbs +31 -0
  62. data/sig/generated/nukadoko/trace_actions.rbs +3 -1
  63. data/sig/generated/nukadoko/tree_passes.rbs +2 -2
  64. data/sig/generated/nukadoko.rbs +11 -0
  65. data/skills/nukadoko/SKILL.md +2 -2
  66. data/skills/nukadoko/references/diagnosing.md +1 -1
  67. data/skills/nukadoko/references/examples/http-api.md +19 -16
  68. data/skills/nukadoko/references/fixtures.md +1 -1
  69. data/skills/nukadoko/references/perturbed-worlds.md +8 -6
  70. data/skills/nukadoko/references/program.md +20 -20
  71. data/skills/nukadoko/references/running.md +2 -2
  72. data/skills/nukadoko/references/scenario-rules.md +2 -2
  73. data/skills/nukadoko/references/verdicts.md +3 -3
  74. data/skills/nukadoko/references/writing-steps.md +1 -1
  75. data/skills/nukadoko-verification/SKILL.md +6 -6
  76. metadata +19 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 469ec78d0a9894519a020a4cc29e409a15977d3241b8b2d90563caed7d3b71e2
4
- data.tar.gz: a69b9814e47df79f92c0c435e48bdb5b90a97188b2421a265f891ebd6a1f2aa3
3
+ metadata.gz: accd5db605b1ffc47adb646fdb20dee28405fa07bb75287852c76166f2694124
4
+ data.tar.gz: 5622bc6c03bc02029347541dd72dd48b80103b06a0bcd813a97f67957041be82
5
5
  SHA512:
6
- metadata.gz: 9b1c6850c722e5186e8d6f227ef67c9f68368cc61d89706b67ea772a97e77881db3f529a04853b4c65d3eae8ddbccd645bd762f137519ad50369e060e3e579df
7
- data.tar.gz: a667506585b11ce283a364bf910897ab38fe6b274a7979744ab2a970d5f72efbc01ff0502de9bc8aedf2225dec87d6be9f53c5596bca8c005b44ed5c311af614
6
+ metadata.gz: 5466755c998989a39dfb454e070f2573059182afe20b56f4cb937fd015602c43d73025bce65385b7af08789b9775c512565035e6fd311d70a8689dbd9b8277a5
7
+ data.tar.gz: 63c90e50cc0341cd64db9af9df3ab953dc940dbfa0acade8b2892fe539cb08b1a9ea20409b2110e72d95c95bb4a0990bdbbb8fa9fc7e4d695e41d65098f92d71
data/CHANGELOG.md CHANGED
@@ -6,6 +6,159 @@ notes come from the section below whose heading starts with `## [<version>]`.
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.4.0] - 2026-11-16
10
+
11
+ ### Changed
12
+
13
+ - The gem accepts `playwright-ruby-client` 1.63.0 and later, in place of
14
+ exactly 1.61.0.
15
+
16
+ ### Fixed
17
+
18
+ - A step record on a Playwright 1.63 driver had no `actions`: the driver
19
+ writes trace format version 9, which the engine now reads.
20
+
21
+ ### Added
22
+
23
+ - `Nukadoko.config(parameterTypes: [...])` registers custom parameter types, as
24
+ the TypeScript engine's `parameterTypes` does: each a `name`, a `regexp`
25
+ (a Ruby Regexp or a string), and an optional `transformer` lambda. A step
26
+ can read a value inside a sentence with no spaces around it, such as
27
+ `優先度{priority:priority}のタスクを足す`, without quotes in the feature
28
+ file. A shape the TypeScript schema refuses is `config-invalid` with its
29
+ words. `nuka check` reports `parameter-type-invalid` for a type that takes
30
+ a built-in name or repeats one, `parameter-type-unused` for one no
31
+ pattern names, and `claim-expected-transformed` for a claim that compares
32
+ with a capture a transformer rewrote, which a run under `--no-check`
33
+ leaves unjudged. A run under `--no-check` stops with
34
+ `parameter-type-collision` when the types do not register.
35
+
36
+ ## [0.3.0] - 2026-11-16
37
+
38
+ ### Changed
39
+
40
+ - **The program moves into the config.** `nukadoko.program.rb` and
41
+ `Nukadoko.program` are gone: the program under test is `program:` in
42
+ `Nukadoko.config`, a lambda that returns the options
43
+ `Nukadoko.program` took, as the TypeScript engine's `program` is. A
44
+ `nuka run --base` compares the config with that lambda cut out, so a
45
+ change to how the program starts is no change to any criterion, and an
46
+ environment's `conditions` and `defaultEnvironments` are compared as
47
+ before. A project root that still holds `nukadoko.program.rb` stops
48
+ every command with `program-file-moved` (exit code 2):
49
+
50
+ ```text
51
+ refused program-file-moved - nukadoko.program.rb is no longer read: the program under test is part of nukadoko.config.rb now, so nukadoko does not start what nukadoko.program.rb describes.
52
+ fix: Move what nukadoko.program.rb describes into nukadoko.config.rb as its program, and delete nukadoko.program.rb; CHANGELOG.md, under "The program moves into the config", shows the move.
53
+ ```
54
+
55
+ `Nukadoko.program` called from the config is refused with
56
+ `config-invalid`. To upgrade, move the options into the config and
57
+ delete `nukadoko.program.rb`. Before:
58
+
59
+ ```ruby
60
+ # nukadoko.program.rb
61
+ Nukadoko.program serve: { command: "bin/rails server -p {port}", ready: "/up" }
62
+ ```
63
+
64
+ After:
65
+
66
+ ```ruby
67
+ # nukadoko.config.rb
68
+ Nukadoko.config(
69
+ program: -> { { serve: { command: "bin/rails server -p {port}", ready: "/up" } } },
70
+ )
71
+ ```
72
+
73
+ Then run `nuka check` until it is green. A `--base` ref from before
74
+ the move needs nothing: the run still reads that ref's program file for
75
+ its base world.
76
+
77
+ ### Fixed
78
+
79
+ - An `is-a "url"` claim takes what the TypeScript engine's WHATWG URL
80
+ parser takes: a host or a path in any script (`http://例え.jp/`), `{`, `}`,
81
+ and `|` in a path or a fragment, and extra slashes after the scheme. It
82
+ refuses a port past 65535 and a label that decodes to no letter, which
83
+ Ruby's URI took. Both engines now judge the same texts the same way.
84
+ - The `text`, `lines`, and `comma-list` views, an `is-a` kind name, and a
85
+ blank expected text trim the spaces JavaScript's trim takes, as the
86
+ TypeScript engine does: a no-break space, an ideographic space, a byte
87
+ order mark, and a line separator. They no longer take a NUL or a next
88
+ line (U+0085). A `comma-list` keeps the empty item after a comma at the
89
+ end, and a docstring that ends in an empty line keeps it in a criterion.
90
+ - A screenshot nukadoko takes (a scenario's `final.png`, a judged view's
91
+ `page.png`, and a `nuka run --step` pause's `page.png`) covers in black
92
+ each element that shows a loaded secret, as text or as a field's value,
93
+ as the TypeScript engine does. When those elements are not found within
94
+ 5 seconds, no screenshot is written. A judged view and a pause show the
95
+ caret.
96
+ - A `--base` run's base and old passes read their env files from head's
97
+ checkout, which holds the ones git ignores, and redact with head's
98
+ secrets as well as the tree's own, as the TypeScript engine does.
99
+ - A `matches` claim reads its pattern as JavaScript's `RegExp` does, as
100
+ the TypeScript engine does, and no longer as a Ruby pattern: `^` and `$`
101
+ match only at the ends of the text, `\s` takes every Unicode space, an
102
+ escaped letter with no meaning is the letter (`\A`, `\h`), a `{` that
103
+ starts no count is a `{`, `[^]` takes any character, a backreference to
104
+ a group that did not match matches nothing, `.` takes one UTF-16 unit,
105
+ and a pattern JavaScript refuses (`(?i)`, `a*+`, `(?#...)`) does not
106
+ build, with V8's reason. A lookbehind Ruby cannot run (one of unbounded
107
+ length) is refused with Ruby's reason.
108
+ - A `has-item` claim on an array whose items are all `false` or `null`,
109
+ none of them of the expected value's type, breaks with the reason that
110
+ no item is of that type, as the TypeScript engine says, instead of
111
+ simply breaking.
112
+ - A step pattern reads its built-in parameter types as the JavaScript
113
+ cucumber-expressions package does, as the TypeScript engine does. A
114
+ `{word}` ends at any Unicode space, so a no-break space no longer joins
115
+ two words. A `{float}` or `{double}` takes the JavaScript pattern and
116
+ reads as `parseFloat` reads it (`1E3` is 1000, a lone sign is NaN). An
117
+ `{int}` past 2**53 is the nearest double, and a `{bigdecimal}` is the
118
+ text as written, not a `BigDecimal`.
119
+ - Args and returns that do not fit their schema fail with zod's words, as
120
+ the TypeScript engine's do: `args validation failed: n: Invalid input:
121
+ expected number, received NaN`. Args refuse a key the schema does not
122
+ declare (`(root): Unrecognized key: "x"`), an `unknown` field may be
123
+ missing, an `integer` past 2**53 is too big, and a step with `returns`
124
+ whose `run` gave back nil says so. An arg that is NaN no longer stops the
125
+ run while its step record is written: JSON has no NaN, so the record
126
+ holds null, as JavaScript writes it.
127
+ - A claim reads its value as the TypeScript engine reads it. A dotted
128
+ `actual` (`body.user.name`) is a path into what observe returned, not
129
+ one key, and a path that finds nothing breaks the claim with where the
130
+ walk stopped (`observe:value.user.name is undefined, since observe:value
131
+ has nothing at user`) instead of failing the step. A view of a value that
132
+ is no text, and an `at` with nothing there, break the claim with the
133
+ TypeScript engine's reason. A claim that compares a value with itself, or
134
+ with one observe received or computed as a boolean, breaks as there.
135
+ - A claim judges a plain JSON copy of each side, as the TypeScript engine
136
+ does: a whole float is the integer JavaScript holds (`2500.0` reads and
137
+ shows as `2500`), an object lists its index keys first, and NaN,
138
+ Infinity, an integer past `Number.MAX_SAFE_INTEGER`, a value of another
139
+ class, a value that holds itself, or one nested past 256 levels leaves
140
+ the claim unjudged with the reason. A step with an unjudged claim fails
141
+ as `claim_unjudged`, as there.
142
+ - `nuka run --no-check` refuses to start when a step's declaration is one
143
+ the TypeScript engine's `defineStep` refuses as its file loads, naming
144
+ the first such file, instead of leaving the step out.
145
+ - An `each` claim reads its array and each item's paths as the TypeScript
146
+ engine does, with the same reasons when a read finds nothing. It breaks
147
+ when a declaration's expected value is one observe received, and when a
148
+ `where` clause implies an item claim whatever the data (`greater-than 10`
149
+ then `at-least 5`), as there. A poll waits on the outcome the record holds.
150
+ - A json view reads its text as JavaScript's `JSON.parse` does and, when
151
+ the text is no JSON, gives V8's reason (`Unexpected token 'a', "a" is not
152
+ valid JSON`, `Expected ',' or '}' after property value in JSON at position
153
+ 6 (line 1 column 7)`) instead of Ruby's. A text Ruby's parser takes and
154
+ JavaScript's refuses, such as one with a comment, is refused.
155
+ - A refusal or a claim reason quotes a value as JavaScript's
156
+ `JSON.stringify` writes it: a literal written `2.0` reads `2`, and
157
+ `1e20` reads `100000000000000000000`, as in the TypeScript engine's
158
+ text. A json view of a text that holds an unpaired surrogate escape
159
+ (`"\ud800"`), which JavaScript reads and a Ruby string cannot hold, is
160
+ refused with that reason instead of the parser's.
161
+
9
162
  ## [0.2.0] - 2026-11-15
10
163
 
11
164
  ### Added
data/README.ja.md CHANGED
@@ -98,7 +98,8 @@ gem が入れる実行ファイルには、`bundle binstubs <gem>` が `bin/<nam
98
98
  `--then` とキャプチャ 1 つと一緒に使うと、claim がその 2 つを比べるので、ステップは書き直さずに使えます。
99
99
  - ブラウザの起動設定は `nukadoko.config.rb` に `Nukadoko.config(browser: { executablePath: "..." })` と書きます。`page` を使うステップは、シナリオごとに自分のブラウザコンテキストを持ちます。ステップの記録には、ページが送ったリクエストとステップのトレースが残ります。
100
100
  - `scratch` を使うステップは `scratch.dir` で新しいディレクトリを得ます。シナリオが終わると消えます。`scratch.copy(source)` は、プロジェクトのファイルかディレクトリの写しを入れた新しいディレクトリを返します。`args:` キーワードを書かない本体は、args なしで呼ばれます。`Nukadoko.run_command(command, args, cwd:, env:, input:, timeout:, redact:)` はプログラムを実行し、`{ exitCode:, signal:, stdout:, stderr: }` を返します。ステップの記録には実行したプロセスが残り、`redact:` に渡した値は `{{secret.NAME}}` になります。
101
- - `Nukadoko.config(envFiles: [".env"])` は env ファイルを `env` フィクスチャに読み込みます。`nukadoko.program.rb` の環境は、その後ろに自分の `envFiles:` を足せます。git が追跡していないファイルと HEAD と違うファイルは秘密の出どころです。その 4 文字以上の値は、ステップの記録、`http.jsonl`、`nuka do` の出力で `{{secret.NAME}}` に置き換わります。ステップが表示したものは、秘密を伏せて stderr に出ます。`secrets: { public: [...], redact: [...] }` で、そのようなキーを平文のままにしたり、追跡しているファイルのキーを伏せたりできます。`nuka check` は、無いファイル、読み飛ばした行、どのファイルにもない `secrets` のキーを警告し、値は表示しません。
101
+ - `Nukadoko.config(envFiles: [".env"])` は env ファイルを `env` フィクスチャに読み込みます。config の `program:` の環境は、その後ろに自分の `envFiles:` を足せます。git が追跡していないファイルと HEAD と違うファイルは秘密の出どころです。その 4 文字以上の値は、ステップの記録、`http.jsonl`、`nuka do` の出力で `{{secret.NAME}}` に置き換わります。ステップが表示したものは、秘密を伏せて stderr に出ます。`secrets: { public: [...], redact: [...] }` で、そのようなキーを平文のままにしたり、追跡しているファイルのキーを伏せたりできます。`nuka check` は、無いファイル、読み飛ばした行、どのファイルにもない `secrets` のキーを警告し、値は表示しません。
102
+ - `Nukadoko.config(parameterTypes: [{ name: "priority", regexp: /高|低/, transformer: ->(s) { s == "高" ? "high" : "low" } }])` は、TypeScript の config の `parameterTypes` と同じようにパラメータ型を登録します。前後に空白のない文の中の値も、`{p:priority}` で読めます。regexp は Ruby の Regexp か文字列です。transformer は省いてもよく、regexp が捕まえたグループを受け取ります。`nuka check` は、組み込みの名前を使う型、どのパターンも使わない型、transformer が書き換えた値と比べる主張を報告します。
102
103
  - プロジェクトのフィクスチャは `nukadoko.config.rb` に書きます。ブロックは値を `use` に渡し、その後ろが後片付けです。例: `Nukadoko.fixture(:store) { |use| use.(Store.new) }`。`scope: :process` にすると、環境ごとの実行全体で 1 つの値を使います。
103
104
  - `parts [CreateTodo, CompleteById]` で、ステップが呼べるステップを宣言します。`call.(CreateTodo, title: args.title)` で 1 つを実行し、args と返り値を確かめます。パターンのない part も書けます。呼び出しは、呼んだステップの記録の `calls` に残ります。`nuka check` は、`parts` の循環と、`mutates false` なのに `mutates true` の part を持つステップを報告します。
104
105
  - `poll timeout_ms: 3000` は、すべての claim が 2 回続けて成り立つか時間切れになるまで、100 ミリ秒おきに `observe` を読み直します。`settled:` には、一度なったら変わらない状態を書きます。2 回続けてその状態なら、壊れた claim を待つのをやめます。読んだ結果はすべてステップの記録に残ります。
@@ -107,10 +108,12 @@ gem が入れる実行ファイルには、`bundle binstubs <gem>` が `bin/<nam
107
108
  - 契約が宣言していない返り値のキーは、zod のオブジェクトと同じく捨てられます。ステップの記録の `returns_dropped` に、捨てたキーが残ります。
108
109
  - `nuka sig` は `sig/nukadoko/steps.rbs` を書きます。Steep を使うと、宣言していない args のキーを読む本体や、形のちがう値を返す本体がエラーになります。
109
110
 
110
- テストするプログラムは `nukadoko.program.rb` に書きます。
111
+ テスト対象のプログラムは `nukadoko.config.rb` の `program:` に書きます。プログラムの起動のしかたを返すラムダです。
111
112
 
112
113
  ```ruby
113
- Nukadoko.program serve: { command: "bin/rails server -p {port}", ready: "/up" }
114
+ Nukadoko.config(
115
+ program: -> { { serve: { command: "bin/rails server -p {port}", ready: "/up" } } },
116
+ )
114
117
  ```
115
118
 
116
119
  ## 開発
data/README.md CHANGED
@@ -53,7 +53,8 @@ end
53
53
  - `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.
54
54
  - 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.
55
55
  - 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}}`.
56
- - `Nukadoko.config(envFiles: [".env"])` loads env files into the `env` fixture, and an environment in `nukadoko.program.rb` 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.
56
+ - `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.
57
+ - `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.
57
58
  - 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.
58
59
  - `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`.
59
60
  - `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.
@@ -62,10 +63,12 @@ end
62
63
  - A returned key the contract does not declare is dropped, as a zod object drops it, and the step record names it under `returns_dropped`.
63
64
  - `nuka sig` writes `sig/nukadoko/steps.rbs`. With Steep, a body that reads an undeclared args key or returns the wrong shape is an error.
64
65
 
65
- The program under test is described in `nukadoko.program.rb`:
66
+ The program under test is described by `program:` in `nukadoko.config.rb`, a lambda that returns how the program starts:
66
67
 
67
68
  ```ruby
68
- Nukadoko.program serve: { command: "bin/rails server -p {port}", ready: "/up" }
69
+ Nukadoko.config(
70
+ program: -> { { serve: { command: "bin/rails server -p {port}", ready: "/up" } } },
71
+ )
69
72
  ```
70
73
 
71
74
  ## Development
@@ -36,8 +36,8 @@ module Nukadoko
36
36
  module AriaSnapshot
37
37
  FRAGMENT = "fragment"
38
38
  # JavaScript's \s, which the TypeScript engine's texts are cut by.
39
- SPACE = "\\s\\u00a0\\u1680\\u2000-\\u200a\\u2028\\u2029\\u202f\\u205f\\u3000\\ufeff"
40
- WS = /[#{SPACE}]/
39
+ SPACE = Spaces::CLASS #: String
40
+ WS = Spaces::SPACE #: Regexp
41
41
  # YAML's indicators: a plain scalar may not start with one, since
42
42
  # YAML reads it as structure.
43
43
  PLAIN_START_REFUSED = [",", "[", "]", "{", "}", "&", "*", "!", "|", ">", "%", "@", "`"].freeze
@@ -66,10 +66,10 @@ module Nukadoko
66
66
  def problem_at(line, message) = Problem.new("line #{line} #{message}")
67
67
 
68
68
  #: (String) -> String
69
- def trim(text) = text.sub(/\A#{WS}+/, "").sub(/#{WS}+\z/, "")
69
+ def trim(text) = Spaces.trim(text)
70
70
 
71
71
  #: (String) -> String
72
- def trim_end(text) = text.sub(/#{WS}+\z/, "")
72
+ def trim_end(text) = Spaces.trim_end(text)
73
73
 
74
74
  #: (String?) -> bool
75
75
  def space?(char) = !char.nil? && char.match?(/\A#{WS}\z/)
data/lib/nukadoko/base.rb CHANGED
@@ -13,14 +13,19 @@ require "rbconfig"
13
13
  #
14
14
  # - base: the ref's code with head's features/ and config, so a new or
15
15
  # changed criterion runs where its behaviour should be absent. The ref's
16
- # program file starts it, or head's when the ref has none.
16
+ # program starts it, or head's when the ref has none: the program goes
17
+ # with the code, so the run writes the ref's config beside head's as
18
+ # nukadoko.tree-program.rb (or the ref's program file from before the
19
+ # program moved into the config as nukadoko.tree-legacy-program.rb).
17
20
  # - old: head's working tree with the ref's features/ and config, so an
18
21
  # unchanged criterion over a changed mapping runs under the steps it was
19
- # approved with.
22
+ # approved with. Head's config goes beside it as nukadoko.tree-program.rb,
23
+ # so head's program starts it.
20
24
  #
21
25
  # The mapping is every file under features/ but a .feature file, the config
22
- # file's bytes, and the program file's conditions and defaultEnvironments,
23
- # which decide where a criterion is required. Every git command runs with
26
+ # file's bytes with its program lambda cut out, and the program's
27
+ # conditions and defaultEnvironments, which decide where a criterion is
28
+ # required. Every git command runs with
24
29
  # hooks off, since a checkout's hook is the project's code and not the
25
30
  # run's. Both trees are removed when the run ends.
26
31
  module Nukadoko
@@ -28,8 +33,6 @@ module Nukadoko
28
33
  class Base
29
34
  NO_HOOKS = ["-c", "core.hooksPath=/dev/null"].freeze
30
35
  FEATURES = "features"
31
- CONFIG = "nukadoko.config.rb"
32
- PROGRAM = "nukadoko.program.rb"
33
36
  STATE = ".nukadoko"
34
37
 
35
38
  attr_reader :ref #: String
@@ -133,7 +136,9 @@ module Nukadoko
133
136
 
134
137
  head_files = working_tree_files
135
138
  ref_files = Base.git(@base_top, "ls-files", "-z", strip: false).first.split("\0").reject(&:empty?)
136
- ref_program = File.exist?(File.join(base_project, PROGRAM)) ? read_program(base_project) : nil
139
+ ref_program = read_program(base_project)
140
+ ref_config = File.join(base_project, CONFIG)
141
+ ref_config_text = File.exist?(ref_config) ? File.read(ref_config) : nil
137
142
  @mapping = compare_mapping(head_files, ref_files, base_project, head_program, ref_program)
138
143
 
139
144
  wanted = selected.map { @changes[_1] }
@@ -141,9 +146,9 @@ module Nukadoko
141
146
  old_needed = wanted.any? { _1&.dig(:change) == "unchanged" && (@mapping[:changed] || _1[:retagged] || _1[:renamed_from]) }
142
147
  write_old_tree(head_files, ref_files) if old_needed
143
148
  if base_needed
144
- overlay_base_tree(head_files, ref_files)
149
+ overlay_base_tree(head_files, ref_files, ref_program && ref_config_text)
145
150
  @base_root = base_project
146
- @program_from_head = !File.exist?(File.join(@base_top, in_repo(PROGRAM))) && File.exist?(File.join(@project, PROGRAM))
151
+ @program_from_head = ref_program.nil? && !(head_program || {}).empty?
147
152
  else
148
153
  @worktree = false
149
154
  Base.git(@top, "worktree", "remove", "--force", "--force", @base_top)
@@ -153,7 +158,7 @@ module Nukadoko
153
158
  end
154
159
 
155
160
  # The environments the old world runs in, with the conditions the ref's
156
- # program file gives each; nil when the ref has no program file, so
161
+ # program gives each; nil when the ref has no program, so
157
162
  # head's environments are the old world's too.
158
163
  #: (Hash[Symbol, untyped]?, Array[String]) -> Array[Environment]?
159
164
  def old_environments_of(program, envs)
@@ -204,18 +209,21 @@ module Nukadoko
204
209
  .to_h { [_1.delete_prefix("#{dir}/"), hash_of(File.join(top, _1))] }
205
210
  end
206
211
 
207
- # The ref's program file read in a process of its own, since loading
208
- # it here would replace head's: its conditions and defaultEnvironments.
209
- #: (String) -> Hash[Symbol, untyped]
212
+ # The ref's program: its program file from before the program moved
213
+ # into the config, or its config's program, read in a process of its
214
+ # own (ProjectProgram.elsewhere). nil when the ref has neither.
215
+ #: (String) -> Hash[Symbol, untyped]?
210
216
  def read_program(root)
211
- script = 'require "nukadoko"; load ARGV[0]; o = Nukadoko.program_options; ' \
212
- 'puts JSON.generate(environments: (o[:environments] || {}).to_h { |k, v| [k, { conditions: v[:conditions] }] }, defaultEnvironments: o[:defaultEnvironments])'
213
- out, err, status = Open3.capture3(RbConfig.ruby, "-I", File.expand_path("..", __dir__.to_s), "-rjson", "-e", script, File.join(root, PROGRAM), chdir: root)
214
- return { problem: err.lines.first.to_s.strip } unless status.success?
215
-
216
- program = JSON.parse(out, symbolize_names: true)
217
- program[:environments] = program[:environments].transform_keys(&:to_s)
218
- program
217
+ legacy = File.join(root, LEGACY_PROGRAM)
218
+ config = File.join(root, CONFIG)
219
+ program = if File.exist?(legacy) then ProjectProgram.elsewhere(legacy, legacy: true) || {}
220
+ elsif File.exist?(config) then ProjectProgram.elsewhere(config, legacy: false)
221
+ end
222
+ return nil if program.nil?
223
+
224
+ { environments: (program[:environments] || {}).transform_keys(&:to_s), defaultEnvironments: program[:defaultEnvironments] }
225
+ rescue Refusal => e
226
+ { problem: e.message }
219
227
  end
220
228
 
221
229
  #: (Hash[Symbol, untyped]?) -> Hash[Symbol, untyped]
@@ -229,7 +237,7 @@ module Nukadoko
229
237
  head = mapping_files(head_files, @top)
230
238
  ref = mapping_files(ref_files, @base_top)
231
239
  files = (head.keys | ref.keys).select { head[_1] != ref[_1] }.sort
232
- config_hash = ->(root) { File.exist?(File.join(root, CONFIG)) ? hash_of(File.join(root, CONFIG)) : nil }
240
+ config_hash = ->(root) { File.exist?(File.join(root, CONFIG)) ? Digest::SHA256.hexdigest(ProjectProgram.mapping_text(File.read(File.join(root, CONFIG)))) : nil }
233
241
  config = config_hash.(@project) != config_hash.(base_project)
234
242
  after = program_mapping(head_program && { environments: (head_program[:environments] || {}).transform_keys(&:to_s), defaultEnvironments: head_program[:defaultEnvironments] })
235
243
  if ref_program&.dig(:problem)
@@ -252,22 +260,34 @@ module Nukadoko
252
260
  File.symlink?(from) ? File.symlink(File.readlink(from), to) : FileUtils.cp(from, to)
253
261
  end
254
262
 
255
- # The ref's checkout loses the ref's mapping and gains head's; the
256
- # ref's program file stays, or head's comes in when the ref has none.
257
- #: (Array[String], Array[String]) -> void
258
- def overlay_base_tree(head_files, ref_files)
263
+ # The ref's checkout loses the ref's mapping and gains head's. The
264
+ # ref's program stays: its program file under the tree's own name, or
265
+ # its config `ref_config` beside head's. When the ref has no program,
266
+ # head's config brings head's.
267
+ #: (Array[String], Array[String], String?) -> void
268
+ def overlay_base_tree(head_files, ref_files, ref_config)
259
269
  ref_files.select { mapping?(_1) }.each { FileUtils.rm_f(File.join(@base_top, _1)) }
260
270
  head_files.select { mapping?(_1) }.each { copy(File.join(@top, _1), File.join(@base_top, _1)) }
261
- program = in_repo(PROGRAM)
262
- copy(File.join(@top, program), File.join(@base_top, program)) if !ref_files.include?(program) && head_files.include?(program)
271
+ legacy = File.join(@base_top, in_repo(LEGACY_PROGRAM))
272
+ if File.exist?(legacy)
273
+ FileUtils.mv(legacy, File.join(@base_top, in_repo(TREE_LEGACY_PROGRAM)))
274
+ elsif ref_config
275
+ File.write(File.join(@base_top, in_repo(TREE_PROGRAM)), ref_config)
276
+ end
263
277
  end
264
278
 
265
279
  # Head's working tree with the ref's mapping in place of its own,
266
- # written before the base checkout is overlaid.
280
+ # written before the base checkout is overlaid. Head's program stays:
281
+ # head's config goes beside the ref's, or a file that names no
282
+ # program when head has no config.
267
283
  #: (Array[String], Array[String]) -> void
268
284
  def write_old_tree(head_files, ref_files)
269
285
  head_files.reject { mapping?(_1) }.each { copy(File.join(@top, _1), File.join(@old_top, _1)) }
270
286
  ref_files.select { mapping?(_1) }.each { copy(File.join(@base_top, _1), File.join(@old_top, _1)) }
287
+ head_config = File.join(@project, CONFIG)
288
+ tree_program = File.join(@old_top, in_repo(TREE_PROGRAM))
289
+ FileUtils.mkdir_p(File.dirname(tree_program))
290
+ File.write(tree_program, File.exist?(head_config) ? File.read(head_config) : "# Head has no config, so no program.\n")
271
291
  end
272
292
  end
273
293
  end
@@ -44,7 +44,7 @@ module Nukadoko
44
44
  # `environments` is the selection a run without --env starts, for
45
45
  # condition-unmet; nil when --env named the selection. `problems` are
46
46
  # what the feature loader found that runs nothing.
47
- # `config` holds what was found in the config and the program file before
47
+ # `config` holds what was found in the config and its program before
48
48
  # any step loaded, such as an env file that is missing.
49
49
  #: (Array[singleton(Step)], Array[Scenario], ?features: bool, ?full: bool, ?conditions: Array[String]?, ?environments: Array[Environment]?, ?problems: Array[FeatureProblem], ?config: Array[Finding]) -> void
50
50
  def initialize(steps, scenarios, features: true, full: false, conditions: nil, environments: nil, problems: [], config: [])
@@ -62,6 +62,11 @@ module Nukadoko
62
62
  %(no .rb step file was found while scanning "features"; no step can ever be registered), Codes.fix("no-step-files-found"), nil)
63
63
  end
64
64
  @findings.concat(config)
65
+ # The config's parameterTypes did not register, so no pattern binds a
66
+ # line; that is said once, not once per pattern.
67
+ if (collision = Pattern.collision)
68
+ @findings << Finding.new("error", "parameter-type-invalid", nil, nil, nil, collision, Codes.fix("parameter-type-invalid"), nil)
69
+ end
65
70
  @usable = steps.reject { definition_broken?(_1) }
66
71
  @usable.each { check_contract(_1) }
67
72
  check_duplicate_patterns
@@ -79,6 +84,7 @@ module Nukadoko
79
84
  if full
80
85
  check_unbound
81
86
  check_from_unused
87
+ check_unused_parameter_types
82
88
  end
83
89
  # Errors, then warnings, then notes, each kind in the order found, as
84
90
  # the TypeScript engine reports them.
@@ -137,7 +143,7 @@ module Nukadoko
137
143
  Pattern.new(pattern)
138
144
  nil
139
145
  rescue Cucumber::CucumberExpressions::UndefinedParameterTypeError => e
140
- types = Pattern::REGISTRY.parameter_types.map(&:name).reject(&:empty?).sort
146
+ types = Pattern.registry.parameter_types.map(&:name).reject(&:empty?).sort
141
147
  ["unknown-parameter-type", "#{head}: #{e.message} This project's registered parameter types are: #{types.join(", ")}."]
142
148
  rescue StandardError => e
143
149
  ["pattern-syntax-error", "#{head}: #{e.message}"]
@@ -224,6 +230,54 @@ module Nukadoko
224
230
  end
225
231
  end
226
232
 
233
+ # A config parameter type no pattern names.
234
+ #: () -> void
235
+ def check_unused_parameter_types
236
+ used = @steps.flat_map { (pattern = _1.pattern) ? pattern.scan(/\{(?:[^}:]*:)?([^}]*)\}/).flatten : [] }
237
+ (Nukadoko.config_options[:parameterTypes] || []).each do |type|
238
+ name = type[:name].to_s
239
+ next if used.include?(name)
240
+
241
+ findings << Finding.new("note", "parameter-type-unused", CONFIG, nil, nil,
242
+ %(Configured parameter type "#{name}" is not referenced by any typed or compat pattern.), Codes.fix("parameter-type-unused"), nil)
243
+ end
244
+ end
245
+
246
+ # A claim whose expected value is an args key a type with a
247
+ # transformer fills compares with what code made of the line, while
248
+ # the record would name the sentence as its source.
249
+ #: (singleton(Step)) -> void
250
+ def check_transformed(step)
251
+ transformed = Pattern.transformed
252
+ claims = step.claims
253
+ pattern = step.pattern
254
+ return if transformed.empty? || claims.nil? || pattern.nil?
255
+
256
+ keys = {} #: Hash[String, String]
257
+ claims.each_with_index do |claim, index|
258
+ label = "claims[#{index}]"
259
+ each = claim[:each]
260
+ unless each
261
+ keys[claim[:expected].to_s] ||= label if claim[:expected].is_a?(String)
262
+ next
263
+ end
264
+ items = (Array(each[:where]).each_with_index.map { |item, i| ["#{label}.each.where[#{i}]", item] } +
265
+ Array(each[:claims]).each_with_index.map { |item, i| ["#{label}.each.claims[#{i}]", item] }) #: Array[[String, Hash[Symbol, untyped]]]
266
+ items.each { |item_label, item| keys[item[:expected].to_s] ||= item_label if item[:expected].is_a?(String) }
267
+ end
268
+ pattern.scan(Pattern::NAMED).each do |match|
269
+ key, type = Array(match).map(&:to_s)
270
+ label = keys[key.to_s]
271
+ next unless label && transformed.include?(type.to_s)
272
+
273
+ findings << Finding.about_step("error", "claim-expected-transformed", step,
274
+ %(Step "#{step.step_name}"'s #{label}.expected is args.#{key}, and its pattern "#{pattern}" fills it with the parameter type {#{type}}, ) +
275
+ "whose transformer rewrites the line's text before the claim reads it, so code would decide what the claim compares. " \
276
+ "Capture #{key} with a type that has no transformer, such as {#{key}:string}, and read it with expected_view if it needs one",
277
+ Codes.fix("claim-expected-transformed"))
278
+ end
279
+ end
280
+
227
281
  # A from key every line fills with a capture never takes its value
228
282
  # from the producer it names.
229
283
  #: () -> void
@@ -342,7 +396,7 @@ module Nukadoko
342
396
  fixtures = Nukadoko.project_fixtures
343
397
  return if fixtures.empty?
344
398
 
345
- config = "nukadoko.config.rb"
399
+ config = CONFIG
346
400
  state = Hash.new(:white)
347
401
  visit = lambda do |name, stack|
348
402
  state[name] = :gray
@@ -467,7 +521,7 @@ module Nukadoko
467
521
  if name.nil?
468
522
  boolean = tag.match(/\A@with:([A-Za-z0-9_.-]+)=(true|false)\z/)
469
523
  message = if boolean
470
- "#{tag} names a boolean as text, which reads two ways: write #{boolean[2] == "true" ? "@with:" : "@without:"}#{boolean[1]}, which reads the boolean the program file declares"
524
+ "#{tag} names a boolean as text, which reads two ways: write #{boolean[2] == "true" ? "@with:" : "@without:"}#{boolean[1]}, which reads the boolean the program declares"
471
525
  else
472
526
  "#{tag} does not read as @with:<condition>, @with:<condition>=<value>, or @without:<condition>, so it names no condition"
473
527
  end
@@ -475,7 +529,7 @@ module Nukadoko
475
529
  elsif conditions && !conditions.include?(name)
476
530
  on, off = tag.start_with?("@without:") ? %w[off on] : %w[on off]
477
531
  findings << Finding.new("error", "condition-unknown", uri, line, nil,
478
- %(#{tag} names the condition "#{name}", and no environment in nukadoko.program.rb declares it under conditions. ) +
532
+ %(#{tag} names the condition "#{name}", and no environment in nukadoko.config.rb declares it under conditions. ) +
479
533
  "If #{name} was removed and its #{on} side kept, remove the tag, so the scenario holds everywhere; if its #{off} side was kept, delete the scenario.",
480
534
  Codes.fix("condition-unknown"), nil)
481
535
  end
@@ -551,6 +605,7 @@ module Nukadoko
551
605
  #: () -> void
552
606
  def check_lines
553
607
  undefined = []
608
+ bound = [] #: Array[singleton(Step)]
554
609
  @scenarios.each do |scenario|
555
610
  scenario.steps.each do |line|
556
611
  matches = Engine.matches(@usable, line.text)
@@ -558,6 +613,7 @@ module Nukadoko
558
613
  when 0 then undefined << [scenario, line]
559
614
  when 1
560
615
  step, captures = matches.first
616
+ bound << step
561
617
  check_fill(scenario, line, step, captures)
562
618
  check_position(scenario, line, step)
563
619
  check_kinds(scenario, line, step, captures)
@@ -569,6 +625,7 @@ module Nukadoko
569
625
  end
570
626
  end
571
627
  end
628
+ bound.uniq.each { check_transformed(_1) }
572
629
  @scenarios.each { check_from_order(_1) }
573
630
  @scenarios.each { check_claim_sources(_1) }
574
631
  suppress_undefined(undefined)
@@ -131,9 +131,9 @@ module Nukadoko
131
131
  expected = entry[:expected]
132
132
  name = if expected.is_a?(Hash) then expected[:literal].is_a?(String) ? expected[:literal] : nil
133
133
  elsif [nil, "text"].include?(entry[:expected_view]) && step.args[expected]&.type == :string && captures[expected].is_a?(String)
134
- entry[:expected_view] == "text" ? captures[expected].rstrip : captures[expected]
134
+ entry[:expected_view] == "text" ? Spaces.trim_end(captures[expected]) : captures[expected]
135
135
  end
136
- name.nil? || name.strip.empty? ? nil : name
136
+ name.nil? || Spaces.blank?(name) ? nil : name
137
137
  end
138
138
 
139
139
  # The segments a claim reads before its view, as the run reads them:
@@ -60,7 +60,7 @@ module Nukadoko
60
60
 
61
61
  #: (untyped) -> String
62
62
  def describe(value)
63
- value.is_a?(Symbol) ? JSON.generate(value.to_s) : JSON.generate(value)
63
+ JsJson.generate(value)
64
64
  rescue StandardError
65
65
  value.inspect
66
66
  end