nukadoko 0.5.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (203) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +553 -3
  3. data/README.ja.md +22 -6
  4. data/README.md +13 -7
  5. data/docs/ci.ja.md +542 -0
  6. data/docs/ci.md +635 -0
  7. data/docs/commands.ja.md +1524 -0
  8. data/docs/commands.md +1281 -0
  9. data/docs/engines.json +19 -0
  10. data/docs/execution-events.ja.md +336 -0
  11. data/docs/execution-events.md +423 -0
  12. data/docs/glossary.json +1348 -0
  13. data/docs/guide.ja.md +733 -0
  14. data/docs/guide.md +815 -0
  15. data/docs/intent.ja.md +133 -0
  16. data/docs/intent.md +156 -0
  17. data/docs/layout.ja.md +442 -0
  18. data/docs/layout.md +399 -0
  19. data/docs/releasing.ja.md +186 -0
  20. data/docs/releasing.md +237 -0
  21. data/docs/ruby/reference.ja.md +302 -0
  22. data/docs/ruby/reference.md +368 -0
  23. data/docs/spec.ja.md +8916 -0
  24. data/docs/spec.md +11250 -0
  25. data/docs/tutorial.ja.md +451 -0
  26. data/docs/tutorial.md +458 -0
  27. data/docs/typescript/adopting.ja.md +231 -0
  28. data/docs/typescript/adopting.md +251 -0
  29. data/docs/typescript/doors.ja.md +301 -0
  30. data/docs/typescript/doors.md +329 -0
  31. data/docs/typescript/migration-playwright-test.ja.md +189 -0
  32. data/docs/typescript/migration-playwright-test.md +212 -0
  33. data/docs/typescript/migration.ja.md +391 -0
  34. data/docs/typescript/migration.md +505 -0
  35. data/docs/typescript/reference.ja.md +176 -0
  36. data/docs/typescript/reference.md +197 -0
  37. data/docs/typescript/upgrading.ja.md +1774 -0
  38. data/docs/typescript/upgrading.md +2224 -0
  39. data/docs/web-app.ja.md +627 -0
  40. data/docs/web-app.md +659 -0
  41. data/docs/writing-scenarios.ja.md +544 -0
  42. data/docs/writing-scenarios.md +563 -0
  43. data/lib/nukadoko/base.rb +12 -5
  44. data/lib/nukadoko/changed_files.rb +95 -0
  45. data/lib/nukadoko/check.rb +459 -51
  46. data/lib/nukadoko/claim_drops.rb +271 -0
  47. data/lib/nukadoko/claim_line.rb +24 -4
  48. data/lib/nukadoko/claim_rules.rb +143 -1
  49. data/lib/nukadoko/claim_sides.rb +157 -9
  50. data/lib/nukadoko/cli.rb +403 -50
  51. data/lib/nukadoko/codes.json +246 -21
  52. data/lib/nukadoko/codes.rb +21 -4
  53. data/lib/nukadoko/command.rb +120 -13
  54. data/lib/nukadoko/command_help.rb +128 -0
  55. data/lib/nukadoko/compat.rb +469 -0
  56. data/lib/nukadoko/criteria.rb +1 -1
  57. data/lib/nukadoko/definition.rb +157 -7
  58. data/lib/nukadoko/error_frames.rb +6 -3
  59. data/lib/nukadoko/events/count.rb +146 -0
  60. data/lib/nukadoko/events/counted.rb +114 -0
  61. data/lib/nukadoko/events/format.rb +257 -0
  62. data/lib/nukadoko/events/lists.rb +154 -0
  63. data/lib/nukadoko/events/path.rb +285 -0
  64. data/lib/nukadoko/events/read.rb +284 -0
  65. data/lib/nukadoko/events/reader.rb +490 -0
  66. data/lib/nukadoko/events/selection.rb +252 -0
  67. data/lib/nukadoko/events/tally.rb +438 -0
  68. data/lib/nukadoko/features.rb +2 -2
  69. data/lib/nukadoko/fixtures.rb +160 -35
  70. data/lib/nukadoko/http_recording.rb +6 -2
  71. data/lib/nukadoko/intent.rb +364 -0
  72. data/lib/nukadoko/intent_file.rb +81 -0
  73. data/lib/nukadoko/intent_view.rb +190 -0
  74. data/lib/nukadoko/js_json.rb +2 -1
  75. data/lib/nukadoko/judge.rb +2 -2
  76. data/lib/nukadoko/judgment_file.rb +22 -1
  77. data/lib/nukadoko/judgments.rb +33 -3
  78. data/lib/nukadoko/measure_mcp.rb +202 -0
  79. data/lib/nukadoko/parts.rb +8 -2
  80. data/lib/nukadoko/path_view.rb +252 -0
  81. data/lib/nukadoko/place_rows.rb +161 -0
  82. data/lib/nukadoko/program.rb +1265 -51
  83. data/lib/nukadoko/program_log.rb +122 -0
  84. data/lib/nukadoko/program_shape.rb +385 -0
  85. data/lib/nukadoko/project_fixtures.rb +43 -10
  86. data/lib/nukadoko/project_program.rb +5 -4
  87. data/lib/nukadoko/repeated_prefix.rb +310 -0
  88. data/lib/nukadoko/report_run.rb +3 -3
  89. data/lib/nukadoko/run.rb +1156 -159
  90. data/lib/nukadoko/run_record.rb +70 -46
  91. data/lib/nukadoko/scaffold.rb +24 -6
  92. data/lib/nukadoko/schema.rb +15 -2
  93. data/lib/nukadoko/secrets.rb +55 -5
  94. data/lib/nukadoko/states.rb +478 -0
  95. data/lib/nukadoko/step.rb +71 -2
  96. data/lib/nukadoko/step_fixtures.rb +52 -3
  97. data/lib/nukadoko/summary.rb +803 -30
  98. data/lib/nukadoko/table.rb +4 -2
  99. data/lib/nukadoko/text_fit.rb +20 -7
  100. data/lib/nukadoko/trace.rb +152 -45
  101. data/lib/nukadoko/tree_passes.rb +95 -33
  102. data/lib/nukadoko/underneath.rb +311 -0
  103. data/lib/nukadoko/verdict.rb +18 -1
  104. data/lib/nukadoko/version.rb +1 -1
  105. data/lib/nukadoko/vocabulary.rb +166 -23
  106. data/lib/nukadoko/walk.rb +2 -2
  107. data/lib/nukadoko/walk_step.rb +1 -1
  108. data/lib/nukadoko.rb +23 -0
  109. data/llms.txt +42 -35
  110. data/sig/generated/nukadoko/base.rbs +4 -4
  111. data/sig/generated/nukadoko/changed_files.rbs +42 -0
  112. data/sig/generated/nukadoko/check.rbs +147 -10
  113. data/sig/generated/nukadoko/claim_drops.rbs +135 -0
  114. data/sig/generated/nukadoko/claim_line.rbs +11 -0
  115. data/sig/generated/nukadoko/claim_rules.rbs +49 -4
  116. data/sig/generated/nukadoko/claim_sides.rbs +63 -12
  117. data/sig/generated/nukadoko/cli.rbs +80 -7
  118. data/sig/generated/nukadoko/codes.rbs +19 -4
  119. data/sig/generated/nukadoko/command.rbs +68 -1
  120. data/sig/generated/nukadoko/command_help.rbs +18 -0
  121. data/sig/generated/nukadoko/compat.rbs +392 -0
  122. data/sig/generated/nukadoko/criteria.rbs +1 -1
  123. data/sig/generated/nukadoko/definition.rbs +50 -0
  124. data/sig/generated/nukadoko/error_frames.rbs +1 -1
  125. data/sig/generated/nukadoko/events/count.rbs +69 -0
  126. data/sig/generated/nukadoko/events/counted.rbs +70 -0
  127. data/sig/generated/nukadoko/events/format.rbs +163 -0
  128. data/sig/generated/nukadoko/events/lists.rbs +47 -0
  129. data/sig/generated/nukadoko/events/path.rbs +161 -0
  130. data/sig/generated/nukadoko/events/read.rbs +109 -0
  131. data/sig/generated/nukadoko/events/reader.rbs +226 -0
  132. data/sig/generated/nukadoko/events/selection.rbs +100 -0
  133. data/sig/generated/nukadoko/events/tally.rbs +227 -0
  134. data/sig/generated/nukadoko/features.rbs +6 -4
  135. data/sig/generated/nukadoko/fixtures.rbs +67 -11
  136. data/sig/generated/nukadoko/http_recording.rbs +1 -1
  137. data/sig/generated/nukadoko/intent.rbs +132 -0
  138. data/sig/generated/nukadoko/intent_file.rbs +46 -0
  139. data/sig/generated/nukadoko/intent_view.rbs +69 -0
  140. data/sig/generated/nukadoko/judgment_file.rbs +7 -1
  141. data/sig/generated/nukadoko/judgments.rbs +10 -0
  142. data/sig/generated/nukadoko/measure_mcp.rbs +104 -0
  143. data/sig/generated/nukadoko/parts.rbs +2 -2
  144. data/sig/generated/nukadoko/path_view.rbs +105 -0
  145. data/sig/generated/nukadoko/place_rows.rbs +43 -0
  146. data/sig/generated/nukadoko/program.rbs +627 -23
  147. data/sig/generated/nukadoko/program_log.rbs +67 -0
  148. data/sig/generated/nukadoko/program_shape.rbs +147 -0
  149. data/sig/generated/nukadoko/project_fixtures.rbs +16 -3
  150. data/sig/generated/nukadoko/project_program.rbs +2 -1
  151. data/sig/generated/nukadoko/repeated_prefix.rbs +172 -0
  152. data/sig/generated/nukadoko/report_run.rbs +1 -1
  153. data/sig/generated/nukadoko/run.rbs +286 -41
  154. data/sig/generated/nukadoko/run_record.rbs +20 -12
  155. data/sig/generated/nukadoko/scaffold.rbs +3 -0
  156. data/sig/generated/nukadoko/schema.rbs +5 -0
  157. data/sig/generated/nukadoko/secrets.rbs +26 -3
  158. data/sig/generated/nukadoko/states.rbs +214 -0
  159. data/sig/generated/nukadoko/step.rbs +58 -1
  160. data/sig/generated/nukadoko/step_fixtures.rbs +39 -0
  161. data/sig/generated/nukadoko/summary.rbs +256 -2
  162. data/sig/generated/nukadoko/table.rbs +3 -2
  163. data/sig/generated/nukadoko/trace.rbs +108 -33
  164. data/sig/generated/nukadoko/tree_passes.rbs +36 -8
  165. data/sig/generated/nukadoko/underneath.rbs +141 -0
  166. data/sig/generated/nukadoko/verdict.rbs +8 -0
  167. data/sig/generated/nukadoko/vocabulary.rbs +45 -6
  168. data/skills/nukadoko/SKILL.md +18 -18
  169. data/skills/nukadoko/references/checking-steps.md +16 -83
  170. data/skills/nukadoko/references/diagnosing.md +6 -6
  171. data/skills/nukadoko/references/done.md +22 -0
  172. data/skills/nukadoko/references/evidence.md +19 -6
  173. data/skills/nukadoko/references/exploring.md +22 -7
  174. data/skills/nukadoko/references/fixtures.md +12 -32
  175. data/skills/nukadoko/references/judgments.md +18 -0
  176. data/skills/nukadoko/references/maintenance.md +1 -1
  177. data/skills/nukadoko/references/merge-risk.md +1 -1
  178. data/skills/nukadoko/references/parts.md +46 -23
  179. data/skills/nukadoko/references/{perturbed-worlds.md → perturbed-systems.md} +30 -12
  180. data/skills/nukadoko/references/program.md +168 -169
  181. data/skills/nukadoko/references/reviewing.md +20 -20
  182. data/skills/nukadoko/references/ruby/checking-steps.md +106 -0
  183. data/skills/nukadoko/references/ruby/examples/cli.md +212 -0
  184. data/skills/nukadoko/references/ruby/fixtures.md +34 -0
  185. data/skills/nukadoko/references/ruby/program.md +112 -0
  186. data/skills/nukadoko/references/ruby/step-files.md +115 -0
  187. data/skills/nukadoko/references/running.md +34 -34
  188. data/skills/nukadoko/references/scenario-rules.md +7 -6
  189. data/skills/nukadoko/references/states.md +7 -1
  190. data/skills/nukadoko/references/step-files.md +41 -120
  191. data/skills/nukadoko/references/typescript/checking-steps.md +129 -0
  192. data/skills/nukadoko/references/{examples → typescript/examples}/cli.md +1 -1
  193. data/skills/nukadoko/references/{examples → typescript/examples}/http-api.md +6 -6
  194. data/skills/nukadoko/references/{examples → typescript/examples}/workflow.md +1 -1
  195. data/skills/nukadoko/references/typescript/fixtures.md +56 -0
  196. data/skills/nukadoko/references/typescript/program.md +111 -0
  197. data/skills/nukadoko/references/typescript/step-files.md +104 -0
  198. data/skills/nukadoko/references/verdicts.md +10 -10
  199. data/skills/nukadoko/references/writing-steps.md +67 -67
  200. data/skills/nukadoko/references/writing-the-feature.md +1 -1
  201. data/skills/nukadoko-verification/SKILL.md +13 -8
  202. metadata +103 -7
  203. data/skills/nukadoko/references/ruby.md +0 -80
