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,129 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
# rbs_inline: enabled
|
|
3
|
+
|
|
4
|
+
# The literal rule, as the TypeScript engine reads it. A literal expected
|
|
5
|
+
# value is in neither the sentence's data nor an earlier step's result, so
|
|
6
|
+
# it would let step code carry the criterion again ("the command succeeds"
|
|
7
|
+
# claiming 0). It is allowed only when the sentence states it: its text is
|
|
8
|
+
# a run of the pattern's fixed words joined by one space, a whole number
|
|
9
|
+
# from zero to twelve a fixed word spells (or once and twice), or the fixed
|
|
10
|
+
# value of a word in WORDS. A word inside a capture, an optional group, or
|
|
11
|
+
# an alternation is not fixed, since the sentence a line binds may not say
|
|
12
|
+
# it. A value WORDS fixes is compared with equal alone, or with not-equal
|
|
13
|
+
# right after "not", "neither", or "nor".
|
|
14
|
+
module Nukadoko
|
|
15
|
+
module Engine
|
|
16
|
+
module Literal
|
|
17
|
+
Statement = Data.define(:words, :by_table, :compare, :negated_by)
|
|
18
|
+
|
|
19
|
+
WORDS = { "no" => [0, "", []], "none" => [0, "", []], "nothing" => [0, "", []], "neither" => [0, "", []],
|
|
20
|
+
"never" => [0], "empty" => ["", []] }.freeze
|
|
21
|
+
NUMBERS = %w[zero one two three four five six seven eight nine ten eleven twelve].freeze
|
|
22
|
+
TIMES = { "once" => 1, "twice" => 2 }.freeze
|
|
23
|
+
NEGATING = %w[not neither nor].freeze
|
|
24
|
+
EDGE = /\A[.,;:!?"'`]+|[.,;:!?"'`]+\z/
|
|
25
|
+
|
|
26
|
+
module_function
|
|
27
|
+
|
|
28
|
+
# Every word of the pattern, with whether a matching sentence always holds it.
|
|
29
|
+
#: (String) -> Array[[String, bool]]
|
|
30
|
+
def words(pattern)
|
|
31
|
+
list = []
|
|
32
|
+
word = +""
|
|
33
|
+
fixed = true
|
|
34
|
+
finish = lambda do
|
|
35
|
+
text = word.gsub(EDGE, "")
|
|
36
|
+
list << [text, fixed] if !fixed || !text.empty?
|
|
37
|
+
word = +""
|
|
38
|
+
fixed = true
|
|
39
|
+
end
|
|
40
|
+
i = 0
|
|
41
|
+
while i < pattern.length
|
|
42
|
+
ch = pattern[i].to_s
|
|
43
|
+
if ch == "\\" && i + 1 < pattern.length
|
|
44
|
+
word << pattern[i + 1].to_s
|
|
45
|
+
i += 2
|
|
46
|
+
elsif ch.match?(/\s/)
|
|
47
|
+
finish.()
|
|
48
|
+
i += 1
|
|
49
|
+
elsif ["{", "("].include?(ch)
|
|
50
|
+
close = ch == "{" ? "}" : ")"
|
|
51
|
+
fixed = false
|
|
52
|
+
i += 1
|
|
53
|
+
i += pattern[i] == "\\" ? 2 : 1 while i < pattern.length && pattern[i] != close
|
|
54
|
+
i += 1
|
|
55
|
+
else
|
|
56
|
+
fixed = false if ch == "/"
|
|
57
|
+
word << ch
|
|
58
|
+
i += 1
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
finish.()
|
|
62
|
+
list
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
#: (untyped) -> String?
|
|
66
|
+
def text(literal)
|
|
67
|
+
case literal
|
|
68
|
+
when String then literal
|
|
69
|
+
when Integer then literal.to_s
|
|
70
|
+
when Float then literal.finite? ? (literal == literal.floor ? literal.to_i.to_s : literal.to_s) : nil
|
|
71
|
+
when true, false, nil then literal.nil? ? "null" : literal.to_s
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
#: (String) -> Integer?
|
|
76
|
+
def number_of(word)
|
|
77
|
+
lower = word.downcase
|
|
78
|
+
NUMBERS.index(lower) || TIMES[lower]
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
#: (untyped, untyped) -> bool
|
|
82
|
+
def same?(a, b) = a.is_a?(Array) && b.is_a?(Array) ? a.empty? && b.empty? : a.instance_of?(b.class) && a == b
|
|
83
|
+
|
|
84
|
+
#: (String, untyped) -> Statement?
|
|
85
|
+
def statement(pattern, literal)
|
|
86
|
+
all = words(pattern)
|
|
87
|
+
fixed = all.select(&:last).map(&:first)
|
|
88
|
+
said = text(literal)
|
|
89
|
+
return Statement.new(said, false, nil, nil) if said && !said.empty? && run_of?(fixed, said)
|
|
90
|
+
|
|
91
|
+
spelled = literal.is_a?(Integer) && fixed.find { number_of(_1) == literal }
|
|
92
|
+
return Statement.new(spelled, false, nil, nil) if spelled
|
|
93
|
+
|
|
94
|
+
all.each_with_index do |(word, is_fixed), index|
|
|
95
|
+
next unless is_fixed
|
|
96
|
+
next unless WORDS.fetch(word.downcase, []).any? { same?(literal, _1) }
|
|
97
|
+
next if word.downcase == "neither" && all.drop(index + 1).any? { |w, f| f && w.downcase == "nor" }
|
|
98
|
+
|
|
99
|
+
before = (index.positive? ? all[index - 1] : nil) #: [String, bool]?
|
|
100
|
+
return Statement.new(word, true, "not-equal", before[0]) if before && before[1] && NEGATING.include?(before[0].downcase)
|
|
101
|
+
|
|
102
|
+
return Statement.new(word, true, "equal", nil)
|
|
103
|
+
end
|
|
104
|
+
nil
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
#: (Array[String], String) -> bool
|
|
108
|
+
def run_of?(words, text)
|
|
109
|
+
(0...words.size).any? { |start| (start + 1..words.size).any? { words[start...(_1)].to_a.join(" ") == text } }
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
# How every pattern states `literal`, or nil when one does not: a line
|
|
113
|
+
# may bind any of them, and the first pattern's words name it.
|
|
114
|
+
#: (Array[String], untyped) -> Statement?
|
|
115
|
+
def statement_of_all(patterns, literal)
|
|
116
|
+
return nil if patterns.empty?
|
|
117
|
+
|
|
118
|
+
stated = patterns.filter_map { statement(_1, literal) }
|
|
119
|
+
first = stated.first
|
|
120
|
+
return nil unless first && stated.size == patterns.size
|
|
121
|
+
|
|
122
|
+
Statement.new(first.words, stated.any? { _1.by_table }, first.compare, first.negated_by)
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
#: (Array[String], untyped) -> untyped
|
|
126
|
+
def stated_by_all(patterns, literal) = statement_of_all(patterns, literal)&.words
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
end
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
# rbs_inline: enabled
|
|
3
|
+
|
|
4
|
+
# The `measured` of each claim record: which recorded channel of which step
|
|
5
|
+
# record holds exactly the raw value the claim read, as the TypeScript
|
|
6
|
+
# engine names it. A claim on a `from` value looks in the record of the step
|
|
7
|
+
# that returned it; any other looks in the claim step's own channels. The
|
|
8
|
+
# channels are a process's stdout, stderr, and exit code, an HTTP
|
|
9
|
+
# response's status and body, and a changed file's content. A number
|
|
10
|
+
# channel matches only a number, and a number another channel of the record
|
|
11
|
+
# also holds names no channel: content alone cannot tell which one the value
|
|
12
|
+
# came from, and nil says less than a source that may be false. So does any
|
|
13
|
+
# value while a channel's content is unknown. It is information for a
|
|
14
|
+
# reader, never a condition of the claim.
|
|
15
|
+
module Nukadoko
|
|
16
|
+
module Engine
|
|
17
|
+
module Measured
|
|
18
|
+
module_function
|
|
19
|
+
|
|
20
|
+
# Every channel of a step record, in record order: processes, then
|
|
21
|
+
# HTTP responses, then files. A channel whose content is not on disk
|
|
22
|
+
# whole is unknown.
|
|
23
|
+
#: (String, Hash[Symbol, untyped], String?) -> Array[Hash[Symbol, untyped]]
|
|
24
|
+
def channels(dir, observed, http)
|
|
25
|
+
list = []
|
|
26
|
+
(observed[:processes] || []).each_with_index do |process, index|
|
|
27
|
+
%i[stdout stderr].each do |stream|
|
|
28
|
+
next unless process[stream]
|
|
29
|
+
|
|
30
|
+
text = read(File.join(dir, process[stream]))
|
|
31
|
+
list << (text ? { channel: "observed.processes[#{index}].#{stream}", text: text } : { channel: "observed.processes[#{index}].#{stream}", unknown: true })
|
|
32
|
+
end
|
|
33
|
+
list << { channel: "observed.processes[#{index}].exit_code", number: process[:exit_code] } if process[:exit_code].is_a?(Integer)
|
|
34
|
+
end
|
|
35
|
+
if http
|
|
36
|
+
(read(File.join(dir, http)) || "").each_line.with_index do |line, index|
|
|
37
|
+
entry = begin
|
|
38
|
+
JSON.parse(line, symbolize_names: true)
|
|
39
|
+
rescue JSON::ParserError
|
|
40
|
+
next
|
|
41
|
+
end
|
|
42
|
+
list << { channel: "http.jsonl[#{index}].status", number: entry[:status] } if entry[:status].to_i != 0
|
|
43
|
+
list << kept("http.jsonl[#{index}].response_body", entry[:response_body]) if entry[:response_body]
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
(observed[:files] || []).each_with_index do |file, index|
|
|
47
|
+
list << kept("observed.files[#{index}].content", file[:content]) if file[:content]
|
|
48
|
+
end
|
|
49
|
+
list
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
#: (String, untyped) -> Hash[Symbol, untyped]
|
|
53
|
+
def kept(channel, text)
|
|
54
|
+
text = { text: text } if text.is_a?(String)
|
|
55
|
+
whole = text[:text] && !text[:truncated] && !text[:incomplete]
|
|
56
|
+
whole ? { channel: channel, text: text[:text] } : { channel: channel, unknown: true }
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
#: (String) -> String?
|
|
60
|
+
def read(path)
|
|
61
|
+
File.read(path, encoding: "UTF-8")
|
|
62
|
+
rescue SystemCallError
|
|
63
|
+
nil
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# The channel of `record_id` that holds `raw`, or nil; `skip` is a
|
|
67
|
+
# channel the other side already matched.
|
|
68
|
+
#: (String?, untyped, ^(String) -> Array[Hash[Symbol, untyped]], ?Hash[Symbol, untyped]?) -> Hash[Symbol, untyped]?
|
|
69
|
+
def channel_for(record_id, raw, channels_of, skip = nil)
|
|
70
|
+
return nil unless record_id
|
|
71
|
+
|
|
72
|
+
channels = channels_of.(record_id).reject { skip && skip[:step_record_id] == record_id && skip[:channel] == _1[:channel] }
|
|
73
|
+
return nil if channels.any? { _1[:unknown] }
|
|
74
|
+
|
|
75
|
+
match = channels.find { same?(raw, _1) }
|
|
76
|
+
return nil unless match
|
|
77
|
+
return nil if raw.is_a?(Numeric) && channels.any? { !_1.equal?(match) && holds_number?(_1, raw) }
|
|
78
|
+
|
|
79
|
+
{ step_record_id: record_id, channel: match[:channel] }
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
#: (untyped, Hash[Symbol, untyped]) -> bool
|
|
83
|
+
def same?(raw, channel)
|
|
84
|
+
return false if channel[:unknown]
|
|
85
|
+
return raw.is_a?(Numeric) && raw == channel[:number] if channel.key?(:number)
|
|
86
|
+
return raw == channel[:text] if raw.is_a?(String)
|
|
87
|
+
return false if raw.nil?
|
|
88
|
+
|
|
89
|
+
JSON.parse(JSON.generate(raw)) == JSON.parse(channel[:text])
|
|
90
|
+
rescue JSON::ParserError
|
|
91
|
+
false
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
# Whether a channel holds `n` as a number of its own, not as part of another.
|
|
95
|
+
#: (Hash[Symbol, untyped], Numeric) -> bool
|
|
96
|
+
def holds_number?(channel, number)
|
|
97
|
+
return false if channel[:unknown]
|
|
98
|
+
return channel[:number] == number if channel.key?(:number)
|
|
99
|
+
|
|
100
|
+
written = Regexp.escape(number.to_s)
|
|
101
|
+
channel[:text].match?(/(?<![\w.-])#{written}(?![\w.])/)
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
end
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
# rbs_inline: enabled
|
|
3
|
+
|
|
4
|
+
# The order `nuka run` plays its selection in, and the rerun line that plays
|
|
5
|
+
# it again. File order is the order the targets select. A shuffled order
|
|
6
|
+
# sorts the feature files, then each file's scenarios, by a key made from the
|
|
7
|
+
# seed and each one's path or line. A file stays whole, so one seed names one
|
|
8
|
+
# order at every concurrency. The key does not depend on what else was
|
|
9
|
+
# selected, so any part of a selection runs in the order the whole gave it,
|
|
10
|
+
# and a rerun line can name what ran before a failed scenario.
|
|
11
|
+
#
|
|
12
|
+
# The key is the TypeScript engine's, bit for bit: a seed names the same
|
|
13
|
+
# order in either engine. It works on 32-bit words, and on the UTF-16 code
|
|
14
|
+
# units of the text, as JavaScript's charCodeAt reads them.
|
|
15
|
+
module Nukadoko
|
|
16
|
+
module Engine
|
|
17
|
+
module Order
|
|
18
|
+
MAX_SEED = 0xffff_ffff
|
|
19
|
+
MASK = 0xffff_ffff
|
|
20
|
+
FILE = { kind: "file" }.freeze
|
|
21
|
+
|
|
22
|
+
# `--order`'s value read, or nil when it is none of file, shuffled,
|
|
23
|
+
# and shuffled:<seed>. shuffled alone draws its seed.
|
|
24
|
+
#: (String?) -> Hash[Symbol, untyped]?
|
|
25
|
+
def self.read(value)
|
|
26
|
+
return FILE if value.nil? || value == "file"
|
|
27
|
+
return { kind: "shuffled", seed: SecureRandom.random_number(MAX_SEED + 1) } if value == "shuffled"
|
|
28
|
+
|
|
29
|
+
seed = value[/\Ashuffled:(0|[1-9][0-9]{0,9})\z/, 1]&.to_i
|
|
30
|
+
seed && seed <= MAX_SEED ? { kind: "shuffled", seed: seed } : nil
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
#: (Hash[Symbol, untyped]) -> String
|
|
34
|
+
def self.text(order) = order[:kind] == "file" ? "file" : "shuffled:#{order[:seed]}"
|
|
35
|
+
#: (Hash[Symbol, untyped]) -> Array[String]
|
|
36
|
+
def self.flags(order) = order[:kind] == "file" ? [] : ["--order", text(order)]
|
|
37
|
+
|
|
38
|
+
# The scenarios in the run's order: by file in the order the files
|
|
39
|
+
# first appear, or by the shuffled keys.
|
|
40
|
+
#: (Array[Scenario], Hash[Symbol, untyped]) -> Array[Scenario]
|
|
41
|
+
def self.arrange(scenarios, order)
|
|
42
|
+
files = scenarios.group_by(&:uri)
|
|
43
|
+
return files.values.flatten if order[:kind] == "file"
|
|
44
|
+
|
|
45
|
+
seed = order[:seed]
|
|
46
|
+
files.keys.sort_by { [key(seed, _1), _1] }.flat_map do |uri|
|
|
47
|
+
files[uri].sort_by { [key(seed, "#{uri}:#{_1.line}"), _1.line] }
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# The targets that run, in a shuffled order, what ran before `scenario`
|
|
52
|
+
# in its pass and then `scenario`. A file whose every scenario of the
|
|
53
|
+
# pass is among them is named whole when the run named it whole.
|
|
54
|
+
#: (Array[Scenario], Array[String], Scenario) -> Array[String]
|
|
55
|
+
def self.replay_targets(sequence, whole_files, scenario)
|
|
56
|
+
at = sequence.index { _1.uri == scenario.uri && _1.line == scenario.line }
|
|
57
|
+
ran = at ? sequence.first(at + 1) : [scenario]
|
|
58
|
+
in_pass = sequence.map(&:uri).tally
|
|
59
|
+
ran.chunk_while { _1.uri == _2.uri }.flat_map do |group|
|
|
60
|
+
uri = group.first.uri
|
|
61
|
+
whole_files.include?(uri) && group.size == in_pass[uri] ? [uri] : group.map { "#{uri}:#{_1.line}" }
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# The seed is mixed before the text and the result after it, so two
|
|
66
|
+
# seeds a step apart give unrelated orders.
|
|
67
|
+
#: (Integer, String) -> Integer
|
|
68
|
+
def self.key(seed, text)
|
|
69
|
+
hash = mix(seed ^ 0x9e37_79b9)
|
|
70
|
+
units = text.encode("UTF-16LE").unpack("v*") #: Array[Integer]
|
|
71
|
+
units.each { |unit| hash = ((hash ^ unit) * 0x0100_0193) & MASK }
|
|
72
|
+
mix(hash)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
#: (Integer) -> Integer
|
|
76
|
+
def self.mix(value)
|
|
77
|
+
hash = value & MASK
|
|
78
|
+
hash = ((hash ^ (hash >> 16)) * 0x85eb_ca6b) & MASK
|
|
79
|
+
hash = ((hash ^ (hash >> 13)) * 0xc2b2_ae35) & MASK
|
|
80
|
+
(hash ^ (hash >> 16)) & MASK
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
data/lib/nukadoko/parts.rb
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
+
# rbs_inline: enabled
|
|
2
3
|
|
|
3
4
|
require "time"
|
|
4
5
|
|
|
@@ -15,6 +16,7 @@ module Nukadoko
|
|
|
15
16
|
|
|
16
17
|
attr_reader :calls
|
|
17
18
|
|
|
19
|
+
#: (singleton(Nukadoko::Step), Hash[Symbol, untyped]) -> void
|
|
18
20
|
def initialize(step, fixtures)
|
|
19
21
|
@fixtures = fixtures
|
|
20
22
|
@stack = [step]
|
|
@@ -22,46 +24,65 @@ module Nukadoko
|
|
|
22
24
|
@into = [@calls]
|
|
23
25
|
end
|
|
24
26
|
|
|
27
|
+
|
|
28
|
+
#: () -> Proc
|
|
25
29
|
def to_proc = method(:call).to_proc
|
|
26
30
|
|
|
31
|
+
# A refused call starts nothing, so it records nothing. Every other
|
|
32
|
+
# call is recorded in the order it started, with its result or its
|
|
33
|
+
# error, as the TypeScript engine records it.
|
|
34
|
+
#: (singleton(Nukadoko::Step), ?Hash[String | Symbol, untyped], **untyped) -> untyped
|
|
27
35
|
def call(part, args = {}, **keywords)
|
|
28
36
|
caller = @stack.last
|
|
29
37
|
unless part.is_a?(Class) && part < Step && caller.parts.include?(part)
|
|
30
|
-
raise Refused, "#{caller.step_name}
|
|
38
|
+
raise Refused, %(Step "#{caller.step_name}" called "#{part.respond_to?(:step_name) ? part.step_name : part.inspect}" through call(), but does not list it in its own ) +
|
|
39
|
+
%("parts" (docs/spec.md "Parts"). Add it there. The fixture bag this step runs with is ) +
|
|
40
|
+
%(built from that list before "run" is called, so a part the list does not name has nothing to run with.)
|
|
31
41
|
end
|
|
32
42
|
|
|
33
43
|
args = args.merge(keywords).transform_keys(&:to_s)
|
|
34
|
-
entry = {
|
|
44
|
+
entry = { step: part.step_name, args: args }
|
|
45
|
+
started = Time.now.utc.iso8601(3)
|
|
35
46
|
@into.last << entry
|
|
36
|
-
run(part, args, entry)
|
|
37
|
-
ensure
|
|
38
|
-
entry[:finished_at] = Time.now.utc.iso8601(3) if entry
|
|
47
|
+
run(part, args, entry, started)
|
|
39
48
|
end
|
|
40
49
|
|
|
41
50
|
private
|
|
42
51
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
52
|
+
#: (untyped, Hash[String, untyped], Hash[Symbol, untyped], String) -> untyped
|
|
53
|
+
def run(part, args, entry, started)
|
|
54
|
+
nested = []
|
|
55
|
+
fail_with = lambda do |kind, message|
|
|
56
|
+
entry.merge!(error: { message: message, kind: kind }, started_at: started, finished_at: Time.now.utc.iso8601(3), **(nested.any? ? { calls: nested } : {}))
|
|
57
|
+
end
|
|
58
|
+
problems = part.args.problems(args, strict: true)
|
|
59
|
+
if problems.any?
|
|
60
|
+
message = "args validation failed: #{problems.join("; ")}"
|
|
61
|
+
fail_with.("args_invalid", message)
|
|
62
|
+
raise TypeError, message
|
|
63
|
+
end
|
|
46
64
|
|
|
47
65
|
@stack << part
|
|
48
|
-
@into <<
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
part.returns ? part.returns.load(value) : value
|
|
56
|
-
rescue StandardError => e
|
|
57
|
-
entry[:error] ||= "#{e.class}: #{e.message}"
|
|
58
|
-
raise
|
|
59
|
-
ensure
|
|
60
|
-
if @stack.last == part
|
|
66
|
+
@into << nested
|
|
67
|
+
begin
|
|
68
|
+
value = part.new.run(**part.keywords(@fixtures.slice(*part.fixtures), part.inputs.load(args)))
|
|
69
|
+
rescue StandardError => e
|
|
70
|
+
fail_with.("step_error", e.message) unless entry[:error]
|
|
71
|
+
raise
|
|
72
|
+
ensure
|
|
61
73
|
@stack.pop
|
|
62
74
|
@into.pop
|
|
63
|
-
entry.delete(:calls) if entry[:calls]&.empty?
|
|
64
75
|
end
|
|
76
|
+
value, problems = part.returned(value)
|
|
77
|
+
if problems.any?
|
|
78
|
+
message = "returns validation failed: #{problems.join("; ")}"
|
|
79
|
+
fail_with.("result_invalid", message)
|
|
80
|
+
raise TypeError, message
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
value = part.returns.strip(value) if part.returns
|
|
84
|
+
entry.merge!(result: value, started_at: started, finished_at: Time.now.utc.iso8601(3), **(nested.any? ? { calls: nested } : {}))
|
|
85
|
+
part.returns ? part.returns.load(value) : value
|
|
65
86
|
end
|
|
66
87
|
end
|
|
67
88
|
end
|
data/lib/nukadoko/pattern.rb
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
+
# rbs_inline: enabled
|
|
2
3
|
|
|
3
4
|
require "cucumber/cucumber_expressions/cucumber_expression"
|
|
4
5
|
require "cucumber/cucumber_expressions/parameter_type_registry"
|
|
@@ -9,21 +10,90 @@ require "cucumber/cucumber_expressions/parameter_type_registry"
|
|
|
9
10
|
module Nukadoko
|
|
10
11
|
module Engine
|
|
11
12
|
class Pattern
|
|
13
|
+
CE = Cucumber::CucumberExpressions
|
|
14
|
+
|
|
15
|
+
# The built-in parameter types as the JavaScript package defines them.
|
|
16
|
+
# The gem's own differ: its \s takes no Unicode space, so {word} read
|
|
17
|
+
# "a<no-break space>b" as one word, and its float takes no "1." prefix
|
|
18
|
+
# or the lookahead JavaScript's does, so a line bound to one step in
|
|
19
|
+
# one engine and to none in the other. A value is what the JavaScript
|
|
20
|
+
# transformer gives: Number for an integer (a double past 2**53),
|
|
21
|
+
# parseFloat for a float, and the matched text for a bigdecimal.
|
|
22
|
+
class Registry < Cucumber::CucumberExpressions::ParameterTypeRegistry
|
|
23
|
+
INTEGER = [/-?\d+/, /\d+/].freeze
|
|
24
|
+
FLOAT = /(?=[^\n\r
]*\d[^\n\r
]*)[-+]?\d*(?:\.(?=\d[^\n\r
]*))?\d*(?:\d+[E][+-]?\d+)?/
|
|
25
|
+
WORD = /[^#{Spaces::CLASS}]+/
|
|
26
|
+
STRING = CE::ParameterTypeRegistry::STRING_REGEXP
|
|
27
|
+
ANONYMOUS = /[^\n\r
]*/
|
|
28
|
+
DECIMAL = /\A[-+]?(?:Infinity|(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?)/
|
|
29
|
+
|
|
30
|
+
# JavaScript's Number of a text of digits.
|
|
31
|
+
#: (String?) -> Numeric?
|
|
32
|
+
def self.number(text)
|
|
33
|
+
return nil if text.nil?
|
|
34
|
+
|
|
35
|
+
value = Integer(text, 10)
|
|
36
|
+
value.abs > 2**53 ? value.to_f : value
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# JavaScript's parseFloat: the longest number at the start, or NaN.
|
|
40
|
+
#: (String?) -> Float?
|
|
41
|
+
def self.parse_float(text)
|
|
42
|
+
return nil if text.nil?
|
|
43
|
+
|
|
44
|
+
found = text.sub(/\A[#{Spaces::CLASS}]+/, "")[DECIMAL]
|
|
45
|
+
return Float::NAN if found.nil?
|
|
46
|
+
|
|
47
|
+
sign = found.start_with?("-") ? -1 : 1
|
|
48
|
+
return sign * Float::INFINITY if found.end_with?("Infinity")
|
|
49
|
+
|
|
50
|
+
Float(found.sub(/\.(?=[eE]|\z)/, ""))
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
#: () -> void
|
|
54
|
+
def initialize
|
|
55
|
+
@parameter_type_by_name = {}
|
|
56
|
+
@parameter_types_by_regexp = Hash.new { |hash, regexp| hash[regexp] = [] }
|
|
57
|
+
number = ->(s = nil) { Registry.number(s) }
|
|
58
|
+
float = ->(s = nil) { Registry.parse_float(s) }
|
|
59
|
+
define_parameter_type(CE::ParameterType.new("int", INTEGER, Integer, number, true, true))
|
|
60
|
+
define_parameter_type(CE::ParameterType.new("float", FLOAT, Float, float, true, false))
|
|
61
|
+
define_parameter_type(CE::ParameterType.new("word", WORD, String, ->(s = nil) { s }, false, false))
|
|
62
|
+
define_parameter_type(CE::ParameterType.new("string", STRING, String, lambda { |s1, s2|
|
|
63
|
+
(s1 || s2 || "").gsub('\\"', '"').gsub("\\'", "'")
|
|
64
|
+
}, true, false))
|
|
65
|
+
define_parameter_type(CE::ParameterType.new("", ANONYMOUS, String, ->(s = nil) { s }, false, true))
|
|
66
|
+
define_parameter_type(CE::ParameterType.new("double", FLOAT, Float, float, false, false))
|
|
67
|
+
define_parameter_type(CE::ParameterType.new("bigdecimal", FLOAT, String, ->(s = nil) { s }, false, false))
|
|
68
|
+
%w[byte short long].each { define_parameter_type(CE::ParameterType.new(_1, INTEGER, Integer, number, false, false)) }
|
|
69
|
+
define_parameter_type(CE::ParameterType.new("biginteger", INTEGER, Integer, ->(s = nil) { s && Integer(s, 10) }, false, false))
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
12
73
|
NAMED = /\{([A-Za-z_][\w-]*):([\w-]+)\}/
|
|
13
|
-
REGISTRY =
|
|
74
|
+
REGISTRY = Registry.new
|
|
14
75
|
|
|
15
76
|
attr_reader :source, :keys
|
|
16
77
|
|
|
78
|
+
#: (String) -> void
|
|
17
79
|
def initialize(source)
|
|
18
80
|
@source = source
|
|
19
|
-
@keys = source.scan(NAMED).map(
|
|
20
|
-
@expression =
|
|
81
|
+
@keys = source.scan(NAMED).map { Array(_1).first.to_s }
|
|
82
|
+
@expression = CE::CucumberExpression.new(source.gsub(NAMED, '{\2}'), REGISTRY)
|
|
21
83
|
end
|
|
22
84
|
|
|
85
|
+
#: (String) -> Hash[String, untyped]?
|
|
23
86
|
def match(text)
|
|
24
87
|
found = @expression.match(text)
|
|
25
88
|
found && keys.zip(found.map { _1.value(nil) }).to_h
|
|
26
89
|
end
|
|
90
|
+
|
|
91
|
+
# Each capture's text as the line wrote it, quotes included.
|
|
92
|
+
#: (String) -> Hash[String, String]?
|
|
93
|
+
def texts(text)
|
|
94
|
+
found = @expression.match(text)
|
|
95
|
+
found && keys.zip(found.map { _1.group.value }).to_h
|
|
96
|
+
end
|
|
27
97
|
end
|
|
28
98
|
end
|
|
29
99
|
end
|
data/lib/nukadoko/poll.rb
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
+
# rbs_inline: enabled
|
|
2
3
|
|
|
3
4
|
require "time"
|
|
4
5
|
|
|
@@ -15,16 +16,20 @@ module Nukadoko
|
|
|
15
16
|
class Poll
|
|
16
17
|
INTERVAL = 0.1
|
|
17
18
|
|
|
18
|
-
|
|
19
|
+
# `sides` gives the claim inputs of one reading (Claims.judge).
|
|
20
|
+
#: (Hash[Symbol, untyped], Array[Hash[Symbol, untyped]], Hash[Symbol, untyped], ?(^(untyped) -> ClaimSides::Inputs)?) -> void
|
|
21
|
+
def initialize(options, claims, args, sides = nil)
|
|
19
22
|
@timeout = options.fetch(:timeout_ms) / 1000.0
|
|
20
23
|
@settled = options[:settled] || []
|
|
21
24
|
@claims = claims
|
|
22
25
|
@args = args
|
|
26
|
+
@sides = sides
|
|
23
27
|
end
|
|
24
28
|
|
|
25
29
|
# A reading whose observe raised is kept with the first line of the
|
|
26
30
|
# error, and the poll reads again; only a last reading that raised
|
|
27
31
|
# fails the step with that error.
|
|
32
|
+
#: (Hash[Symbol, untyped]) { () -> untyped } -> untyped
|
|
28
33
|
def call(record)
|
|
29
34
|
deadline = monotonic + @timeout
|
|
30
35
|
readings = []
|
|
@@ -38,8 +43,8 @@ module Nukadoko
|
|
|
38
43
|
sleep INTERVAL
|
|
39
44
|
end
|
|
40
45
|
ensure
|
|
41
|
-
record[:readings] = readings.map { _1.except(:value, :raised) }
|
|
42
|
-
record[:poll] = { readings: readings.size, stop: stop || "timeout" }
|
|
46
|
+
record[:readings] = readings.map { _1.except(:value, :raised, :judged_now) }
|
|
47
|
+
record[:poll] = { readings: readings.size, stop: stop || "timeout", conditions: @settled.map { RunRecord.describe_comparison(_1) } }
|
|
43
48
|
end
|
|
44
49
|
raise readings.last[:raised] if readings.last[:raised]
|
|
45
50
|
|
|
@@ -48,27 +53,35 @@ module Nukadoko
|
|
|
48
53
|
|
|
49
54
|
private
|
|
50
55
|
|
|
56
|
+
#: (Integer) { () -> untyped } -> Hash[Symbol, untyped]
|
|
51
57
|
def read(attempt)
|
|
52
58
|
judge(yield, attempt)
|
|
53
59
|
rescue StandardError => e
|
|
54
60
|
{ attempt: attempt, at: Time.now.utc.iso8601(3), holds: false, error: "#{e.class}: #{e.message.lines.first&.chomp}", raised: e }
|
|
55
61
|
end
|
|
56
62
|
|
|
63
|
+
#: (untyped, Integer) -> Hash[Symbol, untyped]
|
|
57
64
|
def judge(value, attempt)
|
|
58
|
-
judged = Claims.judge(@claims, value, @args)
|
|
59
|
-
reading = { attempt: attempt, at: Time.now.utc.iso8601(3), holds: judged.all? { _1[:holds] }, actuals: judged.map { _1[:actual] }, value: value
|
|
65
|
+
judged = Claims.judge(@claims, value, @args, @sides&.(value))
|
|
66
|
+
reading = { attempt: attempt, at: Time.now.utc.iso8601(3), holds: judged.all? { _1[:holds] }, actuals: judged.map { _1[:actual] }, value: value,
|
|
67
|
+
judged_now: judged.select { _1[:for_judgment] }.map { _1[:actual] } }
|
|
60
68
|
reading[:settled] = @settled.all? { Claims.judge_one(_1, value, {})[:holds] } if @settled.any?
|
|
61
69
|
reading
|
|
62
70
|
end
|
|
63
71
|
|
|
72
|
+
#: (Array[Hash[Symbol, untyped]]) -> String?
|
|
64
73
|
def stop_for(readings)
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
74
|
+
before = readings[-2] or return nil
|
|
75
|
+
last = readings.last #: Hash[Symbol, untyped]
|
|
76
|
+
# A value read for a judgment holds a poll only once two readings
|
|
77
|
+
# read it the same: a judge judges the last reading, and a page
|
|
78
|
+
# still changing would hand them a frame it then left.
|
|
79
|
+
return "held" if last[:holds] && before[:holds] && last[:judged_now] == before[:judged_now]
|
|
68
80
|
|
|
69
81
|
"settled" if last[:settled] && before[:settled]
|
|
70
82
|
end
|
|
71
83
|
|
|
84
|
+
#: () -> Float
|
|
72
85
|
def monotonic = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
73
86
|
end
|
|
74
87
|
end
|