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/pattern.rb
CHANGED
|
@@ -10,8 +10,114 @@ require "cucumber/cucumber_expressions/parameter_type_registry"
|
|
|
10
10
|
module Nukadoko
|
|
11
11
|
module Engine
|
|
12
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
|
+
|
|
13
73
|
NAMED = /\{([A-Za-z_][\w-]*):([\w-]+)\}/
|
|
14
|
-
|
|
74
|
+
BUILT_IN = Registry.new.parameter_types.map(&:name).freeze #: Array[String]
|
|
75
|
+
|
|
76
|
+
# The registry every pattern of the loaded project reads: the built-in
|
|
77
|
+
# types, and the config's parameterTypes on top of them.
|
|
78
|
+
#: () -> Registry
|
|
79
|
+
def self.registry = @registry ||= Registry.new
|
|
80
|
+
|
|
81
|
+
# Why the config's parameterTypes could not be registered, in the
|
|
82
|
+
# TypeScript engine's words, or nil. While it is set no pattern
|
|
83
|
+
# matches a line, as no pattern binds there: nuka check reports it
|
|
84
|
+
# once, as parameter-type-invalid, and a run under --no-check stops.
|
|
85
|
+
#: () -> String?
|
|
86
|
+
def self.collision = @collision
|
|
87
|
+
|
|
88
|
+
# The names of the config's parameter types that have a transformer,
|
|
89
|
+
# whose capture a claim cannot compare with.
|
|
90
|
+
#: () -> Array[String]
|
|
91
|
+
def self.transformed = @transformed || []
|
|
92
|
+
|
|
93
|
+
# Registers the config's parameterTypes: each a name, a regexp, and an
|
|
94
|
+
# optional transformer, given the groups the regexp captured. A type
|
|
95
|
+
# with no transformer gives the text the regexp matched, or its first
|
|
96
|
+
# group, as the JavaScript package does.
|
|
97
|
+
#: (Array[Hash[Symbol, untyped]]) -> void
|
|
98
|
+
def self.configure(types)
|
|
99
|
+
@registry = Registry.new
|
|
100
|
+
@collision = nil
|
|
101
|
+
@transformed = types.select { _1[:transformer] }.map { _1[:name].to_s }
|
|
102
|
+
seen = [] #: Array[String]
|
|
103
|
+
types.each do |type|
|
|
104
|
+
name = type[:name].to_s
|
|
105
|
+
if BUILT_IN.include?(name)
|
|
106
|
+
@collision = %(Custom parameter type "#{name}" collides with one of cucumber-expressions' own built-in parameter types; ) +
|
|
107
|
+
"redefining what {#{name}} means would quietly change the meaning of every pattern that already uses it"
|
|
108
|
+
elsif seen.include?(name)
|
|
109
|
+
@collision = %(Custom parameter type "#{name}" is registered more than once in parameterTypes)
|
|
110
|
+
end
|
|
111
|
+
if @collision
|
|
112
|
+
@registry = Registry.new
|
|
113
|
+
return
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
seen << name
|
|
117
|
+
transformer = type[:transformer] || ->(*groups) { groups.first }
|
|
118
|
+
@registry.define_parameter_type(CE::ParameterType.new(name, type[:regexp], Object, transformer, true, false))
|
|
119
|
+
end
|
|
120
|
+
end
|
|
15
121
|
|
|
16
122
|
attr_reader :source, :keys
|
|
17
123
|
|
|
@@ -19,11 +125,13 @@ module Nukadoko
|
|
|
19
125
|
def initialize(source)
|
|
20
126
|
@source = source
|
|
21
127
|
@keys = source.scan(NAMED).map { Array(_1).first.to_s }
|
|
22
|
-
@expression =
|
|
128
|
+
@expression = CE::CucumberExpression.new(source.gsub(NAMED, '{\2}'), Pattern.registry)
|
|
23
129
|
end
|
|
24
130
|
|
|
25
131
|
#: (String) -> Hash[String, untyped]?
|
|
26
132
|
def match(text)
|
|
133
|
+
return nil if Pattern.collision
|
|
134
|
+
|
|
27
135
|
found = @expression.match(text)
|
|
28
136
|
found && keys.zip(found.map { _1.value(nil) }).to_h
|
|
29
137
|
end
|
|
@@ -31,6 +139,8 @@ module Nukadoko
|
|
|
31
139
|
# Each capture's text as the line wrote it, quotes included.
|
|
32
140
|
#: (String) -> Hash[String, String]?
|
|
33
141
|
def texts(text)
|
|
142
|
+
return nil if Pattern.collision
|
|
143
|
+
|
|
34
144
|
found = @expression.match(text)
|
|
35
145
|
found && keys.zip(found.map { _1.group.value }).to_h
|
|
36
146
|
end
|
data/lib/nukadoko/poll.rb
CHANGED
|
@@ -16,12 +16,14 @@ module Nukadoko
|
|
|
16
16
|
class Poll
|
|
17
17
|
INTERVAL = 0.1
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
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)
|
|
21
22
|
@timeout = options.fetch(:timeout_ms) / 1000.0
|
|
22
23
|
@settled = options[:settled] || []
|
|
23
24
|
@claims = claims
|
|
24
25
|
@args = args
|
|
26
|
+
@sides = sides
|
|
25
27
|
end
|
|
26
28
|
|
|
27
29
|
# A reading whose observe raised is kept with the first line of the
|
|
@@ -60,7 +62,7 @@ module Nukadoko
|
|
|
60
62
|
|
|
61
63
|
#: (untyped, Integer) -> Hash[Symbol, untyped]
|
|
62
64
|
def judge(value, attempt)
|
|
63
|
-
judged = Claims.judge(@claims, value, @args)
|
|
65
|
+
judged = Claims.judge(@claims, value, @args, @sides&.(value))
|
|
64
66
|
reading = { attempt: attempt, at: Time.now.utc.iso8601(3), holds: judged.all? { _1[:holds] }, actuals: judged.map { _1[:actual] }, value: value,
|
|
65
67
|
judged_now: judged.select { _1[:for_judgment] }.map { _1[:actual] } }
|
|
66
68
|
reading[:settled] = @settled.all? { Claims.judge_one(_1, value, {})[:holds] } if @settled.any?
|
data/lib/nukadoko/program.rb
CHANGED
|
@@ -32,18 +32,18 @@ module Nukadoko
|
|
|
32
32
|
declared = self.declared
|
|
33
33
|
(selected.any? ? selected : default_names).map do |name|
|
|
34
34
|
unless name == "default" || declared.key?(name)
|
|
35
|
-
add = "add environments.#{name} to nukadoko.
|
|
36
|
-
fix = if declared.empty? then "Leave out --env or pass --env default (nukadoko.
|
|
35
|
+
add = "add environments.#{name} to the program in nukadoko.config.rb"
|
|
36
|
+
fix = if declared.empty? then "Leave out --env or pass --env default (the program in nukadoko.config.rb defines no other environment), or #{add}."
|
|
37
37
|
else "Pass --env with a name it accepts (#{["default", *declared.keys].uniq.sort.join(", ")}), or #{add}."
|
|
38
38
|
end
|
|
39
|
-
raise Refusal.new("unknown-environment", %(Unknown environment "#{name}": not defined in nukadoko.
|
|
39
|
+
raise Refusal.new("unknown-environment", %(Unknown environment "#{name}": not defined in the environments of the program in nukadoko.config.rb), fix: fix)
|
|
40
40
|
end
|
|
41
41
|
|
|
42
42
|
environment(name)
|
|
43
43
|
end
|
|
44
44
|
end
|
|
45
45
|
|
|
46
|
-
# Whether
|
|
46
|
+
# Whether the config gave a program, so each step names its world.
|
|
47
47
|
#: () -> bool
|
|
48
48
|
def file? = !@options.empty?
|
|
49
49
|
|
|
@@ -71,7 +71,7 @@ module Nukadoko
|
|
|
71
71
|
# Why a run without --env starts the environments it starts.
|
|
72
72
|
#: () -> String
|
|
73
73
|
def chosen_by
|
|
74
|
-
if @options[:defaultEnvironments] then "defaultEnvironments in nukadoko.
|
|
74
|
+
if @options[:defaultEnvironments] then "defaultEnvironments in nukadoko.config.rb"
|
|
75
75
|
elsif default_names == ["default"] then "no environment declares conditions"
|
|
76
76
|
else "the environments that declare conditions"
|
|
77
77
|
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
# rbs_inline: enabled
|
|
3
|
+
|
|
4
|
+
# The names of the files a project keeps nukadoko's settings in, one place
|
|
5
|
+
# for every part of the engine that reads, writes, or names them.
|
|
6
|
+
module Nukadoko
|
|
7
|
+
module Engine
|
|
8
|
+
CONFIG = "nukadoko.config.rb"
|
|
9
|
+
# The program file of releases before the program moved into the
|
|
10
|
+
# config. A project may no longer hold one; a `--base` ref may.
|
|
11
|
+
LEGACY_PROGRAM = "nukadoko.program.rb"
|
|
12
|
+
# What a `--base` run writes into a tree for the program it runs:
|
|
13
|
+
# another config whose program the tree runs, or a ref's legacy file.
|
|
14
|
+
TREE_PROGRAM = "nukadoko.tree-program.rb"
|
|
15
|
+
TREE_LEGACY_PROGRAM = "nukadoko.tree-legacy-program.rb"
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
# rbs_inline: enabled
|
|
3
|
+
|
|
4
|
+
require "json"
|
|
5
|
+
require "open3"
|
|
6
|
+
require "prism"
|
|
7
|
+
require "rbconfig"
|
|
8
|
+
|
|
9
|
+
# A tree's program under test: the `program` lambda of its
|
|
10
|
+
# nukadoko.config.rb, called once. A config with no program has none, and a
|
|
11
|
+
# run starts no world for it.
|
|
12
|
+
#
|
|
13
|
+
# The program goes with the code and the criteria with the config, so a
|
|
14
|
+
# `nuka run --base` tree can hold one side's config and the other side's
|
|
15
|
+
# program. The run writes that program beside the tree's config: the other
|
|
16
|
+
# side's config as nukadoko.tree-program.rb, or a ref's program file from
|
|
17
|
+
# before the program moved into the config as
|
|
18
|
+
# nukadoko.tree-legacy-program.rb. A project's own program file is refused,
|
|
19
|
+
# with the move to make. Boundary: reading the program; starting it is
|
|
20
|
+
# Program's.
|
|
21
|
+
module Nukadoko
|
|
22
|
+
module Engine
|
|
23
|
+
module ProjectProgram
|
|
24
|
+
LIB = File.expand_path("..", __dir__.to_s)
|
|
25
|
+
UPGRADING = 'CHANGELOG.md, under "The program moves into the config"'
|
|
26
|
+
|
|
27
|
+
# The program of the tree at `root`, whose config is already loaded.
|
|
28
|
+
#: (String) -> Hash[Symbol, untyped]
|
|
29
|
+
def self.read(root)
|
|
30
|
+
raise called_in_config unless Nukadoko.legacy_program.nil?
|
|
31
|
+
|
|
32
|
+
legacy_copy = File.join(root, TREE_LEGACY_PROGRAM)
|
|
33
|
+
return elsewhere(legacy_copy, legacy: true) || {} if File.exist?(legacy_copy)
|
|
34
|
+
|
|
35
|
+
tree_copy = File.join(root, TREE_PROGRAM)
|
|
36
|
+
return elsewhere(tree_copy, legacy: false) || {} if File.exist?(tree_copy)
|
|
37
|
+
|
|
38
|
+
legacy = File.join(root, LEGACY_PROGRAM)
|
|
39
|
+
raise moved if File.exist?(legacy)
|
|
40
|
+
|
|
41
|
+
called(Nukadoko.config_options[:program], CONFIG) || {}
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# Nukadoko.program called from the config would describe a program
|
|
45
|
+
# nothing reads, so it is refused rather than left unstarted.
|
|
46
|
+
#: () -> Refusal
|
|
47
|
+
def self.called_in_config
|
|
48
|
+
Refusal.new("config-invalid",
|
|
49
|
+
"Invalid config at #{CONFIG}: Nukadoko.program is no longer read: the program under test is the program: lambda of Nukadoko.config now",
|
|
50
|
+
fix: "Move the options Nukadoko.program took into #{CONFIG} as program: -> { { ... } }; #{UPGRADING}, shows the move.")
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
#: () -> Refusal
|
|
54
|
+
def self.moved
|
|
55
|
+
Refusal.new("program-file-moved",
|
|
56
|
+
"#{LEGACY_PROGRAM} is no longer read: the program under test is part of #{CONFIG} now, " \
|
|
57
|
+
"so nukadoko does not start what #{LEGACY_PROGRAM} describes.",
|
|
58
|
+
fix: "Move what #{LEGACY_PROGRAM} describes into #{CONFIG} as its program, and delete #{LEGACY_PROGRAM}; #{UPGRADING}, shows the move.")
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# What a config's `program` returns, or nil when it has none.
|
|
62
|
+
#: (untyped, String) -> Hash[Symbol, untyped]?
|
|
63
|
+
def self.called(program, name)
|
|
64
|
+
return nil if program.nil?
|
|
65
|
+
unless program.respond_to?(:call)
|
|
66
|
+
raise Refusal.new("config-invalid", "Invalid config at #{name}: program: must be a lambda that returns the program",
|
|
67
|
+
fix: "Write program in #{name} as program: -> { { serve: { command: ..., ready: ... } } }.")
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
value = program.call
|
|
71
|
+
return value if value.is_a?(Hash)
|
|
72
|
+
|
|
73
|
+
raise Refusal.new("config-invalid", "Invalid program at #{name}: the program lambda returned #{value.class}, not a Hash of the program's options",
|
|
74
|
+
fix: "Return the program's options as a Hash from program in #{name}.")
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# The program `file` gives, read in a process of its own, since
|
|
78
|
+
# loading it here would replace this tree's config and fixtures: a
|
|
79
|
+
# config's program, or the options a legacy file passes to
|
|
80
|
+
# Nukadoko.program. Raises a Refusal naming the file when it does not
|
|
81
|
+
# load.
|
|
82
|
+
#: (String, legacy: bool) -> Hash[Symbol, untyped]?
|
|
83
|
+
def self.elsewhere(file, legacy:)
|
|
84
|
+
read = legacy ? "Nukadoko.legacy_program" : "Nukadoko::Engine::ProjectProgram.called(Nukadoko.config_options[:program], ARGV[1])"
|
|
85
|
+
script = "require \"nukadoko\"; load ARGV[0]; puts JSON.generate(#{read})"
|
|
86
|
+
out, err, status = Open3.capture3(RbConfig.ruby, "-I", LIB, "-rjson", "-e", script, file, File.basename(file), chdir: File.dirname(file))
|
|
87
|
+
unless status.success?
|
|
88
|
+
raise Refusal.new("config-invalid", "Could not load #{File.basename(file)}: #{err.lines.first.to_s.strip}",
|
|
89
|
+
fix: "Correct #{File.basename(file)} as the message says.")
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
JSON.parse(out, symbolize_names: true)
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
# The text of a config with its program lambda cut out, so a change to
|
|
96
|
+
# the program alone leaves the config's mapping as it was: the
|
|
97
|
+
# program goes with the code, and a `--base` run compares only what
|
|
98
|
+
# decides how the criteria are read. A config with no program, or
|
|
99
|
+
# with more than one `program:` key, is read whole.
|
|
100
|
+
#: (String) -> String
|
|
101
|
+
def self.mapping_text(text)
|
|
102
|
+
found = [] #: Array[Prism::Node]
|
|
103
|
+
walk = lambda do |node|
|
|
104
|
+
key = node.key if node.is_a?(Prism::AssocNode)
|
|
105
|
+
if key.is_a?(Prism::SymbolNode) && key.unescaped == "program"
|
|
106
|
+
found << node.value
|
|
107
|
+
end
|
|
108
|
+
node.compact_child_nodes.each { walk.(_1) }
|
|
109
|
+
end
|
|
110
|
+
walk.(Prism.parse(text).value)
|
|
111
|
+
return text unless found.size == 1
|
|
112
|
+
|
|
113
|
+
location = found.first.location
|
|
114
|
+
bytes = text.b
|
|
115
|
+
"#{bytes.byteslice(0, location.start_offset)}#{bytes.byteslice(location.end_offset..)}".force_encoding(text.encoding)
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
end
|
data/lib/nukadoko/run.rb
CHANGED
|
@@ -13,14 +13,16 @@ module Nukadoko
|
|
|
13
13
|
module Engine
|
|
14
14
|
class Run
|
|
15
15
|
# `world` is head for a run, or base or old for a tree's pass, which
|
|
16
|
-
# writes into the head run's directory `dir
|
|
16
|
+
# writes into the head run's directory `dir`, and reads its env files
|
|
17
|
+
# from `head`'s root, with head's secrets as well as its own. `base` is the
|
|
17
18
|
# comparison a `--base` run judges its rows by. `scenarios` are in the
|
|
18
19
|
# run's order, which every round of every pass keeps; `records`, when
|
|
19
20
|
# given, gets each scenario's run.json entry as one line as it ends,
|
|
20
21
|
# and `rerun` is what a shuffled run's rerun lines name.
|
|
21
|
-
#: (String, Array[singleton(Step)], Array[Scenario], Hash[Symbol, untyped], ?environments: Array[Environment]?, ?left_out: Integer, ?out: untyped, ?world: String, ?dir: String?, ?base: Base?, ?env_flags: Array[String], ?repeat: Integer, ?concurrency: Integer, ?order: Hash[Symbol, untyped], ?records: IO?, ?rerun: untyped, ?walk: WalkFiles::Handle?) -> void
|
|
22
|
+
#: (String, Array[singleton(Step)], Array[Scenario], Hash[Symbol, untyped], ?environments: Array[Environment]?, ?left_out: Integer, ?out: untyped, ?world: String, ?dir: String?, ?base: Base?, ?env_flags: Array[String], ?repeat: Integer, ?concurrency: Integer, ?order: Hash[Symbol, untyped], ?records: IO?, ?rerun: untyped, ?walk: WalkFiles::Handle?, ?head: Hash[Symbol, untyped]?) -> void
|
|
22
23
|
def initialize(project, steps, scenarios, program, environments: nil, left_out: 0, out: $stdout, world: "head", dir: nil, base: nil, env_flags: [],
|
|
23
|
-
repeat: 1, concurrency: 1, order: Order::FILE, records: nil, rerun: nil, walk: nil)
|
|
24
|
+
repeat: 1, concurrency: 1, order: Order::FILE, records: nil, rerun: nil, walk: nil, head: nil)
|
|
25
|
+
@head = head
|
|
24
26
|
@project = project
|
|
25
27
|
@steps = steps
|
|
26
28
|
@scenarios = scenarios
|
|
@@ -58,7 +60,7 @@ module Nukadoko
|
|
|
58
60
|
tree_cells = {}
|
|
59
61
|
if @base
|
|
60
62
|
begin
|
|
61
|
-
trees = TreePasses.new(@base, @scenarios, cells, @environments, @dir, @out, ->(scenario) { Run.then_judged_by(scenario, executions) })
|
|
63
|
+
trees = TreePasses.new(@base, @scenarios, cells, @environments, @dir, @out, ->(scenario) { Run.then_judged_by(scenario, executions) }, head_root: @project)
|
|
62
64
|
tree_cells = trees.call(executions)
|
|
63
65
|
@world_entries.concat(trees.worlds)
|
|
64
66
|
ensure
|
|
@@ -124,7 +126,7 @@ module Nukadoko
|
|
|
124
126
|
play_in_workers(environment, roles, world, due, ran, runs)
|
|
125
127
|
else
|
|
126
128
|
@process_fixtures = FixtureCache.new
|
|
127
|
-
@browser = Browser.new(world.base_url, Nukadoko.config_options.fetch(:browser, {}))
|
|
129
|
+
@browser = Browser.new(world.base_url, Nukadoko.config_options.fetch(:browser, {}), secrets: -> { secrets })
|
|
128
130
|
play_one = lambda do |scenario|
|
|
129
131
|
@out.puts boundary(scenario.uri, scenario.line, scenario.name, roles[scenario])
|
|
130
132
|
ran.(scenario, play(scenario, environment, roles[scenario], world))
|
|
@@ -249,7 +251,7 @@ module Nukadoko
|
|
|
249
251
|
@out = WorkerOut.new(pipe)
|
|
250
252
|
@records = nil
|
|
251
253
|
@process_fixtures = FixtureCache.new
|
|
252
|
-
@browser = Browser.new(world.base_url, Nukadoko.config_options.fetch(:browser, {}))
|
|
254
|
+
@browser = Browser.new(world.base_url, Nukadoko.config_options.fetch(:browser, {}), secrets: -> { secrets })
|
|
253
255
|
list.each do |scenario|
|
|
254
256
|
execution = play(scenario, environment, roles[scenario], world)
|
|
255
257
|
Marshal.dump([:execution, [scenario.uri, scenario.line], execution, @out.take], pipe)
|
|
@@ -660,7 +662,7 @@ module Nukadoko
|
|
|
660
662
|
@scratch = Scratch.new(@project)
|
|
661
663
|
@scenario_fixtures = FixtureCache.new
|
|
662
664
|
@process_fixtures = FixtureCache.new
|
|
663
|
-
@browser = Browser.new(world.base_url, Nukadoko.config_options.fetch(:browser, {}))
|
|
665
|
+
@browser = Browser.new(world.base_url, Nukadoko.config_options.fetch(:browser, {}), secrets: -> { secrets })
|
|
664
666
|
record = { step_record_id: @id, step: step.step_name, started_at: now }
|
|
665
667
|
execute(step, record, @dir, world, then_line: true, at_line: nil, results: [], origins: origins) { [args, texts] }
|
|
666
668
|
ensure
|
|
@@ -677,6 +679,19 @@ module Nukadoko
|
|
|
677
679
|
|
|
678
680
|
private
|
|
679
681
|
|
|
682
|
+
# A value as a record stores it: JSON has no NaN or Infinity, and
|
|
683
|
+
# JavaScript writes either as null, so an arg a {float} read as "-"
|
|
684
|
+
# reaches the record the TypeScript engine writes.
|
|
685
|
+
#: (untyped) -> untyped
|
|
686
|
+
def stored(value)
|
|
687
|
+
case value
|
|
688
|
+
when Float then value.finite? ? value : nil
|
|
689
|
+
when Hash then value.transform_values { stored(_1) }
|
|
690
|
+
when Array then value.map { stored(_1) }
|
|
691
|
+
else value
|
|
692
|
+
end
|
|
693
|
+
end
|
|
694
|
+
|
|
680
695
|
# Runs one step whose args the block binds, and writes its record and
|
|
681
696
|
# HTTP log into `dir`.
|
|
682
697
|
#: (singleton(Step), Hash[Symbol, untyped], String, World, then_line: bool, at_line: Integer?, results: Array[untyped], origins: Hash[String, String]) { () -> [Hash[String, untyped], Hash[String, String]] } -> Hash[Symbol, untyped]
|
|
@@ -693,11 +708,11 @@ module Nukadoko
|
|
|
693
708
|
begin
|
|
694
709
|
record[:mutates] = step.mutating?
|
|
695
710
|
args, texts = yield
|
|
696
|
-
record[:args] = args
|
|
697
|
-
problems = step.args.problems(args)
|
|
711
|
+
record[:args] = stored(args)
|
|
712
|
+
problems = step.args.problems(args, strict: true)
|
|
698
713
|
if problems.any?
|
|
699
714
|
record[:error_kind] = "args_invalid"
|
|
700
|
-
raise TypeError, "args: #{problems.join("; ")}"
|
|
715
|
+
raise TypeError, "args validation failed: #{problems.join("; ")}"
|
|
701
716
|
end
|
|
702
717
|
|
|
703
718
|
@browser&.step = { step_record_id: record[:step_record_id], step: record[:step], line: at_line }
|
|
@@ -753,6 +768,21 @@ module Nukadoko
|
|
|
753
768
|
record
|
|
754
769
|
end
|
|
755
770
|
|
|
771
|
+
# The args keys the line fills through a parameter type with a
|
|
772
|
+
# transformer, each with why a claim does not compare with it: code
|
|
773
|
+
# made the value, while the record would name the sentence. nuka check
|
|
774
|
+
# reports such a pattern; a run under --no-check agrees with it.
|
|
775
|
+
#: (untyped, Hash[String, String]) -> Hash[String, String]
|
|
776
|
+
def transformed_fills(step, origins)
|
|
777
|
+
pattern = step.pattern.to_s
|
|
778
|
+
pattern.scan(Pattern::NAMED).each_with_object({}) do |(key, type), found|
|
|
779
|
+
next unless Pattern.transformed.include?(type.to_s) && !origins.key?(key.to_s)
|
|
780
|
+
|
|
781
|
+
found[key.to_s] = %(the pattern "#{pattern}" fills args.#{key} with the parameter type {#{type}}, whose transformer rewrites the line's text before the claim reads it, ) +
|
|
782
|
+
"so code would decide what the claim compares, and the claim was not judged"
|
|
783
|
+
end
|
|
784
|
+
end
|
|
785
|
+
|
|
756
786
|
# A Then step's claims are judged on what it observed, or on its args
|
|
757
787
|
# when it reads nothing itself; any other step runs and returns.
|
|
758
788
|
# `step` is a step class whose observe or run its own file defines.
|
|
@@ -773,10 +803,15 @@ module Nukadoko
|
|
|
773
803
|
observed = observed.is_a?(Hash) ? observed.transform_keys(&:to_s).merge(from_values) : observed
|
|
774
804
|
Claims.take_aria_snapshots(step.claims, observed)
|
|
775
805
|
end
|
|
806
|
+
sides = lambda do |observed|
|
|
807
|
+
ClaimSides::Inputs.new(observed: observed, args: args, observes: observes, from_keys: step.from.keys.map(&:to_s),
|
|
808
|
+
labels: ->(key) { origins.fetch(key, "sentence:#{key}") },
|
|
809
|
+
received: observes ? step.inputs.fields.map { _1.name.to_s } : [], transformed: transformed_fills(step, origins))
|
|
810
|
+
end
|
|
776
811
|
# A reading with a page open is timed, so the record can say what the page had received by then.
|
|
777
812
|
read = (plain = read; -> { @browser.reading(&plain) }) if own[:page]
|
|
778
813
|
observed = begin
|
|
779
|
-
step.poll ? Poll.new(step.poll, step.claims, args).call(record, &read) : read.()
|
|
814
|
+
step.poll ? Poll.new(step.poll, step.claims, args, sides).call(record, &read) : read.()
|
|
780
815
|
rescue StandardError => e
|
|
781
816
|
raise unless observes && !step.poll
|
|
782
817
|
|
|
@@ -786,7 +821,7 @@ module Nukadoko
|
|
|
786
821
|
record[:error_kind] = "unobserved"
|
|
787
822
|
raise e.class, "the step observed nothing, so no claim was judged: #{e.message}"
|
|
788
823
|
end
|
|
789
|
-
judged = Claims.judge(step.claims, observed, args)
|
|
824
|
+
judged = Claims.judge(step.claims, observed, args, sides.(observed))
|
|
790
825
|
record[:claims] = judged
|
|
791
826
|
# The value each claim read before its view, for `measured`.
|
|
792
827
|
record[:raw_actuals] = step.claims.map do |declared|
|
|
@@ -803,7 +838,7 @@ module Nukadoko
|
|
|
803
838
|
patterns = [step.pattern].compact
|
|
804
839
|
record[:claim_records] = step.claims.zip(judged).map do |declared, result|
|
|
805
840
|
if declared[:each]
|
|
806
|
-
RunRecord.each_claim(declared, observed,
|
|
841
|
+
RunRecord.each_claim(declared, sides.(observed), origins, texts, patterns: patterns)
|
|
807
842
|
else
|
|
808
843
|
RunRecord.claim(declared, result, origins, texts, observed: observes && !from_values.key?(declared[:actual].to_s.split(".").first), patterns: patterns)
|
|
809
844
|
end
|
|
@@ -814,8 +849,11 @@ module Nukadoko
|
|
|
814
849
|
message = RunRecord.broken_message(record[:claim_records])
|
|
815
850
|
first, *rest = message.split("\n", -1)
|
|
816
851
|
message = ["#{first}#{RunRecord.poll_end(step, record)}", *rest].join("\n")
|
|
817
|
-
|
|
818
|
-
|
|
852
|
+
# A claim nukadoko could not judge is never the criterion failing, so
|
|
853
|
+
# it decides the kind even when another claim broke.
|
|
854
|
+
unjudged = record[:claim_records].any? { _1[:outcome] == "unjudged" }
|
|
855
|
+
record.merge!(status: "failed", outcome: then_line && !unjudged ? :fail : :broke, claim: broken,
|
|
856
|
+
broken_actual: judged[broken][:actual], error_kind: unjudged ? "claim_unjudged" : "claim_broken", error: message)
|
|
819
857
|
else
|
|
820
858
|
value, problems = step.returned(step.new.run(**step.keywords(fixtures.slice(*step.fixtures), step.inputs.load(args))))
|
|
821
859
|
if problems.any?
|
|
@@ -962,8 +1000,15 @@ module Nukadoko
|
|
|
962
1000
|
def read_env(environment)
|
|
963
1001
|
EnvCheck.validate!
|
|
964
1002
|
config = Nukadoko.config_options.fetch(:secrets, {}) #: Hash[Symbol, untyped]
|
|
965
|
-
|
|
966
|
-
|
|
1003
|
+
# A tree's checkout holds no env file git ignores, and head's are
|
|
1004
|
+
# the ones the person keeps.
|
|
1005
|
+
root = @head ? @head[:root].to_s : @project
|
|
1006
|
+
@env_vars = EnvFile.load(root, environment.env_files)
|
|
1007
|
+
@secrets = Secrets.of(root, environment.env_files, public_keys: (config[:public] || []).map(&:to_s), redact_keys: (config[:redact] || []).map(&:to_s))
|
|
1008
|
+
head = @head
|
|
1009
|
+
return unless head
|
|
1010
|
+
|
|
1011
|
+
@secrets = @secrets.with(Secrets.of(root, head[:env_files], public_keys: head[:public], redact_keys: head[:redact]))
|
|
967
1012
|
rescue EnvFile::Unreadable => e
|
|
968
1013
|
raise Refusal.new("env-file-unreadable", e.message)
|
|
969
1014
|
end
|
data/lib/nukadoko/run_record.rb
CHANGED
|
@@ -143,42 +143,43 @@ module Nukadoko
|
|
|
143
143
|
# and item claim as declared, how many items the list held and how
|
|
144
144
|
# many `where` selected, and the judged items, the broken first, at
|
|
145
145
|
# most 20, in index order.
|
|
146
|
-
#: (Hash[Symbol, untyped],
|
|
147
|
-
def each_claim(declared,
|
|
148
|
-
|
|
149
|
-
|
|
146
|
+
#: (Hash[Symbol, untyped], Engine::ClaimSides::Inputs, Hash[String, String], Hash[String, String?], ?patterns: Array[String]) -> Hash[Symbol, untyped]
|
|
147
|
+
def each_claim(declared, inputs, origins, texts, patterns: [])
|
|
148
|
+
sides = Engine::ClaimSides
|
|
149
|
+
args = inputs.args
|
|
150
|
+
observed = inputs.observed
|
|
150
151
|
each = declared[:each]
|
|
151
152
|
where = each[:where] || []
|
|
152
153
|
declarations = { **(where.empty? ? {} : { where: where.map { item_declaration(_1, args, origins, texts, patterns, observed) } }),
|
|
153
154
|
claims: each[:claims].map { item_declaration(_1, args, origins, texts, patterns, observed) } }
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
155
|
+
array = sides.array_side(declared, inputs)
|
|
156
|
+
base = { actual_from: array.place.label, view: declared[:view], at: declared[:at]&.to_s }.compact
|
|
157
|
+
value = array.found[:value]
|
|
158
|
+
count = value.is_a?(Array) ? value.size : 0
|
|
159
|
+
ended = lambda do |reason, results = [], outcome = "broken"|
|
|
160
|
+
base.merge(each: { **declarations, items: count, selected: 0, results: results }, outcome: outcome, reason: reason, measured: nil)
|
|
159
161
|
end
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
end
|
|
163
|
-
return ended.("#{actual_from} could not be read: #{unread.message}") if unread
|
|
162
|
+
stop = array.found.slice(:broken, :unjudged).then { _1.empty? ? nil : _1 } || sides.each_stop(declared, array.place, inputs)
|
|
163
|
+
return ended.(stop[:broken] || stop[:unjudged], [], stop[:unjudged] ? "unjudged" : "broken") if stop
|
|
164
164
|
return ended.("each reads an array, and the value is #{article(json_type(value))}") unless value.is_a?(Array)
|
|
165
165
|
return ended.("the array is empty, and a claim on every item of nothing measures nothing") if value.empty?
|
|
166
166
|
|
|
167
167
|
judged = []
|
|
168
168
|
value.each_with_index do |item, index|
|
|
169
|
-
|
|
170
|
-
|
|
169
|
+
place = sides.place_at(array.place, index.to_s)
|
|
170
|
+
compare = ->(entry) { item_comparison(entry, sides.item_side(item, place, entry), inputs, origins, texts, patterns) }
|
|
171
|
+
where_records = where.map(&compare)
|
|
171
172
|
# A where claim that could not compare says nothing about whether
|
|
172
173
|
# the item belongs, so leaving it out would turn "every item" into
|
|
173
174
|
# "the items that happen to compare".
|
|
174
175
|
if (unjudgeable = where_records.find { _1[:reason] })
|
|
175
176
|
outcome = unjudgeable[:outcome] == "unjudged" ? "unjudged" : "broken"
|
|
176
|
-
return ended.("where could not #{outcome == "unjudged" ? "judge" : "compare"} item #{index}: #{unjudgeable[:reason]}",
|
|
177
|
+
return ended.("where could not #{outcome == "unjudged" ? "judge" : "compare"} item #{index}: #{unjudgeable[:reason]}",
|
|
177
178
|
[{ index: index, selected: false, where: where_records }], outcome)
|
|
178
179
|
end
|
|
179
180
|
next judged << { index: index, selected: false, where: where_records } unless where_records.all? { _1[:outcome] == "held" }
|
|
180
181
|
|
|
181
|
-
claims = each[:claims].map
|
|
182
|
+
claims = each[:claims].map(&compare)
|
|
182
183
|
outcome = claims.any? { _1[:outcome] == "broken" } ? "broken" : claims.any? { _1[:outcome] == "unjudged" } ? "unjudged" : "held"
|
|
183
184
|
identity = outcome == "broken" && item.is_a?(Hash) && IDENTITY_FIELDS.lazy.filter_map do |field|
|
|
184
185
|
v = item.transform_keys(&:to_s)[field]
|
|
@@ -213,12 +214,14 @@ module Nukadoko
|
|
|
213
214
|
expected_text: expected_text)
|
|
214
215
|
end
|
|
215
216
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
217
|
+
# One where or item claim on one item, judged on the side the item gives.
|
|
218
|
+
#: (Hash[Symbol, untyped], Engine::ClaimSides::Side, Engine::ClaimSides::Inputs, Hash[String, String], Hash[String, String?], Array[String]) -> Hash[Symbol, untyped]
|
|
219
|
+
def item_comparison(entry, side, inputs, origins, texts, patterns)
|
|
220
|
+
sides = Engine::ClaimSides
|
|
221
|
+
judged = sides.judge_comparison(entry, side, inputs)
|
|
222
|
+
label = sides.place_counted(sides.place_at(sides.place_viewed(side.place, entry[:view]), entry[:at]&.to_s), entry[:count]).label
|
|
219
223
|
expected_from, expected_text = expected_origin(entry, origins, texts, patterns)
|
|
220
|
-
{ **judged.slice(:actual), actual_from:
|
|
221
|
-
**{ view: entry[:view], at: entry[:at]&.to_s, count: entry[:count] }.compact }
|
|
224
|
+
{ **judged.slice(:actual), actual_from: label, **{ view: entry[:view], at: entry[:at]&.to_s, count: entry[:count] }.compact }
|
|
222
225
|
.merge(compare: entry[:compare], **judged.slice(:expected), expected_from: expected_from,
|
|
223
226
|
**(entry[:expected_view] ? { expected_view: entry[:expected_view] } : {}), expected_text: expected_text,
|
|
224
227
|
**outcome(judged))
|
data/lib/nukadoko/scaffold.rb
CHANGED
|
@@ -73,7 +73,7 @@ module Nukadoko
|
|
|
73
73
|
repeated = captures.map(&:key).tally.select { _2 > 1 }.keys
|
|
74
74
|
return refusal("Refusing to scaffold: the pattern captures #{repeated.map { %("#{_1}") }.join(", ")} more than once, and one args field holds one value") if repeated.any?
|
|
75
75
|
|
|
76
|
-
types = Pattern
|
|
76
|
+
types = Pattern.registry.parameter_types.map(&:name).reject(&:empty?).sort
|
|
77
77
|
unknown = captures.map(&:type).uniq.find { !types.include?(_1) }
|
|
78
78
|
if unknown
|
|
79
79
|
return refusal(%(Refusing to scaffold: the pattern names type "#{unknown}", and this project registers none by that name; registered types: #{types.join(", ")}))
|
|
@@ -918,7 +918,7 @@ module Nukadoko
|
|
|
918
918
|
# itself, with the readings it could not choose between.
|
|
919
919
|
#: (String) -> Hash[Symbol, untyped]
|
|
920
920
|
def self.infer(text)
|
|
921
|
-
generated = generate(text, Pattern
|
|
921
|
+
generated = generate(text, Pattern.registry)
|
|
922
922
|
first = generated.first
|
|
923
923
|
same = generated.all? do |expression|
|
|
924
924
|
expression.parameter_types.size == first.parameter_types.size &&
|