@@ -18,13 +18,15 @@ module Nukadoko
18
18
 
19
19
  # A step's record.json as `nuka run` writes it, in the TypeScript engine's
20
20
  # shape, from what the run kept of the step. The keywords name where it ran:
21
- # the environment, the world, the run, the scenario, and the step's own
21
+ # the environment, the system, the run, the scenario, and the step's own
22
22
  # directory. A record that passed names each step it used; a failed one
23
23
  # names what each gave too, since that is what it failed on.
24
- #: (Hash[Symbol, untyped], environment: String, world_name: String?, run_id: String?, scenario_record_id: String?, evidence_dir: String) -> Hash[Symbol, untyped]
25
- def step_file(record, environment:, world_name:, run_id:, scenario_record_id:, evidence_dir:)
24
+ #: (Hash[Symbol, untyped], environment: String, system_name: String?, run_id: String?, scenario_record_id: String?, evidence_dir: String, ?target_version: String?) -> Hash[Symbol, untyped]
25
+ def step_file(record, environment:, system_name:, run_id:, scenario_record_id:, evidence_dir:, target_version: nil)
26
26
  passed = record[:status] == "passed"
27
- outcome = if passed then { result: record[:result] || {}, returns_dropped: record[:returns_dropped] }.compact
27
+ # A compat step returns nothing nukadoko reads, so its result is null.
28
+ outcome = if passed && record[:mutates].nil? && record[:kind] != "claim" && record[:step].to_s.start_with?("compat: ") then { result: nil }
29
+ elsif passed then { result: record[:result] || {}, returns_dropped: record[:returns_dropped] }.compact
28
30
  else { error: { message: record[:error], kind: record[:error_kind], **(record[:error_at]&.any? ? { at: record[:error_at] } : {}) } }
