nukadoko 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (200) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +541 -3
  3. data/README.ja.md +20 -5
  4. data/README.md +12 -6
  5. data/docs/ci.ja.md +542 -0
  6. data/docs/ci.md +635 -0
  7. data/docs/commands.ja.md +1524 -0
  8. data/docs/commands.md +1281 -0
  9. data/docs/engines.json +19 -0
  10. data/docs/execution-events.ja.md +336 -0
  11. data/docs/execution-events.md +423 -0
  12. data/docs/glossary.json +1348 -0
  13. data/docs/guide.ja.md +733 -0
  14. data/docs/guide.md +815 -0
  15. data/docs/intent.ja.md +133 -0
  16. data/docs/intent.md +156 -0
  17. data/docs/layout.ja.md +442 -0
  18. data/docs/layout.md +399 -0
  19. data/docs/releasing.ja.md +186 -0
  20. data/docs/releasing.md +237 -0
  21. data/docs/ruby/reference.ja.md +302 -0
  22. data/docs/ruby/reference.md +368 -0
  23. data/docs/spec.ja.md +8916 -0
  24. data/docs/spec.md +11250 -0
  25. data/docs/tutorial.ja.md +451 -0
  26. data/docs/tutorial.md +458 -0
  27. data/docs/typescript/adopting.ja.md +231 -0
  28. data/docs/typescript/adopting.md +251 -0
  29. data/docs/typescript/doors.ja.md +301 -0
  30. data/docs/typescript/doors.md +329 -0
  31. data/docs/typescript/migration-playwright-test.ja.md +189 -0
  32. data/docs/typescript/migration-playwright-test.md +212 -0
  33. data/docs/typescript/migration.ja.md +391 -0
  34. data/docs/typescript/migration.md +505 -0
  35. data/docs/typescript/reference.ja.md +176 -0
  36. data/docs/typescript/reference.md +197 -0
  37. data/docs/typescript/upgrading.ja.md +1774 -0
  38. data/docs/typescript/upgrading.md +2224 -0
  39. data/docs/web-app.ja.md +627 -0
  40. data/docs/web-app.md +659 -0
  41. data/docs/writing-scenarios.ja.md +544 -0
  42. data/docs/writing-scenarios.md +563 -0
  43. data/lib/nukadoko/base.rb +12 -5
  44. data/lib/nukadoko/changed_files.rb +95 -0
  45. data/lib/nukadoko/check.rb +459 -51
  46. data/lib/nukadoko/claim_drops.rb +271 -0
  47. data/lib/nukadoko/claim_line.rb +24 -4
  48. data/lib/nukadoko/claim_rules.rb +143 -1
  49. data/lib/nukadoko/claim_sides.rb +157 -9
  50. data/lib/nukadoko/cli.rb +395 -48
  51. data/lib/nukadoko/codes.json +246 -21
  52. data/lib/nukadoko/codes.rb +21 -4
  53. data/lib/nukadoko/command.rb +120 -13
  54. data/lib/nukadoko/command_help.rb +128 -0
  55. data/lib/nukadoko/compat.rb +469 -0
  56. data/lib/nukadoko/criteria.rb +1 -1
  57. data/lib/nukadoko/definition.rb +157 -7
  58. data/lib/nukadoko/error_frames.rb +6 -3
  59. data/lib/nukadoko/events/count.rb +146 -0
  60. data/lib/nukadoko/events/counted.rb +114 -0
  61. data/lib/nukadoko/events/format.rb +257 -0
  62. data/lib/nukadoko/events/lists.rb +154 -0
  63. data/lib/nukadoko/events/path.rb +285 -0
  64. data/lib/nukadoko/events/read.rb +284 -0
  65. data/lib/nukadoko/events/reader.rb +490 -0
  66. data/lib/nukadoko/events/selection.rb +252 -0
  67. data/lib/nukadoko/events/tally.rb +438 -0
  68. data/lib/nukadoko/features.rb +2 -2
  69. data/lib/nukadoko/fixtures.rb +160 -35
  70. data/lib/nukadoko/http_recording.rb +6 -2
  71. data/lib/nukadoko/intent.rb +364 -0
  72. data/lib/nukadoko/intent_file.rb +81 -0
  73. data/lib/nukadoko/intent_view.rb +190 -0
  74. data/lib/nukadoko/js_json.rb +2 -1
  75. data/lib/nukadoko/judge.rb +2 -2
  76. data/lib/nukadoko/judgment_file.rb +1 -1
  77. data/lib/nukadoko/judgments.rb +4 -4
  78. data/lib/nukadoko/measure_mcp.rb +202 -0
  79. data/lib/nukadoko/parts.rb +8 -2
  80. data/lib/nukadoko/path_view.rb +252 -0
  81. data/lib/nukadoko/place_rows.rb +161 -0
  82. data/lib/nukadoko/program.rb +1265 -51
  83. data/lib/nukadoko/program_log.rb +122 -0
  84. data/lib/nukadoko/program_shape.rb +385 -0
  85. data/lib/nukadoko/project_fixtures.rb +43 -10
  86. data/lib/nukadoko/project_program.rb +5 -4
  87. data/lib/nukadoko/repeated_prefix.rb +310 -0
  88. data/lib/nukadoko/report_run.rb +3 -3
  89. data/lib/nukadoko/run.rb +1148 -159
  90. data/lib/nukadoko/run_record.rb +70 -46
  91. data/lib/nukadoko/scaffold.rb +24 -6
  92. data/lib/nukadoko/schema.rb +15 -2
  93. data/lib/nukadoko/secrets.rb +55 -5
  94. data/lib/nukadoko/states.rb +478 -0
  95. data/lib/nukadoko/step.rb +71 -2
  96. data/lib/nukadoko/step_fixtures.rb +52 -3
  97. data/lib/nukadoko/summary.rb +799 -29
  98. data/lib/nukadoko/table.rb +4 -2
  99. data/lib/nukadoko/text_fit.rb +20 -7
  100. data/lib/nukadoko/trace.rb +152 -45
  101. data/lib/nukadoko/tree_passes.rb +95 -33
  102. data/lib/nukadoko/underneath.rb +311 -0
  103. data/lib/nukadoko/version.rb +1 -1
  104. data/lib/nukadoko/vocabulary.rb +166 -23
  105. data/lib/nukadoko/walk.rb +2 -2
  106. data/lib/nukadoko/walk_step.rb +1 -1
  107. data/lib/nukadoko.rb +23 -0
  108. data/llms.txt +41 -34
  109. data/sig/generated/nukadoko/base.rbs +4 -4
  110. data/sig/generated/nukadoko/changed_files.rbs +42 -0
  111. data/sig/generated/nukadoko/check.rbs +147 -10
  112. data/sig/generated/nukadoko/claim_drops.rbs +135 -0
  113. data/sig/generated/nukadoko/claim_line.rbs +11 -0
  114. data/sig/generated/nukadoko/claim_rules.rbs +49 -4
  115. data/sig/generated/nukadoko/claim_sides.rbs +63 -12
  116. data/sig/generated/nukadoko/cli.rbs +80 -7
  117. data/sig/generated/nukadoko/codes.rbs +19 -4
  118. data/sig/generated/nukadoko/command.rbs +68 -1
  119. data/sig/generated/nukadoko/command_help.rbs +18 -0
  120. data/sig/generated/nukadoko/compat.rbs +392 -0
  121. data/sig/generated/nukadoko/criteria.rbs +1 -1
  122. data/sig/generated/nukadoko/definition.rbs +50 -0
  123. data/sig/generated/nukadoko/error_frames.rbs +1 -1
  124. data/sig/generated/nukadoko/events/count.rbs +69 -0
  125. data/sig/generated/nukadoko/events/counted.rbs +70 -0
  126. data/sig/generated/nukadoko/events/format.rbs +163 -0
  127. data/sig/generated/nukadoko/events/lists.rbs +47 -0
  128. data/sig/generated/nukadoko/events/path.rbs +161 -0
  129. data/sig/generated/nukadoko/events/read.rbs +109 -0
  130. data/sig/generated/nukadoko/events/reader.rbs +226 -0
  131. data/sig/generated/nukadoko/events/selection.rbs +100 -0
  132. data/sig/generated/nukadoko/events/tally.rbs +227 -0
  133. data/sig/generated/nukadoko/features.rbs +6 -4
  134. data/sig/generated/nukadoko/fixtures.rbs +67 -11
  135. data/sig/generated/nukadoko/http_recording.rbs +1 -1
  136. data/sig/generated/nukadoko/intent.rbs +132 -0
  137. data/sig/generated/nukadoko/intent_file.rbs +46 -0
  138. data/sig/generated/nukadoko/intent_view.rbs +69 -0
  139. data/sig/generated/nukadoko/judgment_file.rbs +1 -1
  140. data/sig/generated/nukadoko/judgments.rbs +1 -1
  141. data/sig/generated/nukadoko/measure_mcp.rbs +104 -0
  142. data/sig/generated/nukadoko/parts.rbs +2 -2
  143. data/sig/generated/nukadoko/path_view.rbs +105 -0
  144. data/sig/generated/nukadoko/place_rows.rbs +43 -0
  145. data/sig/generated/nukadoko/program.rbs +627 -23
  146. data/sig/generated/nukadoko/program_log.rbs +67 -0
  147. data/sig/generated/nukadoko/program_shape.rbs +147 -0
  148. data/sig/generated/nukadoko/project_fixtures.rbs +16 -3
  149. data/sig/generated/nukadoko/project_program.rbs +2 -1
  150. data/sig/generated/nukadoko/repeated_prefix.rbs +172 -0
  151. data/sig/generated/nukadoko/report_run.rbs +1 -1
  152. data/sig/generated/nukadoko/run.rbs +286 -41
  153. data/sig/generated/nukadoko/run_record.rbs +20 -12
  154. data/sig/generated/nukadoko/scaffold.rbs +3 -0
  155. data/sig/generated/nukadoko/schema.rbs +5 -0
  156. data/sig/generated/nukadoko/secrets.rbs +26 -3
  157. data/sig/generated/nukadoko/states.rbs +214 -0
  158. data/sig/generated/nukadoko/step.rbs +58 -1
  159. data/sig/generated/nukadoko/step_fixtures.rbs +39 -0
  160. data/sig/generated/nukadoko/summary.rbs +256 -2
  161. data/sig/generated/nukadoko/table.rbs +3 -2
  162. data/sig/generated/nukadoko/trace.rbs +108 -33
  163. data/sig/generated/nukadoko/tree_passes.rbs +36 -8
  164. data/sig/generated/nukadoko/underneath.rbs +141 -0
  165. data/sig/generated/nukadoko/vocabulary.rbs +45 -6
  166. data/skills/nukadoko/SKILL.md +18 -18
  167. data/skills/nukadoko/references/checking-steps.md +16 -83
  168. data/skills/nukadoko/references/diagnosing.md +6 -6
  169. data/skills/nukadoko/references/evidence.md +19 -6
  170. data/skills/nukadoko/references/exploring.md +22 -7
  171. data/skills/nukadoko/references/fixtures.md +12 -32
  172. data/skills/nukadoko/references/judgments.md +12 -0
  173. data/skills/nukadoko/references/maintenance.md +1 -1
  174. data/skills/nukadoko/references/merge-risk.md +1 -1
  175. data/skills/nukadoko/references/parts.md +46 -23
  176. data/skills/nukadoko/references/{perturbed-worlds.md → perturbed-systems.md} +30 -12
  177. data/skills/nukadoko/references/program.md +168 -169
  178. data/skills/nukadoko/references/reviewing.md +20 -20
  179. data/skills/nukadoko/references/ruby/checking-steps.md +106 -0
  180. data/skills/nukadoko/references/ruby/examples/cli.md +212 -0
  181. data/skills/nukadoko/references/ruby/fixtures.md +34 -0
  182. data/skills/nukadoko/references/ruby/program.md +112 -0
  183. data/skills/nukadoko/references/ruby/step-files.md +115 -0
  184. data/skills/nukadoko/references/running.md +34 -34
  185. data/skills/nukadoko/references/scenario-rules.md +7 -6
  186. data/skills/nukadoko/references/states.md +7 -1
  187. data/skills/nukadoko/references/step-files.md +41 -120
  188. data/skills/nukadoko/references/typescript/checking-steps.md +129 -0
  189. data/skills/nukadoko/references/{examples → typescript/examples}/cli.md +1 -1
  190. data/skills/nukadoko/references/{examples → typescript/examples}/http-api.md +6 -6
  191. data/skills/nukadoko/references/{examples → typescript/examples}/workflow.md +1 -1
  192. data/skills/nukadoko/references/typescript/fixtures.md +56 -0
  193. data/skills/nukadoko/references/typescript/program.md +111 -0
  194. data/skills/nukadoko/references/typescript/step-files.md +104 -0
  195. data/skills/nukadoko/references/verdicts.md +10 -10
  196. data/skills/nukadoko/references/writing-steps.md +67 -67
  197. data/skills/nukadoko/references/writing-the-feature.md +1 -1
  198. data/skills/nukadoko-verification/SKILL.md +13 -8
  199. metadata +103 -7
  200. data/skills/nukadoko/references/ruby.md +0 -80
