nukadoko 0.1.0 → 0.3.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 +417 -0
- data/README.ja.md +62 -7
- data/README.md +19 -5
- 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 +294 -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/claim_sides.rb +469 -0
- data/lib/nukadoko/claims.rb +576 -37
- data/lib/nukadoko/cli.rb +814 -22
- data/lib/nukadoko/codes.json +947 -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 +88 -0
- data/lib/nukadoko/features.rb +80 -10
- data/lib/nukadoko/fixtures.rb +329 -11
- data/lib/nukadoko/http_recording.rb +68 -0
- data/lib/nukadoko/init.rb +129 -0
- data/lib/nukadoko/js_json.rb +274 -0
- data/lib/nukadoko/js_pattern.rb +531 -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 +43 -22
- data/lib/nukadoko/pattern.rb +73 -3
- data/lib/nukadoko/poll.rb +21 -8
- data/lib/nukadoko/program.rb +105 -17
- data/lib/nukadoko/project_files.rb +17 -0
- data/lib/nukadoko/project_fixtures.rb +17 -2
- data/lib/nukadoko/project_program.rb +119 -0
- 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 +898 -91
- data/lib/nukadoko/run_record.rb +535 -0
- data/lib/nukadoko/scaffold.rb +1015 -0
- data/lib/nukadoko/schema.rb +120 -21
- data/lib/nukadoko/secrets.rb +375 -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/spaces.rb +28 -0
- data/lib/nukadoko/step.rb +68 -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 +122 -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 +60 -2
- data/llms.txt +297 -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 +142 -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/claim_sides.rbs +207 -0
- data/sig/generated/nukadoko/claims.rbs +208 -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 +34 -0
- data/sig/generated/nukadoko/features.rbs +101 -0
- data/sig/generated/nukadoko/fixtures.rbs +175 -0
- data/sig/generated/nukadoko/http_recording.rbs +29 -0
- data/sig/generated/nukadoko/init.rbs +64 -0
- data/sig/generated/nukadoko/js_json.rbs +109 -0
- data/sig/generated/nukadoko/js_pattern.rbs +194 -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 +62 -0
- data/sig/generated/nukadoko/poll.rbs +41 -0
- data/sig/generated/nukadoko/program.rbs +101 -0
- data/sig/generated/nukadoko/project_files.rbs +19 -0
- data/sig/generated/nukadoko/project_fixtures.rbs +57 -0
- data/sig/generated/nukadoko/project_program.rbs +55 -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 +264 -0
- data/sig/generated/nukadoko/run_record.rbs +175 -0
- data/sig/generated/nukadoko/scaffold.rbs +328 -0
- data/sig/generated/nukadoko/schema.rbs +155 -0
- data/sig/generated/nukadoko/secrets.rbs +172 -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/spaces.rbs +31 -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 +26 -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 +342 -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 +109 -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 +133 -1
|
@@ -0,0 +1,519 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
# rbs_inline: enabled
|
|
3
|
+
|
|
4
|
+
# The claims a step may declare, as the TypeScript engine's defineStep
|
|
5
|
+
# reads them: each refusal names a claim the run could judge only one way
|
|
6
|
+
# on every line, or one that lets the line or step code decide what the
|
|
7
|
+
# claim compares. `first_problem` gives the first refusal in the order the
|
|
8
|
+
# TypeScript engine meets it, in its words, so `nuka check` reports one
|
|
9
|
+
# step-file-import-failed per step in both engines. A Ruby args schema has
|
|
10
|
+
# no optional key, no default, and no rewrite, so those refusals have no
|
|
11
|
+
# Ruby counterpart.
|
|
12
|
+
module Nukadoko
|
|
13
|
+
module Engine
|
|
14
|
+
module ClaimRules
|
|
15
|
+
class Refused < StandardError; end
|
|
16
|
+
|
|
17
|
+
# What the rules read about the step besides its claims.
|
|
18
|
+
Shape = Data.define(
|
|
19
|
+
:patterns, #: Array[String]
|
|
20
|
+
:args_keys, #: Array[String]
|
|
21
|
+
:string_args, #: Array[String]
|
|
22
|
+
:from_keys, #: Array[String]
|
|
23
|
+
:capture_keys, #: Array[String]
|
|
24
|
+
:observe, #: bool
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
VIEWS = %w[text lines json comma-list].freeze
|
|
28
|
+
COMPARISON_KEYS = %w[actual view at count compare expected expected_view].freeze
|
|
29
|
+
EACH_CLAIM_KEYS = %w[actual view at each].freeze
|
|
30
|
+
EACH_KEYS = %w[where claims].freeze
|
|
31
|
+
PATH = /\A[^.]+(\.[^.]+)*\z/
|
|
32
|
+
VIEW_MAKES = { "text" => "string", "lines" => "array", "comma-list" => "array", "json" => nil }.freeze
|
|
33
|
+
KIND_JSON_TYPES = { "string" => "string", "text" => "string", "number" => "number", "boolean" => "boolean", "list" => "array",
|
|
34
|
+
"array" => "array", "object" => "object", "null" => "null" }.freeze
|
|
35
|
+
COUNT_COMPARES = %w[equal not-equal greater-than at-least less-than at-most].freeze
|
|
36
|
+
ORDER_COMPARES = %w[greater-than at-least less-than at-most].freeze
|
|
37
|
+
ACTUAL_READS = { "contains-text" => "string", "starts-with-text" => "string", "ends-with-text" => "string", "matches" => "string",
|
|
38
|
+
"fits-text" => "string", "has-item" => "array", "has-same-items" => "array", "has-fields" => "object",
|
|
39
|
+
"lacks-field" => "object", "greater-than" => "number", "at-least" => "number", "less-than" => "number",
|
|
40
|
+
"at-most" => "number" }.freeze
|
|
41
|
+
READS_INSTEAD = {
|
|
42
|
+
"string" => "Read the text with view text, or claim each line or item with each",
|
|
43
|
+
"array" => "Read the text with view lines or comma-list, or claim a value that is an array",
|
|
44
|
+
"object" => "Read the text with view json, or claim a value that is an object",
|
|
45
|
+
"number" => "Read the text with view json, or count the lines or items with count: true"
|
|
46
|
+
}.freeze
|
|
47
|
+
WHERE_DECIDES = %w[equal has-same-items has-fields lacks-field fits-text is-a contains-text starts-with-text ends-with-text matches has-item].freeze
|
|
48
|
+
|
|
49
|
+
module_function
|
|
50
|
+
|
|
51
|
+
# The first reason the TypeScript engine's defineStep would refuse
|
|
52
|
+
# these claims, or nil.
|
|
53
|
+
#: (untyped, Shape) -> String?
|
|
54
|
+
def first_problem(claims, shape)
|
|
55
|
+
validate(claims, shape)
|
|
56
|
+
nil
|
|
57
|
+
rescue Refused => e
|
|
58
|
+
e.message
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
#: (untyped) -> String
|
|
62
|
+
def describe(value)
|
|
63
|
+
JsJson.generate(value)
|
|
64
|
+
rescue StandardError
|
|
65
|
+
value.inspect
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
#: (String) -> String
|
|
69
|
+
def article(word) = word.match?(/\A[aeiou]/) ? "an #{word}" : "a #{word}"
|
|
70
|
+
|
|
71
|
+
#: (String) -> bot
|
|
72
|
+
def refuse(message) = raise(Refused, message)
|
|
73
|
+
|
|
74
|
+
#: (untyped) -> Array[String]?
|
|
75
|
+
def segments(path) = path.is_a?(String) && path.match?(PATH) ? path.split(".") : nil
|
|
76
|
+
|
|
77
|
+
#: (String, untyped, bool) -> void
|
|
78
|
+
def check_path(label, path, optional)
|
|
79
|
+
return if path.nil? && optional
|
|
80
|
+
|
|
81
|
+
refuse(%(#{label} must be a path of dot-separated keys, such as "result.exit_code"; got #{path.nil? ? "undefined" : describe(path)})) unless segments(path)
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
#: (String, Hash[Symbol, untyped], Array[String], String) -> void
|
|
85
|
+
def check_keys(label, value, allowed, what)
|
|
86
|
+
unknown = value.find { |key, entry| !entry.nil? && !allowed.include?(key.to_s) }&.first
|
|
87
|
+
refuse(%(#{label} has the key "#{unknown}", which #{what} does not have. It has #{allowed.join(", ")})) if unknown
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
#: (String, Hash[Symbol, untyped]) -> void
|
|
91
|
+
def check_common(label, claim)
|
|
92
|
+
refuse("#{label}.view must be one of #{VIEWS.join(", ")}; got #{describe(claim[:view])}") if !claim[:view].nil? && !VIEWS.include?(claim[:view])
|
|
93
|
+
check_path("#{label}.at", claim[:at], true)
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
#: (untyped) -> Hash[Symbol, untyped]?
|
|
97
|
+
def literal_of(expected) = expected.is_a?(Hash) && expected.key?(:literal) ? expected : nil
|
|
98
|
+
|
|
99
|
+
#: (untyped) -> bool
|
|
100
|
+
def literal_value?(value)
|
|
101
|
+
case value
|
|
102
|
+
when String, true, false, nil then true
|
|
103
|
+
when Integer then true
|
|
104
|
+
when Float then value.finite?
|
|
105
|
+
when Array then value.empty?
|
|
106
|
+
else false
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
#: (String, Hash[Symbol, untyped], Shape) -> void
|
|
111
|
+
def check_expected_view(label, claim, shape)
|
|
112
|
+
view = claim[:expected_view]
|
|
113
|
+
return if view.nil?
|
|
114
|
+
|
|
115
|
+
refuse("#{label}.expected_view must be one of #{VIEWS.join(", ")}; got #{describe(view)}") unless VIEWS.include?(view)
|
|
116
|
+
refuse("#{label}.expected_view reads the text a line states, and #{label}.expected is not an args key the sentence fills") unless claim[:expected].is_a?(String)
|
|
117
|
+
return if shape.string_args.include?(claim[:expected])
|
|
118
|
+
|
|
119
|
+
refuse("#{label}.expected_view reads text, and args.#{claim[:expected]} is not a plain z.string(), so the line's text is not what reaches the view")
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
#: (String, untyped, untyped, Shape, bool) -> void
|
|
123
|
+
def check_expected(label, expected, compare, shape, from_observe)
|
|
124
|
+
if expected.is_a?(String)
|
|
125
|
+
refuse(%(#{label}.expected names "#{expected}", which from fills from an earlier step. Write { from: "#{expected}" } so the record says so)) if shape.from_keys.include?(expected)
|
|
126
|
+
refuse(%(#{label}.expected names "#{expected}", which is not a key of args)) unless shape.args_keys.include?(expected)
|
|
127
|
+
return
|
|
128
|
+
end
|
|
129
|
+
refuse("#{label}.expected must be an args key the sentence fills, { from }, { literal }, or { observe }; got #{expected.nil? ? "undefined" : describe(expected)}") unless expected.is_a?(Hash)
|
|
130
|
+
refuse("#{label}.expected must have exactly one of from, literal, observe; got #{describe(expected.keys.map(&:to_s))}") unless expected.size == 1
|
|
131
|
+
|
|
132
|
+
if expected.key?(:from)
|
|
133
|
+
check_path("#{label}.expected.from", expected[:from], false)
|
|
134
|
+
key = expected[:from].split(".").first
|
|
135
|
+
refuse(%(#{label}.expected.from starts with "#{key}", which is not a key of this step's from)) unless shape.from_keys.include?(key)
|
|
136
|
+
if shape.capture_keys.include?(key)
|
|
137
|
+
refuse(%(#{label}.expected.from starts with "#{key}", which a pattern captures, so a line fills it and no earlier step does. Name it as a sentence key, or take it out of the pattern))
|
|
138
|
+
end
|
|
139
|
+
elsif expected.key?(:observe)
|
|
140
|
+
check_path("#{label}.expected.observe", expected[:observe], false)
|
|
141
|
+
refuse("#{label}.expected reads observe, and the step has no observe") unless shape.observe
|
|
142
|
+
elsif expected.key?(:literal)
|
|
143
|
+
check_literal(label, expected[:literal], compare, shape, from_observe)
|
|
144
|
+
else
|
|
145
|
+
refuse("#{label}.expected must have exactly one of from, literal, observe; got #{describe(expected.keys.map(&:to_s))}")
|
|
146
|
+
end
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
#: (String, untyped, untyped, Shape, bool) -> void
|
|
150
|
+
def check_literal(label, literal, compare, shape, from_observe)
|
|
151
|
+
refuse("#{label}.expected.literal must be a string, a finite number, a boolean, null, or []; got #{describe(literal)}") unless literal_value?(literal)
|
|
152
|
+
if [true, false].include?(literal) && from_observe
|
|
153
|
+
refuse("#{label}.expected is the boolean #{literal}, and its actual comes from observe. A boolean computed by observe is a judgment made in code: " \
|
|
154
|
+
"return the thing measured (a count, a text, a list) and let the claim compare it")
|
|
155
|
+
end
|
|
156
|
+
unless Literal.statement_of_all(shape.patterns, literal)
|
|
157
|
+
where = shape.patterns.empty? ? "the step has no pattern, so no sentence states it" : "no fixed word of #{shape.patterns.map { %("#{_1}") }.join(" and ")} states it"
|
|
158
|
+
refuse("#{label}.expected is the literal #{describe(literal)}, and #{where}. Put the value in the sentence, as fixed words or as a capture the claim names")
|
|
159
|
+
end
|
|
160
|
+
shape.patterns.each do |pattern|
|
|
161
|
+
stated = Literal.statement(pattern, literal)
|
|
162
|
+
next if stated.nil? || stated.compare.nil? || stated.compare == compare
|
|
163
|
+
|
|
164
|
+
words = stated.compare == "not-equal" ? %(words "#{(stated.negated_by || "not").downcase} #{stated.words}" rule out) : %(word "#{stated.words}" fixes)
|
|
165
|
+
refuse("#{label}.expected is the literal #{describe(literal)}, which the #{words}, and #{label}.compare is #{describe(compare)}. " \
|
|
166
|
+
'A value a word fixes is compared with equal alone, or with not-equal alone right after the word "not", "neither", or "nor" ("is not empty"): ' \
|
|
167
|
+
"another compare against it holds for nearly anything, and the word does not show it")
|
|
168
|
+
end
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
#: (String, Hash[Symbol, untyped]) -> void
|
|
172
|
+
def check_count(label, claim)
|
|
173
|
+
return if claim[:count].nil?
|
|
174
|
+
|
|
175
|
+
refuse("#{label}.count must be true, or left out; got #{describe(claim[:count])}") unless claim[:count] == true
|
|
176
|
+
makes = "#{label} counts the items of its actual value, which makes a number"
|
|
177
|
+
unless COUNT_COMPARES.include?(claim[:compare])
|
|
178
|
+
refuse("#{makes}, and #{claim[:compare]} does not compare two numbers, so the claim would break on every line or hold on every line. Compare the count with #{COUNT_COMPARES.join(", ")}")
|
|
179
|
+
end
|
|
180
|
+
if claim[:view] == "text" && claim[:at].nil?
|
|
181
|
+
refuse("#{label} counts the items of a value read through view text, which always makes a string and never an array, so the claim always breaks. Read the text with view lines to count its lines")
|
|
182
|
+
end
|
|
183
|
+
literal = literal_of(claim[:expected])
|
|
184
|
+
if literal && !literal[:literal].is_a?(Numeric)
|
|
185
|
+
refuse("#{makes}, and its expected value is the literal #{describe(literal[:literal])}, which is never a number, so the claim always breaks. " \
|
|
186
|
+
"State the number in the pattern, as digits or a number word, and write it as a number literal")
|
|
187
|
+
end
|
|
188
|
+
view = claim[:expected_view]
|
|
189
|
+
made = view && VIEW_MAKES[view]
|
|
190
|
+
return unless made
|
|
191
|
+
|
|
192
|
+
refuse("#{makes}, and its expected value is read through expected_view #{view}, which makes #{article(made)} and never a number, so the claim always breaks. Capture the number with {int}, or leave expected_view out")
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
#: (String, Hash[Symbol, untyped]) -> void
|
|
196
|
+
def check_sides(label, claim)
|
|
197
|
+
literal = literal_of(claim[:expected])
|
|
198
|
+
case claim[:compare]
|
|
199
|
+
when "has-fields"
|
|
200
|
+
if literal
|
|
201
|
+
refuse("#{label}.expected is the literal #{describe(literal[:literal])}, which is never an object, and has-fields compares two objects, so the claim always breaks. " \
|
|
202
|
+
'Take the expected object from the docstring, read as JSON with expected_view: "json"')
|
|
203
|
+
end
|
|
204
|
+
return if !claim[:expected].is_a?(String) || claim[:expected_view] == "json"
|
|
205
|
+
|
|
206
|
+
view = claim[:expected_view]
|
|
207
|
+
what = view.nil? ? "is args.#{claim[:expected]}, which a line fills with a capture's value, the docstring's text, or the table's cells" : "reads args.#{claim[:expected]} through expected_view #{view}, which makes #{article(VIEW_MAKES.fetch(view).to_s)}"
|
|
208
|
+
refuse(%(#{label}.expected #{what}, never an object, so has-fields always breaks. Read the docstring as JSON with expected_view: "json"))
|
|
209
|
+
when "lacks-field"
|
|
210
|
+
if literal && !literal[:literal].is_a?(String)
|
|
211
|
+
refuse("#{label}.expected is the literal #{describe(literal[:literal])}, which is never the name of a field, and lacks-field names the field its actual object lacks, so the claim always breaks. " \
|
|
212
|
+
"State the field's name in the pattern's fixed words")
|
|
213
|
+
end
|
|
214
|
+
view = claim[:expected_view]
|
|
215
|
+
return unless view && VIEW_MAKES[view] == "array"
|
|
216
|
+
|
|
217
|
+
refuse("#{label}.expected reads args.#{claim[:expected]} through expected_view #{view}, which makes an array and never the name of a field, so lacks-field always breaks. Name one field, and leave expected_view out")
|
|
218
|
+
when "fits-text"
|
|
219
|
+
expected = claim[:expected]
|
|
220
|
+
return if !expected.is_a?(Hash) || literal
|
|
221
|
+
|
|
222
|
+
key, what = if expected.key?(:from) then ["from", "a value a step returned"]
|
|
223
|
+
elsif expected.key?(:observe) then ["observe", "a value observe read"]
|
|
224
|
+
end
|
|
225
|
+
return unless key
|
|
226
|
+
|
|
227
|
+
refuse(%(#{label}.expected reads { #{key}: #{describe(expected[key.to_sym])} }, #{what}, and fits-text reads each "..." line, each "[..]", and each "[..:name]" of its expected text as a stand-in, so a value that holds one lets text nobody stated fit. ) +
|
|
228
|
+
"Take the expected text from the sentence: a docstring, a capture, or a literal")
|
|
229
|
+
when "is-a"
|
|
230
|
+
return unless literal
|
|
231
|
+
|
|
232
|
+
kind = literal[:literal].is_a?(String) && Claims::VALUE_KINDS.find { _1.casecmp?(literal[:literal]) }
|
|
233
|
+
refuse("#{label}.expected is the literal #{describe(literal[:literal])}, and is-a names one of the kinds #{Claims::VALUE_KINDS.join(", ")}, so the claim always breaks. State one of them in the pattern's fixed words") unless kind
|
|
234
|
+
|
|
235
|
+
view = claim[:view]
|
|
236
|
+
made = view.nil? || !claim[:at].nil? ? nil : VIEW_MAKES[view]
|
|
237
|
+
return if made.nil? || KIND_JSON_TYPES[kind.downcase] != made
|
|
238
|
+
|
|
239
|
+
instead = made == "string" ? "Name a kind a string may not be, such as uuid, date, timestamp, or url, or claim the value itself" : "Claim what its items are with each, or claim the value itself"
|
|
240
|
+
refuse("#{label} reads its actual value through view #{view}, which always makes #{article(made.to_s)}, so is-a #{describe(literal[:literal])} holds whenever the view applies and states nothing. #{instead}")
|
|
241
|
+
end
|
|
242
|
+
end
|
|
243
|
+
|
|
244
|
+
#: (String, Hash[Symbol, untyped]) -> void
|
|
245
|
+
def check_actual_view(label, claim)
|
|
246
|
+
return if claim[:view].nil? || !claim[:at].nil? || !claim[:count].nil?
|
|
247
|
+
|
|
248
|
+
reads = ACTUAL_READS[claim[:compare]]
|
|
249
|
+
made = VIEW_MAKES[claim[:view]]
|
|
250
|
+
return if reads.nil? || made.nil? || made == reads
|
|
251
|
+
|
|
252
|
+
refuse("#{label} reads its actual value through view #{claim[:view]}, which always makes #{article(made)} and never #{article(reads)}, so #{claim[:compare]} always breaks. #{READS_INSTEAD.fetch(reads)}")
|
|
253
|
+
end
|
|
254
|
+
|
|
255
|
+
#: (String, Hash[Symbol, untyped], Shape, bool, bool) -> void
|
|
256
|
+
def check_aria_snapshot(label, claim, shape, item, from_observe)
|
|
257
|
+
takes = "fits-aria-snapshot takes the ARIA snapshot of a locator or page that observe returns"
|
|
258
|
+
if item
|
|
259
|
+
refuse("#{label} compares with fits-aria-snapshot, and an item of each is plain JSON, never a locator or a page, while #{takes}, so the claim always breaks. " \
|
|
260
|
+
"Claim the snapshot at the top level, with actual naming the key observe returns it under")
|
|
261
|
+
end
|
|
262
|
+
unless from_observe
|
|
263
|
+
refuse("#{label}.actual reads a value an earlier step returned, which is plain JSON and never a locator or a page, and #{takes}, so the claim always breaks. Return the locator or page from observe, and name its key in actual")
|
|
264
|
+
end
|
|
265
|
+
%i[view at count].each do |key|
|
|
266
|
+
next if claim[key].nil?
|
|
267
|
+
|
|
268
|
+
refuse("#{label} has #{key}, and #{takes} at actual, with nothing between the value and the snapshot. Name the locator or page in actual, and drop #{key}")
|
|
269
|
+
end
|
|
270
|
+
expected = claim[:expected]
|
|
271
|
+
if (literal = literal_of(expected))
|
|
272
|
+
refuse("#{label}.expected is the literal #{describe(literal[:literal])}, and the expected ARIA snapshot of fits-aria-snapshot is a tree of lines the line states, which the pattern's fixed words are not. Take the expected snapshot from the docstring")
|
|
273
|
+
end
|
|
274
|
+
if expected.is_a?(Hash)
|
|
275
|
+
source = expected.key?(:from) ? "a value a step returned" : "a value observe read"
|
|
276
|
+
refuse("#{label}.expected reads #{describe(expected)}, #{source}, and the expected ARIA snapshot of fits-aria-snapshot is the tree the line states: " \
|
|
277
|
+
"a tree a program wrote could be the actual tree copied, so the claim would hold whatever the page shows. Take the expected snapshot from the docstring")
|
|
278
|
+
end
|
|
279
|
+
unless claim[:expected_view].nil?
|
|
280
|
+
refuse("#{label}.expected_view is #{describe(claim[:expected_view])}, and fits-aria-snapshot reads the expected ARIA snapshot from the text the line states, as it is. Drop expected_view")
|
|
281
|
+
end
|
|
282
|
+
return unless expected.is_a?(String) && !shape.string_args.include?(expected)
|
|
283
|
+
|
|
284
|
+
refuse("#{label}.expected is args.#{expected}, which is not a plain z.string(), and fits-aria-snapshot reads the expected ARIA snapshot from the text the line states, " \
|
|
285
|
+
"so a table or a schema of another type would never reach it as that text. Declare args.#{expected} as z.string(), and fill it with the docstring")
|
|
286
|
+
end
|
|
287
|
+
|
|
288
|
+
#: (String, Hash[Symbol, untyped], bool) -> void
|
|
289
|
+
def check_judged(label, claim, item)
|
|
290
|
+
if item
|
|
291
|
+
refuse("#{label} compares with judged-as inside each, and a judgment cites one value a Then read, not one of many items. Claim the value at the top level, and name it in actual")
|
|
292
|
+
end
|
|
293
|
+
expected = claim[:expected]
|
|
294
|
+
if expected.is_a?(Hash) && !expected.key?(:literal)
|
|
295
|
+
refuse("#{label}.expected reads #{describe(expected)}, and the quality a judge reads a judged-as value against is the sentence's own words, so a reader of the feature sees what was asked. " \
|
|
296
|
+
"Take it from a capture, or from the pattern's fixed words as a literal")
|
|
297
|
+
end
|
|
298
|
+
return if claim[:expected_view].nil?
|
|
299
|
+
|
|
300
|
+
refuse("#{label}.expected_view is #{describe(claim[:expected_view])}, and a judge reads the quality as the sentence states it. Drop expected_view")
|
|
301
|
+
end
|
|
302
|
+
|
|
303
|
+
#: (String, Hash[Symbol, untyped], Shape, bool, bool) -> void
|
|
304
|
+
def check_comparison(label, claim, shape, item, from_observe)
|
|
305
|
+
refuse("#{label} has each, which a claim inside each cannot have") unless claim[:each].nil?
|
|
306
|
+
check_keys(label, claim, COMPARISON_KEYS, item ? "a claim on one item" : "a claim")
|
|
307
|
+
check_path("#{label}.actual", claim[:actual], item)
|
|
308
|
+
check_common(label, claim)
|
|
309
|
+
refuse("#{label}.compare must be one of #{Claims::COMPARES.join(", ")}; got #{claim[:compare].nil? ? "undefined" : describe(claim[:compare])}") unless Claims::COMPARES.include?(claim[:compare])
|
|
310
|
+
check_expected(label, claim[:expected], claim[:compare], shape, from_observe)
|
|
311
|
+
check_expected_view(label, claim, shape)
|
|
312
|
+
check_count(label, claim)
|
|
313
|
+
check_sides(label, claim)
|
|
314
|
+
check_actual_view(label, claim)
|
|
315
|
+
check_aria_snapshot(label, claim, shape, item, from_observe) if claim[:compare] == "fits-aria-snapshot"
|
|
316
|
+
check_judged(label, claim, item) if claim[:compare] == "judged-as"
|
|
317
|
+
end
|
|
318
|
+
|
|
319
|
+
#: (Hash[Symbol, untyped]) -> Array[String]
|
|
320
|
+
def item_path(claim)
|
|
321
|
+
split = ->(path) { path.is_a?(String) ? (segments(path) || [path]) : [] }
|
|
322
|
+
[*split.(claim[:actual]), *split.(claim[:at])]
|
|
323
|
+
end
|
|
324
|
+
|
|
325
|
+
#: (Hash[Symbol, untyped]) -> Array[String]
|
|
326
|
+
def item_read_path(claim)
|
|
327
|
+
path = item_path(claim)
|
|
328
|
+
return path unless claim[:compare] == "lacks-field"
|
|
329
|
+
|
|
330
|
+
literal = literal_of(claim[:expected])
|
|
331
|
+
literal && literal[:literal].is_a?(String) ? [*path, literal[:literal]] : path
|
|
332
|
+
end
|
|
333
|
+
|
|
334
|
+
#: (Array[String], Array[String]) -> bool
|
|
335
|
+
def overlap?(a, b) = a.first([a.size, b.size].min) == b.first([a.size, b.size].min)
|
|
336
|
+
|
|
337
|
+
#: (Hash[Symbol, untyped], Hash[Symbol, untyped]) -> bool
|
|
338
|
+
def one_item_value?(a, b)
|
|
339
|
+
return false if a[:view] != b[:view] || a[:count] != b[:count]
|
|
340
|
+
return item_path(a) == item_path(b) if a[:view].nil?
|
|
341
|
+
|
|
342
|
+
item_path({ actual: a[:actual] }) == item_path({ actual: b[:actual] }) && item_path({ at: a[:at] }) == item_path({ at: b[:at] })
|
|
343
|
+
end
|
|
344
|
+
|
|
345
|
+
#: (Array[String]) -> String
|
|
346
|
+
def described_item(path) = path.empty? ? "the item itself" : "the item at #{path.join(".")}"
|
|
347
|
+
|
|
348
|
+
#: (untyped) -> String?
|
|
349
|
+
def literal_json_type(literal)
|
|
350
|
+
case literal
|
|
351
|
+
when nil then "null"
|
|
352
|
+
when Array then "array"
|
|
353
|
+
when String then "string"
|
|
354
|
+
when Numeric then "number"
|
|
355
|
+
when true, false then "boolean"
|
|
356
|
+
end
|
|
357
|
+
end
|
|
358
|
+
|
|
359
|
+
#: (untyped, Shape) -> void
|
|
360
|
+
def validate(claims, shape)
|
|
361
|
+
refuse("claims must be a non-empty array. A claim step with no claim passes without judging anything") if !claims.is_a?(Array) || claims.empty?
|
|
362
|
+
|
|
363
|
+
claims.each_with_index do |claim, index|
|
|
364
|
+
label = "claims[#{index}]"
|
|
365
|
+
refuse("#{label} must be an object with actual, compare, and expected, or actual and each") unless claim.is_a?(Hash)
|
|
366
|
+
|
|
367
|
+
check_path("#{label}.actual", claim[:actual], false)
|
|
368
|
+
head = claim[:actual].split(".").first.to_s
|
|
369
|
+
from_observe = !shape.from_keys.include?(head)
|
|
370
|
+
refuse(%(#{label}.actual starts with "#{head}", which is not a key of this step's from, and the step has no observe to read it)) if from_observe && !shape.observe
|
|
371
|
+
if !from_observe && shape.capture_keys.include?(head)
|
|
372
|
+
refuse(%(#{label}.actual starts with "#{head}", which a pattern captures, so a line would fill the value the claim measures. Take it out of the pattern, so an earlier step fills it))
|
|
373
|
+
end
|
|
374
|
+
if from_observe && shape.args_keys.include?(head)
|
|
375
|
+
refuse(%(#{label}.actual starts with "#{head}", an args key the sentence fills. A claim's actual is a value an earlier step returned (a from key) or one observe read))
|
|
376
|
+
end
|
|
377
|
+
if claim[:each].nil?
|
|
378
|
+
check_comparison(label, claim, shape, false, from_observe)
|
|
379
|
+
next
|
|
380
|
+
end
|
|
381
|
+
refuse("#{label} has both each and compare/expected. A claim compares one value, or applies each to an array") unless claim[:compare].nil? && claim[:expected].nil?
|
|
382
|
+
|
|
383
|
+
check_keys(label, claim, EACH_CLAIM_KEYS, "a claim with each")
|
|
384
|
+
check_common(label, claim)
|
|
385
|
+
check_each(label, claim[:each], shape, from_observe)
|
|
386
|
+
end
|
|
387
|
+
check_observe_read(claims, shape)
|
|
388
|
+
check_captures_read(claims, shape)
|
|
389
|
+
end
|
|
390
|
+
|
|
391
|
+
#: (String, untyped, Shape, bool) -> void
|
|
392
|
+
def check_each(label, each, shape, from_observe)
|
|
393
|
+
refuse("#{label}.each.claims must be a non-empty array of claims on one item") if !each.is_a?(Hash) || !each[:claims].is_a?(Array) || each[:claims].empty?
|
|
394
|
+
check_keys("#{label}.each", each, EACH_KEYS, "each")
|
|
395
|
+
refuse("#{label}.each.where must be a non-empty array of claims on one item, or left out") if !each[:where].nil? && (!each[:where].is_a?(Array) || each[:where].empty?)
|
|
396
|
+
|
|
397
|
+
where = each[:where] || []
|
|
398
|
+
lists = [["where", where], ["claims", each[:claims]]] #: Array[[String, Array[untyped]]]
|
|
399
|
+
lists.each do |list, entries|
|
|
400
|
+
entries.each_with_index do |entry, item_index|
|
|
401
|
+
item_label = "#{label}.each.#{list}[#{item_index}]"
|
|
402
|
+
refuse("#{item_label} must be an object with compare and expected") unless entry.is_a?(Hash)
|
|
403
|
+
|
|
404
|
+
check_comparison(item_label, entry, shape, true, from_observe)
|
|
405
|
+
end
|
|
406
|
+
end
|
|
407
|
+
where.each_with_index do |entry, where_index|
|
|
408
|
+
next unless WHERE_DECIDES.include?(entry[:compare])
|
|
409
|
+
|
|
410
|
+
place = item_read_path(entry)
|
|
411
|
+
overlapping = each[:claims].index { overlap?(item_read_path(_1), place) }
|
|
412
|
+
next if overlapping.nil?
|
|
413
|
+
|
|
414
|
+
other = item_read_path(each[:claims][overlapping])
|
|
415
|
+
relation = if other.size == place.size then "the same place"
|
|
416
|
+
elsif other.size > place.size then "a place inside it"
|
|
417
|
+
else "a place that holds it"
|
|
418
|
+
end
|
|
419
|
+
refuse("#{label}.each.where[#{where_index}] selects by #{described_item(place)} with #{entry[:compare]}, and #{label}.each.claims[#{overlapping}] reads #{described_item(other)}, #{relation}, " \
|
|
420
|
+
"so where selects the items by the value the claim then judges and \"every item\" says nothing. Select by another value, or drop where")
|
|
421
|
+
end
|
|
422
|
+
where.each_with_index do |entry, where_index|
|
|
423
|
+
literal = literal_of(entry[:expected])
|
|
424
|
+
type = if ORDER_COMPARES.include?(entry[:compare]) then "number"
|
|
425
|
+
elsif entry[:compare] == "not-equal" && literal then literal_json_type(literal[:literal])
|
|
426
|
+
end
|
|
427
|
+
next if type.nil?
|
|
428
|
+
|
|
429
|
+
claim_index = each[:claims].index do |item|
|
|
430
|
+
named = literal_of(item[:expected])&.dig(:literal)
|
|
431
|
+
kind = named.is_a?(String) ? Claims::VALUE_KINDS.find { _1.casecmp?(named) } : nil
|
|
432
|
+
item[:compare] == "is-a" && kind && KIND_JSON_TYPES[kind.to_s.downcase] == type && one_item_value?(entry, item)
|
|
433
|
+
end
|
|
434
|
+
next if claim_index.nil?
|
|
435
|
+
|
|
436
|
+
kind = literal_of(each[:claims][claim_index][:expected]).to_h[:literal].to_s
|
|
437
|
+
refuse("#{label}.each.where[#{where_index}] selects by #{described_item(item_path(entry))} with #{entry[:compare]}, which holds only on #{article(type)}, " \
|
|
438
|
+
"and #{label}.each.claims[#{claim_index}] claims is-a #{JSON.generate(kind)} on the same value, so every item where selects holds it, whatever the data, " \
|
|
439
|
+
"and the claim measures nothing. Claim what the value is beyond its type, or drop the claim")
|
|
440
|
+
end
|
|
441
|
+
end
|
|
442
|
+
|
|
443
|
+
# The args keys observe never receives, each with the side a claim
|
|
444
|
+
# reads it on: a key a claim names as its expected value (a sentence
|
|
445
|
+
# key, or the head of a from path), and the from key a claim's actual
|
|
446
|
+
# starts with when that claim, or an item claim under its each, takes
|
|
447
|
+
# its expected value from observe. So observe cannot return what it
|
|
448
|
+
# will be compared with, either way.
|
|
449
|
+
#: (Array[Hash[Symbol, untyped]], Array[String]) -> Hash[String, String]
|
|
450
|
+
def withheld_keys(claims, from_keys)
|
|
451
|
+
keys = {} #: Hash[String, String]
|
|
452
|
+
claims.each do |claim|
|
|
453
|
+
entries = claim[:each] ? [*(claim[:each][:where] || []), *claim[:each][:claims]] : [claim]
|
|
454
|
+
entries.each do |entry|
|
|
455
|
+
expected = entry[:expected]
|
|
456
|
+
if expected.is_a?(String) then keys[expected] = "expected"
|
|
457
|
+
elsif expected.is_a?(Hash) && expected[:from] then keys[expected[:from].to_s.split(".").first.to_s] = "expected"
|
|
458
|
+
elsif expected.is_a?(Hash) && expected.key?(:observe)
|
|
459
|
+
head = claim[:actual].to_s.split(".").first.to_s
|
|
460
|
+
keys[head] = "actual" if from_keys.include?(head) && !keys.key?(head)
|
|
461
|
+
end
|
|
462
|
+
end
|
|
463
|
+
end
|
|
464
|
+
keys
|
|
465
|
+
end
|
|
466
|
+
|
|
467
|
+
# An observe no claim reads changes no verdict; a key it returns under
|
|
468
|
+
# a from key's name never reaches a claim, since the from value wins.
|
|
469
|
+
#: (Array[Hash[Symbol, untyped]], Shape) -> void
|
|
470
|
+
def check_observe_read(claims, shape)
|
|
471
|
+
return unless shape.observe
|
|
472
|
+
|
|
473
|
+
read = claims.any? do |claim|
|
|
474
|
+
next true unless shape.from_keys.include?(claim[:actual].to_s.split(".").first.to_s)
|
|
475
|
+
|
|
476
|
+
entries = claim[:each] ? [*(claim[:each][:where] || []), *claim[:each][:claims]] : [claim]
|
|
477
|
+
entries.any? { _1[:expected].is_a?(Hash) && _1[:expected].key?(:observe) }
|
|
478
|
+
end
|
|
479
|
+
return if read
|
|
480
|
+
|
|
481
|
+
refuse("the step has observe, and no claim reads what it returns: every claim's actual is a key of from, and no expected value is { observe }. " \
|
|
482
|
+
"A key observe returns under a from key's name never reaches a claim, since the from value wins. " \
|
|
483
|
+
"Rename the key observe returns so no from key has its name, or drop observe")
|
|
484
|
+
end
|
|
485
|
+
|
|
486
|
+
# A value the line states that no claim reads, in a step with no
|
|
487
|
+
# observe to receive it, is a value nothing checks.
|
|
488
|
+
#: (Array[Hash[Symbol, untyped]], Shape) -> void
|
|
489
|
+
def check_captures_read(claims, shape)
|
|
490
|
+
return if shape.observe
|
|
491
|
+
|
|
492
|
+
read = keys_read(claims)
|
|
493
|
+
unread = shape.capture_keys.find { !read.include?(_1) }
|
|
494
|
+
return unless unread
|
|
495
|
+
|
|
496
|
+
refuse(%(the pattern captures "#{unread}", and no claim reads it, and the step has no observe to receive it, so nothing checks the value the line states. ) +
|
|
497
|
+
%(Compare a claim with "#{unread}", or take it out of the pattern))
|
|
498
|
+
end
|
|
499
|
+
|
|
500
|
+
# The args keys the claims read: the head of each actual path, a
|
|
501
|
+
# sentence key named as an expected value, and the head of a from
|
|
502
|
+
# expected path, in every claim and in each each's where and claims.
|
|
503
|
+
#: (Array[Hash[Symbol, untyped]]) -> Array[String]
|
|
504
|
+
def keys_read(claims)
|
|
505
|
+
head = ->(path) { path.to_s.split(".").first.to_s }
|
|
506
|
+
claims.flat_map do |claim|
|
|
507
|
+
items = claim[:each] ? [*(claim[:each][:where] || []), *claim[:each][:claims]] : [claim]
|
|
508
|
+
expected = items.map do |item|
|
|
509
|
+
value = item[:expected]
|
|
510
|
+
if value.is_a?(String) then value
|
|
511
|
+
elsif value.is_a?(Hash) && value[:from] then head.(value[:from])
|
|
512
|
+
end
|
|
513
|
+
end
|
|
514
|
+
[head.(claim[:actual]), *expected]
|
|
515
|
+
end.compact.uniq
|
|
516
|
+
end
|
|
517
|
+
end
|
|
518
|
+
end
|
|
519
|
+
end
|