29
31
  end
30
32
  processes = record[:processes]
@@ -33,20 +35,25 @@ module Nukadoko
33
35
  end
34
36
  { schema_version: SCHEMA_VERSION, nukadoko: VERSION, step_record_id: record[:step_record_id], step: record[:step], kind: "run",
35
37
  args: record[:args] || {}, **(record[:args_origin]&.any? ? { args_origin: record[:args_origin] } : {}),
36
- **outcome, status: record[:status], environment: environment, world_name: world_name,
38
+ **outcome, status: record[:status], environment: environment, system_name: system_name,
39
+ **(target_version ? { target_version: target_version } : {}),
37
40
  scenario_record_id: scenario_record_id, run_id: run_id, started_at: record[:started_at], finished_at: record[:finished_at],
38
41
  evidence: { dir: evidence_dir, screenshots: [], **(record[:attachments] ? { attachments: record[:attachments] } : {}),
39
42
  **(record[:scratch] ? { scratch: record[:scratch] } : {}),
40
- **(record[:http_file] ? { http: "http.jsonl" } : {}), **(record[:trace] ? { trace: record[:trace] } : {}),
43
+ **(record[:http_file] ? { http: "http.jsonl" } : {}), **(record[:mcp_count] ? { mcp: McpCalls::FILE } : {}),
44
+ **(record[:trace] ? { trace: record[:trace] } : {}),
41
45
  **(record[:named_traces] ? { named_traces: record[:named_traces] } : {}) },
42
46
  observed: { processes: processes&.any? ? processes : nil, http: record[:http_count].to_i.positive? ? record[:http_count] : nil,
43
- files: record[:files], unmeasured: [], **(record.key?(:program_log) ? { program_log: record[:program_log] } : {}) },
44
- mutates: record[:mutates], **(used.any? ? { used: used } : {}), **(record[:sections] ? { sections: record[:sections] } : {}),
47
+ files: record[:files], unmeasured: [], **(record[:mcp_count] ? { mcp: record[:mcp_count] } : {}),
48
+ **(record.key?(:program_log) ? { program_log: record[:program_log] } : {}),
49
+ **(record.key?(:events) ? { events: record[:events] } : {}) },
50
+ mutates: record[:mutates], **(record[:page_events] ? { page_events: record[:page_events] } : {}),
51
+ **(record[:http_omitted] ? { http_omitted: record[:http_omitted] } : {}), **(used.any? ? { used: used } : {}), **(record[:sections] ? { sections: record[:sections] } : {}),
45
52
  **(record[:calls] ? { calls: record[:calls] } : {}), **(record[:polls] ? { polls: record[:polls] } : {}),