@@ -0,0 +1,311 @@
1
+ # frozen_string_literal: true
2
+ # rbs_inline: enabled
3
+
4
+ require "uri"
5
+
6
+ # The failures underneath an execution (docs/spec.md "Failures
7
+ # underneath"): what its steps saw of the program failing, grouped by what
8
+ # an `@expects:` tag names; which of them no tag of the scenario accepts,
9
+ # which turns a pass broke in its cell; and the findings that say so.
10
+ # Pure, over a step's page events and the entries of its http.jsonl, and
11
+ # over run.json's scenarios. Writing those is Run#execute's, and folding
12
+ # the program's execution events into a step's `path` is the system's stop.
13
+ #
14
+ # Only a measured failure is counted: an entry of http.jsonl with a status
15
+ # from 500 to 599, and an error the page threw that nothing caught. Each is
16
+ # the failing party's own statement: the server chose the status, and the
17
+ # browser found no handler for what the page threw. What could not be seen
18
+ # (a page error past the record's cap, a page's request left out of
19
+ # http.jsonl, whose status was never kept) is kept apart as `unseen`, and
20
+ # is never counted as a failure.
21
+ module Nukadoko
22
+ module Engine
23
+ module Underneath
24
+ PREFIX = "@expects:"
25
+ FAILED_STATUS = (500..599) #: Range[Integer]
26
+
27
+ # The kinds in the order a failure is looked for under one step: the
28
+ # server's answer, the program's own report, then the page.
29
+ KIND_ORDER = %w[status error page-error].freeze
30
+
31
+ module_function
32
+
33
+ # The failure `tag` names, as [kind, value], or nil when it does not
34
+ # read as `@expects:<kind>=<value>` (Check.expects_problem says why).
35
+ #: (String) -> [String, String]?
36
+ def read_tag(tag)
37
+ return nil unless tag.start_with?(PREFIX)
38
+
39
+ kind, value = tag.delete_prefix(PREFIX).split("=", 2)
40
+ rule = Check::EXPECTED[kind.to_s]
41
+ rule && value && value.match?(rule[0]) ? [kind.to_s, value] : nil
42
+ end
43
+
44
+ #: (String, String) -> String
45
+ def tag_text(kind, value) = "#{PREFIX}#{kind}=#{value}"
46
+
47
+ # The `@expects:` tags among a criterion's tags that read, each once,
48
+ # in the order the tags first name them.
49
+ #: (Array[String]) -> Array[String]
50
+ def tags_of(tags) = tags.filter_map { (read = read_tag(_1)) && tag_text(read[0], read[1]) }.uniq
51
+
52
+ # A step's `underneath`, from its page events, its http.jsonl entries
53
+ # (nil when the file could not be read), how many entries could not
54
+ # be written, and the page requests left out of it by type. nil when
55
+ # the step saw no failure and missed nothing.
56
+ #: (Hash[Symbol, untyped]?, Array[Hash[Symbol, untyped]?]?, Integer?, Hash[untyped, Integer]?) -> Hash[Symbol, untyped]?
57
+ def of_record(page_events, http, http_log_failed, http_omitted)
58
+ statuses = status_groups(http || [])
59
+ page_errors = page_error_groups(page_events)
60
+ kept = (page_events && page_events[:page_errors] || []).size
61
+ total = page_events&.dig(:truncated, :page_errors)
62
+ past_cap = total ? total - kept : 0
63
+ http_lines = http.nil? ? nil : http.count(&:nil?) + http_log_failed.to_i
64
+ omitted = (http_omitted || {}).values.sum
65
+ unseen = { **(http_lines.nil? || http_lines.positive? ? { http_lines: http_lines } : {}),
66
+ **(omitted.positive? ? { http_omitted: omitted } : {}), **(past_cap.positive? ? { page_errors: past_cap } : {}) }
67
+ underneath = { **(statuses.empty? ? {} : { statuses: statuses }), **(page_errors.empty? ? {} : { page_errors: page_errors }),
68
+ **(unseen.empty? ? {} : { unseen: unseen }) }
69
+ underneath.empty? ? nil : underneath
70
+ end
71
+
72
+ #: (Array[Hash[Symbol, untyped]?]) -> Array[Hash[Symbol, untyped]]
73
+ def status_groups(http)
74
+ groups = {} #: Hash[Integer, Hash[Symbol, untyped]]
75
+ http.each_with_index do |entry, index|
76
+ next unless entry
77
+
78
+ status = entry[:status]
79
+ next unless status.is_a?(Integer) && FAILED_STATUS.cover?(status)
80
+
81
+ if (group = groups[status])
82
+ group[:count] += 1
83
+ next
84
+ end
85
+ groups[status] = { count: 1, first: { method: entry[:method], url: entry[:url], via: entry[:via], http_line: index, **(entry[:as] ? { as: entry[:as] } : {}) } }
86
+ end
87
+ groups.sort_by(&:first).map { |status, group| { status: status, **group } }
88
+ end
89
+
90
+ #: (Hash[Symbol, untyped]?) -> Array[Hash[Symbol, untyped]]
91
+ def page_error_groups(page_events)
92
+ groups = {} #: Hash[String?, Hash[Symbol, untyped]]
93
+ (page_events && page_events[:page_errors] || []).each do |entry|
94
+ name = entry[:name]
95
+ if (group = groups[name])
96
+ group[:count] += 1
97
+ next
98
+ end
99
+ groups[name] = { count: 1, first: { message: Summary.first_error_line(entry[:message]), **(entry[:as] ? { as: entry[:as] } : {}) } }
100
+ end
101
+ groups.map { |name, group| { name: name, **group } }
102
+ end
103
+
104
+ # A field of a hash read from either engine's run.json or in process.
105
+ #: (Hash[untyped, untyped]?, Symbol) -> untyped
106
+ def at(hash, key)
107
+ return nil unless hash.is_a?(Hash)
108
+
109
+ hash.key?(key) ? hash[key] : hash[key.to_s]
110
+ end
111
+
112
+ # Whether a hash holds a key, a null value included: an unread
113
+ # http.jsonl is a null count.
114
+ #: (untyped, Symbol) -> bool
115
+ def has?(hash, key) = hash.is_a?(Hash) && (hash.key?(key) || hash.key?(key.to_s))
116
+
117
+ # What one step shows of one kind, each as the key a tag names, a
118
+ # count, and where the first one is. An unhandled error is the step's
119
+ # `path` entry, which the system's stop folded from every line of its
120
+ # trace; a `handled: true` error is the program going on, not failing.
121
+ #: (String, Hash[Symbol, untyped]) -> Array[Hash[Symbol, untyped]]
122
+ def found_under(kind, step)
123
+ underneath = at(step, :underneath)
124
+ case kind
125
+ when "status"
126
+ (at(underneath, :statuses) || []).map { { kind: "status", value: at(_1, :status).to_s, count: at(_1, :count), first: at(_1, :first) } }
127
+ when "error"
128
+ (at(at(step, :path), :entries) || []).filter_map do |entry|
129
+ next unless at(entry, :kind) == "error" && at(entry, :handled) != true
130
+
131
+ { kind: "error", value: at(entry, :class).to_s, count: at(entry, :count) }
132
+ end
133
+ else
134
+ (at(underneath, :page_errors) || []).map { { kind: "page-error", value: at(_1, :name), count: at(_1, :count), first: at(_1, :first) } }
135
+ end
136
+ end
137
+
138
+ # Every failure underneath `execution`, steps in order and, within a
139
+ # step, in KIND_ORDER, each with the tag that accepts it or nil.
140
+ #: (Hash[Symbol, untyped]) -> Array[Hash[Symbol, untyped]]
141
+ def failures(execution)
142
+ accepted = (execution[:expects] || []).select { read_tag(_1) }
143
+ (execution[:steps] || []).each_with_index.flat_map do |step, index|
144
+ KIND_ORDER.flat_map do |kind|
145
+ found_under(kind, step).map do |found|
146
+ tag = found[:value].nil? ? nil : tag_text(found[:kind], found[:value])
147
+ { **found, step: index, line: step[:line] || execution[:line], expected_by: tag && accepted.include?(tag) ? tag : nil }
148
+ end
149
+ end
150
+ end
151
+ end
152
+
153
+ # The first failure underneath `execution` no tag of its scenario
154
+ # accepts: what turns a pass broke.
155
+ #: (Hash[Symbol, untyped]) -> Hash[Symbol, untyped]?
156
+ def first_unexpected(execution) = failures(execution).find { _1[:expected_by].nil? }
157
+
158
+ # A request as a reason names it: its method and its path. The port
159
+ # of a system differs from run to run, so the full URL would make two
160
+ # runs that failed the same way disagree.
161
+ #: (Hash[Symbol, untyped]) -> String
162
+ def request_of(first)
163
+ path = URI(first[:url].to_s).path
164
+ "#{first[:method]} #{path.nil? || path.empty? ? first[:url] : path}"
165
+ rescue URI::Error
166
+ "#{first[:method]} #{first[:url]}"
167
+ end
168
+
169
+ # The cell's reason for `failure`: the step's line and the failure's
170
+ # key, never a count or a message, so two runs that failed the same
171
+ # way agree.
172
+ #: (Hash[Symbol, untyped]) -> String
173
+ def reason(failure)
174
+ unnamed = "which no @expects tag of the scenario names"
175
+ line = failure[:line]
176
+ case failure[:kind]
177
+ when "status" then "the step at line #{line} got a #{failure[:value]} response to #{request_of(failure[:first])}, #{unnamed}"
178
+ when "error" then "the program reported an unhandled #{failure[:value]} in the trace of the step at line #{line}, #{unnamed}"
179
+ else
180
+ if failure[:value].nil?
181
+ "the page threw an uncaught error with no name while the step at line #{line} ran, which no @expects tag can name"
182
+ else "the page threw an uncaught #{failure[:value]} while the step at line #{line} ran, #{unnamed}"
183
+ end
184
+ end
185
+ end
186
+
187
+ #: (Integer, String, String) -> String
188
+ def count_of(count, one, many) = "#{count} #{count == 1 ? one : many}"
189
+
190
+ # `failure` as a finding and the summary name it, with where its
191
+ # first occurrence is.
192
+ #: (Hash[Symbol, untyped]) -> String
193
+ def text(failure)
194
+ first = failure[:first]
195
+ case failure[:kind]
196
+ when "status"
197
+ "#{count_of(failure[:count], "response", "responses")} with status #{failure[:value]}, first #{at(first, :method)} #{at(first, :url)} " \
198
+ "(#{at(first, :via)}, http.jsonl[#{at(first, :http_line)}])"
199
+ when "error" then "#{count_of(failure[:count], "line", "lines")} of the program's execution events reporting an unhandled #{failure[:value]}"
200
+ else
201
+ what = failure[:value].nil? ? "error with no name" : failure[:value]
202
+ "#{count_of(failure[:count], "uncaught #{what}", "uncaught #{what}s")} from the page, first #{JSON.generate(at(first, :message))}"
203
+ end
204
+ end
205
+
206
+ # Whether a claim of `steps` was judged on lines still on their way.
207
+ #: (Array[Hash[Symbol, untyped]]) -> bool
208
+ def judged_too_early?(steps)
209
+ steps.any? { |step| (at(step, :claims) || []).any? { (late = at(_1, :after_system_stop)) && at(late, :outcome) != at(_1, :outcome) } }
210
+ end
211
+
212
+ # The failure underneath that turns `execution` broke in its cell:
213
+ # it passed, no claim of it was judged too early (its own broke), and
214
+ # a failure underneath it is one no tag of its scenario accepts. Only
215
+ # a pass: a fail is already the first failure that counts.
216
+ #: (Hash[Symbol, untyped]) -> Hash[Symbol, untyped]?
217
+ def demoting(execution)
218
+ return nil unless execution[:status] == "passed" && !judged_too_early?(execution[:steps] || [])
219
+
220
+ first_unexpected(execution)
221
+ end
222
+
223
+ # One `unexpected-failure` finding per head required execution a
224
+ # failure underneath turned broke, per scenario and environment,
225
+ # since the runs of `--repeat` would say it again. It names every
226
+ # failure no tag accepts under the first step that has one, and its
227
+ # `fix:` spells the tag for each.
228
+ #: (Array[Hash[Symbol, untyped]], label: ^(Hash[Symbol, untyped]) -> String, rerun: ^(Hash[Symbol, untyped]) -> String?) -> Array[Hash[Symbol, untyped]]
229
+ def unexpected_findings(scenarios, label:, rerun:)
230
+ findings = {} #: Hash[String, Hash[Symbol, untyped]]
231
+ scenarios.each do |scenario|
232
+ next if scenario[:system] || scenario[:role] == "control"
233
+
234
+ first = demoting(scenario)
235
+ key = "#{scenario[:feature]}:#{scenario[:line]}:#{scenario[:environment]}"
236
+ next if first.nil? || findings.key?(key)
237
+
238
+ step = scenario[:steps][first[:step]]
239
+ unexpected = failures(scenario).select { _1[:step] == first[:step] && _1[:expected_by].nil? }
240
+ tags = unexpected.filter_map { _1[:value] && tag_text(_1[:kind], _1[:value]) }.uniq
241
+ record = step[:record] ? "; record #{step[:record]}" : ""
242
+ findings[key] = {
243
+ severity: "failed", code: "unexpected-failure", file: scenario[:feature], line: first[:line],
244
+ message: "#{label.(scenario)}: its steps passed, and the program failed underneath the step at line #{first[:line]}, " \
245
+ "#{JSON.generate(step[:text])}, in a way no @expects tag names, so its cell is broke: #{unexpected.map { text(_1) }.join("; ")}#{record}",
246
+ fix: if tags.empty? then "Fix what failed: the page threw an error with no name, which no @expects tag can accept."
247
+ else "Fix what failed. A scenario that causes it on purpose names it on its Scenario line: #{tags.join(" ")}"
248
+ end,
249
+ do: rerun.(scenario)
250
+ }.compact
251
+ end
252
+ findings.values
253
+ end
254
+
255
+ # Whether an execution was watched for a kind whole, so a tag of that
256
+ # kind that matched nothing there matched nothing that happened:
257
+ # every entry of http.jsonl read and no page request left out of it,
258
+ # the page errors of a browser kept, or the program's events read
259
+ # with no line that may be any line and no gap where an error could
260
+ # still be. A step that sent no request has a gap too
261
+ # (`no-requests`), and no error of its trace can be missing.
262
+ #: (String, Hash[Symbol, untyped]) -> bool
263
+ def watched?(kind, execution)
264
+ steps = execution[:steps] || []
265
+ case kind
266
+ when "status"
267
+ steps.all? do |step|
268
+ unseen = at(at(step, :underneath), :unseen)
269
+ at(step, :record_unreadable) != true && !(has?(unseen, :http_lines) || has?(unseen, :http_omitted))
270
+ end
271
+ when "error"
272
+ steps.any? { at(_1, :path) } &&
273
+ steps.all? { (path = at(_1, :path)).nil? || (at(path, :maybe).to_i.zero? && (at(path, :open) || []).all? { |open| at(open, :gap) == "no-requests" }) }
274
+ else
275
+ !execution[:browser].nil? && steps.all? { at(_1, :record_unreadable) != true && at(at(at(_1, :underneath), :unseen), :page_errors).nil? }
276
+ end
277
+ end
278
+
279
+ NOT_SEEN = { "status" => ->(value) { "no step got a #{value} response" },
280
+ "error" => ->(value) { "the program reported no unhandled #{value}" },
281
+ "page-error" => ->(value) { "the page threw no uncaught #{value}" } }.freeze #: Hash[String, ^(String) -> String]
282
+
283
+ # One `expects-unseen` note per tag of a head required scenario, per
284
+ # environment, whose every execution passed and matched no failure
285
+ # that tag accepts, where each was watched for its kind whole. A tag
286
+ # left in place after its failure stopped happening accepts that
287
+ # failure in every later run.
288
+ #: (Array[Hash[Symbol, untyped]], label: ^(Hash[Symbol, untyped]) -> String) -> Array[Hash[Symbol, untyped]]
289
+ def unseen_notes(scenarios, label:)
290
+ cells = scenarios.reject { _1[:system] || _1[:role] == "control" || (_1[:expects] || []).empty? }
291
+ .group_by { [_1[:feature], _1[:line], _1[:environment]] }
292
+ cells.values.flat_map do |executions|
293
+ passed = executions.all? { _1[:status] == "passed" && !judged_too_early?(_1[:steps] || []) && first_unexpected(_1).nil? }
294
+ next [] unless passed
295
+
296
+ matched = executions.flat_map { |execution| failures(execution).filter_map { _1[:expected_by] } }
297
+ first = executions.first
298
+ first[:expects].filter_map do |tag|
299
+ kind, value = read_tag(tag)
300
+ next unless kind && value && !matched.include?(tag) && executions.all? { watched?(kind, _1) }
301
+
302
+ where = executions.size == 1 ? "its execution" : "any of its #{executions.size} executions"
303
+ { severity: "note", code: "expects-unseen", file: first[:feature], line: first[:line],
304
+ message: "#{label.(first)}: #{tag} accepts a failure that did not happen: #{NOT_SEEN.fetch(kind).(value)} in #{where}",
305
+ fix: Codes.fix("expects-unseen") }
306
+ end
307
+ end
308
+ end
309
+ end
310
+ end
311
+ end
@@ -2,5 +2,5 @@
2
2
  # rbs_inline: enabled
