nukadoko 0.1.0 → 0.2.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 +291 -0
- data/README.ja.md +58 -5
- data/README.md +15 -3
- data/exe/nuka +8 -0
- data/lib/nukadoko/aria_snapshot.rb +1008 -0
- data/lib/nukadoko/aria_tree.rb +150 -0
- data/lib/nukadoko/base.rb +274 -0
- data/lib/nukadoko/check.rb +669 -22
- data/lib/nukadoko/claim_check.rb +177 -0
- data/lib/nukadoko/claim_check_run.rb +293 -0
- data/lib/nukadoko/claim_line.rb +381 -0
- data/lib/nukadoko/claim_rules.rb +519 -0
- data/lib/nukadoko/claims.rb +407 -30
- data/lib/nukadoko/cli.rb +802 -19
- data/lib/nukadoko/codes.json +942 -0
- data/lib/nukadoko/codes.rb +19 -0
- data/lib/nukadoko/command.rb +214 -12
- data/lib/nukadoko/criteria.rb +172 -0
- data/lib/nukadoko/definition.rb +33 -41
- data/lib/nukadoko/env_check.rb +90 -0
- data/lib/nukadoko/features.rb +80 -10
- data/lib/nukadoko/fixtures.rb +296 -10
- data/lib/nukadoko/http_recording.rb +68 -0
- data/lib/nukadoko/init.rb +130 -0
- data/lib/nukadoko/judge.rb +221 -0
- data/lib/nukadoko/judgment_file.rb +78 -0
- data/lib/nukadoko/judgments.rb +256 -0
- data/lib/nukadoko/literal.rb +129 -0
- data/lib/nukadoko/measured.rb +105 -0
- data/lib/nukadoko/order.rb +84 -0
- data/lib/nukadoko/parts.rb +42 -21
- data/lib/nukadoko/pattern.rb +11 -1
- data/lib/nukadoko/poll.rb +17 -6
- data/lib/nukadoko/program.rb +105 -17
- data/lib/nukadoko/project_fixtures.rb +17 -2
- data/lib/nukadoko/report_allure.rb +751 -0
- data/lib/nukadoko/report_messages.rb +167 -0
- data/lib/nukadoko/report_run.rb +169 -0
- data/lib/nukadoko/run.rb +865 -88
- data/lib/nukadoko/run_record.rb +532 -0
- data/lib/nukadoko/scaffold.rb +1015 -0
- data/lib/nukadoko/schema.rb +61 -4
- data/lib/nukadoko/secrets.rb +359 -0
- data/lib/nukadoko/selection.rb +163 -0
- data/lib/nukadoko/signature.rb +4 -1
- data/lib/nukadoko/skill.rb +36 -0
- data/lib/nukadoko/step.rb +62 -21
- data/lib/nukadoko/summary.rb +662 -0
- data/lib/nukadoko/table.rb +34 -2
- data/lib/nukadoko/text_fit.rb +179 -0
- data/lib/nukadoko/trace.rb +244 -0
- data/lib/nukadoko/trace_actions.rb +116 -0
- data/lib/nukadoko/tree_passes.rb +119 -0
- data/lib/nukadoko/verdict.rb +128 -0
- data/lib/nukadoko/version.rb +2 -1
- data/lib/nukadoko/vocabulary.rb +6 -0
- data/lib/nukadoko/walk.rb +305 -0
- data/lib/nukadoko/walk_files.rb +473 -0
- data/lib/nukadoko/walk_step.rb +149 -0
- data/lib/nukadoko.rb +36 -0
- data/llms.txt +296 -0
- data/sig/generated/nukadoko/aria_snapshot.rbs +331 -0
- data/sig/generated/nukadoko/aria_tree.rbs +142 -0
- data/sig/generated/nukadoko/base.rbs +136 -0
- data/sig/generated/nukadoko/check.rbs +255 -0
- data/sig/generated/nukadoko/claim_check.rbs +118 -0
- data/sig/generated/nukadoko/claim_check_run.rbs +88 -0
- data/sig/generated/nukadoko/claim_line.rbs +158 -0
- data/sig/generated/nukadoko/claim_rules.rbs +172 -0
- data/sig/generated/nukadoko/claims.rbs +165 -0
- data/sig/generated/nukadoko/cli.rbs +182 -0
- data/sig/generated/nukadoko/codes.rbs +16 -0
- data/sig/generated/nukadoko/command.rbs +109 -0
- data/sig/generated/nukadoko/criteria.rbs +83 -0
- data/sig/generated/nukadoko/definition.rbs +30 -0
- data/sig/generated/nukadoko/env_check.rbs +38 -0
- data/sig/generated/nukadoko/features.rbs +101 -0
- data/sig/generated/nukadoko/fixtures.rbs +152 -0
- data/sig/generated/nukadoko/http_recording.rbs +29 -0
- data/sig/generated/nukadoko/init.rbs +66 -0
- data/sig/generated/nukadoko/judge.rbs +64 -0
- data/sig/generated/nukadoko/judgment_file.rbs +39 -0
- data/sig/generated/nukadoko/judgments.rbs +120 -0
- data/sig/generated/nukadoko/literal.rbs +71 -0
- data/sig/generated/nukadoko/measured.rbs +42 -0
- data/sig/generated/nukadoko/order.rbs +54 -0
- data/sig/generated/nukadoko/parts.rbs +35 -0
- data/sig/generated/nukadoko/pattern.rbs +28 -0
- data/sig/generated/nukadoko/poll.rbs +40 -0
- data/sig/generated/nukadoko/program.rbs +101 -0
- data/sig/generated/nukadoko/project_fixtures.rbs +57 -0
- data/sig/generated/nukadoko/report_allure.rbs +268 -0
- data/sig/generated/nukadoko/report_messages.rbs +68 -0
- data/sig/generated/nukadoko/report_run.rbs +102 -0
- data/sig/generated/nukadoko/run.rbs +257 -0
- data/sig/generated/nukadoko/run_record.rbs +174 -0
- data/sig/generated/nukadoko/scaffold.rbs +328 -0
- data/sig/generated/nukadoko/schema.rbs +137 -0
- data/sig/generated/nukadoko/secrets.rbs +157 -0
- data/sig/generated/nukadoko/selection.rbs +73 -0
- data/sig/generated/nukadoko/signature.rbs +17 -0
- data/sig/generated/nukadoko/skill.rbs +20 -0
- data/sig/generated/nukadoko/step.rbs +115 -0
- data/sig/generated/nukadoko/summary.rbs +204 -0
- data/sig/generated/nukadoko/table.rbs +43 -0
- data/sig/generated/nukadoko/text_fit.rbs +70 -0
- data/sig/generated/nukadoko/trace.rbs +127 -0
- data/sig/generated/nukadoko/trace_actions.rbs +40 -0
- data/sig/generated/nukadoko/tree_passes.rbs +48 -0
- data/sig/generated/nukadoko/verdict.rbs +56 -0
- data/sig/generated/nukadoko/version.rbs +5 -0
- data/sig/generated/nukadoko/vocabulary.rbs +25 -0
- data/sig/generated/nukadoko/walk.rbs +139 -0
- data/sig/generated/nukadoko/walk_files.rbs +189 -0
- data/sig/generated/nukadoko/walk_step.rbs +50 -0
- data/sig/generated/nukadoko.rbs +15 -0
- data/sig/nukadoko.rbs +5 -48
- data/skills/nukadoko/SKILL.md +120 -0
- data/skills/nukadoko/references/checking-steps.md +200 -0
- data/skills/nukadoko/references/diagnosing.md +200 -0
- data/skills/nukadoko/references/done.md +99 -0
- data/skills/nukadoko/references/evidence.md +124 -0
- data/skills/nukadoko/references/examples/cli.md +230 -0
- data/skills/nukadoko/references/examples/http-api.md +339 -0
- data/skills/nukadoko/references/examples/workflow.md +173 -0
- data/skills/nukadoko/references/exploring.md +184 -0
- data/skills/nukadoko/references/fixtures.md +198 -0
- data/skills/nukadoko/references/from-prose.md +51 -0
- data/skills/nukadoko/references/judgments.md +95 -0
- data/skills/nukadoko/references/maintenance.md +97 -0
- data/skills/nukadoko/references/merge-risk.md +74 -0
- data/skills/nukadoko/references/parts.md +152 -0
- data/skills/nukadoko/references/perturbed-worlds.md +107 -0
- data/skills/nukadoko/references/program.md +200 -0
- data/skills/nukadoko/references/reviewing.md +200 -0
- data/skills/nukadoko/references/running.md +200 -0
- data/skills/nukadoko/references/scenario-rules.md +188 -0
- data/skills/nukadoko/references/states.md +66 -0
- data/skills/nukadoko/references/step-files.md +200 -0
- data/skills/nukadoko/references/verdicts.md +200 -0
- data/skills/nukadoko/references/writing-steps.md +200 -0
- data/skills/nukadoko/references/writing-the-feature.md +165 -0
- data/skills/nukadoko/scripts/claude-code-verdict-hook.mjs +99 -0
- data/skills/nukadoko/scripts/merge-risk.jq +56 -0
- data/skills/nukadoko-verification/SKILL.md +263 -0
- metadata +121 -1
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
# rbs_inline: enabled
|
|
3
|
+
|
|
4
|
+
require "json"
|
|
5
|
+
|
|
6
|
+
# One claim record as one line of plain text, in the words the TypeScript
|
|
7
|
+
# engine uses: the step's failure message and the run summary read it, so
|
|
8
|
+
# the two never describe one claim differently. It reads a record already
|
|
9
|
+
# written and judges nothing. Where two values part under `equal` or
|
|
10
|
+
# `has-same-items`, it names the place or the items they do not share.
|
|
11
|
+
module Nukadoko
|
|
12
|
+
module Engine
|
|
13
|
+
module ClaimLine
|
|
14
|
+
# A value longer than this is cut in a line; the record keeps it whole.
|
|
15
|
+
VALUE_TEXT_LIMIT = 120
|
|
16
|
+
DIFFERENCE_CONTEXT = 20
|
|
17
|
+
ITEM_PAIRS_LIMIT = 250_000
|
|
18
|
+
LISTED_ITEMS = 3
|
|
19
|
+
|
|
20
|
+
module_function
|
|
21
|
+
|
|
22
|
+
#: (untyped) -> String
|
|
23
|
+
def value_text(value)
|
|
24
|
+
text = JSON.generate(value)
|
|
25
|
+
text.size > VALUE_TEXT_LIMIT ? "#{text[0, VALUE_TEXT_LIMIT]}..." : text
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
#: (Hash[Symbol, untyped]) -> String
|
|
29
|
+
def expected_text(record) = record.key?(:expected) ? "#{value_text(record[:expected])} (#{record[:expected_from]})" : record[:expected_from]
|
|
30
|
+
|
|
31
|
+
#: (Hash[Symbol, untyped]) -> String
|
|
32
|
+
def comparison_text(record)
|
|
33
|
+
actual = record.key?(:actual) ? snapshot_excerpt_text(record) || "#{value_text(record[:actual])} (#{record[:actual_from]})" : record[:actual_from]
|
|
34
|
+
"#{actual} #{record[:compare]} #{expected_text(record)}"
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# The actual side of a broken fits-aria-snapshot claim as the lines
|
|
38
|
+
# the misfit points at, with their numbers, since a page's snapshot is
|
|
39
|
+
# longer than the line shows and its first lines are seldom where the
|
|
40
|
+
# two part.
|
|
41
|
+
#: (Hash[Symbol, untyped]) -> String?
|
|
42
|
+
def snapshot_excerpt_text(record)
|
|
43
|
+
return nil unless record[:compare] == "fits-aria-snapshot" && record[:outcome] == "broken" && !record[:reason]
|
|
44
|
+
return nil unless record[:actual].is_a?(String) && record[:expected].is_a?(String)
|
|
45
|
+
|
|
46
|
+
excerpt = AriaSnapshot.excerpt(record[:actual], record[:expected]) or return nil
|
|
47
|
+
lines = excerpt[:first] == excerpt[:last] ? "line #{excerpt[:first]}" : "lines #{excerpt[:first]} to #{excerpt[:last]}"
|
|
48
|
+
"#{JSON.generate(excerpt[:text])} (#{lines} of #{record[:actual_from]})"
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
#: (untyped, untyped) -> String?
|
|
52
|
+
def aria_snapshot_difference(actual, expected) = actual.is_a?(String) && expected.is_a?(String) ? AriaSnapshot.difference(actual, expected) : nil
|
|
53
|
+
|
|
54
|
+
#: (Hash[Symbol, untyped]) -> String
|
|
55
|
+
def item_declaration_text(entry)
|
|
56
|
+
actual = "#{"count of " if entry[:count]}#{entry[:actual] || "item"}#{" as #{entry[:view]}" if entry[:view]}#{" at #{entry[:at]}" if entry[:at]}"
|
|
57
|
+
"#{actual} #{entry[:compare]} #{expected_text(entry)}"
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
#: (Integer) -> String
|
|
61
|
+
def item_count(count) = count == 1 ? "1 item" : "#{count} items"
|
|
62
|
+
|
|
63
|
+
#: (Hash[Symbol, untyped]) -> String
|
|
64
|
+
def each_text(record)
|
|
65
|
+
each = record[:each]
|
|
66
|
+
selected = each[:selected] == each[:items] ? "" : ", #{each[:selected]} selected"
|
|
67
|
+
where = each[:where] ? " where #{each[:where].map { item_declaration_text(_1) }.join(" and ")}" : ""
|
|
68
|
+
"each of #{record[:actual_from]} (#{item_count(each[:items])}#{selected})#{where}: #{each[:claims].map { item_declaration_text(_1) }.join(" and ")}"
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
#: (Hash[Symbol, untyped]) -> bool
|
|
72
|
+
def each?(record) = record.key?(:each)
|
|
73
|
+
#: (Hash[Symbol, untyped]) -> String
|
|
74
|
+
def claim_text(record) = each?(record) ? each_text(record) : comparison_text(record)
|
|
75
|
+
|
|
76
|
+
#: (untyped) -> bool
|
|
77
|
+
def plain_object?(value) = value.is_a?(Hash)
|
|
78
|
+
#: (untyped, untyped) -> bool
|
|
79
|
+
def same_json?(a, b) = JSON.generate(a) == JSON.generate(b) && a.class == b.class
|
|
80
|
+
|
|
81
|
+
# The first place two JSON values differ: a path of keys and indexes,
|
|
82
|
+
# and what each side holds there, :none for a side with nothing.
|
|
83
|
+
#: (untyped, untyped, Array[String]) -> [Array[String], untyped, untyped]?
|
|
84
|
+
def difference_in(actual, expected, path)
|
|
85
|
+
if actual.is_a?(Array) && expected.is_a?(Array)
|
|
86
|
+
[actual.size, expected.size].max.times do |index|
|
|
87
|
+
found = difference_in(actual.fetch(index, :none), expected.fetch(index, :none), [*path, index.to_s])
|
|
88
|
+
return found if found
|
|
89
|
+
end
|
|
90
|
+
return nil
|
|
91
|
+
end
|
|
92
|
+
if plain_object?(actual) && plain_object?(expected)
|
|
93
|
+
(actual.keys + (expected.keys - actual.keys)).each do |key|
|
|
94
|
+
found = difference_in(actual.fetch(key, :none), expected.fetch(key, :none), [*path, key.to_s])
|
|
95
|
+
return found if found
|
|
96
|
+
end
|
|
97
|
+
return nil
|
|
98
|
+
end
|
|
99
|
+
same_json?(actual, expected) ? nil : [path, actual, expected]
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
#: (untyped) -> String
|
|
103
|
+
def side_text(value) = value == :none ? "nothing" : value_text(value)
|
|
104
|
+
|
|
105
|
+
#: (String, String) -> String
|
|
106
|
+
def text_difference(actual, expected)
|
|
107
|
+
if actual.include?("\n") || expected.include?("\n")
|
|
108
|
+
actual_lines = actual.split("\n", -1)
|
|
109
|
+
expected_lines = expected.split("\n", -1)
|
|
110
|
+
line = 0
|
|
111
|
+
line += 1 while line < [actual_lines.size, expected_lines.size].max && actual_lines[line] == expected_lines[line]
|
|
112
|
+
return "line #{line + 1}: actual #{side_text(actual_lines.fetch(line, :none))}, expected #{side_text(expected_lines.fetch(line, :none))}"
|
|
113
|
+
end
|
|
114
|
+
a = actual.chars
|
|
115
|
+
e = expected.chars
|
|
116
|
+
at = 0
|
|
117
|
+
at += 1 while at < a.size && a[at] == e[at]
|
|
118
|
+
start = [0, at - DIFFERENCE_CONTEXT].max
|
|
119
|
+
around = ->(points) { "#{"..." if start.positive?}#{points[start...(at + DIFFERENCE_CONTEXT)]&.join}#{"..." if points.size > at + DIFFERENCE_CONTEXT}" }
|
|
120
|
+
"character #{at + 1}: actual #{JSON.generate(around.(a))}, expected #{JSON.generate(around.(e))}"
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
#: (untyped, untyped) -> String?
|
|
124
|
+
def equal_difference(actual, expected)
|
|
125
|
+
if actual.is_a?(String) && expected.is_a?(String)
|
|
126
|
+
return nil if actual == expected
|
|
127
|
+
|
|
128
|
+
long = JSON.generate(actual).size > VALUE_TEXT_LIMIT || JSON.generate(expected).size > VALUE_TEXT_LIMIT
|
|
129
|
+
return long || actual.include?("\n") || expected.include?("\n") ? "first difference at #{text_difference(actual, expected)}" : nil
|
|
130
|
+
end
|
|
131
|
+
return nil unless (actual.is_a?(Array) && expected.is_a?(Array)) || (plain_object?(actual) && plain_object?(expected))
|
|
132
|
+
|
|
133
|
+
found = difference_in(actual, expected, []) or return nil
|
|
134
|
+
first = "first difference at #{difference_at(*found)}"
|
|
135
|
+
actual.is_a?(Array) ? list_difference(actual, expected, first) : first
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
#: (Array[untyped], untyped, untyped) -> String
|
|
139
|
+
def difference_at(path, actual, expected)
|
|
140
|
+
if actual.is_a?(String) && expected.is_a?(String) && equal_difference(actual, expected)
|
|
141
|
+
return "#{path.join(".")}, #{text_difference(actual, expected)}"
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
"#{path.join(".")}: actual #{side_text(actual)}, expected #{side_text(expected)}"
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
#: (untyped, untyped) -> bool
|
|
148
|
+
def same?(a, b) = Claims.same?(a, b) && a.class == b.class || (a.is_a?(Numeric) && b.is_a?(Numeric) && a == b)
|
|
149
|
+
|
|
150
|
+
#: (Array[untyped], Array[untyped]) -> [Integer, Integer]
|
|
151
|
+
def shared_ends(actual, expected)
|
|
152
|
+
shorter = [actual.size, expected.size].min
|
|
153
|
+
start = 0
|
|
154
|
+
start += 1 while start < shorter && same?(actual[start], expected[start])
|
|
155
|
+
tail = 0
|
|
156
|
+
tail += 1 while tail < shorter - start && same?(actual[-1 - tail], expected[-1 - tail])
|
|
157
|
+
[start, tail]
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
#: (Array[untyped], Array[untyped]) -> Hash[Symbol, Array[Integer]]?
|
|
161
|
+
def unpaired_items(actual, expected)
|
|
162
|
+
start, tail = shared_ends(actual, expected)
|
|
163
|
+
actual_end = actual.size - tail
|
|
164
|
+
expected_end = expected.size - tail
|
|
165
|
+
return nil if (actual_end - start) * (expected_end - start) > ITEM_PAIRS_LIMIT
|
|
166
|
+
|
|
167
|
+
missing = (start...expected_end).to_a
|
|
168
|
+
extra = []
|
|
169
|
+
(start...actual_end).each do |index|
|
|
170
|
+
at = missing.index { same?(actual[index], expected[_1]) }
|
|
171
|
+
at ? missing.delete_at(at) : extra << index
|
|
172
|
+
end
|
|
173
|
+
{ missing: missing, extra: extra }
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
# The items a longest run of equal items, in order, leaves out, so an
|
|
177
|
+
# inserted item is one extra item and not a change to every one after it.
|
|
178
|
+
#: (Array[untyped], Array[untyped]) -> Hash[Symbol, untyped]?
|
|
179
|
+
def aligned_items(actual, expected)
|
|
180
|
+
start, tail = shared_ends(actual, expected)
|
|
181
|
+
a_count = actual.size - tail - start
|
|
182
|
+
e_count = expected.size - tail - start
|
|
183
|
+
return nil if a_count * e_count > ITEM_PAIRS_LIMIT
|
|
184
|
+
|
|
185
|
+
eq = ->(a, e) { same?(actual[start + a], expected[start + e]) }
|
|
186
|
+
longest = Array.new(a_count + 1) { Array.new(e_count + 1, 0) }
|
|
187
|
+
(a_count - 1).downto(0) do |a|
|
|
188
|
+
(e_count - 1).downto(0) do |e|
|
|
189
|
+
longest[a][e] = eq.(a, e) ? longest[a + 1][e + 1] + 1 : [longest[a + 1][e], longest[a][e + 1]].max
|
|
190
|
+
end
|
|
191
|
+
end
|
|
192
|
+
missing = []
|
|
193
|
+
extra = []
|
|
194
|
+
changed = []
|
|
195
|
+
stretch = { actual: [], expected: [] }
|
|
196
|
+
close = lambda do
|
|
197
|
+
if stretch[:actual].size == stretch[:expected].size
|
|
198
|
+
stretch[:actual].each_with_index { |index, offset| changed << { actual: index, expected: stretch[:expected][offset] } }
|
|
199
|
+
else
|
|
200
|
+
missing.concat(stretch[:expected])
|
|
201
|
+
extra.concat(stretch[:actual])
|
|
202
|
+
end
|
|
203
|
+
stretch = { actual: [], expected: [] }
|
|
204
|
+
end
|
|
205
|
+
a = e = 0
|
|
206
|
+
while a < a_count || e < e_count
|
|
207
|
+
if a < a_count && e < e_count && eq.(a, e)
|
|
208
|
+
close.()
|
|
209
|
+
a += 1
|
|
210
|
+
e += 1
|
|
211
|
+
elsif e < e_count && (a == a_count || longest[a + 1][e] <= longest[a][e + 1])
|
|
212
|
+
stretch[:expected] << start + e
|
|
213
|
+
e += 1
|
|
214
|
+
else
|
|
215
|
+
stretch[:actual] << start + a
|
|
216
|
+
a += 1
|
|
217
|
+
end
|
|
218
|
+
end
|
|
219
|
+
close.()
|
|
220
|
+
{ missing: missing, extra: extra, changed: changed }
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
#: (Array[Integer], Array[untyped]) -> String
|
|
224
|
+
def listed_items(indexes, items)
|
|
225
|
+
shown = indexes.first(LISTED_ITEMS).map { "#{value_text(items[_1])} (item #{_1})" }
|
|
226
|
+
more = indexes.size - shown.size
|
|
227
|
+
more.zero? ? shown.join(", ") : "#{shown.join(", ")}, and #{more} more"
|
|
228
|
+
end
|
|
229
|
+
|
|
230
|
+
#: (Hash[Symbol, untyped], Array[untyped], Array[untyped]) -> String?
|
|
231
|
+
def unshared_text(unshared, actual, expected)
|
|
232
|
+
head = ->(indexes, side) { "#{indexes.size} #{side} #{indexes.size == 1 ? "item is" : "items are"}" }
|
|
233
|
+
parts = []
|
|
234
|
+
parts << "#{head.(unshared[:missing], "expected")} missing: #{listed_items(unshared[:missing], expected)}" if unshared[:missing].any?
|
|
235
|
+
parts << "#{head.(unshared[:extra], "actual")} extra: #{listed_items(unshared[:extra], actual)}" if unshared[:extra].any?
|
|
236
|
+
parts.empty? ? nil : parts.join("; ")
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
#: (Array[Hash[Symbol, Integer]], Array[untyped], Array[untyped]) -> String?
|
|
240
|
+
def changed_text(changed, actual, expected)
|
|
241
|
+
first = changed.first or return nil
|
|
242
|
+
found = difference_in(actual[first[:actual]], expected[first[:expected]], []) or return nil
|
|
243
|
+
item = first[:actual] == first[:expected] ? "item #{first[:actual]}" : "item #{first[:actual]} (expected item #{first[:expected]})"
|
|
244
|
+
where = "#{found[0].empty? ? "" : " at "}#{difference_at(*found)}"
|
|
245
|
+
changed.size == 1 ? "#{item} changed#{where}" : "#{changed.size} items changed, first #{item}#{where}"
|
|
246
|
+
end
|
|
247
|
+
|
|
248
|
+
#: (Array[untyped], Array[untyped], String) -> String
|
|
249
|
+
def list_difference(actual, expected, first)
|
|
250
|
+
unpaired = unpaired_items(actual, expected)
|
|
251
|
+
return "the same items in another order, #{first}" if unpaired && unpaired[:missing].empty? && unpaired[:extra].empty?
|
|
252
|
+
|
|
253
|
+
aligned = aligned_items(actual, expected)
|
|
254
|
+
return first if aligned.nil? || (aligned[:missing].empty? && aligned[:extra].empty?)
|
|
255
|
+
|
|
256
|
+
[unshared_text(aligned, actual, expected), changed_text(aligned[:changed], actual, expected)].compact.join("; ")
|
|
257
|
+
end
|
|
258
|
+
|
|
259
|
+
#: (untyped, untyped) -> String?
|
|
260
|
+
def same_items_difference(actual, expected)
|
|
261
|
+
return nil unless actual.is_a?(Array) && expected.is_a?(Array)
|
|
262
|
+
|
|
263
|
+
unpaired = unpaired_items(actual, expected)
|
|
264
|
+
unpaired && unshared_text(unpaired, actual, expected)
|
|
265
|
+
end
|
|
266
|
+
|
|
267
|
+
# The first expected field a broken has-fields claim's object lacks or
|
|
268
|
+
# holds another value at, found by the matcher that judged it.
|
|
269
|
+
#: (untyped, untyped) -> String?
|
|
270
|
+
def fields_difference(actual, expected)
|
|
271
|
+
misfit = Claims.field_misfit(actual, expected) or return nil
|
|
272
|
+
at = misfit[:path].join(".")
|
|
273
|
+
case misfit[:kind]
|
|
274
|
+
when "missing" then "first field that does not fit at #{at}: actual nothing, expected #{value_text(misfit[:expected])}"
|
|
275
|
+
when "length" then "first field that does not fit at #{at}: actual #{item_count(misfit[:actual])}, expected #{item_count(misfit[:expected])}"
|
|
276
|
+
else "first field that does not fit at #{difference_at(misfit[:path], misfit[:actual], misfit[:expected])}"
|
|
277
|
+
end
|
|
278
|
+
end
|
|
279
|
+
|
|
280
|
+
# How far a broken fits-text claim's text fit, and the line where it
|
|
281
|
+
# stopped, or the two named stand-ins that broke it.
|
|
282
|
+
#: (untyped, untyped) -> String?
|
|
283
|
+
def fits_difference(actual, expected)
|
|
284
|
+
return nil unless actual.is_a?(String) && expected.is_a?(String)
|
|
285
|
+
|
|
286
|
+
fit = TextFit.fit(actual, expected)
|
|
287
|
+
return nil if fit[:fits]
|
|
288
|
+
return readings_difference(fit[:readings][0], fit[:readings][1]) if fit[:readings]
|
|
289
|
+
return "every expected line fits, and actual line #{fit[:at]} is left over: actual #{side_text(fit.fetch(:actual, :none))}" unless fit.key?(:expected)
|
|
290
|
+
|
|
291
|
+
fitted = case fit[:fitted]
|
|
292
|
+
when 0 then ""
|
|
293
|
+
when 1 then "expected line 1 fits, and "
|
|
294
|
+
else "expected lines 1 to #{fit[:fitted]} fit, and "
|
|
295
|
+
end
|
|
296
|
+
"#{fitted}expected line #{fit[:fitted] + 1} fits nothing from actual line #{fit[:at]}: actual #{side_text(fit.fetch(:actual, :none))}, expected #{value_text(fit[:expected])}"
|
|
297
|
+
end
|
|
298
|
+
|
|
299
|
+
#: (Hash[Symbol, untyped], Hash[Symbol, untyped]) -> String
|
|
300
|
+
def readings_difference(first, after)
|
|
301
|
+
where = if first[:at] == after[:at] then "in actual line #{first[:at]}: actual #{value_text(first[:line])}"
|
|
302
|
+
else "in actual lines #{first[:at]} and #{after[:at]}: actual #{value_text(first[:line])}, then #{value_text(after[:line])}"
|
|
303
|
+
end
|
|
304
|
+
read = if first[:name] == after[:name] then "[..:#{first[:name]}] reads #{value_text(first[:text])} and then #{value_text(after[:text])}"
|
|
305
|
+
else "[..:#{first[:name]}] and [..:#{after[:name]}] both read #{value_text(first[:text])}"
|
|
306
|
+
end
|
|
307
|
+
"every expected line fits, but #{read} #{where}"
|
|
308
|
+
end
|
|
309
|
+
|
|
310
|
+
# The field a broken lacks-field claim's object holds, with its value,
|
|
311
|
+
# since a long object may not show it and a null reads as absent.
|
|
312
|
+
#: (untyped, untyped) -> String?
|
|
313
|
+
def present_field_difference(actual, expected)
|
|
314
|
+
return nil unless plain_object?(actual) && expected.is_a?(String)
|
|
315
|
+
|
|
316
|
+
object = Claims.normal(actual)
|
|
317
|
+
object.key?(expected) ? "field #{JSON.generate(expected)} is present and holds #{value_text(object[expected])}" : nil
|
|
318
|
+
end
|
|
319
|
+
|
|
320
|
+
DIFFERENCES = { "equal" => :equal_difference, "has-same-items" => :same_items_difference, "has-fields" => :fields_difference,
|
|
321
|
+
"lacks-field" => :present_field_difference, "fits-text" => :fits_difference,
|
|
322
|
+
"fits-aria-snapshot" => :aria_snapshot_difference }.freeze
|
|
323
|
+
|
|
324
|
+
#: (Hash[Symbol, untyped]) -> String
|
|
325
|
+
def difference_text(record)
|
|
326
|
+
return "" if each?(record) || record[:outcome] != "broken" || record[:reason]
|
|
327
|
+
|
|
328
|
+
describe = DIFFERENCES[record[:compare]]
|
|
329
|
+
return "" unless describe && record.key?(:actual) && record.key?(:expected)
|
|
330
|
+
|
|
331
|
+
difference = send(describe, record[:actual], record[:expected])
|
|
332
|
+
difference ? "; #{difference}" : ""
|
|
333
|
+
end
|
|
334
|
+
|
|
335
|
+
#: (Hash[Symbol, untyped]) -> String
|
|
336
|
+
def reason_text(record) = record[:reason] ? ": #{record[:reason]}" : difference_text(record)
|
|
337
|
+
|
|
338
|
+
#: (Hash[Symbol, untyped]) -> String
|
|
339
|
+
def named_outcome(record) = record[:outcome] == "unjudged" ? "unjudged" : "broken"
|
|
340
|
+
|
|
341
|
+
#: (Hash[Symbol, untyped]) -> Hash[Symbol, untyped]?
|
|
342
|
+
def named_item(record)
|
|
343
|
+
outcome = named_outcome(record)
|
|
344
|
+
record[:each][:results].find { _1[:selected] && _1[:outcome] == outcome }
|
|
345
|
+
end
|
|
346
|
+
|
|
347
|
+
#: (Hash[Symbol, untyped]) -> String
|
|
348
|
+
def item_claim_text(claim) = claim[:outcome] == "unjudged" && claim[:reason] ? "#{comparison_text(claim)}: #{claim[:reason]}" : comparison_text(claim)
|
|
349
|
+
|
|
350
|
+
#: (Hash[Symbol, untyped]) -> String
|
|
351
|
+
def item_name(item) = item[:identity] ? "item #{item[:index]} (#{item[:identity][:field]} #{value_text(item[:identity][:value])})" : "item #{item[:index]}"
|
|
352
|
+
|
|
353
|
+
# The claim and its outcome on one line. A broken each names its
|
|
354
|
+
# first broken item and that item's first broken comparison.
|
|
355
|
+
#: (Hash[Symbol, untyped]) -> String
|
|
356
|
+
def line(record)
|
|
357
|
+
text = "#{claim_text(record)} #{record[:outcome]}#{reason_text(record)}"
|
|
358
|
+
return text unless each?(record)
|
|
359
|
+
|
|
360
|
+
item = named_item(record)
|
|
361
|
+
claim = item&.dig(:claims)&.find { _1[:outcome] == named_outcome(record) }
|
|
362
|
+
item && claim ? "#{text}; #{item_name(item)}: #{item_claim_text(claim)}" : text
|
|
363
|
+
end
|
|
364
|
+
|
|
365
|
+
#: (Hash[Symbol, untyped]) -> Array[String]
|
|
366
|
+
def named_item_lines(record)
|
|
367
|
+
item = named_item(record) or return []
|
|
368
|
+
item[:claims].select { _1[:outcome] == named_outcome(record) }.map { " #{item_name(item)}: #{line(_1)}" }
|
|
369
|
+
end
|
|
370
|
+
|
|
371
|
+
# A claim step's failure: one line per claim that broke or was not
|
|
372
|
+
# judged, the first line naming the first one.
|
|
373
|
+
#: (Array[Hash[Symbol, untyped]]) -> String
|
|
374
|
+
def broken_claims_message(records)
|
|
375
|
+
records.select { %w[broken unjudged].include?(_1[:outcome]) }.flat_map do |record|
|
|
376
|
+
["claim #{record[:outcome]}: #{claim_text(record)}#{reason_text(record)}", *(each?(record) ? named_item_lines(record) : [])]
|
|
377
|
+
end.join("\n")
|
|
378
|
+
end
|
|
379
|
+
end
|
|
380
|
+
end
|
|
381
|
+
end
|