46
53
  **(record[:required_env] ? { required_env: record[:required_env] } : {}),
47
54
  **(record[:actions] ? { actions: record[:actions] } : {}), **(record[:actions_truncated] || record[:attachments_total] ? { truncated: { actions: record[:actions_truncated], evidence: record[:attachments_total] }.compact } : {}),
48
55
  **(record[:fixtures] ? { fixtures: record[:fixtures] } : {}),
49
- **(record[:claim_records] ? { claims: record[:claim_records], observation: record[:observation] || "observed", **poll_fields(record), **page_fields(record) } : {}) }
56
+ **(record[:claim_records] ? { claims: record[:claim_records], observation: record[:observation] || "observed", **poll_fields(record), **read_fields(record) } : {}) }
50
57
  end
51
58
 
52
59
  # One comparison, as run.json's steps[].claims[] holds it. `origins`
@@ -62,13 +69,21 @@ module Nukadoko
62
69
  actual_from = "ARIA snapshot of #{base}" if declared[:compare] == "fits-aria-snapshot"
63
70
  actual_from = "ARIA snapshot of observe:#{Claims.judged_path(declared)}" if judged[:aria]
64
71
  expected_from, expected_text = expected_origin(declared, origins, texts, patterns)
65
- { **judged.slice(:actual), actual_from: actual_from, **{ view: declared[:view], at: declared[:at]&.to_s, count: declared[:count] }.compact,
72
+ { **judged.slice(:actual, :actual_range, :counted, :left_out), actual_from: actual_from, **{ view: declared[:view], at: declared[:at]&.to_s, count: declared[:count] }.compact,
66
73
  compare: declared[:compare], **judged.slice(:expected), expected_from: expected_from,
67
74
  **{ expected_view: declared[:expected_view] }.compact }.merge(expected_text: expected_text, **outcome(judged), measured: nil)
68
75
  end
69
76
 
70
77
  READING_MAX_BYTES = 1024
71
78
 
79
+ # What the page received and showed, with each events key's reading
80
+ # before the judged view, in the TypeScript engine's order.
81
+ #: (Hash[Symbol, untyped], ?String?) -> Hash[Symbol, untyped]
82
+ def read_fields(record, under = nil)
83
+ page = page_fields(record, under)
84
+ { **page.except(:judged_view), **(record[:events_read] ? { events_read: record[:events_read] } : {}), **page.slice(:judged_view) }
85
+ end
86
+
72
87
  # What a claim step's page had received by its judged reading, and
73
88
  # what the page showed right after it. A file is named from the step
74
89
  # record's directory, or from the run's when `under` names the step's.
@@ -106,7 +121,7 @@ module Nukadoko
106
121
 
107
122
  #: (untyped) -> Hash[Symbol, untyped]
108
123
  def reading_value(value)
109
- text = JSON.generate(value)
124
+ text = JsJson.generate(value)
110
125
  text.bytesize <= READING_MAX_BYTES ? { value: value } : { json_start: text.byteslice(0, READING_MAX_BYTES).to_s.scrub(""), json_bytes: text.bytesize }
111
126
  end
112
127
 
@@ -134,7 +149,7 @@ module Nukadoko
134
149
  in String => key then key
135
150
  in { from: key } then "from #{key}"
136
151
  in { observe: key } then "observe #{key}"
137
- in { literal: value } then JSON.generate(value)
152
+ in { literal: value } then JsJson.generate(value)
138
153
  end
139
154
  "#{"count of " if claim[:count]}#{claim[:actual]}#{" as #{claim[:view]}" if claim[:view]}#{" at #{claim[:at]}" if claim[:at]} " \
140
155
  "#{claim[:compare]} #{expected}#{" as #{claim[:expected_view]}" if claim[:expected_view]}"
@@ -169,10 +184,14 @@ module Nukadoko
169
184
  return ended.("the array is empty, and a claim on every item of nothing measures nothing") if value.empty?
170
185
 
171
186
  judged = []
187
+ array_path = sides.array_path(declared, inputs)
172
188
  value.each_with_index do |item, index|
173
189
  place = sides.place_at(array.place, index.to_s)
174
- compare = ->(entry) { item_comparison(entry, sides.item_side(item, place, entry), inputs, origins, texts, patterns) }
175
- where_records = where.map(&compare)
190
+ compare = lambda do |entry, in_where = false|
191
+ item_comparison(entry, sides.item_side(item, place, entry), inputs, origins, texts, patterns,
192
+ value_path: sides.item_path(array_path, index, entry), where: in_where)
193
+ end
194
+ where_records = where.map { compare.(_1, true) }
176
195
  # A where claim that could not compare says nothing about whether
177
196
  # the item belongs, so leaving it out would turn "every item" into
178
197
  # "the items that happen to compare".
@@ -219,10 +238,10 @@ module Nukadoko
219
238
  end
220
239
 
221
240
  # One where or item claim on one item, judged on the side the item gives.
222
- #: (Hash[Symbol, untyped], Engine::ClaimSides::Side, Engine::ClaimSides::Inputs, Hash[String, String], Hash[String, String?], Array[String]) -> Hash[Symbol, untyped]
223
- def item_comparison(entry, side, inputs, origins, texts, patterns)
241
+ #: (Hash[Symbol, untyped], Engine::ClaimSides::Side, Engine::ClaimSides::Inputs, Hash[String, String], Hash[String, String?], Array[String], ?value_path: Array[String]?, ?where: bool) -> Hash[Symbol, untyped]
242
+ def item_comparison(entry, side, inputs, origins, texts, patterns, value_path: nil, where: false)
224
243
  sides = Engine::ClaimSides
225
- judged = sides.judge_comparison(entry, side, inputs)
244
+ judged = sides.judge_comparison(entry, side, inputs, value_path: value_path, where: where)
226
245
  label = sides.place_counted(sides.place_at(sides.place_viewed(side.place, entry[:view]), entry[:at]&.to_s), entry[:count]).label
227
246
  expected_from, expected_text = expected_origin(entry, origins, texts, patterns)
228
247
  { **judged.slice(:actual), actual_from: label, **{ view: entry[:view], at: entry[:at]&.to_s, count: entry[:count] }.compact }
@@ -320,7 +339,7 @@ module Nukadoko
320
339
  # proves the criterion tells the behaviour apart.
321
340
  #: (Hash[Symbol, untyped]) -> bool
322
341
  def proves?(cell)
323
- absent = cell[:world] == "base" || (cell[:world] != "old" && cell[:role] == "control")
342
+ absent = cell[:system] == "base" || (cell[:system] != "old" && cell[:role] == "control")
324
343
  absent && cell[:outcome] == "fail" && cell[:runs] >= Table.proof_runs
325
344
  end
326
345
 
@@ -329,7 +348,7 @@ module Nukadoko
329
348
  case cell[:outcome]
330
349
  when "not-run" then "did not run #{where}: #{cell[:reason] || "no execution was recorded"}"
331
350
  when "fail" then "a claim broke at line #{cell[:line]} #{where}"
332
- when "broke" then "stopped at line #{cell[:line]} #{where} before a claim there was judged"
351
+ when "broke" then cell[:reason] ? "#{where}, #{cell[:reason]}" : "stopped at line #{cell[:line]} #{where} before a claim there was judged"
333
352
  when "stopped" then "the walk was stopped with nuka step stop after line #{cell[:line]} #{where}, so the steps after it did not run and nothing shows it holds"
334
353
  else "its #{runs_text(cell[:runs])} #{where} disagree, the first that did not pass at line #{cell[:line]}"
335
354
  end
@@ -347,11 +366,11 @@ module Nukadoko
347
366
 
348
367
  # The environments a row needs a base cell and an old cell in, from its
349
368
  # head cells: none unless every required head cell passed; an
350
- # unchanged row runs in the old world when something under it
369
+ # unchanged row runs in the old system when something under it
351
370
  # changed; a new or changed row runs at the base unless a head
352
371
  # control already proves it, or it carries @held.
353
372
  #: (Array[Hash[Symbol, untyped]], Hash[Symbol, untyped]?, Array[Hash[Symbol, untyped]]) -> Hash[Symbol, Array[String]]
354
- def planned_world_cells(head_cells, context, old_roles)
373
+ def planned_system_cells(head_cells, context, old_roles)
355
374
  none = { base: [], old: [] }
356
375
  return none unless context
357
376
 
@@ -371,17 +390,17 @@ module Nukadoko
371
390
  end
372
391
 
373
392
  #: (Hash[Symbol, untyped]) -> String
374
- def world_cell_clause(cell)
375
- where = cell[:world] == "old" ? "in the old world in #{cell[:environment]}" : "at the base in #{cell[:environment]}"
376
- line = cell[:world] == "old" ? "line #{cell[:line]} of the base's feature file" : "line #{cell[:line]}"
393
+ def system_cell_clause(cell)
394
+ where = cell[:system] == "old" ? "in the old system in #{cell[:environment]}" : "at the base in #{cell[:environment]}"
395
+ line = cell[:system] == "old" ? "line #{cell[:line]} of the base's feature file" : "line #{cell[:line]}"
377
396
  case cell[:outcome]
378
397
  when "not-run" then "it did not run #{where}: #{cell[:reason] || "no execution was recorded"}"
379
398
  when "pass" then "it passed #{where}"
380
- when "broke" then "it stopped at #{line} #{where} before a claim there was judged"
399
+ when "broke" then cell[:reason] ? "#{where}, #{cell[:reason]}" : "it stopped at #{line} #{where} before a claim there was judged"
381
400
  when "stopped" then "the walk was stopped after #{line} #{where}"
382
401
  when "flaky" then "its #{runs_text(cell[:runs])} #{where} disagree, the first that did not pass at #{line}"
383
402
  else
384
- if cell[:world] == "base" && cell[:runs] < Table.proof_runs
403
+ if cell[:system] == "base" && cell[:runs] < Table.proof_runs
385
404
  "a claim broke at #{line} #{where} in only #{runs_text(cell[:runs])}, and proof needs #{Table.proof_runs}"
386
405
  else
387
406
  "a claim broke at #{line} #{where}"
@@ -390,9 +409,9 @@ module Nukadoko
390
409
  end
391
410
 
392
411
  #: (Array[Hash[Symbol, untyped]]) -> String
393
- def world_cells_clause(cells)
394
- template = world_cell_clause(cells.first.merge(environment: "\u0000"))
395
- same = cells.select { world_cell_clause(_1.merge(environment: "\u0000")) == template }.map { _1[:environment] }
412
+ def system_cells_clause(cells)
413
+ template = system_cell_clause(cells.first.merge(environment: "\u0000"))
414
+ same = cells.select { system_cell_clause(_1.merge(environment: "\u0000")) == template }.map { _1[:environment] }
396
415
  template.sub("\u0000") { same.join(", ") }
397
416
  end
398
417
 
@@ -405,10 +424,10 @@ module Nukadoko
405
424
  # did not pass, or for a row with no required cell; proven when a
406
425
  # control fails at a Then the same way in each proof run. Under
407
426
  # `--base` (`context`), red too for a new or changed row nothing proves
408
- # (unproven) and an unchanged row the old world does not pass (moved).
427
+ # (unproven) and an unchanged row the old system does not pass (moved).
409
428
  #: (Array[Hash[Symbol, untyped]], ?Hash[Symbol, untyped]?) -> [String, String]
410
429
  def judge_row(cells, context = nil)
411
- head = cells.select { _1[:world] == "head" }
430
+ head = cells.select { _1[:system] == "head" }
412
431
  required = head.select { _1[:role] == "required" }
413
432
  if required.empty?
414
433
  return ["failed", "no environment of this run meets its conditions, so every cell is a control and nothing shows that it holds"]
@@ -436,21 +455,21 @@ module Nukadoko
436
455
  if context[:change] == "unchanged"
437
456
  changed = underneath_change(context)
438
457
  if changed
439
- old = cells.select { _1[:world] == "old" }
458
+ old = cells.select { _1[:system] == "old" }
440
459
  moved = old.reject { _1[:outcome] == "pass" }
441
- return ["moved", "passes in #{passed_in}, but #{changed} and the old world did not run it"] if old.empty?
442
- return ["moved", "passes in #{passed_in}, but #{changed}, and #{world_cells_clause(moved)}"] if moved.any?
460
+ return ["moved", "passes in #{passed_in}, but #{changed} and the old system did not run it"] if old.empty?
461
+ return ["moved", "passes in #{passed_in}, but #{changed}, and #{system_cells_clause(moved)}"] if moved.any?
443
462
  end
444
463
  if proof
445
464
  proven = control_proof_reason(passed_in, proof)
446
- return ["proven", changed ? "#{proven}, and it passed in the old world, where the base's mapping runs head's code" : proven]
465
+ return ["proven", changed ? "#{proven}, and it passed in the old system, where the base's mapping runs head's code" : proven]
447
466
  end
448
467
  return ["held", "passes in #{passed_in}, and neither it nor the mapping changed since the base"] unless changed
449
468
 
450
- return ["held", "passes in #{passed_in}, and in the old world, where the base's mapping runs head's code"]
469
+ return ["held", "passes in #{passed_in}, and in the old system, where the base's mapping runs head's code"]
451
470
  end
452
471
 
453
- base = cells.select { _1[:world] == "base" }
472
+ base = cells.select { _1[:system] == "base" }
454
473
  base_proof = base.find { proves?(_1) }
455
474
  if base_proof
456
475
  proven = "passes in #{passed_in}, and a claim broke at line #{base_proof[:line]} at the base in #{base_proof[:environment]} in each of #{runs_text(base_proof[:runs])}"
@@ -462,36 +481,41 @@ module Nukadoko
462
481
  return ["held", "passes in #{passed_in} and at the base, as @held says"] if base.any? && base.all? { _1[:outcome] == "pass" }
463
482
 
464
483
  short = base.reject { _1[:outcome] == "pass" }
465
- clause = short.empty? ? "it did not run at the base" : world_cells_clause(short)
484
+ clause = short.empty? ? "it did not run at the base" : system_cells_clause(short)
466
485
  return ["unproven", "passes in #{passed_in}, and @held says the base has this behaviour, but #{clause}"]
467
486
  end
468
487
  absent = [*base.map { "base #{_1[:environment]}: #{cell_text(_1)}#{" (#{_1[:reason]})" if _1[:outcome] == "not-run" && _1[:reason]}" },
469
488
  *controls.map { "control #{_1[:environment]}: #{cell_text(_1)}" }]
470
- # A Then whose claims a reader judges compares nothing, so no world
471
- # can prove it, and no world can leave it unproven either: the
489
+ # A Then whose claims a reader judges compares nothing, so no system
490
+ # can prove it, and no system can leave it unproven either: the
472
491
  # judgment column decides it, and the row is held on what the
473
492
  # machine compared, which is everything before that Then.
474
493
  if context[:then_judges_no_claim] == "judgment"
475
- return ["held", "passes in #{passed_in}, and its Then asks for a judgment and compares nothing, so no world can show it failing where its behaviour is absent: " \
494
+ return ["held", "passes in #{passed_in}, and its Then asks for a judgment and compares nothing, so no system can show it failing where its behaviour is absent: " \
476
495
  "its judgment decides it"]
477
496
  end
478
497
  if context[:then_judges_no_claim]
479
- return ["unproven", "passes in #{passed_in}, but no claim step stands in its Then position, so no world can show a Then failing where its behaviour is absent" \
498
+ then_text = context[:then_judges_no_claim] == "compat" ? "its Then is a compat step, which judges no claim" : "no claim step stands in its Then position"
499
+ return ["unproven", "passes in #{passed_in}, but #{then_text}, so no system can show a Then failing where its behaviour is absent" \
480
500
  "#{absent.empty? ? "" : " (#{absent.join(", ")})"}"]
481
501
  end
482
502
  if absent.empty?
483
- return ["unproven", "passes in #{passed_in}, and no world where its behaviour is absent ran it, so nothing shows a Then failing without the change"]
503
+ return ["unproven", "passes in #{passed_in}, and no system where its behaviour is absent ran it, so nothing shows a Then failing without the change"]
484
504
  end
485
505
 
486
506
  ["unproven", "passes in #{passed_in}, and nothing shows a Then failing where its behaviour is absent (#{absent.join(", ")})"]
487
507
  end
488
508
 
489
- #: (Array[Hash[Symbol, untyped]]) -> Hash[Symbol, Integer]
490
- def counts(scenarios)
509
+ # The head scenarios by status, and the head cells of the table that
510
+ # did not run, a required one and a control apart: a system whose
511
+ # program did not start runs none of its cells.
512
+ #: (Array[Hash[Symbol, untyped]], ?Array[Hash[Symbol, untyped]]) -> Hash[Symbol, Integer]
513
+ def counts(scenarios, rows = [])
491
514
  head = scenarios.reject { _1[:role] == "control" }
492
515
  controls = scenarios.select { _1[:role] == "control" }
516
+ not_run = ->(role) { rows.sum { |row| row[:cells].count { _1[:system] == "head" && _1[:role] == role && _1[:outcome] == "not-run" } } }
493
517
  { scenarios: head.size, passed: head.count { _1[:status] == "passed" }, failed: head.count { _1[:status] == "failed" },
494
- stopped: head.count { _1[:status] == "stopped" }, not_run: 0, controls: controls.size, controls_not_run: 0 }
518
+ stopped: head.count { _1[:status] == "stopped" }, not_run: not_run.("required"), controls: controls.size, controls_not_run: not_run.("control") }
495
519
  end
496
520
 
497
521
  # The commit HEAD named when the run started, whether the tree had an
@@ -625,7 +625,7 @@ module Nukadoko
625
625
  return Scaffold.refusal("Refusing to scaffold: --description is empty; say what the step does, or leave the flag out for a TODO that nuka check reports")
626
626
  end
627
627
 
628
- if entry && !File.file?(File.join(@project, entry))
628
+ if entry && !File.file?(File.expand_path(entry, @project))
629
629
  looked = Pathname.new(File.expand_path(entry, @project)).relative_path_from(Pathname.new(File.expand_path(@project))).to_s
630
630
  order = @command_before_name && entry.match?(VALID_NAME) ? "; #{Scaffold.command_took_the_name(entry)}" : ""
631
631
  return Scaffold.refusal("Refusing to scaffold: entry point #{JSON.generate(entry)} is not a file (looked at #{looked}); pass the path of the program the step runs, " \
@@ -844,7 +844,8 @@ module Nukadoko
844
844
  .select { |_, line| Engine.matches(usable, line.text).empty? }
845
845
  return [[], ["nothing to scaffold: every line in #{target} matches a step"]] if undefined.empty?
846
846
 
847
- project_lines = (@scenarios + selected).flat_map { |scenario| scenario.steps.map { ["#{scenario.uri}:#{_1.line}", _1.text] } }
847
+ project_lines = (@scenarios + selected).flat_map { |scenario| scenario.steps.map { ["#{scenario.uri}:#{_1.line}", _1] } }
848
+ targets = undefined.to_set { |scenario, line| "#{scenario.uri}:#{line.line}" }
848
849
  reading = undefined.map { _2.text }.uniq.to_h { [_1, Scaffold.infer(_1)] }
849
850
  notes = []
850
851
  planned = {}
@@ -862,15 +863,29 @@ module Nukadoko
862
863
  notes << %(#{where}: "#{texts.first}" reads as #{read[:readings].map { JSON.generate(_1) }.join(" or ")}, so the stub's pattern is the line as written, ) +
863
864
  "with no capture; put a {key:type} capture in it by hand"
864
865
  elsif pattern.match?(NAMED)
865
- other = project_lines.find { |_, text| reading.dig(text, :pattern) != pattern && Pattern.new(pattern).match(text) }
866
+ # A line elsewhere that no step matches and that reads as this
867
+ # same pattern shares the stub when it also sits where this line
868
+ # does (a Then or not) and carries what it carries, since one
869
+ # stub is a claim step or not and takes one args shape. Any other
870
+ # line it matches would match two steps, or bind a stub that
871
+ # does not fit it.
872
+ matcher = Pattern.new(pattern)
873
+ line = group.first[1]
874
+ other = project_lines.find do |at, candidate|
875
+ text = candidate.text
876
+ next false unless matcher.match(text)
877
+
878
+ Engine.matches(usable, text).any? || (reading[text] ||= Scaffold.infer(text))[:pattern] != pattern ||
879
+ (!targets.include?(at) && (outcome?(candidate) != outcome?(line) || attachment_of(candidate) != attachment_of(line)))
880
+ end
866
881
  if other
867
882
  if texts.size > 1
868
- notes << "#{where}: its pattern #{JSON.generate(pattern)} would also match \"#{other[1]}\" (#{other[0]}), and its Examples rows have no single line " \
883
+ notes << "#{where}: its pattern #{JSON.generate(pattern)} would also match \"#{other[1].text}\" (#{other[0]}), and its Examples rows have no single line " \
869
884
  "to write instead, so no stub was written"
870
885
  next
871
886
  end
872
887
  pattern = Scaffold.literal_pattern(texts.first)
873
- notes << "#{where}: #{JSON.generate(read[:pattern])} would also match \"#{other[1]}\" (#{other[0]}), so the stub's pattern is the line as written, with no capture"
888
+ notes << "#{where}: #{JSON.generate(read[:pattern])} would also match \"#{other[1].text}\" (#{other[0]}), so the stub's pattern is the line as written, with no capture"
874
889
  end
875
890
  end
876
891
  (planned[pattern] ||= []).concat(group)
@@ -882,7 +897,7 @@ module Nukadoko
882
897
  planned.each do |pattern, lines|
883
898
  name = distinct(Scaffold.name_for(pattern)) { |candidate| taken.include?(candidate) || File.exist?(File.join(@project, Scaffold.file_of(candidate))) || Scaffold.class_refusal(candidate) }
884
899
  where = "#{lines.first[0].uri}:#{lines.first[1].line}"
885
- then_step = lines.any? { _2.kind.to_s == "Outcome" }
900
+ then_step = lines.any? { outcome?(_2) }
886
901
  kinds = lines.map { attachment_of(_2) }.uniq
887
902
  attachment = kinds.size == 1 ? kinds.first : nil
888
903
  captures = Scaffold.read_pattern(pattern)
@@ -984,6 +999,9 @@ module Nukadoko
984
999
  #: (PickleStep) -> String?
985
1000
  def attachment_of(line) = line.doc_string ? "docstring" : (line.table ? "table" : nil)
986
1001
 
1002
+ #: (PickleStep) -> bool
1003
+ def outcome?(line) = line.kind.to_s == "Outcome"
1004
+
987
1005
  # What every feature line the pattern matches carries, or nil when no
988
1006
  # line matches or the lines disagree.
989
1007
  #: (String) -> String?
@@ -300,7 +300,11 @@ module Nukadoko
300
300
  properties = fields.to_h do |field|
301
301
  type = Schema.json_type(field.type, output, field.checks)
302
302
  type = { default: field.default, **type } if field.default?
303
- [field.name, type.merge(field.description ? { description: field.description } : {})]
303
+ type = type.merge(field.description ? { description: field.description } : {})
304
+ # zod writes a type list it folded from a nullable after the field's
305
+ # own keys, not before them as it writes a single type.
306
+ type = { **type.except(:type), type: type[:type] } if type[:type].is_a?(Array)
307
+ [field.name, type]
304
308
  end
305
309
  schema = { type: "object", properties: properties } #: Hash[Symbol, untyped]
306
310
  # zod's output side always holds a defaulted key; the input may leave it out.
@@ -321,7 +325,7 @@ module Nukadoko
321
325
  { type: "integer", **number_bounds(checks, -SAFE, SAFE) }
322
326
  in :number then { type: "number", **number_bounds(checks, nil, nil) }
323
327
  in :unknown then {}
324
- in [:nullable, inner] then { anyOf: [json_type(inner, output, checks), { type: "null" }] }
328
+ in [:nullable, inner] then nullable_json_type(json_type(inner, output, checks))
325
329
  in [:enum, values] then { type: "string", enum: values }
326
330
  in [:array, item] then { **length_bounds(checks, :minItems, :maxItems), type: "array", items: json_type(item, output) }
327
331
  in [:checked, inner, own] then json_type(inner, output, own)
@@ -329,6 +333,15 @@ module Nukadoko
329
333
  end
330
334
  end
331
335
 
336
+ # zod 4.6 folds a nullable whose inner schema is one bare type into a
337
+ # type list, and keeps anyOf when the inner schema says more than its type.
338
+ #: (Hash[Symbol, untyped]) -> Hash[Symbol, untyped]
339
+ def self.nullable_json_type(inner)
340
+ return { type: [inner[:type], "null"] } if inner.keys == [:type] && inner[:type].is_a?(String)
341
+
342
+ { anyOf: [inner, { type: "null" }] }
343
+ end
344
+
332
345
  #: (Hash[Symbol, untyped], Integer?, Integer?) -> Hash[Symbol, untyped]
333
346
  def self.number_bounds(checks, floor, ceiling)
334
347
  low = if checks[:positive] then { exclusiveMinimum: 0 }
@@ -218,14 +218,37 @@ module Nukadoko
218
218
  #: Array[[String, String]]
219
219
  attr_reader :pairs
220
220
 
221
- #: (?Hash[String, String] | Array[[String, String]]) -> void
222
- def initialize(values = {})
221
+ # The trace id prefixes of the systems whose ids redaction leaves as
222
+ # they are. nukadoko made those ids at random, so they hold no secret,
223
+ # and a short secret that happens to occur in one would otherwise
224
+ # change the id a line of program.log carries, and the step it
225
+ # belongs to.
226
+ #: Array[String]
227
+ attr_reader :keep
228
+
229
+ # `keep` is positional, so a Hash written without braces is still
230
+ # the values.
231
+ #: (?Hash[String, String] | Array[[String, String]], ?Array[String]) -> void
232
+ def initialize(values = {}, keep = [])
223
233
  @pairs = values.to_a.uniq
224
234
  @values = @pairs.to_h
235
+ @keep = keep.uniq
236
+ @kept = Secrets.trace_ids(@keep)
225
237
  @replacements = replacements
226
238
  @pattern = @replacements.empty? ? nil : Regexp.union((@replacements.keys + @replacements.values.uniq).sort_by { -_1.length })
227
239
  end
228
240
 
241
+ # A system's trace ids, a prefix and then hexadecimal characters to 32
242
+ # in all, and the traceparent values that hold them, in either case,
243
+ # as a line's trace id is read.
244
+ #: (Array[String]) -> Regexp?
245
+ def self.trace_ids(prefixes)
246
+ hex = prefixes.select { _1.match?(/\A\h{1,31}\z/) }
247
+ return nil if hex.empty?
248
+
249
+ Regexp.union(hex.map { |prefix| /(?:00-)?#{prefix}\h{#{Trace::ID_LENGTH - prefix.length}}(?:-\h{16}-\h{2})?/i })
250
+ end
251
+
229
252
  #: () -> bool
230
253
  def empty? = @pairs.empty?
231
254
 
@@ -233,7 +256,7 @@ module Nukadoko
233
256
  # own, since the tree's config must not decide which of head's values
234
257
  # may print.
235
258
  #: (Secrets) -> Secrets
236
- def with(other) = Secrets.new(@pairs + other.pairs)
259
+ def with(other) = Secrets.new(@pairs + other.pairs, @keep + other.keep)
237
260
 
238
261
  # Every loaded value, each once.
239
262
  #: () -> Array[String]
@@ -263,17 +286,44 @@ module Nukadoko
263
286
 
264
287
  # One pass over every spelling and every token, longest first, so a
265
288
  # token already in the text matches as itself and a second redaction
266
- # changes nothing.
289
+ # changes nothing. A spelling that overlaps a kept trace id is still
290
+ # written as its token outside the id.
267
291
  #: (String) -> String
268
292
  def redact_string(text)
269
293
  pattern = @pattern
270
294
  return text unless pattern
271
295
 
272
- text.gsub(pattern) { |found| @replacements.fetch(found, found) }
296
+ kept = @kept
297
+ spans = kept ? text.enum_for(:scan, kept).map { Regexp.last_match&.offset(0) || [0, 0] } : []
298
+ return text.gsub(pattern) { |found| @replacements.fetch(found, found) } if spans.empty?
299
+
300
+ text.gsub(pattern) do |found|
301
+ token = @replacements[found]
302
+ token ? keeping(found, Regexp.last_match&.begin(0).to_i, spans, token) : found
303
+ end
273
304
  end
274
305
 
275
306
  private
276
307
 
308
+ # `found`, at `offset` in its text, with each run of its characters
309
+ # outside every kept span written as `token`, and each character
310
+ # inside one left as it is.
311
+ #: (String, Integer, Array[[Integer, Integer]], String) -> String
312
+ def keeping(found, offset, spans, token)
313
+ outside = false
314
+ found.each_char.with_index.map do |char, index|
315
+ at = offset + index
316
+ if spans.any? { |from, to| at >= from && at < to }
317
+ outside = false
318
+ char
319
+ elsif outside then ""
320
+ else
321
+ outside = true
322
+ token
323
+ end
324
+ end.join
325
+ end
326
+
277
327
  # Each spelling a record can hold a value in: the value, its
278
328
  # percent-encoded forms (as encodeURIComponent writes it, and with `'`
279
329
  # as `%27`, as a URL's href does), its form-urlencoded form, and the