3
3
 
4
4
  module Nukadoko
5
- VERSION = "0.6.0"
5
+ VERSION = "0.7.0"
6
6
  end
@@ -8,24 +8,125 @@ module Nukadoko
8
8
  module Vocabulary
9
9
  BROWSER = %i[page context pageAs page_as].freeze
10
10
 
11
- #: (singleton(Step), String) -> Hash[Symbol, untyped]
12
- def self.entry(step, project)
11
+ #: (singleton(Step), String, ?Array[singleton(Step)]) -> Hash[Symbol, untyped]
12
+ def self.entry(step, project, steps = [step])
13
+ compat = step #: untyped
14
+ return { name: step.step_name, kind: "compat", file: step.file.delete_prefix("#{project}/"), patterns: compat.compat_patterns } if compat?(step)
15
+
13
16
  {
14
17
  name: step.step_name, kind: "typed", file: step.file.delete_prefix("#{project}/"),
15
- patterns: [step.pattern].compact, description: step.description, mutates: step.mutating?,
18
+ patterns: step.patterns, description: step.description, mutates: step.mutating?, timeout: step.timeout,
16
19
  parts: step.parts.empty? ? nil : step.parts.map(&:step_name),
17
- from: from(step), claims: step.claims, poll: step.poll,
20
+ from: from(step), claims: step.claims, poll: step.poll, events: events(step), files: files(step), **states(step, steps),
18
21
  needs: step.bag.map(&:to_s).sort, needs_browser: step.bag.intersect?(BROWSER)
19
22
  }.compact
