nukadoko 0.4.0 → 0.6.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +78 -0
- data/README.ja.md +12 -2
- data/README.md +10 -3
- data/lib/nukadoko/check.rb +15 -4
- data/lib/nukadoko/cli.rb +10 -4
- data/lib/nukadoko/command.rb +22 -4
- data/lib/nukadoko/error_frames.rb +44 -0
- data/lib/nukadoko/features.rb +3 -1
- data/lib/nukadoko/fixtures.rb +108 -7
- data/lib/nukadoko/judgment_file.rb +21 -0
- data/lib/nukadoko/judgments.rb +30 -0
- data/lib/nukadoko/run.rb +126 -27
- data/lib/nukadoko/run_record.rb +9 -5
- data/lib/nukadoko/schema.rb +165 -37
- data/lib/nukadoko/step_fixtures.rb +225 -0
- data/lib/nukadoko/summary.rb +4 -1
- data/lib/nukadoko/verdict.rb +18 -1
- data/lib/nukadoko/version.rb +1 -1
- data/lib/nukadoko/vocabulary.rb +1 -1
- data/lib/nukadoko.rb +2 -0
- data/llms.txt +3 -2
- data/sig/generated/nukadoko/command.rbs +13 -4
- data/sig/generated/nukadoko/error_frames.rbs +24 -0
- data/sig/generated/nukadoko/fixtures.rbs +38 -2
- data/sig/generated/nukadoko/judgment_file.rbs +6 -0
- data/sig/generated/nukadoko/judgments.rbs +10 -0
- data/sig/generated/nukadoko/run.rbs +25 -4
- data/sig/generated/nukadoko/schema.rbs +91 -27
- data/sig/generated/nukadoko/step_fixtures.rbs +129 -0
- data/sig/generated/nukadoko/verdict.rbs +8 -0
- data/skills/nukadoko/SKILL.md +1 -1
- data/skills/nukadoko/references/done.md +22 -0
- data/skills/nukadoko/references/judgments.md +6 -0
- data/skills/nukadoko/references/ruby.md +80 -0
- metadata +6 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8e53cd82516de0c5338bbe7bf875e534dbdffec55bef983e17e0b4e5c42e7e5b
|
|
4
|
+
data.tar.gz: ee731ea548a72f78147c3f9a81b81728eb99b69040467c2ec00397c02137b799
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4724272cb7bd2529912b710f5b0ce67e161a8cee08aafd82f849ef8d3e7b8d57e6ec9b715659889ca5dae623a85a7065b0c9c129dd0630c33654b620a25b5498
|
|
7
|
+
data.tar.gz: 1bddca443dbabb8b0d4b0f69b5e99245c54b5c2278323a7ccde3d5420ddcd1032ba67d789f571e81d4d164a6cd1e9220dfa608ec2f8c97675876d33bd15dd086
|
data/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,84 @@ notes come from the section below whose heading starts with `## [<version>]`.
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [0.6.0] - 2026-11-17
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- `nuka verdict --trailer` prints one git trailer line,
|
|
14
|
+
`Nukadoko-Verdict: <passed|failed|stale|none|unknown> run <id> tree <id>`,
|
|
15
|
+
to stamp a commit, and exits 0 whatever it says. `--json` carries the
|
|
16
|
+
same line as `trailer`. The same as the TypeScript engine.
|
|
17
|
+
- Under `--base`, each judgment a read cites carries `in_base`, and a row
|
|
18
|
+
that stands on a judgment the change added says so in its `judgment`
|
|
19
|
+
limit. The same as the TypeScript engine.
|
|
20
|
+
|
|
21
|
+
## [0.5.0] - 2026-11-16
|
|
22
|
+
|
|
23
|
+
### Added
|
|
24
|
+
|
|
25
|
+
- The fixtures the TypeScript engine gives on ctx and the Ruby engine
|
|
26
|
+
lacked: `context`, `pageAs` (a browser context of its own per name, with
|
|
27
|
+
`trace.<name>.zip` per step and `final.<name>.png` per scenario),
|
|
28
|
+
`section`, `poll` (a block called until it gives a value, kept in
|
|
29
|
+
`polls`), `evidence` (`attach` and `path`, kept in
|
|
30
|
+
`evidence.attachments`), and `resultOf`. Before, `nuka check` accepted
|
|
31
|
+
some of these names and the run then failed with "the Ruby engine has no
|
|
32
|
+
fixture ... yet"; now each name check accepts is one the run gives.
|
|
33
|
+
- `base_url:`, `require_env:`, `page_as:`, and `result_of:` name the same
|
|
34
|
+
fixtures as `baseURL:`, `requireEnv:`, `pageAs:`, and `resultOf:`, so a
|
|
35
|
+
step body passes RuboCop's naming cops.
|
|
36
|
+
- A step record lists each key `requireEnv` was asked for in
|
|
37
|
+
`required_env`, as the TypeScript engine does. An empty value counts as
|
|
38
|
+
missing.
|
|
39
|
+
|
|
40
|
+
- A project fixture can name a builtin (`page`, `request`, `env`,
|
|
41
|
+
`requireEnv`, `baseURL`, `scratch`), and one with a builtin's name
|
|
42
|
+
replaces it for every step while its own keyword of that name is the
|
|
43
|
+
builtin, so `Nukadoko.fixture(:page) { |use, page:| ...; use.(page) }`
|
|
44
|
+
wraps the page each step gets. `nuka check` reports `page-override-unowned`
|
|
45
|
+
for a `page` override that names no browser fixture.
|
|
46
|
+
|
|
47
|
+
- The `request` fixture sends an absolute `https` URL over TLS and works in
|
|
48
|
+
a project with no program, so a step can call a third-party API and keep
|
|
49
|
+
its requests in `http.jsonl`. A path in a world with no URL is refused
|
|
50
|
+
with that reason.
|
|
51
|
+
|
|
52
|
+
- `args` and `returns` declare what zod declares: `array :todos do ... end`
|
|
53
|
+
for a list of objects, `numbers` and `integers` beside `strings`,
|
|
54
|
+
`array :x, of:` for any item type, `optional: true`, `default:`, and the
|
|
55
|
+
bounds `min:`, `max:`, `positive:`, and `negative:` (and `each:` for an
|
|
56
|
+
array's items). The problems and the JSON Schema `nuka describe` prints
|
|
57
|
+
are zod's. A key `from` fills in some scenarios only can be optional, and
|
|
58
|
+
stays absent where no producer ran.
|
|
59
|
+
- The README says how files under `features/steps/` load, so a helper
|
|
60
|
+
module named after its file can be used from any step.
|
|
61
|
+
|
|
62
|
+
### Changed
|
|
63
|
+
|
|
64
|
+
- An `integer` field's JSON Schema has the `minimum` and `maximum` zod
|
|
65
|
+
gives `z.int()`.
|
|
66
|
+
|
|
67
|
+
- `Nukadoko.run_command(..., unbundled: true)` runs the command with the
|
|
68
|
+
environment from before Bundler set up nuka, so `bin/rails runner` in
|
|
69
|
+
another Ruby project loads its own Gemfile instead of nuka's.
|
|
70
|
+
|
|
71
|
+
- A failed step record whose `error.kind` is `step_error` carries
|
|
72
|
+
`error.at`: the project's own backtrace frames, each `path:line` relative
|
|
73
|
+
to the project root, at most five, redacted like the message. A reader
|
|
74
|
+
finds the line that raised without calling the step again.
|
|
75
|
+
|
|
76
|
+
### Fixed
|
|
77
|
+
|
|
78
|
+
- Every command stopped with `NoMethodError` on a feature file that has a
|
|
79
|
+
`Rule:`. The engine now reads the scenarios and the background under each
|
|
80
|
+
rule.
|
|
81
|
+
- A page step could wait forever when the run did not start through
|
|
82
|
+
`exe/nuka` and the locale was not UTF-8 (`LANG` unset): the Playwright
|
|
83
|
+
client read the driver's output as US-ASCII and its reader thread died on
|
|
84
|
+
the first non-ASCII byte. The engine sets UTF-8 before it starts the
|
|
85
|
+
driver.
|
|
86
|
+
|
|
9
87
|
## [0.4.0] - 2026-11-16
|
|
10
88
|
|
|
11
89
|
### Changed
|
data/README.ja.md
CHANGED
|
@@ -44,8 +44,15 @@ end
|
|
|
44
44
|
```
|
|
45
45
|
|
|
46
46
|
- nil を許すフィールドには `null: true` を付けます。`enum :outcome, %w[accepted refused]` はその語だけを許し、Steep はリテラルの和として扱います。
|
|
47
|
+
- `optional: true` はキーがなくてもよいことを表し、本体には nil が渡ります(zod の `.optional()`)。`from` が一部のシナリオでだけ埋めるキーに使います。`default: 10` は、キーがないときにその値を渡します(`.default(10)`)。`min:`、`max:`、`positive: true`、`negative: true` は、数の値、文字列の長さ、配列の要素数の範囲を決め、zod と同じメッセージを出します。
|
|
48
|
+
- `array :todos do string :id end` はオブジェクトの配列です。`strings`、`numbers`、`integers` は 1 つのスカラー型の配列で、`array :ids, of: :string` は任意の要素型を指定します。`each: { positive: true }` はすべての要素の範囲を決めます。
|
|
49
|
+
- `features/steps/` の下の `*.rb` は、`features/steps/lib/` の補助ファイルも含めてすべて読み込まれます。ステップのクラスはファイル名を CamelCase にした名前で探します(`add_todo.rb` は `AddTodo` を定義します)。補助モジュールも同じ決まりで名付ければ(`lib/todo_api.rb` は `TodoApi`)、どのステップからも `require` なしで使えます。
|
|
47
50
|
- パターンの取り出し部分にはすべて名前を付けます。名前は `args` のキーです。
|
|
48
51
|
- `run`(Then ステップでは `observe`)のキーワード引数が、ステップが使うフィクスチャです。`nuka check` は本体を呼ばずに `Method#parameters` で読みます。
|
|
52
|
+
- `request` フィクスチャは `get`、`post`、`put`、`patch`、`delete` を送り、それぞれをステップの `http.jsonl` に記録します。パスはプログラムの URL につなげます。`http` か `https` の絶対 URL はその場所に送るので、外部の API も呼べます。プログラムのないプロジェクトでも使えます。
|
|
53
|
+
- `context` は `page` が属するブラウザコンテキストです。`page_as.("aki", { javaScriptEnabled: false })` は、その名前だけのブラウザコンテキストのページを返します。シナリオに 2 人目がいても、その人の cookie は別になります。同じ名前で後から呼ぶと、同じページが返ります。呼んだステップには `trace.aki.zip` が残り、シナリオの終わりに `final.aki.png` が残ります。
|
|
54
|
+
- `section.("label")` は本体がどこまで進んだかを記録の `sections` に残します。`poll.(description: "the order", timeout: 30_000, interval: 500) { 値か nil }` は、ブロックが値を返すまで呼び直します。時間切れなら `Nukadoko::PollTimeoutError` を出し、呼び出しごとに `polls` に残します。`evidence.attach(name, body)` はステップ自身のディレクトリにファイルを書き、`evidence.path(name)` はそこに書くためのパスを返します。どちらも記録の `evidence.attachments` に載ります。`result_of.(MakeTotal)` は、シナリオの前のステップが最後に返した値を読みます。まだなければ nil です。
|
|
55
|
+
- `base_url:`、`require_env:`、`page_as:`、`result_of:` は、`baseURL`、`requireEnv`、`pageAs`、`resultOf` の snake_case の名前です。RuboCop の命名の cop に引っかかりません。どちらの名前でも同じフィクスチャです。`require_env.("KEY")` はキーがないか空のときに例外を出し、記録の `required_env` に聞いたキーを並べます。
|
|
49
56
|
- Then ステップは `claims` と、世界を読む `observe` を書きます。claim の判定は nukadoko が行います。claim が比べる args のキーは `observe` に渡されません。
|
|
50
57
|
|
|
51
58
|
## コマンド
|
|
@@ -61,8 +68,9 @@ seed が同じなら、TypeScript 版と同じ順番です。
|
|
|
61
68
|
`--concurrency` は、feature ファイルを丸ごと、その数の worker プロセスに分けて実行します。
|
|
62
69
|
Feature の行に `@nukadoko:serial` があるファイルは、ほかのファイルのあとに 1 つずつ実行します。
|
|
63
70
|
`--repeat` は選んだシナリオをその回数だけ実行し、`--proof-runs` は control を何回実行するかを決め、`--records` はシナリオの記録を終わるたびに stdout に書きます。
|
|
64
|
-
- `nuka verdict [--json]` は、いちばん新しい run が今の作業ツリーを判定し、赤を残さなかったかを答えます。
|
|
71
|
+
- `nuka verdict [--json] [--trailer]` は、いちばん新しい run が今の作業ツリーを判定し、赤を残さなかったかを答えます。
|
|
65
72
|
run は始めません。
|
|
73
|
+
`--trailer` は、その答えでコミットに印を付ける git の trailer を 1 行出し、終了コード 0 で終わります。
|
|
66
74
|
- `nuka judge <feature>:<line> [--run <id>] [--json]` は、Then が判断を求める基準(`judged-as` の claim)について、run が読んだ値を見せます。
|
|
67
75
|
`--meets` か `--misses` に `--by <who>` と `--because <一文>` を付けると、その値の判断を `judgments/<feature>.json` に記録します。
|
|
68
76
|
次の run は、この記録と照らして基準を読みます。
|
|
@@ -98,9 +106,11 @@ gem が入れる実行ファイルには、`bundle binstubs <gem>` が `bin/<nam
|
|
|
98
106
|
`--then` とキャプチャ 1 つと一緒に使うと、claim がその 2 つを比べるので、ステップは書き直さずに使えます。
|
|
99
107
|
- ブラウザの起動設定は `nukadoko.config.rb` に `Nukadoko.config(browser: { executablePath: "..." })` と書きます。`page` を使うステップは、シナリオごとに自分のブラウザコンテキストを持ちます。ステップの記録には、ページが送ったリクエストとステップのトレースが残ります。
|
|
100
108
|
- `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}}` になります。
|
|
109
|
+
プログラムは nuka の環境変数を受け継ぎ、`bundle exec` の下では nuka の Gemfile を指します。
|
|
110
|
+
別の Ruby プロジェクトのコマンド(`bin/rails runner` など)を動かすときは、`unbundled: true` で Bundler が入る前の環境変数を使います。
|
|
101
111
|
- `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
112
|
- `Nukadoko.config(parameterTypes: [{ name: "priority", regexp: /高|低/, transformer: ->(s) { s == "高" ? "high" : "low" } }])` は、TypeScript の config の `parameterTypes` と同じようにパラメータ型を登録します。前後に空白のない文の中の値も、`{p:priority}` で読めます。regexp は Ruby の Regexp か文字列です。transformer は省いてもよく、regexp が捕まえたグループを受け取ります。`nuka check` は、組み込みの名前を使う型、どのパターンも使わない型、transformer が書き換えた値と比べる主張を報告します。
|
|
103
|
-
- プロジェクトのフィクスチャは `nukadoko.config.rb` に書きます。ブロックは値を `use` に渡し、その後ろが後片付けです。例: `Nukadoko.fixture(:store) { |use| use.(Store.new) }`。`scope: :process` にすると、環境ごとの実行全体で 1
|
|
113
|
+
- プロジェクトのフィクスチャは `nukadoko.config.rb` に書きます。ブロックは値を `use` に渡し、その後ろが後片付けです。例: `Nukadoko.fixture(:store) { |use| use.(Store.new) }`。`scope: :process` にすると、環境ごとの実行全体で 1 つの値を使います。キーワード引数は、フィクスチャが使うもの(別のプロジェクトのフィクスチャか、`page`、`request`、`env`、`requireEnv`、`baseURL`、`scratch` などの組み込み)を表します。組み込みと同じ名前のフィクスチャは、すべてのステップでそれを置き換えます。そのフィクスチャ自身の `page:` は組み込みの page なので、包んで渡せます。例: `Nukadoko.fixture(:page) { |use, page:| page.set_default_navigation_timeout(10_000); use.(page) }`。`page`、`context`、`pageAs` のどれも受け取らない `page` の上書きは、`nuka check` が `page-override-unowned` で止めます。
|
|
104
114
|
- `parts [CreateTodo, CompleteById]` で、ステップが呼べるステップを宣言します。`call.(CreateTodo, title: args.title)` で 1 つを実行し、args と返り値を確かめます。パターンのない part も書けます。呼び出しは、呼んだステップの記録の `calls` に残ります。`nuka check` は、`parts` の循環と、`mutates false` なのに `mutates true` の part を持つステップを報告します。
|
|
105
115
|
- `poll timeout_ms: 3000` は、すべての claim が 2 回続けて成り立つか時間切れになるまで、100 ミリ秒おきに `observe` を読み直します。`settled:` には、一度なったら変わらない状態を書きます。2 回続けてその状態なら、壊れた claim を待つのをやめます。読んだ結果はすべてステップの記録に残ります。
|
|
106
116
|
- `nuka steps [--json]` は語彙の一覧を出します。`nuka describe <step>` は 1 つのステップを、args と返り値の JSON Schema とともに出します。項目は TypeScript 版と同じです。
|
data/README.md
CHANGED
|
@@ -34,8 +34,15 @@ end
|
|
|
34
34
|
```
|
|
35
35
|
|
|
36
36
|
- A field takes `null: true` when nil is allowed. `enum :outcome, %w[accepted refused]` allows only those words, and Steep sees them as a union of literals.
|
|
37
|
+
- `optional: true` lets the key be absent, and the body reads nil, as zod's `.optional()`: a key that `from` fills in some scenarios only. `default: 10` reads an absent key as that value, as `.default(10)`. `min:`, `max:`, `positive: true`, and `negative: true` bound a number's value, a string's length, and an array's item count, with zod's messages.
|
|
38
|
+
- `array :todos do string :id end` is a list of objects. `strings`, `numbers`, and `integers` are lists of one scalar type, and `array :ids, of: :string` names any item type. `each: { positive: true }` bounds every item.
|
|
39
|
+
- Every `*.rb` file under `features/steps/` is loaded, a helper under `features/steps/lib/` too. A step class is looked up by the CamelCase form of its file name (`add_todo.rb` defines `AddTodo`), so a helper module named the same way (`lib/todo_api.rb` defines `TodoApi`) can be used from any step without a `require`.
|
|
37
40
|
- Every capture in the pattern is named, and each name is a key of `args`.
|
|
38
41
|
- The keyword arguments of `run` (or `observe`, in a Then step) name the fixtures the step needs. `nuka check` reads them with `Method#parameters`, without calling the body.
|
|
42
|
+
- The `request` fixture sends `get`, `post`, `put`, `patch`, and `delete` and records each in the step's `http.jsonl`. A path joins the program's URL; an absolute `http` or `https` URL goes where it names, so a step can call a third-party API, in a project with no program too.
|
|
43
|
+
- `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
|
+
- `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
|
+
- `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`.
|
|
39
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.
|
|
40
47
|
|
|
41
48
|
## Commands
|
|
@@ -43,7 +50,7 @@ end
|
|
|
43
50
|
- `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.
|
|
44
51
|
- `nuka check [--json]` reports what is wrong before anything runs.
|
|
45
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.
|
|
46
|
-
- `nuka verdict [--json]` says whether the newest run judged the working tree as it is now and left nothing red. It never starts a run.
|
|
53
|
+
- `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.
|
|
47
54
|
- `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.
|
|
48
55
|
- `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.
|
|
49
56
|
- `nuka run <feature>:<line> --step` walks one scenario a step at a time: after each step it waits until `nuka step` answers. `nuka step wait [--walk <n>] [--timeout <s>] [--json]` prints where the walk stands: the step it paused after, its record, and a screenshot and an ARIA snapshot of the page it left open. `nuka step next <pause> --walk <n>` runs the next step, and `nuka step stop <pause> --walk <n>` skips the rest, which leaves the scenario stopped and its row red. Either engine's `nuka step` answers either engine's walk.
|
|
@@ -52,10 +59,10 @@ end
|
|
|
52
59
|
- `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.
|
|
53
60
|
- `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
61
|
- 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
|
-
- 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}}`.
|
|
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`.
|
|
56
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.
|
|
57
64
|
- `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.
|
|
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.
|
|
65
|
+
- 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`).
|
|
59
66
|
- `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`.
|
|
60
67
|
- `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.
|
|
61
68
|
- `nuka steps [--json]` lists the vocabulary, and `nuka describe <step>` prints one step with the JSON Schema of its args and returns, in the fields the TypeScript engine prints.
|
data/lib/nukadoko/check.rb
CHANGED
|
@@ -35,7 +35,7 @@ module Nukadoko
|
|
|
35
35
|
end
|
|
36
36
|
end
|
|
37
37
|
|
|
38
|
-
FIXTURES = %w[baseURL call context env evidence page pageAs poll request requireEnv
|
|
38
|
+
FIXTURES = %w[baseURL base_url call context env evidence page pageAs page_as poll request requireEnv require_env resultOf result_of scratch section].freeze
|
|
39
39
|
|
|
40
40
|
class Check
|
|
41
41
|
attr_reader :findings #: Array[Finding]
|
|
@@ -326,6 +326,9 @@ module Nukadoko
|
|
|
326
326
|
"Remove or move lines so that exactly one of steps #{quoted} runs before this line.", nil)
|
|
327
327
|
next
|
|
328
328
|
end
|
|
329
|
+
# An optional key may stay empty: the schema says absent is fine.
|
|
330
|
+
next unless step.args.required_names.include?(key)
|
|
331
|
+
|
|
329
332
|
undefined = scenario.steps.first(index).each_index.select { Engine.matches(@usable, scenario.steps[_1].text).empty? }
|
|
330
333
|
issue = { index: index, step: step.step_name, key: key, candidates: names }
|
|
331
334
|
next held << issue.merge(undefined: undefined) if undefined.any?
|
|
@@ -387,7 +390,7 @@ module Nukadoko
|
|
|
387
390
|
"If #{which} is meant to run #{steps_phrase.(held.flat_map { _1[:candidates] }.uniq)}, reword that line to match that step's pattern. Otherwise fix the undefined-step finding first, then run nuka check again: a held-back finding that still applies is reported then.", nil)
|
|
388
391
|
end
|
|
389
392
|
|
|
390
|
-
SCENARIO_ONLY = FIXTURES - %w[env requireEnv baseURL]
|
|
393
|
+
SCENARIO_ONLY = FIXTURES - %w[env requireEnv require_env baseURL base_url]
|
|
391
394
|
|
|
392
395
|
# Fixture definitions that can never resolve, and (in a whole-project
|
|
393
396
|
# check) one no step reaches.
|
|
@@ -416,6 +419,14 @@ module Nukadoko
|
|
|
416
419
|
end
|
|
417
420
|
fixtures.each_key { visit.(_1, []) if state[_1] == :white }
|
|
418
421
|
|
|
422
|
+
# An override of page that names no browser fixture cannot hand back
|
|
423
|
+
# a page the engine launched, records, and traces.
|
|
424
|
+
if (page = fixtures[:page]) && (page.dependencies & %i[page context pageAs page_as]).empty?
|
|
425
|
+
findings << Finding.new("error", "page-override-unowned", config, nil, nil,
|
|
426
|
+
%(fixture "page" overrides the builtin page but destructures none of "page", "context", or "pageAs": there is no way for it to hand back a page the executor still owns and measures),
|
|
427
|
+
Codes.fix("page-override-unowned"), nil)
|
|
428
|
+
end
|
|
429
|
+
|
|
419
430
|
fixtures.each_value do |fixture|
|
|
420
431
|
next unless fixture.scope == :process
|
|
421
432
|
|
|
@@ -778,7 +789,7 @@ module Nukadoko
|
|
|
778
789
|
# attachment can never be, fail binding with certainty.
|
|
779
790
|
#: (Scenario, PickleStep, singleton(Step), Hash[String, untyped]) -> void
|
|
780
791
|
def check_fill(scenario, line, step, captures)
|
|
781
|
-
missing = step.args.
|
|
792
|
+
missing = step.args.required_names - captures.keys - step.from.keys
|
|
782
793
|
if line.table || line.doc_string
|
|
783
794
|
if missing.size != 1
|
|
784
795
|
detail = missing.empty? ? "every args key is already consumed by named captures or declared from" : "#{missing.size} args keys are left unconsumed (#{missing.join(", ")}); exactly one is required"
|
|
@@ -833,7 +844,7 @@ module Nukadoko
|
|
|
833
844
|
#: (Scenario, PickleStep, singleton(Step), Hash[String, untyped]) -> void
|
|
834
845
|
def check_unfit_trees(scenario, line, step, captures)
|
|
835
846
|
claims = step.claims or return
|
|
836
|
-
docstring_keys = line.doc_string ? step.args.
|
|
847
|
+
docstring_keys = line.doc_string ? step.args.required_names - captures.keys - step.from.keys.map(&:to_s) : []
|
|
837
848
|
claims.each_with_index do |claim, index|
|
|
838
849
|
key = claim[:expected]
|
|
839
850
|
next if claim[:each] || claim[:compare] != "fits-aria-snapshot" || !key.is_a?(String)
|
data/lib/nukadoko/cli.rb
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
# TypeScript engine prints, so an agent reads both engines the same way.
|
|
6
6
|
module Nukadoko
|
|
7
7
|
class CLI
|
|
8
|
-
FLAGS = %w[--json --no-check --dry-run --then --replace --allure --records --meets --misses --step].freeze
|
|
8
|
+
FLAGS = %w[--json --no-check --dry-run --then --replace --allure --records --meets --misses --step --trailer].freeze
|
|
9
9
|
REPEATED = %w[--tag --env --use].freeze
|
|
10
10
|
VALUED = %w[--format --out --base --repeat --concurrency --order --proof-runs --args --pattern --description --feature --command --request --from --cwd --body --argv
|
|
11
11
|
--run --by --because --walk --timeout].freeze
|
|
@@ -44,7 +44,8 @@ module Nukadoko
|
|
|
44
44
|
alone
|
|
45
45
|
nuka verdict say whether the newest run judged the working tree as
|
|
46
46
|
it is now and left nothing red; exits 1 when it did
|
|
47
|
-
not, and never starts a run
|
|
47
|
+
not, and never starts a run; --trailer prints one git
|
|
48
|
+
trailer line to stamp a commit, and exits 0
|
|
48
49
|
nuka judge <target> show the values a run read for a criterion whose Then
|
|
49
50
|
asks for a judgment (<feature file>:<scenario line>),
|
|
50
51
|
or record a judgment of them with --meets or --misses
|
|
@@ -443,7 +444,7 @@ module Nukadoko
|
|
|
443
444
|
return refuse(Engine::Refusal.new("step-args-invalid", "--args must be a JSON object", fix: args_fix, run: describe)) unless given.is_a?(Hash)
|
|
444
445
|
end
|
|
445
446
|
args, origins, used = used_args(step, @options["--use"])
|
|
446
|
-
if @options["--args"].empty? && (step.args.
|
|
447
|
+
if @options["--args"].empty? && (step.args.required_names - args.keys).any?
|
|
447
448
|
return refuse(Engine::Refusal.new("step-args-invalid", "--args is required unless --use supplies this step's arguments", fix: args_fix, run: describe))
|
|
448
449
|
end
|
|
449
450
|
|
|
@@ -761,13 +762,18 @@ module Nukadoko
|
|
|
761
762
|
#: () -> Integer
|
|
762
763
|
def verdict
|
|
763
764
|
answer = Engine::Verdict.new(@project)
|
|
765
|
+
# --trailer observes: a stamp never blocks, so only the exit code
|
|
766
|
+
# moves, and the envelope still says what the verdict was.
|
|
767
|
+
trailer = @options.key?("--trailer")
|
|
764
768
|
if @json
|
|
765
769
|
emit({ **head("verdict", answer.open? ? "failed" : "passed", answer.findings), **answer.envelope_fields }, answer.findings, "verdict")
|
|
770
|
+
elsif trailer
|
|
771
|
+
@out.puts answer.trailer
|
|
766
772
|
else
|
|
767
773
|
@out.puts answer.headline
|
|
768
774
|
emit({}, answer.findings, "verdict")
|
|
769
775
|
end
|
|
770
|
-
answer.open? ? 1 : 0
|
|
776
|
+
answer.open? && !trailer ? 1 : 0
|
|
771
777
|
end
|
|
772
778
|
|
|
773
779
|
# What check says about the env files; a file it cannot read, or a key
|
data/lib/nukadoko/command.rb
CHANGED
|
@@ -21,8 +21,11 @@ module Nukadoko
|
|
|
21
21
|
# no exit code to read. `input` (or `stdin`) is written to the program's
|
|
22
22
|
# stdin. `redact` names secrets the step holds itself, which the record
|
|
23
23
|
# writes as `{{secret.NAME}}` while the program still gets the real value.
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
# `unbundled: true` runs the command with the environment from before
|
|
25
|
+
# Bundler set up nuka (no BUNDLE_GEMFILE, no -rbundler/setup in RUBYOPT),
|
|
26
|
+
# for a command in another Ruby project, which has a Gemfile of its own.
|
|
27
|
+
#: (String, ?Array[String], ?cwd: String, ?env: Hash[String | Symbol, String], ?input: String?, ?stdin: String?, ?timeout: Numeric?, ?redact: Hash[String | Symbol, String], ?files: bool, ?unbundled: bool) -> Hash[Symbol, untyped]
|
|
28
|
+
def self.run_command(command, args = [], cwd: Dir.pwd, env: {}, input: nil, stdin: nil, timeout: nil, redact: {}, files: false, unbundled: false)
|
|
26
29
|
stdin = input.nil? ? stdin : input
|
|
27
30
|
held = Engine::Secrets.new(redact.to_h { |name, value| [name.to_s, value.to_s] })
|
|
28
31
|
recording = Engine::Processes.current
|
|
@@ -33,6 +36,7 @@ module Nukadoko
|
|
|
33
36
|
traceparent = (Engine::Trace.current&.process_traceparent unless env.key?("TRACEPARENT"))
|
|
34
37
|
chosen = env
|
|
35
38
|
env = env.merge("TRACEPARENT" => traceparent) if traceparent
|
|
39
|
+
env = Engine::Processes.unbundled(env) if unbundled
|
|
36
40
|
before = Engine::FileWalk.snapshot(cwd) if recording || files
|
|
37
41
|
started = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
38
42
|
# A group of its own, so its close tells whether anything it started still runs.
|
|
@@ -70,12 +74,26 @@ module Nukadoko
|
|
|
70
74
|
#: () -> bool
|
|
71
75
|
def self.groups? = !Gem.win_platform?
|
|
72
76
|
|
|
77
|
+
# `env` on top of the environment Bundler found when it set up nuka:
|
|
78
|
+
# each variable Bundler added is unset and each one it changed is put
|
|
79
|
+
# back. Without Bundler loaded there is nothing to undo.
|
|
80
|
+
#: (Hash[String, String?]) -> Hash[String, String?]
|
|
81
|
+
def self.unbundled(env)
|
|
82
|
+
return env unless defined?(::Bundler) && ::Bundler.respond_to?(:unbundled_env)
|
|
83
|
+
|
|
84
|
+
original = ::Bundler.unbundled_env
|
|
85
|
+
added = (ENV.keys - original.keys).to_h { [_1, nil] }
|
|
86
|
+
changed = original.reject { |key, value| ENV[key] == value }
|
|
87
|
+
added.merge(changed).merge(env)
|
|
88
|
+
end
|
|
89
|
+
|
|
73
90
|
# Runs the command to its close, its stdin closed after `input`.
|
|
74
|
-
#: (Hash[String, String], Array[String], String, String?, Numeric?, group: bool) -> [String, String, Process::Status, bool?]
|
|
91
|
+
#: (Hash[String, String?], Array[String], String, String?, Numeric?, group: bool) -> [String, String, Process::Status, bool?]
|
|
75
92
|
def self.spawn(env, argv, cwd, input, timeout, group:)
|
|
76
93
|
options = { chdir: cwd } #: Hash[Symbol, untyped]
|
|
77
94
|
options[:pgroup] = true if group && groups?
|
|
78
|
-
|
|
95
|
+
# A nil value unsets the variable, which Open3's signature leaves out.
|
|
96
|
+
Open3.popen3(_ = env, *argv, **options) do |stdin, out, err, thread|
|
|
79
97
|
stdin.write(input.to_s)
|
|
80
98
|
stdin.close
|
|
81
99
|
readers = [Thread.new { out.read }, Thread.new { err.read }]
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
# rbs_inline: enabled
|
|
3
|
+
|
|
4
|
+
# Where a step's own code raised, as the project's own frames of the
|
|
5
|
+
# backtrace. A step record's error message says what went wrong but not
|
|
6
|
+
# where, so a reader had to call the step again outside nukadoko to find the
|
|
7
|
+
# line. The frames kept are the ones a reader can open and change: inside
|
|
8
|
+
# the project root, and outside the gem and any installed bundle, as the
|
|
9
|
+
# TypeScript engine leaves out node_modules.
|
|
10
|
+
module Nukadoko
|
|
11
|
+
module Engine
|
|
12
|
+
module ErrorFrames
|
|
13
|
+
# The first few frames are where the code was when it raised; the rest
|
|
14
|
+
# is the call chain a reader rarely needs.
|
|
15
|
+
MAX = 5
|
|
16
|
+
GEM_ROOT = File.expand_path("../..", __dir__.to_s)
|
|
17
|
+
|
|
18
|
+
module_function
|
|
19
|
+
|
|
20
|
+
# Each frame as `path:line` relative to `root`, in backtrace order,
|
|
21
|
+
# without repeats.
|
|
22
|
+
#: (Exception, String) -> Array[String]
|
|
23
|
+
def of(error, root)
|
|
24
|
+
# A root under a symlink (macOS /var) names files by either spelling.
|
|
25
|
+
roots = [File.expand_path(root), (File.realpath(root) rescue nil)].compact.uniq
|
|
26
|
+
frames = [] #: Array[String]
|
|
27
|
+
(error.backtrace_locations || []).each do |location|
|
|
28
|
+
file = location.absolute_path || location.path
|
|
29
|
+
next unless file && File.absolute_path?(file)
|
|
30
|
+
base = roots.find { file.start_with?("#{_1}/") }
|
|
31
|
+
next if file.start_with?("#{GEM_ROOT}/") || base.nil?
|
|
32
|
+
|
|
33
|
+
relative = file.delete_prefix("#{base}/")
|
|
34
|
+
next if relative.split("/").include?("vendor") && relative.include?("/bundle/")
|
|
35
|
+
|
|
36
|
+
frame = "#{relative}:#{location.lineno}"
|
|
37
|
+
frames << frame unless frames.include?(frame)
|
|
38
|
+
break if frames.size == MAX
|
|
39
|
+
end
|
|
40
|
+
frames
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
data/lib/nukadoko/features.rb
CHANGED
|
@@ -96,7 +96,9 @@ module Nukadoko
|
|
|
96
96
|
def self.collect_lines(node, lines, background, headers, names)
|
|
97
97
|
node.tags&.each { lines[_1.id] = _1.location.line }
|
|
98
98
|
node.children.each do |child|
|
|
99
|
-
|
|
99
|
+
# A rule's own children are RuleChild values, which hold a background or
|
|
100
|
+
# a scenario and never another rule.
|
|
101
|
+
next collect_lines(child.rule, lines, background, headers, names) if child.respond_to?(:rule) && child.rule
|
|
100
102
|
|
|
101
103
|
scenario = child.scenario || child.background
|
|
102
104
|
next unless scenario
|
data/lib/nukadoko/fixtures.rb
CHANGED
|
@@ -28,12 +28,25 @@ module Nukadoko
|
|
|
28
28
|
class Request
|
|
29
29
|
attr_reader :log #: Array[Hash[Symbol, untyped]]
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
# `base_url` is the world's URL, which a path joins onto; a project with
|
|
32
|
+
# no program has none. An absolute URL, http or https, goes where it
|
|
33
|
+
# names, so a step can call a third-party API and still have its
|
|
34
|
+
# requests recorded.
|
|
35
|
+
#: (String?) -> void
|
|
32
36
|
def initialize(base_url)
|
|
33
|
-
@base = URI(base_url)
|
|
37
|
+
@base = base_url && URI(base_url)
|
|
34
38
|
@log = []
|
|
35
39
|
end
|
|
36
40
|
|
|
41
|
+
#: (String) -> URI::Generic
|
|
42
|
+
def target(path)
|
|
43
|
+
named = URI(path.to_s)
|
|
44
|
+
return named if named.absolute?
|
|
45
|
+
raise ArgumentError, %(The request fixture needs an absolute URL for "#{path}": this world has no program, so there is no base URL to join a path onto) unless @base
|
|
46
|
+
|
|
47
|
+
URI.join(@base.to_s, path.to_s)
|
|
48
|
+
end
|
|
49
|
+
|
|
37
50
|
BODY_TEXT = 16 * 1024
|
|
38
51
|
|
|
39
52
|
#: (Float) -> Integer
|
|
@@ -57,7 +70,8 @@ module Nukadoko
|
|
|
57
70
|
# `data:` is sent as JSON; `body:` is sent as it is, for a request
|
|
58
71
|
# whose body is meant to be wrong.
|
|
59
72
|
define_method(verb) do |path, data: nil, body: nil, headers: {}|
|
|
60
|
-
|
|
73
|
+
# @type self: Request
|
|
74
|
+
uri = target(path)
|
|
61
75
|
klass = Net::HTTP.const_get(verb.capitalize)
|
|
62
76
|
req = klass.new(uri, headers)
|
|
63
77
|
if data
|
|
@@ -73,7 +87,7 @@ module Nukadoko
|
|
|
73
87
|
entry = { method: verb.upcase, url: uri.to_s, **(path.to_s == uri.to_s ? {} : { declared_url: path.to_s }) }
|
|
74
88
|
stamp = traceparent ? { traceparent: traceparent, traceparent_sent_to: [Trace.origin(uri)] } : {}
|
|
75
89
|
begin
|
|
76
|
-
res = HttpRecording.unrecorded { Net::HTTP.start(uri.host.to_s, uri.port) { _1.request(req) } }
|
|
90
|
+
res = HttpRecording.unrecorded { Net::HTTP.start(uri.host.to_s, uri.port, use_ssl: uri.scheme == "https") { _1.request(req) } }
|
|
77
91
|
rescue StandardError => e
|
|
78
92
|
@log << entry.merge(status: 0, duration_ms: Request.since(started), via: "request", **stamp, **Request.body(:request_body, req.body),
|
|
79
93
|
error: e.message.lines.first.to_s.chomp)
|
|
@@ -139,11 +153,22 @@ module Nukadoko
|
|
|
139
153
|
false
|
|
140
154
|
end
|
|
141
155
|
|
|
142
|
-
#: (
|
|
143
|
-
def
|
|
156
|
+
#: () -> untyped
|
|
157
|
+
def launch
|
|
144
158
|
require "playwright"
|
|
159
|
+
# playwright-ruby-client parses each driver message from a buffer in
|
|
160
|
+
# the default external encoding. Under US-ASCII (LANG unset) its reader
|
|
161
|
+
# thread dies on the first non-ASCII byte and the step waits forever.
|
|
162
|
+
# exe/nuka sets UTF-8, but a run started another way (a Rake task, a
|
|
163
|
+
# script that calls the CLI) reaches here without it.
|
|
164
|
+
Encoding.default_external = Encoding::UTF_8 unless @execution
|
|
145
165
|
@execution ||= Playwright.create(playwright_cli_executable_path: ENV.fetch("PLAYWRIGHT_CLI", "npx playwright"))
|
|
146
166
|
@browser ||= @execution.playwright.chromium.launch(**@launch_options)
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
#: (String, Array[Hash[Symbol, untyped]]) -> [untyped, ^() -> void]
|
|
170
|
+
def page_for(step_dir, log)
|
|
171
|
+
launch
|
|
147
172
|
@context ||= @browser.new_context(baseURL: @base_url).tap do |context|
|
|
148
173
|
context.tracing.start(screenshots: true, snapshots: true)
|
|
149
174
|
watch_requests(context)
|
|
@@ -368,7 +393,7 @@ module Nukadoko
|
|
|
368
393
|
# nil when it opened none.
|
|
369
394
|
#: () -> Hash[Symbol, untyped]?
|
|
370
395
|
def scenario_browser
|
|
371
|
-
@context && @browser ? { type: "chromium", version: @browser.version } : nil
|
|
396
|
+
(@context || named.any?) && @browser ? { type: "chromium", version: @browser.version } : nil
|
|
372
397
|
end
|
|
373
398
|
|
|
374
399
|
# Closes the scenario's context, and returns the screenshot of its
|
|
@@ -382,12 +407,88 @@ module Nukadoko
|
|
|
382
407
|
FileUtils.mkdir_p(dir)
|
|
383
408
|
shots << { file: "final.png", at: Time.now.utc.iso8601(3) } if masked_shot(@page, File.join(dir, "final.png"), monotonic + VIEW_TIMEOUT_MS / 1000.0, bounded: false)
|
|
384
409
|
end
|
|
410
|
+
named.each do |name, held|
|
|
411
|
+
if dir
|
|
412
|
+
FileUtils.mkdir_p(dir)
|
|
413
|
+
file = "final.#{name}.png"
|
|
414
|
+
shots << { file: file, at: Time.now.utc.iso8601(3), as: name } if masked_shot(held[:page], File.join(dir, file), monotonic + VIEW_TIMEOUT_MS / 1000.0, bounded: false)
|
|
415
|
+
end
|
|
416
|
+
held[:context].tracing.stop rescue nil
|
|
417
|
+
held[:context].close rescue nil
|
|
418
|
+
end
|
|
419
|
+
@named = {}
|
|
385
420
|
@context&.tracing&.stop
|
|
386
421
|
@context&.close
|
|
387
422
|
@context = @page = nil
|
|
388
423
|
shots
|
|
389
424
|
end
|
|
390
425
|
|
|
426
|
+
CONTEXT_NAME = /\A[a-z0-9][a-z0-9-]{0,63}\z/
|
|
427
|
+
|
|
428
|
+
# The page of a browser context of its own, named `name`, so a second
|
|
429
|
+
# person in the scenario has cookies and storage of their own. The
|
|
430
|
+
# context opens on the first call for the name in the scenario, with
|
|
431
|
+
# `options` over the world's base URL, and a later call gets the same
|
|
432
|
+
# page. Each step that calls it gets a trace chunk, trace.<name>.zip,
|
|
433
|
+
# and the page's requests go to the step's log with `as`.
|
|
434
|
+
#: (String, Hash[untyped, untyped]?, String, Array[Hash[Symbol, untyped]]) -> untyped
|
|
435
|
+
def page_as(name, options, step_dir, log)
|
|
436
|
+
unless name.is_a?(String) && name.match?(CONTEXT_NAME)
|
|
437
|
+
raise InvalidContextNameError, "pageAs name #{name.inspect} is not valid. Use 1 to 64 lowercase letters, digits, and hyphens, " \
|
|
438
|
+
"starting with a letter or a digit: the name becomes part of evidence file names such as trace.<name>.zip."
|
|
439
|
+
end
|
|
440
|
+
asked = options&.to_h { |key, value| [key.to_sym, value] }&.compact
|
|
441
|
+
held = named[name]
|
|
442
|
+
if held
|
|
443
|
+
if asked && asked != held[:options]
|
|
444
|
+
raise ContextOptionsConflictError, "pageAs(#{name.inspect}) already opened that context in this scenario with other options. " \
|
|
445
|
+
"A context keeps the options it was created with: pass the same options, or none, on a later call."
|
|
446
|
+
end
|
|
447
|
+
else
|
|
448
|
+
launch
|
|
449
|
+
context = @browser.new_context(baseURL: @base_url, **(asked || {}))
|
|
450
|
+
context.tracing.start(screenshots: true, snapshots: true)
|
|
451
|
+
held = named[name] = { context: context, page: context.new_page, options: asked || {} }
|
|
452
|
+
end
|
|
453
|
+
unless step_named.key?(name)
|
|
454
|
+
held[:context].tracing.start_chunk
|
|
455
|
+
listener = ->(req) { log << { method: req.method, url: req.url, via: "page", as: name } }
|
|
456
|
+
held[:page].on("request", listener)
|
|
457
|
+
step_named[name] = [step_dir, listener]
|
|
458
|
+
end
|
|
459
|
+
held[:page]
|
|
460
|
+
end
|
|
461
|
+
|
|
462
|
+
# Ends the step's chunk of each named context it reached, and names
|
|
463
|
+
# the files, in the order the contexts opened.
|
|
464
|
+
#: () -> Array[Hash[Symbol, String]]
|
|
465
|
+
def finish_named
|
|
466
|
+
traces = [] #: Array[Hash[Symbol, String]]
|
|
467
|
+
named.each do |name, held|
|
|
468
|
+
step_dir, listener = step_named[name]
|
|
469
|
+
next unless step_dir
|
|
470
|
+
|
|
471
|
+
held[:page].off("request", listener)
|
|
472
|
+
file = "trace.#{name}.zip"
|
|
473
|
+
held[:context].tracing.stop_chunk(path: File.join(step_dir, file))
|
|
474
|
+
traces << { as: name, file: file }
|
|
475
|
+
rescue StandardError
|
|
476
|
+
nil
|
|
477
|
+
end
|
|
478
|
+
@step_named = {}
|
|
479
|
+
traces
|
|
480
|
+
end
|
|
481
|
+
|
|
482
|
+
private
|
|
483
|
+
|
|
484
|
+
#: () -> Hash[String, Hash[Symbol, untyped]]
|
|
485
|
+
def named = (@named ||= {})
|
|
486
|
+
|
|
487
|
+
#: () -> Hash[String, [String, untyped]]
|
|
488
|
+
def step_named = (@step_named ||= {})
|
|
489
|
+
|
|
490
|
+
public
|
|
491
|
+
|
|
391
492
|
#: () -> void
|
|
392
493
|
def close
|
|
393
494
|
@browser&.close
|
|
@@ -73,6 +73,27 @@ module Nukadoko
|
|
|
73
73
|
name.delete_prefix(prefix.empty? ? "" : "#{prefix}/") if now != before&.b
|
|
74
74
|
end.sort
|
|
75
75
|
end
|
|
76
|
+
|
|
77
|
+
# What `commit` holds as the judgments of a feature file: its
|
|
78
|
+
# entries, none when it holds no such file, or why the file did not
|
|
79
|
+
# parse. nil when git does not answer.
|
|
80
|
+
#: (String, String, String) -> Hash[Symbol, untyped]?
|
|
81
|
+
def at_commit(project, commit, feature)
|
|
82
|
+
prefix, ok = Base.git(project, "rev-parse", "--show-prefix")
|
|
83
|
+
return nil unless ok
|
|
84
|
+
|
|
85
|
+
prefix = prefix.delete_suffix("/")
|
|
86
|
+
name = prefix.empty? ? of(feature) : "#{prefix}/#{of(feature)}"
|
|
87
|
+
top, ok = Base.git(project, "rev-parse", "--show-toplevel")
|
|
88
|
+
return nil unless ok
|
|
89
|
+
|
|
90
|
+
listed, ok = Base.git(top, "ls-tree", "-z", "--name-only", commit, "--", name, strip: false)
|
|
91
|
+
return nil unless ok
|
|
92
|
+
return { entries: [] } unless listed.split("\0").include?(name)
|
|
93
|
+
|
|
94
|
+
text, ok = Base.git(top, "show", "#{commit}:#{name}", strip: false)
|
|
95
|
+
ok ? Judgments.parse_file(text.dup.force_encoding("UTF-8")) : nil
|
|
96
|
+
end
|
|
76
97
|
end
|
|
77
98
|
end
|
|
78
99
|
end
|