nukadoko 0.2.0 → 0.4.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 +153 -0
- data/README.ja.md +6 -3
- data/README.md +6 -3
- data/lib/nukadoko/aria_snapshot.rb +4 -4
- data/lib/nukadoko/base.rb +49 -29
- data/lib/nukadoko/check.rb +62 -5
- data/lib/nukadoko/claim_check.rb +2 -2
- data/lib/nukadoko/claim_rules.rb +1 -1
- data/lib/nukadoko/claim_sides.rb +481 -0
- data/lib/nukadoko/claims.rb +182 -20
- data/lib/nukadoko/cli.rb +24 -7
- data/lib/nukadoko/codes.json +20 -15
- data/lib/nukadoko/criteria.rb +1 -1
- data/lib/nukadoko/env_check.rb +1 -3
- data/lib/nukadoko/fixtures.rb +53 -21
- data/lib/nukadoko/init.rb +0 -1
- data/lib/nukadoko/js_json.rb +274 -0
- data/lib/nukadoko/js_pattern.rb +531 -0
- data/lib/nukadoko/parameter_types.rb +54 -0
- data/lib/nukadoko/parts.rb +1 -1
- data/lib/nukadoko/pattern.rb +112 -2
- data/lib/nukadoko/poll.rb +5 -3
- data/lib/nukadoko/program.rb +5 -5
- data/lib/nukadoko/project_files.rb +17 -0
- data/lib/nukadoko/project_program.rb +119 -0
- data/lib/nukadoko/run.rb +62 -17
- data/lib/nukadoko/run_record.rb +25 -22
- data/lib/nukadoko/scaffold.rb +2 -2
- data/lib/nukadoko/schema.rb +60 -18
- data/lib/nukadoko/secrets.rb +20 -4
- data/lib/nukadoko/spaces.rb +28 -0
- data/lib/nukadoko/step.rb +7 -1
- data/lib/nukadoko/text_fit.rb +1 -1
- data/lib/nukadoko/trace_actions.rb +4 -2
- data/lib/nukadoko/tree_passes.rb +6 -3
- data/lib/nukadoko/version.rb +1 -1
- data/lib/nukadoko.rb +26 -2
- data/llms.txt +20 -18
- data/sig/generated/nukadoko/aria_snapshot.rbs +2 -2
- data/sig/generated/nukadoko/base.rbs +24 -18
- data/sig/generated/nukadoko/check.rbs +11 -1
- data/sig/generated/nukadoko/claim_sides.rbs +216 -0
- data/sig/generated/nukadoko/claims.rbs +46 -3
- data/sig/generated/nukadoko/cli.rbs +1 -1
- data/sig/generated/nukadoko/env_check.rbs +0 -4
- data/sig/generated/nukadoko/fixtures.rbs +25 -2
- data/sig/generated/nukadoko/init.rbs +0 -2
- data/sig/generated/nukadoko/js_json.rbs +109 -0
- data/sig/generated/nukadoko/js_pattern.rbs +194 -0
- data/sig/generated/nukadoko/parameter_types.rbs +27 -0
- data/sig/generated/nukadoko/pattern.rbs +59 -1
- data/sig/generated/nukadoko/poll.rbs +3 -2
- data/sig/generated/nukadoko/program.rbs +1 -1
- data/sig/generated/nukadoko/project_files.rbs +19 -0
- data/sig/generated/nukadoko/project_program.rbs +55 -0
- data/sig/generated/nukadoko/run.rbs +17 -3
- data/sig/generated/nukadoko/run_record.rbs +5 -4
- data/sig/generated/nukadoko/schema.rbs +22 -4
- data/sig/generated/nukadoko/secrets.rbs +17 -2
- data/sig/generated/nukadoko/spaces.rbs +31 -0
- data/sig/generated/nukadoko/trace_actions.rbs +3 -1
- data/sig/generated/nukadoko/tree_passes.rbs +2 -2
- data/sig/generated/nukadoko.rbs +11 -0
- data/skills/nukadoko/SKILL.md +2 -2
- data/skills/nukadoko/references/diagnosing.md +1 -1
- data/skills/nukadoko/references/examples/http-api.md +19 -16
- data/skills/nukadoko/references/fixtures.md +1 -1
- data/skills/nukadoko/references/perturbed-worlds.md +8 -6
- data/skills/nukadoko/references/program.md +20 -20
- data/skills/nukadoko/references/running.md +2 -2
- data/skills/nukadoko/references/scenario-rules.md +2 -2
- data/skills/nukadoko/references/verdicts.md +3 -3
- data/skills/nukadoko/references/writing-steps.md +1 -1
- data/skills/nukadoko-verification/SKILL.md +6 -6
- metadata +19 -5
data/lib/nukadoko/claims.rb
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
# key, `{ literal: v }`, or `{ from: key }` for an args key an earlier step
|
|
8
8
|
# filled. The judge returns every comparison it made, so a broken claim shows
|
|
9
9
|
# what was read.
|
|
10
|
-
require "
|
|
10
|
+
require "ipaddr"
|
|
11
11
|
require_relative "text_fit"
|
|
12
12
|
|
|
13
13
|
module Nukadoko
|
|
@@ -106,12 +106,29 @@ module Nukadoko
|
|
|
106
106
|
taken[:text] ? taken : taken.transform_values { "observe:#{path} #{_1}" }
|
|
107
107
|
end
|
|
108
108
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
109
|
+
# `inputs` says where each side sits, so a top-level comparison is read
|
|
110
|
+
# as the TypeScript engine reads it (ClaimSides); without it, a claim
|
|
111
|
+
# reads `observed` as the value of each key.
|
|
112
|
+
#: (Array[Hash[Symbol, untyped]], untyped, untyped, ?ClaimSides::Inputs?) -> Array[Hash[Symbol, untyped]]
|
|
113
|
+
def self.judge(claims, observed, args, inputs = nil)
|
|
114
|
+
claims.map do |claim|
|
|
115
|
+
sided = !claim[:each] && claim[:compare] != "fits-aria-snapshot" && !(claim[:compare] == "judged-as" && aria_judged(claim, observed))
|
|
116
|
+
next each_judged(claim, inputs) if inputs && claim[:each]
|
|
117
|
+
|
|
118
|
+
inputs && sided ? ClaimSides.judge(claim, inputs) : judge_one(claim, observed, args)
|
|
119
|
+
end
|
|
112
120
|
end
|
|
113
121
|
|
|
114
|
-
|
|
122
|
+
# An each judged as its record judges it, so a poll waits on the
|
|
123
|
+
# outcome the record will hold.
|
|
124
|
+
#: (Hash[Symbol, untyped], ClaimSides::Inputs) -> Hash[Symbol, untyped]
|
|
125
|
+
def self.each_judged(claim, inputs)
|
|
126
|
+
record = RunRecord.each_claim(claim, inputs, {}, {})
|
|
127
|
+
{ holds: record[:outcome] == "held", **(record[:reason] ? { reason: record[:reason] } : {}),
|
|
128
|
+
**(record[:outcome] == "unjudged" ? { unjudged: true } : {}) }
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
# `top` is what observe returned, which an expected { observe } reads
|
|
115
132
|
# from inside an each as well. A claim on an item with no actual reads
|
|
116
133
|
# the item itself.
|
|
117
134
|
#: (Hash[Symbol, untyped], untyped, untyped, ?untyped) -> Hash[Symbol, untyped]
|
|
@@ -178,7 +195,7 @@ module Nukadoko
|
|
|
178
195
|
in { from: String => key } then read(args, key)
|
|
179
196
|
in { observe: String => path } then dig(read(top, path.split(".").first), path.split(".").drop(1).join(".").then { _1.empty? ? nil : _1 })
|
|
180
197
|
end
|
|
181
|
-
claim[:expected_view] == "json" ?
|
|
198
|
+
claim[:expected_view] == "json" ? JsJson.parse(value) : value
|
|
182
199
|
end
|
|
183
200
|
|
|
184
201
|
VIEWS = %w[text lines comma-list json].freeze
|
|
@@ -190,10 +207,10 @@ module Nukadoko
|
|
|
190
207
|
raise ArgumentError, "view #{name} reads a string, and the value is #{value.inspect}" unless value.is_a?(String)
|
|
191
208
|
|
|
192
209
|
case name
|
|
193
|
-
when "text" then value
|
|
194
|
-
when "lines" then value.
|
|
195
|
-
when "comma-list" then value.
|
|
196
|
-
when "json" then
|
|
210
|
+
when "text" then Spaces.trim_end(value)
|
|
211
|
+
when "lines" then (text = Spaces.trim_end(value)).empty? ? [] : text.split(/\r?\n/, -1)
|
|
212
|
+
when "comma-list" then (text = Spaces.trim(value)).empty? ? [] : text.split(",", -1).map { Spaces.trim(_1) }
|
|
213
|
+
when "json" then JsJson.parse(value)
|
|
197
214
|
else raise ArgumentError, "unknown view #{name}"
|
|
198
215
|
end
|
|
199
216
|
end
|
|
@@ -270,16 +287,159 @@ module Nukadoko
|
|
|
270
287
|
|
|
271
288
|
# A text a URL parser accepts can still be no URL a program wrote, so
|
|
272
289
|
# the scheme needs "//" and no character a reader cannot see may appear.
|
|
290
|
+
# The rest is what the WHATWG URL parser, which the TypeScript engine
|
|
291
|
+
# uses, refuses for http and https: a missing host, a port that is not
|
|
292
|
+
# a number up to 65535, a host with a character no domain may hold, and
|
|
293
|
+
# an IPv4 or IPv6 address that does not parse. A path, a query, and a
|
|
294
|
+
# fragment can hold anything, as a browser takes them.
|
|
273
295
|
#: (untyped) -> bool
|
|
274
296
|
def self.url?(value)
|
|
275
297
|
return false unless value.is_a?(String) && value.match?(%r{\Ahttps?://}i) && !value.match?(/[\s\p{Cc}\p{Cf}]/)
|
|
276
298
|
|
|
277
|
-
|
|
278
|
-
%
|
|
279
|
-
|
|
299
|
+
rest = value.sub(%r{\Ahttps?:[/\\]*}i, "")
|
|
300
|
+
authority = rest[%r{\A[^/\\?#]*}].to_s
|
|
301
|
+
at = authority.rindex("@")
|
|
302
|
+
host_port = at ? authority[(at + 1)..].to_s : authority
|
|
303
|
+
host, port = split_host_port(host_port)
|
|
304
|
+
return false if host.nil? || host.empty?
|
|
305
|
+
return false unless port.nil? || (port.match?(/\A\d*\z/) && port.to_i <= 65_535)
|
|
306
|
+
|
|
307
|
+
host.start_with?("[") ? ipv6?(host[1...-1].to_s) : domain?(host)
|
|
308
|
+
end
|
|
309
|
+
|
|
310
|
+
# The host and the port of `host:port`, a colon inside brackets kept.
|
|
311
|
+
#: (String) -> [String?, String?]
|
|
312
|
+
def self.split_host_port(text)
|
|
313
|
+
if text.start_with?("[")
|
|
314
|
+
close = text.index("]")
|
|
315
|
+
return [nil, nil] unless close
|
|
316
|
+
|
|
317
|
+
after = text[(close + 1)..].to_s
|
|
318
|
+
return [nil, nil] unless after.empty? || after.start_with?(":")
|
|
319
|
+
|
|
320
|
+
return [text[0..close], after.empty? ? nil : after[1..]]
|
|
321
|
+
end
|
|
322
|
+
colon = text.index(":")
|
|
323
|
+
colon ? [text[0...colon], text[(colon + 1)..]] : [text, nil]
|
|
324
|
+
end
|
|
325
|
+
|
|
326
|
+
#: (String) -> bool
|
|
327
|
+
def self.ipv6?(text)
|
|
328
|
+
return false if text.empty? || text.include?("%")
|
|
329
|
+
|
|
330
|
+
IPAddr.new(text).ipv6?
|
|
331
|
+
rescue IPAddr::Error
|
|
280
332
|
false
|
|
281
333
|
end
|
|
282
334
|
|
|
335
|
+
FORBIDDEN_DOMAIN = /[\u0000- #%\/:<>?@\[\\\]^|\u007f]/
|
|
336
|
+
|
|
337
|
+
# A host percent-decoded and mapped as UTS #46 maps it (NFKC, then
|
|
338
|
+
# lower case), which holds no character a domain may not, and whose
|
|
339
|
+
# last label, when it reads as a number, is an IPv4 address.
|
|
340
|
+
#: (String) -> bool
|
|
341
|
+
def self.domain?(host)
|
|
342
|
+
decoded = host.b.gsub(/%(\h\h)/n) { Regexp.last_match(1).to_s.hex.chr }.force_encoding("UTF-8")
|
|
343
|
+
return false unless decoded.valid_encoding?
|
|
344
|
+
|
|
345
|
+
mapped = decoded.unicode_normalize(:nfkc).downcase.tr("。.。", "...")
|
|
346
|
+
return false if mapped.empty? || mapped.match?(FORBIDDEN_DOMAIN) || mapped.include?("�")
|
|
347
|
+
|
|
348
|
+
labels = mapped.split(".", -1)
|
|
349
|
+
# Node checks an xn-- label only in a host that is not all ASCII.
|
|
350
|
+
return false if !decoded.ascii_only? && labels.any? { _1.start_with?("xn--") && !punycode_label?(_1) }
|
|
351
|
+
last = labels.last == "" && labels.size > 1 ? labels[-2] : labels.last
|
|
352
|
+
return true unless last.to_s.match?(/\A(?:\d+|0[xX]\h*)\z/)
|
|
353
|
+
|
|
354
|
+
ipv4?(labels)
|
|
355
|
+
end
|
|
356
|
+
|
|
357
|
+
# Whether a label written as `xn--` decodes, under RFC 3492, to a
|
|
358
|
+
# label UTS #46 keeps: one with a character outside ASCII, no control,
|
|
359
|
+
# joiner, or unassigned character, and already in its mapped form.
|
|
360
|
+
#: (String) -> bool
|
|
361
|
+
def self.punycode_label?(label)
|
|
362
|
+
decoded = punycode_decode(label[4..].to_s)
|
|
363
|
+
!decoded.nil? && !decoded.ascii_only? && !decoded.match?(/[\p{Cc}\p{Cf}\p{Cn}\p{Co}\p{Cs}]/) && decoded == decoded.unicode_normalize(:nfkc).downcase
|
|
364
|
+
end
|
|
365
|
+
|
|
366
|
+
# RFC 3492's decoder, or nil for a text that does not decode.
|
|
367
|
+
#: (String) -> String?
|
|
368
|
+
def self.punycode_decode(text)
|
|
369
|
+
return nil if text.empty?
|
|
370
|
+
|
|
371
|
+
base, damp, tmin, tmax, skew = 36, 700, 1, 26, 38
|
|
372
|
+
cut = text.rindex("-")
|
|
373
|
+
output = cut ? text[0...cut].to_s.codepoints : []
|
|
374
|
+
return nil unless output.all? { _1 < 0x80 }
|
|
375
|
+
|
|
376
|
+
n = 128
|
|
377
|
+
i = 0
|
|
378
|
+
bias = 72
|
|
379
|
+
index = cut ? cut + 1 : 0
|
|
380
|
+
while index < text.length
|
|
381
|
+
old = i
|
|
382
|
+
w = 1
|
|
383
|
+
k = base
|
|
384
|
+
loop do
|
|
385
|
+
return nil if index >= text.length
|
|
386
|
+
|
|
387
|
+
char = text[index].to_s.downcase
|
|
388
|
+
index += 1
|
|
389
|
+
digit = if char.match?(/[a-z]/) then char.ord - 97
|
|
390
|
+
elsif char.match?(/[0-9]/) then char.ord - 22
|
|
391
|
+
else return nil
|
|
392
|
+
end
|
|
393
|
+
i += digit * w
|
|
394
|
+
t = if k <= bias then tmin elsif k >= bias + tmax then tmax else k - bias end
|
|
395
|
+
break if digit < t
|
|
396
|
+
|
|
397
|
+
w *= base - t
|
|
398
|
+
k += base
|
|
399
|
+
end
|
|
400
|
+
length = output.size + 1
|
|
401
|
+
delta = old.zero? ? (i - old) / damp : (i - old) / 2
|
|
402
|
+
delta += delta / length
|
|
403
|
+
k = 0
|
|
404
|
+
while delta > ((base - tmin) * tmax) / 2
|
|
405
|
+
delta /= base - tmin
|
|
406
|
+
k += base
|
|
407
|
+
end
|
|
408
|
+
bias = k + (((base - tmin + 1) * delta) / (delta + skew))
|
|
409
|
+
n += i / length
|
|
410
|
+
i %= length
|
|
411
|
+
return nil if n > 0x10FFFF || n.between?(0xD800, 0xDFFF)
|
|
412
|
+
|
|
413
|
+
output.insert(i, n)
|
|
414
|
+
i += 1
|
|
415
|
+
end
|
|
416
|
+
output.pack("U*")
|
|
417
|
+
end
|
|
418
|
+
|
|
419
|
+
# The WHATWG IPv4 parser: up to four parts, each decimal, octal with a
|
|
420
|
+
# leading 0, or hex with 0x, every part but the last below 256 and the
|
|
421
|
+
# last below what the parts before it leave.
|
|
422
|
+
#: (Array[String]) -> bool
|
|
423
|
+
def self.ipv4?(labels)
|
|
424
|
+
parts = labels.last == "" ? labels[0...-1].to_a : labels
|
|
425
|
+
return false if parts.empty? || parts.size > 4
|
|
426
|
+
|
|
427
|
+
numbers = parts.map do |part|
|
|
428
|
+
number = case part
|
|
429
|
+
when /\A0[xX]\h*\z/ then part[2..].to_s.empty? ? 0 : part[2..].to_s.hex
|
|
430
|
+
when /\A0[0-7]+\z/ then part.to_i(8)
|
|
431
|
+
when /\A0\d+\z/ then nil
|
|
432
|
+
when /\A\d+\z/ then part.to_i
|
|
433
|
+
end
|
|
434
|
+
return false unless number
|
|
435
|
+
|
|
436
|
+
number
|
|
437
|
+
end
|
|
438
|
+
return false if numbers[0...-1].to_a.any? { _1 > 255 }
|
|
439
|
+
|
|
440
|
+
numbers.last.to_i < 256**(5 - numbers.size)
|
|
441
|
+
end
|
|
442
|
+
|
|
283
443
|
KIND_TESTS = {
|
|
284
444
|
"string" => ->(v) { v.is_a?(String) }, "text" => ->(v) { v.is_a?(String) },
|
|
285
445
|
"number" => ->(v) { v.is_a?(Numeric) }, "integer" => ->(v) { v.is_a?(Integer) || (v.is_a?(Float) && v.finite? && v == v.floor) },
|
|
@@ -290,7 +450,7 @@ module Nukadoko
|
|
|
290
450
|
|
|
291
451
|
# The test of the kind `name` names, read trimmed and in any case.
|
|
292
452
|
#: (String) -> untyped
|
|
293
|
-
def self.value_kind(name) = KIND_TESTS[name.
|
|
453
|
+
def self.value_kind(name) = KIND_TESTS[Spaces.trim(name).downcase]
|
|
294
454
|
|
|
295
455
|
#: (untyped) -> String
|
|
296
456
|
def self.json_type(value)
|
|
@@ -309,7 +469,7 @@ module Nukadoko
|
|
|
309
469
|
|
|
310
470
|
# JavaScript's trim, which takes Unicode spaces and a byte order mark.
|
|
311
471
|
#: (String) -> bool
|
|
312
|
-
def self.blank?(text) =
|
|
472
|
+
def self.blank?(text) = Spaces.blank?(text)
|
|
313
473
|
|
|
314
474
|
# Structural equality over JSON values: key order does not count, and
|
|
315
475
|
# 1 equals 1.0, as JSON writes one number.
|
|
@@ -412,15 +572,17 @@ module Nukadoko
|
|
|
412
572
|
end
|
|
413
573
|
return { reason: "matches has an empty expected value, which every string holds" } if expected.empty?
|
|
414
574
|
|
|
575
|
+
# Read as JavaScript's RegExp reads it, as the TypeScript engine does.
|
|
415
576
|
pattern = begin
|
|
416
|
-
|
|
417
|
-
rescue
|
|
577
|
+
JsPattern.compile(expected, timeout: PATTERN_TIMEOUT)
|
|
578
|
+
rescue JsPattern::Invalid => e
|
|
418
579
|
return { reason: "matches could not build a regular expression: #{e.message}" }
|
|
419
580
|
end
|
|
420
|
-
return { reason: "matches has a pattern that matches the empty string, so every string holds it" } if pattern.match?("")
|
|
421
581
|
|
|
422
582
|
begin
|
|
423
|
-
{
|
|
583
|
+
return { reason: "matches has a pattern that matches the empty string, so every string holds it" } if pattern.match?("")
|
|
584
|
+
|
|
585
|
+
{ holds: pattern.match?(JsPattern.units(actual)) }
|
|
424
586
|
rescue Regexp::TimeoutError
|
|
425
587
|
{ stopped: "matches ran for more than #{PATTERN_TIMEOUT} seconds, so nukadoko stopped judging it" }
|
|
426
588
|
end
|
|
@@ -450,7 +612,7 @@ module Nukadoko
|
|
|
450
612
|
{ holds: !normal(actual).key?(expected) }
|
|
451
613
|
when "has-item"
|
|
452
614
|
return { reason: "has-item reads an array, and the actual value is #{article(a_type)}" } unless a_type == "array"
|
|
453
|
-
return { reason: "has-item looks for #{article(e_type)}, and no item is one" } if actual.
|
|
615
|
+
return { reason: "has-item looks for #{article(e_type)}, and no item is one" } if !actual.empty? && actual.none? { json_type(_1) == e_type }
|
|
454
616
|
|
|
455
617
|
{ holds: actual.any? { deep_equal?(_1, expected) } }
|
|
456
618
|
when "has-same-items"
|
data/lib/nukadoko/cli.rb
CHANGED
|
@@ -98,9 +98,10 @@ module Nukadoko
|
|
|
98
98
|
return skill if @command == "skill"
|
|
99
99
|
return init if @command == "init"
|
|
100
100
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
101
|
+
begin
|
|
102
|
+
Nukadoko.load_project(@project)
|
|
103
|
+
rescue Engine::Refusal => e
|
|
104
|
+
return refuse(e)
|
|
104
105
|
end
|
|
105
106
|
steps = Nukadoko.load_steps(File.join(@project, "features", "steps"))
|
|
106
107
|
problems = []
|
|
@@ -261,6 +262,22 @@ module Nukadoko
|
|
|
261
262
|
declared = program.declared.values.flat_map { (_1[:conditions] || {}).keys.map(&:to_s) }
|
|
262
263
|
check = Engine::Check.new(steps, default ? selection.scenarios : kept, conditions: declared,
|
|
263
264
|
environments: (environments if default), problems: selection.problems, config: env_findings)
|
|
265
|
+
# The TypeScript engine refuses a declaration as its step file loads, so
|
|
266
|
+
# such a step file stops its run even under --no-check, naming the
|
|
267
|
+
# first one.
|
|
268
|
+
if @no_check && (failed = check.findings.find { _1.code == "step-file-import-failed" })
|
|
269
|
+
failed = relative(failed)
|
|
270
|
+
stop = { severity: "refused", code: failed.code, message: "#{failed.file}: #{failed.message}", fix: failed.fix, do: "nuka check" }
|
|
271
|
+
return finish("run", false, findings: [stop], verdict: "refused", exit_code: 2)
|
|
272
|
+
end
|
|
273
|
+
# The TypeScript engine builds its bindings before any scenario starts,
|
|
274
|
+
# so parameter types that do not register stop a run under --no-check
|
|
275
|
+
# too.
|
|
276
|
+
if @no_check && (collision = Engine::Pattern.collision)
|
|
277
|
+
stop = { severity: "refused", code: "parameter-type-collision", message: collision,
|
|
278
|
+
fix: "Rename the parameter type, or remove one of the two registrations.", do: "nuka run --help" }
|
|
279
|
+
return finish("run", false, findings: [stop], verdict: "refused", exit_code: 2)
|
|
280
|
+
end
|
|
264
281
|
# Only the check's errors hold a run back, so only they are reported.
|
|
265
282
|
findings = @no_check ? [] : check.findings.map { relative(_1).to_h }.select { _1[:severity] == "error" }
|
|
266
283
|
unless @no_check || check.passed?
|
|
@@ -356,10 +373,10 @@ module Nukadoko
|
|
|
356
373
|
environment = Engine::Program.new(Nukadoko.program_options).environments([plan[:environment]]).first
|
|
357
374
|
usable = Engine::Check.new(steps, scenarios).usable
|
|
358
375
|
run = Engine::Run.new(@project, usable, scenarios, Nukadoko.program_options, environments: [environment],
|
|
359
|
-
world: plan[:world], dir: plan[:dir], out: @out)
|
|
376
|
+
world: plan[:world], dir: plan[:dir], out: @out, head: plan[:head])
|
|
360
377
|
{ results: run.tree_pass, worlds: run.world_entries }
|
|
361
378
|
rescue Engine::Refusal => e
|
|
362
|
-
{ not_run: "the #{plan[:world]} tree's program
|
|
379
|
+
{ not_run: "the #{plan[:world]} tree's program does not give this environment: #{e.message}" }
|
|
363
380
|
end
|
|
364
381
|
File.write(plan[:result], JSON.generate(result))
|
|
365
382
|
0
|
|
@@ -516,7 +533,7 @@ module Nukadoko
|
|
|
516
533
|
|
|
517
534
|
# Why --env left out every selected scenario, and the run that meets
|
|
518
535
|
# them: the run without --env when it does, else the first environment
|
|
519
|
-
# of the program
|
|
536
|
+
# of the program that meets each, or else one that meets some.
|
|
520
537
|
#: (Array[Engine::Scenario], Engine::Program) -> Hash[Symbol, String]
|
|
521
538
|
def left_out_stop(left_out, program)
|
|
522
539
|
envs = @options["--env"]
|
|
@@ -533,7 +550,7 @@ module Nukadoko
|
|
|
533
550
|
candidates = [*program.declared.keys, *(program.declared.key?("default") ? [] : ["default"])] - envs
|
|
534
551
|
other = candidates.find { meets_each.([_1]) } || candidates.find { |name| left_out.any? { meets?(_1, [program.environment(name)]) } }
|
|
535
552
|
unless other
|
|
536
|
-
return finding.merge(fix: "#{without}, which does not meet #{them} either, and no environment of nukadoko.
|
|
553
|
+
return finding.merge(fix: "#{without}, which does not meet #{them} either, and no environment of nukadoko.config.rb meets #{them}. " \
|
|
537
554
|
"Declare the conditions #{count == 1 ? "it needs" : "they need"} on an environment, or change #{count == 1 ? "its" : "their"} tags.")
|
|
538
555
|
end
|
|
539
556
|
|
data/lib/nukadoko/codes.json
CHANGED
|
@@ -131,13 +131,13 @@
|
|
|
131
131
|
},
|
|
132
132
|
"condition-tag-malformed": {
|
|
133
133
|
"severity": "error",
|
|
134
|
-
"description": "A tag starts with @with: or @without: but does not read as @with:<condition>, @with:<condition>=<value>, or @without:<condition>, so it names no condition. @with:<condition>=true and =false are malformed too: a value written as text is not the boolean the program
|
|
134
|
+
"description": "A tag starts with @with: or @without: but does not read as @with:<condition>, @with:<condition>=<value>, or @without:<condition>, so it names no condition. @with:<condition>=true and =false are malformed too: a value written as text is not the boolean the program declares.",
|
|
135
135
|
"fix": "Rewrite the tag as @with:<condition>, @with:<condition>=<value>, or @without:<condition>; a condition name holds letters, digits, \"_\", \".\", or \"-\", a value holds no whitespace and no \"@\", and a boolean is @with:<condition> or @without:<condition>."
|
|
136
136
|
},
|
|
137
137
|
"condition-unknown": {
|
|
138
138
|
"severity": "error",
|
|
139
|
-
"description": "A condition tag names a condition that no environment in nukadoko.
|
|
140
|
-
"fix": "Declare the condition under the conditions of the environments that set it up in nukadoko.
|
|
139
|
+
"description": "A condition tag names a condition that no environment in the program in nukadoko.config.ts declares under conditions, so no environment sets it up.",
|
|
140
|
+
"fix": "Declare the condition under the conditions of the environments that set it up in the program in nukadoko.config.ts, or remove the tag."
|
|
141
141
|
},
|
|
142
142
|
"condition-unmet": {
|
|
143
143
|
"severity": "error",
|
|
@@ -237,12 +237,12 @@
|
|
|
237
237
|
"environment-env-file-missing": {
|
|
238
238
|
"severity": "warning",
|
|
239
239
|
"description": "An entry in one environment's own envFiles does not exist on disk.",
|
|
240
|
-
"fix": "Create the file, or remove it from that environment's envFiles in nukadoko.
|
|
240
|
+
"fix": "Create the file, or remove it from that environment's envFiles in the program in nukadoko.config.ts."
|
|
241
241
|
},
|
|
242
242
|
"events-inlet-missing": {
|
|
243
243
|
"severity": "error",
|
|
244
|
-
"description": "A step's events counts execution events, and a world the run would serve names no {events} in its program
|
|
245
|
-
"fix": "Set the variable the program reads to {events} under env in the program
|
|
244
|
+
"description": "A step's events counts execution events, and a world the run would serve names no {events} in its program, so the program has no file to write them to and each claim on the count is unjudged there (inlet-unnamed).",
|
|
245
|
+
"fix": "Set the variable the program reads to {events} under env in the program, such as EXECUTION_EVENTS: \"{events}\", and have the program append its execution events to that file."
|
|
246
246
|
},
|
|
247
247
|
"events-late": {
|
|
248
248
|
"severity": "note",
|
|
@@ -261,7 +261,7 @@
|
|
|
261
261
|
},
|
|
262
262
|
"events-unread": {
|
|
263
263
|
"severity": "warning",
|
|
264
|
-
"description": "A step's events counts execution events, and a world the run would start is one nukadoko does not serve (a url, or a project
|
|
264
|
+
"description": "A step's events counts execution events, and a world the run would start is one nukadoko does not serve (a url, or a project whose config has no program), so it reads no execution events there and each claim on the count is unjudged (world-unread).",
|
|
265
265
|
"fix": "Run those scenarios in a world nukadoko serves, with {events} in env, or select one with --env."
|
|
266
266
|
},
|
|
267
267
|
"expects-tag-malformed": {
|
|
@@ -271,8 +271,8 @@
|
|
|
271
271
|
},
|
|
272
272
|
"expects-unread": {
|
|
273
273
|
"severity": "warning",
|
|
274
|
-
"description": "An @expects:error= tag accepts an unhandled error the program reports in its execution events, and no world the run would start reads them (the program
|
|
275
|
-
"fix": "Name {events} in env of nukadoko.
|
|
274
|
+
"description": "An @expects:error= tag accepts an unhandled error the program reports in its execution events, and no world the run would start reads them (the program names no {events}, the world runs at a url, or there is no program), so the tag can never match.",
|
|
275
|
+
"fix": "Name {events} in env of the program in nukadoko.config.ts for a world the run starts, such as env: { EXECUTION_EVENTS: \"{events}\" }, and have the program append its execution events there, or remove the tag."
|
|
276
276
|
},
|
|
277
277
|
"expects-unseen": {
|
|
278
278
|
"severity": "note",
|
|
@@ -564,9 +564,14 @@
|
|
|
564
564
|
"description": "The program a world served exited while the scenarios still ran, so the requests after that found nothing listening.",
|
|
565
565
|
"fix": "Read the world's program.log, which the message names, for why the program exited."
|
|
566
566
|
},
|
|
567
|
+
"program-file-moved": {
|
|
568
|
+
"severity": "refused",
|
|
569
|
+
"description": "The project root holds a program file (nukadoko.program.ts, .mts, or .rb), which an earlier release read and this one does not: the program is part of the config now.",
|
|
570
|
+
"fix": "Move what the program file describes into the config as its program (program: () => ({ ... }) in nukadoko.config.ts, program: -> { { ... } } in nukadoko.config.rb), and delete the program file; CHANGELOG.md, under \"The program moves into the config\", shows the move."
|
|
571
|
+
},
|
|
567
572
|
"program-list-unread": {
|
|
568
573
|
"severity": "warning",
|
|
569
|
-
"description": "A command under lists in nukadoko.
|
|
574
|
+
"description": "A command under lists in the program in nukadoko.config.ts failed, passed its limit, or printed a line that is not one entry of its list, so that world's list was not read and nothing of it counts.",
|
|
570
575
|
"fix": "Correct the command the message names, or what it prints: one JSON object per line, in the shape docs/spec.md \"Lists\" gives for its kind. Its stderr is in the world's program.log."
|
|
571
576
|
},
|
|
572
577
|
"program-log-late": {
|
|
@@ -576,12 +581,12 @@
|
|
|
576
581
|
},
|
|
577
582
|
"program-placeholder-unfilled": {
|
|
578
583
|
"severity": "error",
|
|
579
|
-
"description": "A command or an env value in nukadoko.
|
|
584
|
+
"description": "A command or an env value in the program in nukadoko.config.ts names a placeholder a world that nuka run with the same --env flags would start has no value for: {port} or {url} in a world with neither serve nor url, {condition.<name>} in one whose environment does not declare that condition, or anything but {root} in a build command.",
|
|
580
585
|
"fix": "Remove the placeholder from the field the message names, or give the world what fills it: serve or url for {port} or {url}, the condition under its environment's conditions for {condition.<name>}; in a build command, write only {root}, or move the command to prepare."
|
|
581
586
|
},
|
|
582
587
|
"program-start-failed": {
|
|
583
588
|
"severity": "failed",
|
|
584
|
-
"description": "The program in nukadoko.
|
|
589
|
+
"description": "The program in nukadoko.config.ts did not start for a world: a build or prepare command failed or did not finish within its timeout_ms, the server did not answer its ready path in time, or setup or the url function threw or did not finish within its timeout_ms. The world's scenarios did not run.",
|
|
585
590
|
"fix": "Correct what the message names; the end of the world's program.log is in the message, and the whole file is in the world's directory."
|
|
586
591
|
},
|
|
587
592
|
"proof-run-incomplete": {
|
|
@@ -856,8 +861,8 @@
|
|
|
856
861
|
},
|
|
857
862
|
"unknown-environment": {
|
|
858
863
|
"severity": "refused",
|
|
859
|
-
"description": "--env names an environment that nukadoko.
|
|
860
|
-
"fix": "Pass default or an environment nukadoko.
|
|
864
|
+
"description": "--env names an environment that the program in nukadoko.config.ts does not define.",
|
|
865
|
+
"fix": "Pass default or an environment the program in nukadoko.config.ts defines, or add it to environments there."
|
|
861
866
|
},
|
|
862
867
|
"unknown-parameter-type": {
|
|
863
868
|
"severity": "error",
|
|
@@ -887,7 +892,7 @@
|
|
|
887
892
|
"version-probe-failed": {
|
|
888
893
|
"severity": "warning",
|
|
889
894
|
"description": "The environment's version probe did not answer, so the records have no target version.",
|
|
890
|
-
"fix": "Correct the environment's version setting in nukadoko.
|
|
895
|
+
"fix": "Correct the environment's version setting in the program in nukadoko.config.ts, or the endpoint it names."
|
|
891
896
|
},
|
|
892
897
|
"walk-failed": {
|
|
893
898
|
"severity": "failed",
|
data/lib/nukadoko/criteria.rb
CHANGED
|
@@ -110,7 +110,7 @@ module Nukadoko
|
|
|
110
110
|
def step_lines(step)
|
|
111
111
|
lines = ["#{step.keyword.strip} #{step.text}"]
|
|
112
112
|
if (doc = step.doc_string)
|
|
113
|
-
lines.push("#{doc.delimiter}#{doc.media_type}", *doc.content.split("\n"), doc.delimiter)
|
|
113
|
+
lines.push("#{doc.delimiter}#{doc.media_type}", *doc.content.split("\n", -1), doc.delimiter)
|
|
114
114
|
end
|
|
115
115
|
step.data_table&.rows&.each { lines << row_line(_1) }
|
|
116
116
|
lines
|
data/lib/nukadoko/env_check.rb
CHANGED
|
@@ -10,8 +10,6 @@
|
|
|
10
10
|
module Nukadoko
|
|
11
11
|
module Engine
|
|
12
12
|
module EnvCheck
|
|
13
|
-
CONFIG = "nukadoko.config.rb"
|
|
14
|
-
PROGRAM = "nukadoko.program.rb"
|
|
15
13
|
# `KEY` counts only as a whole underscore-delimited word, so MONKEY,
|
|
16
14
|
# KEYWORD, and APIKEY are not guessed to be secrets.
|
|
17
15
|
SECRET_LOOKING = /SECRET|PASSWORD|TOKEN|CREDENTIAL|(?:^|_)KEY(?:_|$)/i
|
|
@@ -42,7 +40,7 @@ module Nukadoko
|
|
|
42
40
|
environments.each do |name, paths|
|
|
43
41
|
paths.reject(&exists).each do |path|
|
|
44
42
|
found << warning("environment-env-file-missing", path, %(environments.#{name}.envFiles names "#{path}", which does not exist),
|
|
45
|
-
%(Create #{path}, or remove "#{path}" from environments.#{name}.envFiles in #{
|
|
43
|
+
%(Create #{path}, or remove "#{path}" from environments.#{name}.envFiles in #{CONFIG}.))
|
|
46
44
|
end
|
|
47
45
|
end
|
|
48
46
|
defined = EnvFile.load(project, all)
|
data/lib/nukadoko/fixtures.rb
CHANGED
|
@@ -5,6 +5,7 @@ require "net/http"
|
|
|
5
5
|
require "json"
|
|
6
6
|
require "fileutils"
|
|
7
7
|
require "time"
|
|
8
|
+
require "timeout"
|
|
8
9
|
|
|
9
10
|
# Fixtures are built by the engine, not the step, so what they record is
|
|
10
11
|
# measured: every request a step sends goes through Request and lands in the
|
|
@@ -89,10 +90,53 @@ module Nukadoko
|
|
|
89
90
|
# TypeScript engine. Requests the page sends are recorded by the engine's
|
|
90
91
|
# own listener, and each step gets a trace chunk.
|
|
91
92
|
class Browser
|
|
92
|
-
|
|
93
|
-
|
|
93
|
+
# `secrets` gives the run's loaded secrets when a screenshot is taken,
|
|
94
|
+
# since an environment's env files are read after the browser is made.
|
|
95
|
+
#: (String?, ?Hash[Symbol, untyped], ?secrets: ^() -> Secrets) -> void
|
|
96
|
+
def initialize(base_url, launch_options = {}, secrets: -> { Secrets.new })
|
|
94
97
|
@base_url = base_url
|
|
95
98
|
@launch_options = launch_options
|
|
99
|
+
@secrets = secrets
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
# Opaque, so a masked secret leaves no trace of its glyphs.
|
|
103
|
+
MASK_COLOR = "#000000"
|
|
104
|
+
|
|
105
|
+
# Locators for every element of `page`, in every frame, that shows a
|
|
106
|
+
# loaded secret: as text, or as the value of an input or textarea, which
|
|
107
|
+
# is not text `get_by_text` reads, and a step may have typed the secret
|
|
108
|
+
# there. The text redaction of a record cannot reach pixels, and
|
|
109
|
+
# marking or rewriting the elements would change the page the next step
|
|
110
|
+
# reads. Only the value as written is found, not an encoded spelling;
|
|
111
|
+
# `get_by_text` ignores case, which costs pixels, never a leak.
|
|
112
|
+
#: (untyped) -> Array[untyped]
|
|
113
|
+
def secret_masks(page)
|
|
114
|
+
values = @secrets.call.shown_values.select { _1.length >= Secrets::MIN_LENGTH }
|
|
115
|
+
return [] if values.empty?
|
|
116
|
+
|
|
117
|
+
page.frames.flat_map do |frame|
|
|
118
|
+
fields = frame.locator("input, textarea")
|
|
119
|
+
held = fields.evaluate_all("(elements) => elements.map((element) => String(element.value ?? ''))") #: Array[String]
|
|
120
|
+
values.map { frame.get_by_text(_1) } + held.each_index.select { |index| values.any? { held[index].include?(_1) } }.map { fields.nth(_1) }
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
# A screenshot of `page` at `path` with what shows a secret covered,
|
|
125
|
+
# true once written. No screenshot rather than one that shows a
|
|
126
|
+
# secret: masks not found by `deadline` (a monotonic time) give none,
|
|
127
|
+
# and the image is written only once it arrived. `bounded` holds the
|
|
128
|
+
# screenshot to the deadline too, as a pause and a judged view do.
|
|
129
|
+
#: (untyped, String, Float, ?caret: String?, ?bounded: bool) -> bool
|
|
130
|
+
def masked_shot(page, path, deadline, caret: nil, bounded: true)
|
|
131
|
+
masks = Timeout.timeout([deadline - monotonic, 0.001].max) { secret_masks(page) }
|
|
132
|
+
left = ((deadline - monotonic) * 1000).floor
|
|
133
|
+
return false if bounded && left <= 0
|
|
134
|
+
|
|
135
|
+
image = page.screenshot(mask: masks, maskColor: MASK_COLOR, **(bounded ? { timeout: left } : {}), **(caret ? { caret: caret } : {}))
|
|
136
|
+
File.binwrite(path, image)
|
|
137
|
+
true
|
|
138
|
+
rescue StandardError, Timeout::Error
|
|
139
|
+
false
|
|
96
140
|
end
|
|
97
141
|
|
|
98
142
|
#: (String, Array[Hash[Symbol, untyped]]) -> [untyped, ^() -> void]
|
|
@@ -227,12 +271,9 @@ module Nukadoko
|
|
|
227
271
|
def view_files(dir, ended, aria_in_claims)
|
|
228
272
|
FileUtils.mkdir_p(File.join(dir, "judged"))
|
|
229
273
|
title = (@page.title rescue nil)
|
|
230
|
-
shot =
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
rescue StandardError
|
|
234
|
-
nil
|
|
235
|
-
end
|
|
274
|
+
shot = if masked_shot(@page, File.join(dir, "judged", "page.png"), monotonic + VIEW_TIMEOUT_MS / 1000.0, caret: "initial")
|
|
275
|
+
{ file: "judged/page.png", after_reading_ms: ((monotonic - ended) * 1000).round }
|
|
276
|
+
end
|
|
236
277
|
aria = aria_in_claims ? nil : begin
|
|
237
278
|
tree = @page.aria_snapshot(mode: "ai")
|
|
238
279
|
File.write(File.join(dir, "judged", "page.aria.yml"), tree.end_with?("\n") ? tree : "#{tree}\n")
|
|
@@ -301,12 +342,8 @@ module Nukadoko
|
|
|
301
342
|
nil
|
|
302
343
|
end
|
|
303
344
|
@page.on("request", @held)
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
"#{recorded_as}/page.png"
|
|
307
|
-
rescue StandardError
|
|
308
|
-
nil
|
|
309
|
-
end
|
|
345
|
+
# The caret shows, as the person would see the field they type in.
|
|
346
|
+
shot = masked_shot(@page, File.join(dir, "page.png"), monotonic + VIEW_TIMEOUT_MS / 1000.0, caret: "initial") ? "#{recorded_as}/page.png" : nil
|
|
310
347
|
aria = begin
|
|
311
348
|
tree = @page.aria_snapshot(mode: "ai", timeout: VIEW_TIMEOUT_MS)
|
|
312
349
|
File.write(File.join(dir, "page.aria.yml"), tree.end_with?("\n") ? tree : "#{tree}\n")
|
|
@@ -342,13 +379,8 @@ module Nukadoko
|
|
|
342
379
|
def end_scenario(dir = nil)
|
|
343
380
|
shots = [] #: Array[Hash[Symbol, untyped]]
|
|
344
381
|
if dir && @page
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
@page.screenshot(path: File.join(dir, "final.png"))
|
|
348
|
-
shots << { file: "final.png", at: Time.now.utc.iso8601(3) }
|
|
349
|
-
rescue StandardError
|
|
350
|
-
nil
|
|
351
|
-
end
|
|
382
|
+
FileUtils.mkdir_p(dir)
|
|
383
|
+
shots << { file: "final.png", at: Time.now.utc.iso8601(3) } if masked_shot(@page, File.join(dir, "final.png"), monotonic + VIEW_TIMEOUT_MS / 1000.0, bounded: false)
|
|
352
384
|
end
|
|
353
385
|
@context&.tracing&.stop
|
|
354
386
|
@context&.close
|
data/lib/nukadoko/init.rb
CHANGED
|
@@ -20,7 +20,6 @@ require "fileutils"
|
|
|
20
20
|
module Nukadoko
|
|
21
21
|
module Engine
|
|
22
22
|
class Init
|
|
23
|
-
CONFIG = "nukadoko.config.rb"
|
|
24
23
|
STEPS = File.join("features", "steps")
|
|
25
24
|
# `.env` files are ignored since a committed one is configuration, not
|
|
26
25
|
# a secret source; `!.env.example` must follow `.env.*` to re-include it.
|