20
23
  end
21
24
 
22
- #: (singleton(Step), String) -> Hash[Symbol, untyped]
23
- def self.describe(step, project)
25
+ # `nuka steps <target>`: the steps the selected lines bind, and the steps
26
+ # those call through `parts`, each with the lines that bind it and the
27
+ # listed steps that call it. A line binds a step only when exactly one
28
+ # step matches it, as `nuka check` judges. A line that binds no single
29
+ # step is a finding: a list that leaves out the step a line was meant
30
+ # to bind reads as complete.
31
+ #: (Array[singleton(Step)], Array[Engine::Scenario]) -> [Array[[singleton(Step), Hash[Symbol, untyped]]], Array[Hash[Symbol, untyped]]]
32
+ def self.of_targets(steps, scenarios)
33
+ lines = Hash.new { |h, k| h[k] = [] } #: Hash[singleton(Step), Array[String]]
34
+ findings = [] #: Array[Hash[Symbol, untyped]]
35
+ seen = {} #: Hash[String, bool]
36
+ scenarios.each do |scenario|
37
+ scenario.steps.each do |line|
38
+ where = "#{scenario.uri}:#{line.line}"
39
+ # A Background line and an outline step repeat in each scenario;
40
+ # the line is one place to edit, so it is named once.
41
+ next if seen[where]
42
+
43
+ seen[where] = true
44
+ matched = Engine.matches(steps, line.text).map(&:first).uniq
45
+ at = { severity: "error", file: scenario.uri, line: line.line }
46
+ case matched.size
47
+ when 1 then lines[matched.first] << where
48
+ when 0
49
+ findings << { **at, code: "undefined-step", message: %(No step definition matches "#{line.text}"),
50
+ do: "nuka scaffold --feature #{Engine::Selection.shell_word(scenario.uri)}" }
51
+ else
52
+ findings << { **at, code: "ambiguous-step", message: %("#{line.text}" matches more than one step: #{matched.map(&:step_name).sort.join(", ")}) }
53
+ end
54
+ end
55
+ end
56
+ part_of = Hash.new { |h, k| h[k] = [] } #: Hash[singleton(Step), Array[String]]
57
+ listed = lines.keys
58
+ pending = listed.dup
59
+ until pending.empty?
60
+ caller = pending.shift #: singleton(Step)
61
+ (compat?(caller) ? [] : caller.parts).each do |part|
62
+ part_of[part] << caller.step_name unless part_of[part].include?(caller.step_name)
63
+ next if listed.include?(part)
64
+
65
+ listed << part
66
+ pending << part
67
+ end
68
+ end
69
+ places = steps.select { listed.include?(_1) }.map do |step|
70
+ place = { lines: lines.fetch(step, []), **(part_of.key?(step) ? { part_of: part_of[step] } : {}) } #: Hash[Symbol, untyped]
71
+ [step, place] #: [singleton(Step), Hash[Symbol, untyped]]
72
+ end
73
+ [places, findings]
74
+ end
75
+
76
+ #: (singleton(Step), String, ?Array[singleton(Step)]) -> Hash[Symbol, untyped]
77
+ def self.describe(step, project, steps = [step])
78
+ if compat?(step)
79
+ compat = step #: untyped
80
+ return { kind: "compat", name: step.step_name, file: step.file.delete_prefix("#{project}/"), pattern: compat.registration.source,
81
+ message: %(compat steps have no type contract; promote this pattern to a Nukadoko::Step to add one (docs/ruby/reference.md "Compat steps")) }
82
+ end
83
+
24
84
  # A step with no returns returns an empty object, as zod's default says.
25
85
  returns = step.returns&.json_schema(output: true) || { "$schema": "https://json-schema.org/draft/2020-12/schema", default: {}, type: "object", properties: {}, additionalProperties: false }
26
- entry(step, project).merge(args: step.args.json_schema, returns: returns)
86
+ entry(step, project, steps).merge(args: step.args.json_schema, returns: returns)
87
+ end
88
+
89
+
90
+ # `events` for a claim step that declares any: each key's `of` by step
91
+ # name, and its count as declared.
92
+ #: (singleton(Step)) -> Hash[String, Hash[Symbol, untyped]]?
93
+ def self.events(step)
94
+ return nil unless step.claims && step.events.any?
95
+
96
+ step.events.transform_values do |entry|
97
+ { of: Engine::ChangedFiles.producers(entry).map(&:step_name), count: Engine::Events::Selection.normalize(entry[:count] || entry["count"]) }
98
+ end
99
+ end
100
+
101
+ # `files` for a claim step that declares any: each key's `of` by step
102
+ # name, and its change and directory when it names them.
103
+ #: (singleton(Step)) -> Hash[String, Hash[Symbol, untyped]]?
104
+ def self.files(step)
105
+ return nil unless step.claims && step.files.any?
106
+
107
+ step.files.transform_values do |entry|
108
+ { of: Engine::ChangedFiles.producers(entry).map(&:step_name), change: entry[:change] || entry["change"], under: Engine::ChangedFiles.under(entry) }.compact
109
+ end
27
110
  end
28
111
 
112
+ # `requires`, `gives`, and `ends` for a step that declares any.
113
+ # `given_by` names each step with a pattern whose gives names the
114
+ # state: the steps a line can run.
115
+ #: (singleton(Step), Array[singleton(Step)]) -> Hash[Symbol, untyped]
116
+ def self.states(step, steps)
117
+ declared = step.states
118
+ return {} unless declared
119
+
120
+ summary = ->(use) { use.key ? { state: use.state, key: use.key } : { state: use.state } }
121
+ givers = lambda do |state|
122
+ steps.select { |other| other.patterns.any? && other.states&.gives&.any? { _1.state == state } }.map(&:step_name)
123
+ end
124
+ {
125
+ requires: declared.requires.empty? ? nil : declared.requires.map { summary.(_1).merge(given_by: givers.(_1.state)) },
126
+ gives: declared.gives.empty? ? nil : declared.gives.map(&summary),
127
+ ends: declared.ends.empty? ? nil : declared.ends.map(&summary)
128
+ }.compact
129
+ end
29
130
 
30
131
  #: (singleton(Step)) -> Hash[untyped, untyped]?
31
132
  def self.from(step)
@@ -37,26 +138,68 @@ module Nukadoko
37
138
  end
38
139
  end
39
140
 
40
- #: (singleton(Step)) -> String
41
- def self.text(step)
42
- lines = ["#{step.step_name} typed #{step.claims ? "claims" : step.mutating? ? "mutates" : "read-only"}",
43
- " #{step.pattern || "(no pattern)"}", " #{step.description}"]
44
- (step.claims || []).each { lines << " claim: #{claim_text(_1)}" }
45
- ((step.poll.is_a?(Hash) && step.poll[:settled]) || []).each { lines << " settled: #{claim_text(_1)}" }
46
- lines.join("\n")
141
+ #: (untyped) -> bool
142
+ def self.compat?(step) = step.respond_to?(:compat?) && step.compat?
143
+
144
+ #: (singleton(Step), ?Array[singleton(Step)], ?Hash[Symbol, untyped]) -> String
145
+ def self.text(step, steps = [step], place = {})
146
+ return "#{step.step_name} compat" if compat?(step)
147
+
148
+ browser = step.bag.intersect?(BROWSER) ? " browser" : ""
149
+ header = "#{step.step_name} typed #{step.claims ? "claims" : step.mutating? ? "mutates" : "read-only"}#{browser}#{" timeout #{step.timeout}ms" if step.timeout}"
150
+ items = [*(step.patterns.empty? ? ["(no pattern)"] : step.patterns), step.description]
151
+ (events(step) || {}).each do |key, entry|
152
+ items << "events: #{key} counts #{Engine::Events::Selection.describe(entry[:count])} of #{entry[:of].join(" or ")}"
153
+ end
154
+ (files(step) || {}).each do |key, entry|
155
+ items << "files: #{key} lists the files the commands of #{entry[:of].join(" or ")} #{Engine::ChangedFiles.describe(entry)}"
156
+ end
157
+ (step.claims || []).each { items << "claim: #{claim_text(_1)}" }
158
+ ((step.poll.is_a?(Hash) && step.poll[:settled]) || []).each { items << "settled: #{claim_text(_1)}" }
159
+ states = states(step, steps)
160
+ (states[:requires] || []).each do |use|
161
+ items << "requires: #{use[:key] ? "#{use[:state]} for #{use[:key]}" : use[:state]}, #{use[:given_by].empty? ? "given by no step" : "given by #{use[:given_by].join(" or ")}"}"
162
+ end
163
+ (states[:gives] || []).each { items << "gives: #{_1[:key] ? "#{_1[:state]} for #{_1[:key]}" : _1[:state]}" }
164
+ (states[:ends] || []).each { items << "ends: #{_1[:key] ? "#{_1[:state]} for #{_1[:key]}" : _1[:state]}" }
165
+ items << "lines: #{place[:lines].join(" ")}" if place[:lines]&.any?
166
+ items << "part of: #{place[:part_of].join(" ")}" if place[:part_of]
167
+ [header, *items.flat_map { wrap(_1.to_s) }].join("\n")
168
+ end
169
+
170
+ WIDTH = 80
171
+
172
+ # One item at two spaces, broken at spaces only, its later lines at
173
+ # four: a pattern or a description split mid-word could not be copied
174
+ # as the thing it names, so a word wider than the line keeps a line of
175
+ # its own.
176
+ #: (String) -> Array[String]
177
+ def self.wrap(text)
178
+ lines = [] #: Array[String]
179
+ current = ""
180
+ indent = 2
181
+ text.split(/ /, -1).each do |word|
182
+ candidate = current.empty? ? "#{" " * indent}#{word}" : "#{current} #{word}"
183
+ if !current.empty? && candidate.size > WIDTH
184
+ lines << current
185
+ indent = 4
186
+ current = "#{" " * indent}#{word}"
187
+ else current = candidate
188
+ end
189
+ end
190
+ lines << current unless current.empty?
191
+ lines
47
192
  end
48
193
 
194
+ # A declared claim as one line: `count of orders equal n`, or
195
+ # `each of items: price greater-than 0` for a claim on each item.
49
196
  #: (Hash[Symbol, untyped]) -> String
50
197
  def self.claim_text(claim)
51
- return "each #{claim[:actual]}" if claim[:each]
52
-
53
- actual = [claim[:actual], claim[:view] && "as #{claim[:view]}", claim[:at] && "at #{claim[:at]}"].compact.join(" ")
54
- expected = case claim[:expected]
55
- in String => key then key
56
- in { literal: value } then value.to_json
57
- in { from: key } then "from #{key}"
58
- end
59
- "#{actual} #{claim[:compare]} #{expected}"
198
+ return Engine::RunRecord.describe_comparison(claim) unless claim[:each]
199
+
200
+ item = ->(entry) { Engine::RunRecord.describe_comparison({ actual: "item" }.merge(entry.compact)) }
201
+ where = claim[:each][:where] ? " where #{claim[:each][:where].map(&item).join(" and ")}" : ""
202
+ "each of #{claim[:actual]}#{" as #{claim[:view]}" if claim[:view]}#{" at #{claim[:at]}" if claim[:at]}#{where}: #{claim[:each][:claims].map(&item).join(" and ")}"
60
203
  end
61
204
  end
62
205
  end
data/lib/nukadoko/walk.rb CHANGED
@@ -27,7 +27,7 @@ module Nukadoko
27
27
  class TransitionError < StandardError; end
28
28
 
29
29
  START_KEYS = %i[number pid target started_at].freeze
30
- RUN_KEYS = %i[run_id run_dir scenario world].freeze
30
+ RUN_KEYS = %i[run_id run_dir scenario system].freeze
31
31
 
32
32
  module_function
33
33
 
@@ -264,7 +264,7 @@ module Nukadoko
264
264
  when "gone"
265
265
  last = seen[:last]
266
266
  finding = { severity: "failed", code: "walk-gone",
267
- message: "the nuka run --step process (pid #{last[:pid]}) ended without recording how: it was killed or it crashed, so its world and browser may still run",
267
+ message: "the nuka run --step process (pid #{last[:pid]}) ended without recording how: it was killed or it crashed, so its system and browser may still run",
268
268
  do: restart_command(last[:target]) }
269
269
  { exit_code: 1, findings: [finding], fields: { walk: "gone", last: last } }
270
270
  when "ended"
@@ -110,7 +110,7 @@ module Nukadoko
110
110
  *(pause[:failure] ? [" failure: #{Engine::Walk.failure_text(pause)}"] : []),
111
111
  " record: #{joined(run_dir, pause[:record])}/record.json",
112
112
  *views,
113
- *(seen[:world] ? [" world: #{seen[:world][:url]}"] : []),
113
+ *(seen[:system] ? [" system: #{seen[:system][:url]}"] : []),
114
114
  " do: #{Engine::Walk.answer_command(seen[:number], pause[:pause], "next")}#{stop}"
115
115
  ]
116
116
  "#{lines.join("\n")}\n"
data/lib/nukadoko.rb CHANGED
@@ -9,12 +9,16 @@ require_relative "nukadoko/spaces"
9
9
  require_relative "nukadoko/js_pattern"
10
10
  require_relative "nukadoko/schema"
11
11
  require_relative "nukadoko/step"
12
+ require_relative "nukadoko/states"
13
+ require_relative "nukadoko/changed_files"
12
14
  require_relative "nukadoko/pattern"
15
+ require_relative "nukadoko/compat"
13
16
  require_relative "nukadoko/features"
14
17
  require_relative "nukadoko/codes"
15
18
  require_relative "nukadoko/selection"
16
19
  require_relative "nukadoko/js_json"
17
20
  require_relative "nukadoko/claims"
21
+ require_relative "nukadoko/claim_drops"
18
22
  require_relative "nukadoko/claim_sides"
19
23
  require_relative "nukadoko/aria_snapshot"
20
24
  require_relative "nukadoko/judgments"
@@ -29,6 +33,16 @@ require_relative "nukadoko/claim_check"
29
33
  require_relative "nukadoko/claim_check_run"
30
34
  require_relative "nukadoko/check"
31
35
  require_relative "nukadoko/trace"
36
+ require_relative "nukadoko/measure_mcp"
37
+ require_relative "nukadoko/events/format"
38
+ require_relative "nukadoko/events/lists"
39
+ require_relative "nukadoko/events/selection"
40
+ require_relative "nukadoko/events/counted"
41
+ require_relative "nukadoko/events/tally"
42
+ require_relative "nukadoko/events/reader"
43
+ require_relative "nukadoko/events/count"
44
+ require_relative "nukadoko/events/path"
45
+ require_relative "nukadoko/events/read"
32
46
  require_relative "nukadoko/trace_actions"
33
47
  require_relative "nukadoko/step_fixtures"
34
48
  require_relative "nukadoko/fixtures"
@@ -42,10 +56,19 @@ require_relative "nukadoko/poll"
42
56
  require_relative "nukadoko/claim_rules"
43
57
  require_relative "nukadoko/definition"
44
58
  require_relative "nukadoko/vocabulary"
59
+ require_relative "nukadoko/program_shape"
60
+ require_relative "nukadoko/program_log"
45
61
  require_relative "nukadoko/program"
46
62
  require_relative "nukadoko/project_program"
47
63
  require_relative "nukadoko/parameter_types"
48
64
  require_relative "nukadoko/table"
65
+ require_relative "nukadoko/place_rows"
66
+ require_relative "nukadoko/path_view"
67
+ require_relative "nukadoko/intent"
68
+ require_relative "nukadoko/intent_file"
69
+ require_relative "nukadoko/intent_view"
70
+ require_relative "nukadoko/underneath"
71
+ require_relative "nukadoko/repeated_prefix"
49
72
  require_relative "nukadoko/order"
50
73
  require_relative "nukadoko/run_record"
51
74
  require_relative "nukadoko/criteria"