nukadoko 0.5.0 → 0.7.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 +553 -3
- data/README.ja.md +22 -6
- data/README.md +13 -7
- data/docs/ci.ja.md +542 -0
- data/docs/ci.md +635 -0
- data/docs/commands.ja.md +1524 -0
- data/docs/commands.md +1281 -0
- data/docs/engines.json +19 -0
- data/docs/execution-events.ja.md +336 -0
- data/docs/execution-events.md +423 -0
- data/docs/glossary.json +1348 -0
- data/docs/guide.ja.md +733 -0
- data/docs/guide.md +815 -0
- data/docs/intent.ja.md +133 -0
- data/docs/intent.md +156 -0
- data/docs/layout.ja.md +442 -0
- data/docs/layout.md +399 -0
- data/docs/releasing.ja.md +186 -0
- data/docs/releasing.md +237 -0
- data/docs/ruby/reference.ja.md +302 -0
- data/docs/ruby/reference.md +368 -0
- data/docs/spec.ja.md +8916 -0
- data/docs/spec.md +11250 -0
- data/docs/tutorial.ja.md +451 -0
- data/docs/tutorial.md +458 -0
- data/docs/typescript/adopting.ja.md +231 -0
- data/docs/typescript/adopting.md +251 -0
- data/docs/typescript/doors.ja.md +301 -0
- data/docs/typescript/doors.md +329 -0
- data/docs/typescript/migration-playwright-test.ja.md +189 -0
- data/docs/typescript/migration-playwright-test.md +212 -0
- data/docs/typescript/migration.ja.md +391 -0
- data/docs/typescript/migration.md +505 -0
- data/docs/typescript/reference.ja.md +176 -0
- data/docs/typescript/reference.md +197 -0
- data/docs/typescript/upgrading.ja.md +1774 -0
- data/docs/typescript/upgrading.md +2224 -0
- data/docs/web-app.ja.md +627 -0
- data/docs/web-app.md +659 -0
- data/docs/writing-scenarios.ja.md +544 -0
- data/docs/writing-scenarios.md +563 -0
- data/lib/nukadoko/base.rb +12 -5
- data/lib/nukadoko/changed_files.rb +95 -0
- data/lib/nukadoko/check.rb +459 -51
- data/lib/nukadoko/claim_drops.rb +271 -0
- data/lib/nukadoko/claim_line.rb +24 -4
- data/lib/nukadoko/claim_rules.rb +143 -1
- data/lib/nukadoko/claim_sides.rb +157 -9
- data/lib/nukadoko/cli.rb +403 -50
- data/lib/nukadoko/codes.json +246 -21
- data/lib/nukadoko/codes.rb +21 -4
- data/lib/nukadoko/command.rb +120 -13
- data/lib/nukadoko/command_help.rb +128 -0
- data/lib/nukadoko/compat.rb +469 -0
- data/lib/nukadoko/criteria.rb +1 -1
- data/lib/nukadoko/definition.rb +157 -7
- data/lib/nukadoko/error_frames.rb +6 -3
- data/lib/nukadoko/events/count.rb +146 -0
- data/lib/nukadoko/events/counted.rb +114 -0
- data/lib/nukadoko/events/format.rb +257 -0
- data/lib/nukadoko/events/lists.rb +154 -0
- data/lib/nukadoko/events/path.rb +285 -0
- data/lib/nukadoko/events/read.rb +284 -0
- data/lib/nukadoko/events/reader.rb +490 -0
- data/lib/nukadoko/events/selection.rb +252 -0
- data/lib/nukadoko/events/tally.rb +438 -0
- data/lib/nukadoko/features.rb +2 -2
- data/lib/nukadoko/fixtures.rb +160 -35
- data/lib/nukadoko/http_recording.rb +6 -2
- data/lib/nukadoko/intent.rb +364 -0
- data/lib/nukadoko/intent_file.rb +81 -0
- data/lib/nukadoko/intent_view.rb +190 -0
- data/lib/nukadoko/js_json.rb +2 -1
- data/lib/nukadoko/judge.rb +2 -2
- data/lib/nukadoko/judgment_file.rb +22 -1
- data/lib/nukadoko/judgments.rb +33 -3
- data/lib/nukadoko/measure_mcp.rb +202 -0
- data/lib/nukadoko/parts.rb +8 -2
- data/lib/nukadoko/path_view.rb +252 -0
- data/lib/nukadoko/place_rows.rb +161 -0
- data/lib/nukadoko/program.rb +1265 -51
- data/lib/nukadoko/program_log.rb +122 -0
- data/lib/nukadoko/program_shape.rb +385 -0
- data/lib/nukadoko/project_fixtures.rb +43 -10
- data/lib/nukadoko/project_program.rb +5 -4
- data/lib/nukadoko/repeated_prefix.rb +310 -0
- data/lib/nukadoko/report_run.rb +3 -3
- data/lib/nukadoko/run.rb +1156 -159
- data/lib/nukadoko/run_record.rb +70 -46
- data/lib/nukadoko/scaffold.rb +24 -6
- data/lib/nukadoko/schema.rb +15 -2
- data/lib/nukadoko/secrets.rb +55 -5
- data/lib/nukadoko/states.rb +478 -0
- data/lib/nukadoko/step.rb +71 -2
- data/lib/nukadoko/step_fixtures.rb +52 -3
- data/lib/nukadoko/summary.rb +803 -30
- data/lib/nukadoko/table.rb +4 -2
- data/lib/nukadoko/text_fit.rb +20 -7
- data/lib/nukadoko/trace.rb +152 -45
- data/lib/nukadoko/tree_passes.rb +95 -33
- data/lib/nukadoko/underneath.rb +311 -0
- data/lib/nukadoko/verdict.rb +18 -1
- data/lib/nukadoko/version.rb +1 -1
- data/lib/nukadoko/vocabulary.rb +166 -23
- data/lib/nukadoko/walk.rb +2 -2
- data/lib/nukadoko/walk_step.rb +1 -1
- data/lib/nukadoko.rb +23 -0
- data/llms.txt +42 -35
- data/sig/generated/nukadoko/base.rbs +4 -4
- data/sig/generated/nukadoko/changed_files.rbs +42 -0
- data/sig/generated/nukadoko/check.rbs +147 -10
- data/sig/generated/nukadoko/claim_drops.rbs +135 -0
- data/sig/generated/nukadoko/claim_line.rbs +11 -0
- data/sig/generated/nukadoko/claim_rules.rbs +49 -4
- data/sig/generated/nukadoko/claim_sides.rbs +63 -12
- data/sig/generated/nukadoko/cli.rbs +80 -7
- data/sig/generated/nukadoko/codes.rbs +19 -4
- data/sig/generated/nukadoko/command.rbs +68 -1
- data/sig/generated/nukadoko/command_help.rbs +18 -0
- data/sig/generated/nukadoko/compat.rbs +392 -0
- data/sig/generated/nukadoko/criteria.rbs +1 -1
- data/sig/generated/nukadoko/definition.rbs +50 -0
- data/sig/generated/nukadoko/error_frames.rbs +1 -1
- data/sig/generated/nukadoko/events/count.rbs +69 -0
- data/sig/generated/nukadoko/events/counted.rbs +70 -0
- data/sig/generated/nukadoko/events/format.rbs +163 -0
- data/sig/generated/nukadoko/events/lists.rbs +47 -0
- data/sig/generated/nukadoko/events/path.rbs +161 -0
- data/sig/generated/nukadoko/events/read.rbs +109 -0
- data/sig/generated/nukadoko/events/reader.rbs +226 -0
- data/sig/generated/nukadoko/events/selection.rbs +100 -0
- data/sig/generated/nukadoko/events/tally.rbs +227 -0
- data/sig/generated/nukadoko/features.rbs +6 -4
- data/sig/generated/nukadoko/fixtures.rbs +67 -11
- data/sig/generated/nukadoko/http_recording.rbs +1 -1
- data/sig/generated/nukadoko/intent.rbs +132 -0
- data/sig/generated/nukadoko/intent_file.rbs +46 -0
- data/sig/generated/nukadoko/intent_view.rbs +69 -0
- data/sig/generated/nukadoko/judgment_file.rbs +7 -1
- data/sig/generated/nukadoko/judgments.rbs +10 -0
- data/sig/generated/nukadoko/measure_mcp.rbs +104 -0
- data/sig/generated/nukadoko/parts.rbs +2 -2
- data/sig/generated/nukadoko/path_view.rbs +105 -0
- data/sig/generated/nukadoko/place_rows.rbs +43 -0
- data/sig/generated/nukadoko/program.rbs +627 -23
- data/sig/generated/nukadoko/program_log.rbs +67 -0
- data/sig/generated/nukadoko/program_shape.rbs +147 -0
- data/sig/generated/nukadoko/project_fixtures.rbs +16 -3
- data/sig/generated/nukadoko/project_program.rbs +2 -1
- data/sig/generated/nukadoko/repeated_prefix.rbs +172 -0
- data/sig/generated/nukadoko/report_run.rbs +1 -1
- data/sig/generated/nukadoko/run.rbs +286 -41
- data/sig/generated/nukadoko/run_record.rbs +20 -12
- data/sig/generated/nukadoko/scaffold.rbs +3 -0
- data/sig/generated/nukadoko/schema.rbs +5 -0
- data/sig/generated/nukadoko/secrets.rbs +26 -3
- data/sig/generated/nukadoko/states.rbs +214 -0
- data/sig/generated/nukadoko/step.rbs +58 -1
- data/sig/generated/nukadoko/step_fixtures.rbs +39 -0
- data/sig/generated/nukadoko/summary.rbs +256 -2
- data/sig/generated/nukadoko/table.rbs +3 -2
- data/sig/generated/nukadoko/trace.rbs +108 -33
- data/sig/generated/nukadoko/tree_passes.rbs +36 -8
- data/sig/generated/nukadoko/underneath.rbs +141 -0
- data/sig/generated/nukadoko/verdict.rbs +8 -0
- data/sig/generated/nukadoko/vocabulary.rbs +45 -6
- data/skills/nukadoko/SKILL.md +18 -18
- data/skills/nukadoko/references/checking-steps.md +16 -83
- data/skills/nukadoko/references/diagnosing.md +6 -6
- data/skills/nukadoko/references/done.md +22 -0
- data/skills/nukadoko/references/evidence.md +19 -6
- data/skills/nukadoko/references/exploring.md +22 -7
- data/skills/nukadoko/references/fixtures.md +12 -32
- data/skills/nukadoko/references/judgments.md +18 -0
- data/skills/nukadoko/references/maintenance.md +1 -1
- data/skills/nukadoko/references/merge-risk.md +1 -1
- data/skills/nukadoko/references/parts.md +46 -23
- data/skills/nukadoko/references/{perturbed-worlds.md → perturbed-systems.md} +30 -12
- data/skills/nukadoko/references/program.md +168 -169
- data/skills/nukadoko/references/reviewing.md +20 -20
- data/skills/nukadoko/references/ruby/checking-steps.md +106 -0
- data/skills/nukadoko/references/ruby/examples/cli.md +212 -0
- data/skills/nukadoko/references/ruby/fixtures.md +34 -0
- data/skills/nukadoko/references/ruby/program.md +112 -0
- data/skills/nukadoko/references/ruby/step-files.md +115 -0
- data/skills/nukadoko/references/running.md +34 -34
- data/skills/nukadoko/references/scenario-rules.md +7 -6
- data/skills/nukadoko/references/states.md +7 -1
- data/skills/nukadoko/references/step-files.md +41 -120
- data/skills/nukadoko/references/typescript/checking-steps.md +129 -0
- data/skills/nukadoko/references/{examples → typescript/examples}/cli.md +1 -1
- data/skills/nukadoko/references/{examples → typescript/examples}/http-api.md +6 -6
- data/skills/nukadoko/references/{examples → typescript/examples}/workflow.md +1 -1
- data/skills/nukadoko/references/typescript/fixtures.md +56 -0
- data/skills/nukadoko/references/typescript/program.md +111 -0
- data/skills/nukadoko/references/typescript/step-files.md +104 -0
- data/skills/nukadoko/references/verdicts.md +10 -10
- data/skills/nukadoko/references/writing-steps.md +67 -67
- data/skills/nukadoko/references/writing-the-feature.md +1 -1
- data/skills/nukadoko-verification/SKILL.md +13 -8
- metadata +103 -7
- data/skills/nukadoko/references/ruby.md +0 -80
data/lib/nukadoko/check.rb
CHANGED
|
@@ -35,7 +35,7 @@ module Nukadoko
|
|
|
35
35
|
end
|
|
36
36
|
end
|
|
37
37
|
|
|
38
|
-
FIXTURES = %w[baseURL base_url call context env evidence page pageAs page_as poll request requireEnv require_env resultOf result_of scratch section].freeze
|
|
38
|
+
FIXTURES = %w[baseURL base_url call context env evidence page pageAs page_as poll request requireEnv require_env resultOf result_of scratch section services setupResult setup_result].freeze
|
|
39
39
|
|
|
40
40
|
class Check
|
|
41
41
|
attr_reader :findings #: Array[Finding]
|
|
@@ -46,8 +46,10 @@ module Nukadoko
|
|
|
46
46
|
# what the feature loader found that runs nothing.
|
|
47
47
|
# `config` holds what was found in the config and its program before
|
|
48
48
|
# any step loaded, such as an env file that is missing.
|
|
49
|
-
#: (Array[singleton(Step)], Array[Scenario], ?features: bool, ?full: bool, ?conditions: Array[String]?, ?environments: Array[Environment]?, ?problems: Array[FeatureProblem], ?config: Array[Finding]) -> void
|
|
50
|
-
def initialize(steps, scenarios, features: true, full: false, conditions: nil, environments: nil, problems: [], config: [])
|
|
49
|
+
#: (Array[singleton(Step)], Array[Scenario], ?features: bool, ?full: bool, ?conditions: Array[String]?, ?environments: Array[Environment]?, ?problems: Array[FeatureProblem], ?config: Array[Finding], ?systems: (Array[Hash[Symbol, untyped]] | false | nil)) -> void
|
|
50
|
+
def initialize(steps, scenarios, features: true, full: false, conditions: nil, environments: nil, problems: [], config: [], systems: false)
|
|
51
|
+
@systems = systems
|
|
52
|
+
@full = full
|
|
51
53
|
@steps = steps
|
|
52
54
|
@scenarios = scenarios
|
|
53
55
|
@conditions = conditions
|
|
@@ -62,6 +64,19 @@ module Nukadoko
|
|
|
62
64
|
%(no .rb step file was found while scanning "features"; no step can ever be registered), Codes.fix("no-step-files-found"), nil)
|
|
63
65
|
end
|
|
64
66
|
@findings.concat(config)
|
|
67
|
+
# A glue file that raised while it loaded registered nothing.
|
|
68
|
+
Compat.load_failures.each do |file, message|
|
|
69
|
+
relative = file.delete_prefix("#{Dir.pwd}/")
|
|
70
|
+
@findings << Finding.new("error", "step-file-import-failed", relative, nil, nil, "#{relative}: #{message}", Codes.fix("step-file-import-failed"), nil)
|
|
71
|
+
end
|
|
72
|
+
# A compat hook's tags in a shape the door does not read would
|
|
73
|
+
# select scenarios differently than cucumber-ruby, so it is refused
|
|
74
|
+
# before anything runs.
|
|
75
|
+
Compat.hooks.each do |hook|
|
|
76
|
+
hook.tags.reject { Compat.tag_expression?(_1) }.each do |expression|
|
|
77
|
+
@findings << Finding.new("error", "unsupported-hook-tag-expression", nil, nil, nil, Compat.unsupported_tags(expression), Codes.fix("unsupported-hook-tag-expression"), nil)
|
|
78
|
+
end
|
|
79
|
+
end
|
|
65
80
|
# The config's parameterTypes did not register, so no pattern binds a
|
|
66
81
|
# line; that is said once, not once per pattern.
|
|
67
82
|
if (collision = Pattern.collision)
|
|
@@ -71,27 +86,42 @@ module Nukadoko
|
|
|
71
86
|
@usable.each { check_contract(_1) }
|
|
72
87
|
check_duplicate_patterns
|
|
73
88
|
check_parts
|
|
89
|
+
check_state_shapes
|
|
74
90
|
check_shapes
|
|
91
|
+
# In the TypeScript engine's order: the fixture graph, what the
|
|
92
|
+
# feature files themselves say (a file that does not parse, then a
|
|
93
|
+
# misplaced serial tag, then an outline that does not run), the
|
|
94
|
+
# tags, the conditions no environment meets, and then each line.
|
|
95
|
+
check_fixtures
|
|
96
|
+
problems.sort_by.with_index { |problem, i| [PROBLEM_ORDER.index(problem.code) || PROBLEM_ORDER.size, i] }.each do |problem|
|
|
97
|
+
findings << Finding.new("error", problem.code, problem.uri, problem.line, nil, problem.message, Codes.fix(problem.code), nil)
|
|
98
|
+
end
|
|
75
99
|
check_tags(conditions)
|
|
100
|
+
check_conditions_met(environments) if environments
|
|
76
101
|
check_lines
|
|
77
102
|
# One finding per cause: each undefined line already names the
|
|
78
103
|
# scaffold command for its file, so the missing step files would be
|
|
79
104
|
# said a second time.
|
|
80
105
|
@findings.reject! { _1.code == "no-step-files-found" } if steps.empty? && @findings.any? { _1.code == "undefined-step" }
|
|
81
|
-
check_fixtures(full)
|
|
82
|
-
check_conditions_met(environments) if environments
|
|
83
|
-
problems.each { |problem| findings << Finding.new("error", problem.code, problem.uri, problem.line, nil, problem.message, Codes.fix(problem.code), nil) }
|
|
84
106
|
if full
|
|
85
|
-
check_unbound
|
|
86
107
|
check_from_unused
|
|
108
|
+
check_unbound
|
|
87
109
|
check_unused_parameter_types
|
|
110
|
+
check_unused_fixtures
|
|
111
|
+
check_unmeasured_mcp
|
|
88
112
|
end
|
|
89
|
-
# Errors, then warnings, then notes
|
|
90
|
-
# the TypeScript engine
|
|
113
|
+
# Errors, then warnings, then notes. Errors and warnings keep the
|
|
114
|
+
# order found; notes go by kind, as the TypeScript engine lists them.
|
|
91
115
|
rank = { "error" => 0, "warning" => 1, "note" => 2 }
|
|
92
|
-
@findings = @findings.uniq { [_1.code, _1.file, _1.line, _1.message] }.each_with_index.sort_by
|
|
116
|
+
@findings = @findings.uniq { [_1.code, _1.file, _1.line, _1.message] }.each_with_index.sort_by do |f, i|
|
|
117
|
+
[rank.fetch(f.severity, 3), f.severity == "note" ? NOTE_ORDER.index(f.code) || NOTE_ORDER.size : 0, i]
|
|
118
|
+
end.map(&:first)
|
|
93
119
|
end
|
|
94
120
|
|
|
121
|
+
PROBLEM_ORDER = %w[feature-parse-error serial-tag-on-scenario outline-does-not-run].freeze
|
|
122
|
+
NOTE_ORDER = %w[from-unused pattern-unbound step-description-todo schema-field-undescribed parameter-type-unused fixture-unused
|
|
123
|
+
mcp-transport-unmeasured].freeze
|
|
124
|
+
|
|
95
125
|
#: () -> bool
|
|
96
126
|
def passed? = findings.none? { _1.severity == "error" }
|
|
97
127
|
|
|
@@ -102,10 +132,9 @@ module Nukadoko
|
|
|
102
132
|
# that fails to import, so it can never match a line.
|
|
103
133
|
#: (singleton(Step)) -> bool
|
|
104
134
|
def definition_broken?(step)
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
end
|
|
135
|
+
broken = step.patterns.filter_map { pattern_problem(step, _1) }
|
|
136
|
+
broken.each { findings << Finding.new("error", _1[0], step.file, nil, step.step_name, _1[1], Codes.fix(_1[0]), nil) }
|
|
137
|
+
return true if broken.any?
|
|
109
138
|
problems = Definition.new(step).problems
|
|
110
139
|
problems.each do |problem|
|
|
111
140
|
findings << Finding.about_step("error", "step-file-import-failed", step, problem,
|
|
@@ -118,9 +147,8 @@ module Nukadoko
|
|
|
118
147
|
|
|
119
148
|
# Why the step's pattern cannot be read, as the TypeScript engine says
|
|
120
149
|
# it: the first broken capture, then what cucumber-expressions refuses.
|
|
121
|
-
#: (singleton(Step)) -> [String, String]?
|
|
122
|
-
def pattern_problem(step)
|
|
123
|
-
pattern = step.pattern or return nil
|
|
150
|
+
#: (singleton(Step), String) -> [String, String]?
|
|
151
|
+
def pattern_problem(step, pattern)
|
|
124
152
|
head = %(Step "#{step.step_name}" pattern "#{pattern}")
|
|
125
153
|
keys = []
|
|
126
154
|
rest = pattern.gsub(/\./, "")
|
|
@@ -149,15 +177,15 @@ module Nukadoko
|
|
|
149
177
|
["pattern-syntax-error", "#{head}: #{e.message}"]
|
|
150
178
|
end
|
|
151
179
|
|
|
152
|
-
NUMBER_TYPES = %w[int float
|
|
153
|
-
STRING_TYPES = %w[string word].freeze
|
|
180
|
+
NUMBER_TYPES = %w[int float biginteger byte short long double].freeze
|
|
181
|
+
STRING_TYPES = %w[string word bigdecimal].freeze
|
|
154
182
|
|
|
155
183
|
# A capture hands the step a number or a string, and an args field of
|
|
156
184
|
# the other kind can never hold it.
|
|
157
|
-
#: (singleton(Step)) -> Array[Array[untyped]]
|
|
158
|
-
def capture_mismatches(step)
|
|
185
|
+
#: (singleton(Step), String) -> Array[Array[untyped]]
|
|
186
|
+
def capture_mismatches(step, pattern)
|
|
159
187
|
fields = step.args.fields.to_h { [_1.name.to_s, _1.type] }
|
|
160
|
-
|
|
188
|
+
pattern.scan(Pattern::NAMED).filter_map do |key, type|
|
|
161
189
|
declared = fields[key]
|
|
162
190
|
captured = if NUMBER_TYPES.include?(type) then "number"
|
|
163
191
|
elsif STRING_TYPES.include?(type) then "string"
|
|
@@ -176,20 +204,23 @@ module Nukadoko
|
|
|
176
204
|
#: (singleton(Step)) -> void
|
|
177
205
|
def check_contract(step)
|
|
178
206
|
keys = step.args.fields.map { _1.name.to_s }
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
207
|
+
step.patterns.each do |pattern|
|
|
208
|
+
(Pattern.new(pattern).keys - keys).each do |key|
|
|
209
|
+
findings << Finding.about_step("error", "unknown-capture-key", step,
|
|
210
|
+
%(Step "#{step.step_name}" pattern "#{pattern}" binds key "#{key}", which is not a key of its args schema),
|
|
211
|
+
"Rename the capture to a key of the args schema, or add the key to the schema.")
|
|
212
|
+
end
|
|
183
213
|
end
|
|
214
|
+
check_alias_keys(step)
|
|
184
215
|
undescribed = [step.args, step.returns].compact.flat_map(&:fields).reject(&:description)
|
|
185
216
|
if undescribed.any?
|
|
186
217
|
findings << Finding.about_step("note", "schema-field-undescribed", step,
|
|
187
218
|
"Step \"#{step.step_name}\" has schema fields with no description: #{undescribed.map(&:name).join(", ")}",
|
|
188
219
|
"Give each field a description, so nuka steps and an agent can say what it means.")
|
|
189
220
|
end
|
|
190
|
-
capture_mismatches(step).each do |key, type, captured, held|
|
|
221
|
+
step.patterns.flat_map { |pattern| capture_mismatches(step, pattern).map { [pattern, *_1] } }.each do |pattern, key, type, captured, held|
|
|
191
222
|
findings << Finding.new("error", "capture-type-mismatch", step.file, nil, step.step_name,
|
|
192
|
-
%(Step "#{step.step_name}" pattern "#{
|
|
223
|
+
%(Step "#{step.step_name}" pattern "#{pattern}" binds key "#{key}" as {#{type}} (a #{captured}), but args declares "#{key}" as a #{held}),
|
|
193
224
|
"Make the capture type and the args field type agree: change the {key:type} in the pattern, or declare the field with the type the capture gives.", nil)
|
|
194
225
|
end
|
|
195
226
|
known = FIXTURES + Nukadoko.project_fixtures.keys.map(&:to_s)
|
|
@@ -200,16 +231,31 @@ module Nukadoko
|
|
|
200
231
|
end
|
|
201
232
|
end
|
|
202
233
|
|
|
234
|
+
# Every wording of one step must hand it the same args, or which line
|
|
235
|
+
# was written would decide what the step receives.
|
|
236
|
+
#: (singleton(Step)) -> void
|
|
237
|
+
def check_alias_keys(step)
|
|
238
|
+
return if step.patterns.size < 2
|
|
239
|
+
|
|
240
|
+
keys = step.patterns.map { [_1, Pattern.new(_1).keys.uniq] }
|
|
241
|
+
return if keys.map { _2.sort }.uniq.size == 1
|
|
242
|
+
|
|
243
|
+
findings << Finding.about_step("error", "alias-key-mismatch", step,
|
|
244
|
+
"Step \"#{step.step_name}\" has patterns that bind different key sets: #{keys.map { %("#{_1}" -> {#{_2.join(", ")}}) }.join("; ")}",
|
|
245
|
+
Codes.fix("alias-key-mismatch"))
|
|
246
|
+
end
|
|
247
|
+
|
|
203
248
|
# Two patterns that read the same once their names go would match the
|
|
204
249
|
# same lines; the later file is named, with every step that shares it.
|
|
205
250
|
#: () -> void
|
|
206
251
|
def check_duplicate_patterns
|
|
207
|
-
@usable.
|
|
252
|
+
owned = @usable.sort_by(&:file).flat_map { |step| step.patterns.map { |pattern| [step, pattern] } } #: Array[[singleton(Step), String]]
|
|
253
|
+
owned.group_by { |_, pattern| pattern.gsub(Pattern::NAMED) { "{#{Regexp.last_match(2)}}" } }.each do |text, group|
|
|
208
254
|
next if group.size < 2
|
|
209
255
|
|
|
210
|
-
|
|
211
|
-
findings << Finding.new("error", "duplicate-pattern",
|
|
212
|
-
%(Multiple patterns normalize to the same text "#{text}": #{
|
|
256
|
+
last = group.last or next
|
|
257
|
+
findings << Finding.new("error", "duplicate-pattern", last[0].file, nil, nil,
|
|
258
|
+
%(Multiple patterns normalize to the same text "#{text}": #{group.map { |step, pattern| %(#{step.step_name} ("#{pattern}")) }.join(", ")}),
|
|
213
259
|
Codes.fix("duplicate-pattern"), nil)
|
|
214
260
|
end
|
|
215
261
|
end
|
|
@@ -230,10 +276,62 @@ module Nukadoko
|
|
|
230
276
|
end
|
|
231
277
|
end
|
|
232
278
|
|
|
279
|
+
# An MCP client made on a transport built inside its own `new` call,
|
|
280
|
+
# as in `MCP::Client.new(transport: MCP::Client::Stdio.new(...))`.
|
|
281
|
+
# That transport exists nowhere but in the argument, so nothing can
|
|
282
|
+
# wrap it in measure_mcp later, and no call the client sends reaches
|
|
283
|
+
# a step record. Only that one shape can end one way: a transport
|
|
284
|
+
# built first and passed by name may be wrapped on another line. It
|
|
285
|
+
# reads the source text of each step file and each project fixture's
|
|
286
|
+
# block, and never runs one.
|
|
287
|
+
#: () -> void
|
|
288
|
+
def check_unmeasured_mcp
|
|
289
|
+
@steps.each do |step|
|
|
290
|
+
classes = Check.transports_built_in_new(File.exist?(step.file) ? File.read(step.file) : "")
|
|
291
|
+
next if classes.empty?
|
|
292
|
+
|
|
293
|
+
findings << Finding.new("note", "mcp-transport-unmeasured", step.file, nil, step.step_name,
|
|
294
|
+
Check.unmeasured_message(%(Step "#{step.step_name}"), classes), UNMEASURED_FIX, nil)
|
|
295
|
+
end
|
|
296
|
+
fixtures = [] #: Array[[Symbol, String, Integer]]
|
|
297
|
+
Nukadoko.project_fixtures.each_value do |fixture|
|
|
298
|
+
at = fixture.block.source_location
|
|
299
|
+
fixtures << [fixture.name, at[0], at[1]] if at
|
|
300
|
+
end
|
|
301
|
+
fixtures.each do |name, file, line|
|
|
302
|
+
next unless File.exist?(file)
|
|
303
|
+
|
|
304
|
+
ends = fixtures.filter_map { |_, other, start| start if other == file && start > line }.min
|
|
305
|
+
lines = File.readlines(file)[(line - 1)...(ends ? ends - 1 : nil)] || []
|
|
306
|
+
classes = Check.transports_built_in_new(lines.join)
|
|
307
|
+
next if classes.empty?
|
|
308
|
+
|
|
309
|
+
findings << Finding.new("note", "mcp-transport-unmeasured", CONFIG, nil, nil,
|
|
310
|
+
Check.unmeasured_message(%(Fixture "#{name}"), classes), UNMEASURED_FIX, nil)
|
|
311
|
+
end
|
|
312
|
+
end
|
|
313
|
+
|
|
314
|
+
UNMEASURED = /Client\.new\(\s*transport:\s*((?:::)?(?:[A-Z]\w*::)*(?:Stdio|HTTP))\.new\b/
|
|
315
|
+
UNMEASURED_FIX = "Pass the transport through Nukadoko.measure_mcp: MCP::Client.new(transport: Nukadoko.measure_mcp(MCP::Client::Stdio.new(...)))."
|
|
316
|
+
|
|
317
|
+
# The transport classes `source` builds inside an MCP client's `new`
|
|
318
|
+
# call, in the order written, comments left out.
|
|
319
|
+
#: (String) -> Array[String]
|
|
320
|
+
def self.transports_built_in_new(source)
|
|
321
|
+
code = source.lines.map { _1.sub(/(?<![\w"'])#.*$/, "") }.join
|
|
322
|
+
code.scan(UNMEASURED).flatten
|
|
323
|
+
end
|
|
324
|
+
|
|
325
|
+
#: (String, Array[String]) -> String
|
|
326
|
+
def self.unmeasured_message(subject, classes)
|
|
327
|
+
"#{subject} makes an MCP client on a new #{classes.uniq.join(", ")} inside MCP::Client.new, so nothing wraps it in measure_mcp: " \
|
|
328
|
+
"its calls reach no step record and carry no trace context."
|
|
329
|
+
end
|
|
330
|
+
|
|
233
331
|
# A config parameter type no pattern names.
|
|
234
332
|
#: () -> void
|
|
235
333
|
def check_unused_parameter_types
|
|
236
|
-
used = @steps.flat_map {
|
|
334
|
+
used = @steps.flat_map { _1.patterns.flat_map { |pattern| pattern.scan(/\{(?:[^}:]*:)?([^}]*)\}/).flatten } }
|
|
237
335
|
(Nukadoko.config_options[:parameterTypes] || []).each do |type|
|
|
238
336
|
name = type[:name].to_s
|
|
239
337
|
next if used.include?(name)
|
|
@@ -250,8 +348,7 @@ module Nukadoko
|
|
|
250
348
|
def check_transformed(step)
|
|
251
349
|
transformed = Pattern.transformed
|
|
252
350
|
claims = step.claims
|
|
253
|
-
|
|
254
|
-
return if transformed.empty? || claims.nil? || pattern.nil?
|
|
351
|
+
return if transformed.empty? || claims.nil? || step.patterns.empty?
|
|
255
352
|
|
|
256
353
|
keys = {} #: Hash[String, String]
|
|
257
354
|
claims.each_with_index do |claim, index|
|
|
@@ -265,8 +362,7 @@ module Nukadoko
|
|
|
265
362
|
Array(each[:claims]).each_with_index.map { |item, i| ["#{label}.each.claims[#{i}]", item] }) #: Array[[String, Hash[Symbol, untyped]]]
|
|
266
363
|
items.each { |item_label, item| keys[item[:expected].to_s] ||= item_label if item[:expected].is_a?(String) }
|
|
267
364
|
end
|
|
268
|
-
pattern.scan(Pattern::NAMED).each do |
|
|
269
|
-
key, type = Array(match).map(&:to_s)
|
|
365
|
+
step.patterns.flat_map { |pattern| pattern.scan(Pattern::NAMED).map { [pattern, *Array(_1).map(&:to_s)] } }.each do |pattern, key, type|
|
|
270
366
|
label = keys[key.to_s]
|
|
271
367
|
next unless label && transformed.include?(type.to_s)
|
|
272
368
|
|
|
@@ -341,6 +437,265 @@ module Nukadoko
|
|
|
341
437
|
hold_from_order(scenario, held) if held.any?
|
|
342
438
|
end
|
|
343
439
|
|
|
440
|
+
# A claim step's files chooses its producer by the same order rule:
|
|
441
|
+
# a key whose `of` names no step an earlier line runs, or two that
|
|
442
|
+
# earlier lines run, leaves each claim on the list unjudged. Whether
|
|
443
|
+
# that producer will run a command is not known before it runs (a
|
|
444
|
+
# helper may call run_command), so the check stays silent there.
|
|
445
|
+
#: (Scenario) -> void
|
|
446
|
+
def check_files_order(scenario)
|
|
447
|
+
resolved = scenario.steps.map { |line| (m = Engine.matches(@usable, line.text).map(&:first).uniq).size == 1 ? m.first : nil }
|
|
448
|
+
resolved.each_with_index do |step, index|
|
|
449
|
+
next unless step&.claims
|
|
450
|
+
|
|
451
|
+
before = resolved.first(index).compact.map(&:step_name)
|
|
452
|
+
undefined_before = scenario.steps.first(index).any? { Engine.matches(@usable, _1.text).empty? }
|
|
453
|
+
READINGS.each do |reading|
|
|
454
|
+
entries = step.public_send(reading[:option])
|
|
455
|
+
next unless entries.is_a?(Hash)
|
|
456
|
+
|
|
457
|
+
entries.each do |key, entry|
|
|
458
|
+
of = (entry[:of] || entry["of"] if entry.is_a?(Hash)) #: untyped
|
|
459
|
+
names = (of.is_a?(Array) ? of : [of]).filter_map { |cls| cls.step_name if cls && @usable.include?(cls) } #: Array[String]
|
|
460
|
+
next if names.empty?
|
|
461
|
+
|
|
462
|
+
ran = names.select { before.include?(_1) }
|
|
463
|
+
next if ran.size == 1
|
|
464
|
+
|
|
465
|
+
where = %(Step "#{step.step_name}"'s #{reading[:option]}.#{key})
|
|
466
|
+
line = scenario.steps[index].line
|
|
467
|
+
if ran.size >= 2
|
|
468
|
+
findings << Finding.new("error", "#{reading[:option]}-producer-ambiguous", scenario.uri, line, step.step_name,
|
|
469
|
+
"#{where} #{reading[:reads].("one of steps #{producer_names(names)}")}, and #{producer_names(ran)} each ran earlier in this scenario, " \
|
|
470
|
+
"so the run cannot choose #{reading[:choose]}, and #{reading[:unjudged]}",
|
|
471
|
+
"Remove or move lines so that exactly one of steps #{producer_names(ran)} runs before this line.", nil)
|
|
472
|
+
next
|
|
473
|
+
end
|
|
474
|
+
next if undefined_before
|
|
475
|
+
|
|
476
|
+
status = names.map { |name| resolved.any? { _1&.step_name == name } ? %("#{name}" runs only at or after this line) : %("#{name}" runs nowhere in this scenario) }.join("; ")
|
|
477
|
+
whose = names.size == 1 ? %(step "#{names.first}") : "exactly one of steps #{producer_names(names)}"
|
|
478
|
+
unjudged = reading[:unjudged].sub(/\A./, &:upcase)
|
|
479
|
+
findings << Finding.new("error", "#{reading[:option]}-producer-missing", scenario.uri, line, step.step_name,
|
|
480
|
+
"#{where} #{reading[:reads].(whose)}, and no earlier line runs it: #{status}. #{unjudged}#{reading[:missing_tail]}",
|
|
481
|
+
"Put a line that runs #{whose} earlier in the scenario, or, if an earlier line runs the step #{reading[:means]}, " \
|
|
482
|
+
"list that step in #{reading[:option]}.#{key}.of of step \"#{step.step_name}\".", nil)
|
|
483
|
+
end
|
|
484
|
+
end
|
|
485
|
+
end
|
|
486
|
+
end
|
|
487
|
+
|
|
488
|
+
# Each service an events key of a bound step names, with the step and
|
|
489
|
+
# the key, once each.
|
|
490
|
+
#: (Array[singleton(Step)]) -> Array[Hash[Symbol, String]]
|
|
491
|
+
def services_counted(bound)
|
|
492
|
+
counted = {} #: Hash[String, Hash[Symbol, String]]
|
|
493
|
+
bound.select { _1.claims && _1.events.is_a?(Hash) }.each do |step|
|
|
494
|
+
step.events.each do |key, entry|
|
|
495
|
+
service = entry.is_a?(Hash) ? (entry[:service] || entry["service"]) : nil
|
|
496
|
+
next unless service.is_a?(String)
|
|
497
|
+
|
|
498
|
+
counted["#{step.step_name}\u0000#{key}"] = { step_name: step.step_name, key: key.to_s, service: service.to_s }
|
|
499
|
+
end
|
|
500
|
+
end
|
|
501
|
+
counted.values
|
|
502
|
+
end
|
|
503
|
+
|
|
504
|
+
# `events-inlet-missing` and `events-service-unknown` (errors) and
|
|
505
|
+
# `events-unread` (warnings) for the systems a run starts, when a
|
|
506
|
+
# bound step declares events: a system nukadoko serves whose program
|
|
507
|
+
# names no `{events}`, one whose program has no service an events key
|
|
508
|
+
# names, and a system it does not serve, or a project with no program
|
|
509
|
+
# to start one. The fix is the program's, so one finding per system
|
|
510
|
+
# says it once.
|
|
511
|
+
#: (Array[singleton(Step)]) -> void
|
|
512
|
+
def check_events_systems(bound)
|
|
513
|
+
names = bound.select { _1.claims && _1.events.is_a?(Hash) && _1.events.any? }.map(&:step_name)
|
|
514
|
+
return if names.empty?
|
|
515
|
+
|
|
516
|
+
counting = "#{names.size == 1 ? "step" : "steps"} #{producer_names(names)} #{names.size == 1 ? "counts" : "count"} execution events"
|
|
517
|
+
if @systems.nil?
|
|
518
|
+
findings << Finding.new("warning", "events-unread", CONFIG, nil, nil,
|
|
519
|
+
"#{counting}, and #{CONFIG} has no program, so no system starts and nukadoko reads no execution events: each claim on a count is unjudged (system-unread)",
|
|
520
|
+
%(Add program: to #{CONFIG} with serve, the command that starts the program, and {events} in env, such as program: -> { { serve: { command: "bin/rails server -p {port}" }, env: { "EXECUTION_EVENTS" => "{events}" } } }.), nil)
|
|
521
|
+
return
|
|
522
|
+
end
|
|
523
|
+
named = services_counted(bound)
|
|
524
|
+
@systems.each do |system|
|
|
525
|
+
# A key that names a service the system does not have counts the
|
|
526
|
+
# lines of nothing, whatever the program writes.
|
|
527
|
+
services = system[:services] || []
|
|
528
|
+
named.reject { services.include?(_1[:service]) }.each do |entry|
|
|
529
|
+
findings << Finding.new("error", "events-service-unknown", CONFIG, nil, nil,
|
|
530
|
+
"system #{system[:name]}: step \"#{entry[:step_name]}\"'s events.#{entry[:key]}.service is \"#{entry[:service]}\", " \
|
|
531
|
+
"which is no service of the program, whose services are #{producer_names(services)}, so the count counts no line and each claim on it reads 0",
|
|
532
|
+
"Name one of the services #{producer_names(services)} in events.#{entry[:key]}.service of step \"#{entry[:step_name]}\", " \
|
|
533
|
+
"or leave service out to count every service's lines.", nil)
|
|
534
|
+
end
|
|
535
|
+
if system[:kind] == "serve"
|
|
536
|
+
next if system[:events]
|
|
537
|
+
|
|
538
|
+
findings << Finding.new("error", "events-inlet-missing", CONFIG, nil, nil,
|
|
539
|
+
"system #{system[:name]}: #{counting}, and the program names no {events}, so the program has no file to write them to: each claim on a count is unjudged (inlet-unnamed)",
|
|
540
|
+
%(Name {events} in env of #{CONFIG} for system #{system[:name]}, such as env: { "EXECUTION_EVENTS" => "{events}" }, and have the program append its execution events to that file (docs/execution-events.md).), nil)
|
|
541
|
+
next
|
|
542
|
+
end
|
|
543
|
+
why = system[:kind] == "url" ? "the program runs at a url, which nukadoko does not start" : "it has neither serve nor url, so no program runs"
|
|
544
|
+
findings << Finding.new("warning", "events-unread", CONFIG, nil, nil,
|
|
545
|
+
"system #{system[:name]}: #{counting}, and #{why}, so nukadoko reads no execution events there: each claim on a count is unjudged (system-unread)",
|
|
546
|
+
"Run these scenarios in a system nukadoko serves: give system #{system[:name]} serve in #{CONFIG}, with {events} in env, or select one that has it with --env.", nil)
|
|
547
|
+
end
|
|
548
|
+
end
|
|
549
|
+
|
|
550
|
+
# `setup-result-missing` (errors) and `steps-reach-command` (notes)
|
|
551
|
+
# for the systems a run starts, judged only for steps a selected line
|
|
552
|
+
# binds: a step nothing runs stops no run.
|
|
553
|
+
#
|
|
554
|
+
# setup-result-missing is an error because a bag is a declaration
|
|
555
|
+
# rather than a branch: a step whose bag names setup_result builds it
|
|
556
|
+
# every time it runs, so in a system whose program declares no setup it
|
|
557
|
+
# can only raise. The bag is closed over the project's fixtures, so a
|
|
558
|
+
# fixture that reads setup_result for its step is judged with it.
|
|
559
|
+
#
|
|
560
|
+
# steps-reach-command is a note because the text says only that the
|
|
561
|
+
# call is written, never that it is reached: a branch, or a system the
|
|
562
|
+
# project does not select, may leave it alone. The run refuses the
|
|
563
|
+
# call itself (command-refused), which is what catches a call made
|
|
564
|
+
# through a helper. A job that must not ship such a call runs
|
|
565
|
+
# nuka check --fail-on steps-reach-command.
|
|
566
|
+
#: (Array[[singleton(Step), String, Integer]]) -> void
|
|
567
|
+
def check_steps_reach(bound_at)
|
|
568
|
+
systems = @systems || []
|
|
569
|
+
without_setup = systems.reject { _1[:setup] }.map { _1[:name].to_s }
|
|
570
|
+
# A note of a whole-project check only: a check of one target reads
|
|
571
|
+
# the lines it was given, and the body's text is the project's.
|
|
572
|
+
url_only = @full ? systems.select { _1[:steps_reach] == "url" }.map { _1[:name].to_s } : []
|
|
573
|
+
return if without_setup.empty? && url_only.empty?
|
|
574
|
+
|
|
575
|
+
missing = [] #: Array[String]
|
|
576
|
+
called = [] #: Array[String]
|
|
577
|
+
bound_at.each do |step, uri, line|
|
|
578
|
+
name = step.step_name
|
|
579
|
+
if without_setup.any? && !missing.include?(name) && reads_setup_result?(step)
|
|
580
|
+
missing << name
|
|
581
|
+
findings << Finding.new("error", "setup-result-missing", uri, line, name,
|
|
582
|
+
%(step "#{name}", or a fixture it needs, requires setup_result, and #{Check.named_systems(without_setup)} declares no setup, ) +
|
|
583
|
+
"so nothing makes a value for it: reading it raises there, every time",
|
|
584
|
+
"Write setup in the program in #{CONFIG} for #{Check.named_systems(without_setup)} and return what the steps read, such as { tenant: tenant }, " \
|
|
585
|
+
"or stop the step and its fixtures requiring setup_result.", nil)
|
|
586
|
+
end
|
|
587
|
+
next if url_only.empty? || called.include?(name)
|
|
588
|
+
next unless Check.calls_run_command?(File.exist?(step.file) ? File.read(step.file) : "")
|
|
589
|
+
|
|
590
|
+
called << name
|
|
591
|
+
findings << Finding.new("note", "steps-reach-command", uri, line, name,
|
|
592
|
+
Check.command_message(%(step "#{name}"), url_only), COMMAND_FIX, nil)
|
|
593
|
+
end
|
|
594
|
+
return if url_only.empty?
|
|
595
|
+
|
|
596
|
+
check_fixtures_reach(bound_at.map(&:first).uniq, url_only)
|
|
597
|
+
end
|
|
598
|
+
|
|
599
|
+
COMMAND_FIX = "Send the request to the service's URL instead (base_url, or services[:<name>].url), such as its test API, " \
|
|
600
|
+
"and create and read the state the scenario needs through that API."
|
|
601
|
+
RUN_COMMAND = /\bNukadoko\.run_command\b/
|
|
602
|
+
|
|
603
|
+
# Whether `source` calls the helper that starts a process, comments
|
|
604
|
+
# left out, as the MCP check reads a file. The qualified spelling only:
|
|
605
|
+
# a project's own run_command is not this helper, and naming it would
|
|
606
|
+
# teach a reader to ignore the note.
|
|
607
|
+
#: (String) -> bool
|
|
608
|
+
def self.calls_run_command?(source)
|
|
609
|
+
source.lines.map { _1.sub(/(?<![\w"'])#.*$/, "") }.join.match?(RUN_COMMAND)
|
|
610
|
+
end
|
|
611
|
+
|
|
612
|
+
#: (String, Array[String]) -> String
|
|
613
|
+
def self.command_message(subject, systems)
|
|
614
|
+
"the body of #{subject} calls Nukadoko.run_command, which starts a process, and #{named_systems(systems)} declares stepsReach: \"url\", " \
|
|
615
|
+
"so that system refuses the call and the cell is broke (command-refused)"
|
|
616
|
+
end
|
|
617
|
+
|
|
618
|
+
# The systems a finding names: system staging-on, or every one of them.
|
|
619
|
+
#: (Array[String]) -> String
|
|
620
|
+
def self.named_systems(names) = names.size == 1 ? "system #{names.first}" : "systems #{names.join(", ")}"
|
|
621
|
+
|
|
622
|
+
# A project fixture a bound step needs, whose own lines call the
|
|
623
|
+
# helper: the fixture's text says nothing about which systems would
|
|
624
|
+
# build it, so a step that needs it is what brings it into the check.
|
|
625
|
+
#: (Array[singleton(Step)], Array[String]) -> void
|
|
626
|
+
def check_fixtures_reach(steps, url_only)
|
|
627
|
+
fixtures = Nukadoko.project_fixtures
|
|
628
|
+
needed = closed_bag(steps.flat_map(&:bag)).select { fixtures.key?(_1) }
|
|
629
|
+
return if needed.empty?
|
|
630
|
+
|
|
631
|
+
places = [] #: Array[[Symbol, String, Integer]]
|
|
632
|
+
fixtures.each_value do |fixture|
|
|
633
|
+
at = fixture.block.source_location
|
|
634
|
+
places << [fixture.name, at[0], at[1]] if at
|
|
635
|
+
end
|
|
636
|
+
needed.each do |name|
|
|
637
|
+
place = places.find { _1.first == name }
|
|
638
|
+
next unless place
|
|
639
|
+
|
|
640
|
+
_, file, line = place
|
|
641
|
+
next unless File.exist?(file)
|
|
642
|
+
|
|
643
|
+
ends = places.filter_map { |_, other, start| start if other == file && start > line }.min
|
|
644
|
+
lines = File.readlines(file)[(line - 1)...(ends ? ends - 1 : nil)] || []
|
|
645
|
+
next unless Check.calls_run_command?(lines.join)
|
|
646
|
+
|
|
647
|
+
findings << Finding.new("note", "steps-reach-command", CONFIG, nil, nil,
|
|
648
|
+
Check.command_message(%(fixture "#{name}"), url_only), COMMAND_FIX, nil)
|
|
649
|
+
end
|
|
650
|
+
end
|
|
651
|
+
|
|
652
|
+
# Whether the step's bag, closed over the project's fixtures, builds
|
|
653
|
+
# the setup_result builtin. A project fixture of that name replaces
|
|
654
|
+
# the builtin unless it names itself, as the resolver reads it.
|
|
655
|
+
#: (singleton(Step)) -> bool
|
|
656
|
+
def reads_setup_result?(step)
|
|
657
|
+
fixtures = Nukadoko.project_fixtures
|
|
658
|
+
closed_bag(step.bag).any? do |name|
|
|
659
|
+
next false unless %i[setupResult setup_result].include?(name)
|
|
660
|
+
|
|
661
|
+
!fixtures.key?(name) || fixtures[name].dependencies.include?(name)
|
|
662
|
+
end
|
|
663
|
+
end
|
|
664
|
+
|
|
665
|
+
# Every fixture name a bag reaches, its project fixtures' own
|
|
666
|
+
# dependencies included.
|
|
667
|
+
#: (Array[Symbol]) -> Array[Symbol]
|
|
668
|
+
def closed_bag(names)
|
|
669
|
+
fixtures = Nukadoko.project_fixtures
|
|
670
|
+
reached = [] #: Array[Symbol]
|
|
671
|
+
pending = names.dup
|
|
672
|
+
until pending.empty?
|
|
673
|
+
name = pending.shift
|
|
674
|
+
next if reached.include?(name)
|
|
675
|
+
|
|
676
|
+
reached << name
|
|
677
|
+
pending.concat(fixtures[name].dependencies) if fixtures.key?(name)
|
|
678
|
+
end
|
|
679
|
+
reached
|
|
680
|
+
end
|
|
681
|
+
|
|
682
|
+
# A reading of an earlier step that a claim step declares by key,
|
|
683
|
+
# each with an `of`: what the findings call it, and what is left
|
|
684
|
+
# unjudged.
|
|
685
|
+
READINGS = [
|
|
686
|
+
{ option: "events", reads: ->(whose) { "counts the execution events of #{whose}" }, choose: "whose events to count",
|
|
687
|
+
unjudged: "each claim on the count is unjudged", missing_tail: " (producer-not-run)", means: "whose execution events the claim means" },
|
|
688
|
+
{ option: "files", reads: ->(whose) { "reads the files the commands of #{whose} changed" }, choose: "whose files to read",
|
|
689
|
+
unjudged: "each claim on the list is unjudged", missing_tail: "", means: "whose files the claim means" }
|
|
690
|
+
].freeze #: Array[Hash[Symbol, untyped]]
|
|
691
|
+
|
|
692
|
+
# `"a"`, `"a" and "b"`, `"a", "b", and "c"`, as the run names candidates.
|
|
693
|
+
#: (Array[String]) -> String
|
|
694
|
+
def producer_names(names)
|
|
695
|
+
each = names.map { %("#{_1}") }
|
|
696
|
+
each.size <= 2 ? each.join(" and ") : "#{each[0...-1].to_a.join(", ")}, and #{each.last}"
|
|
697
|
+
end
|
|
698
|
+
|
|
344
699
|
# What a claim step's claims read, from the producers of its from
|
|
345
700
|
# values on the earlier lines of the scenario (ClaimCheck).
|
|
346
701
|
#: (Scenario) -> void
|
|
@@ -390,12 +745,11 @@ module Nukadoko
|
|
|
390
745
|
"If #{which} is meant to run #{steps_phrase.(held.flat_map { _1[:candidates] }.uniq)}, reword that line to match that step's pattern. Otherwise fix the undefined-step finding first, then run nuka check again: a held-back finding that still applies is reported then.", nil)
|
|
391
746
|
end
|
|
392
747
|
|
|
393
|
-
SCENARIO_ONLY = FIXTURES - %w[env requireEnv require_env baseURL base_url]
|
|
748
|
+
SCENARIO_ONLY = FIXTURES - %w[env requireEnv require_env baseURL base_url services setupResult setup_result]
|
|
394
749
|
|
|
395
|
-
# Fixture definitions that can never resolve
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
def check_fixtures(full)
|
|
750
|
+
# Fixture definitions that can never resolve.
|
|
751
|
+
#: () -> void
|
|
752
|
+
def check_fixtures
|
|
399
753
|
fixtures = Nukadoko.project_fixtures
|
|
400
754
|
return if fixtures.empty?
|
|
401
755
|
|
|
@@ -439,8 +793,13 @@ module Nukadoko
|
|
|
439
793
|
Codes.fix("fixture-scope-violation"), nil)
|
|
440
794
|
end
|
|
441
795
|
end
|
|
442
|
-
|
|
796
|
+
end
|
|
443
797
|
|
|
798
|
+
# In a whole-project check, a fixture no step reaches.
|
|
799
|
+
#: () -> void
|
|
800
|
+
def check_unused_fixtures
|
|
801
|
+
fixtures = Nukadoko.project_fixtures
|
|
802
|
+
config = CONFIG
|
|
444
803
|
reachable = []
|
|
445
804
|
pending = @steps.flat_map(&:bag)
|
|
446
805
|
until pending.empty?
|
|
@@ -570,6 +929,28 @@ module Nukadoko
|
|
|
570
929
|
end
|
|
571
930
|
end
|
|
572
931
|
|
|
932
|
+
# A state some steps name with a holder key and others without leaves
|
|
933
|
+
# every line that requires it unjudged, so that is said rather than
|
|
934
|
+
# left silent, pointed at a step of the shape fewer steps use.
|
|
935
|
+
#: () -> void
|
|
936
|
+
def check_state_shapes
|
|
937
|
+
States.shape_issues(@usable).each do |issue|
|
|
938
|
+
step = @usable.find { _1.step_name == issue[:step] }
|
|
939
|
+
findings << Finding.new("error", "state-shape-mismatch", step&.file, nil, issue[:step], issue[:message], issue[:fix], nil)
|
|
940
|
+
end
|
|
941
|
+
end
|
|
942
|
+
|
|
943
|
+
# Per feature file rather than per scenario, so a Background line
|
|
944
|
+
# every scenario reaches the same way is one finding.
|
|
945
|
+
#: () -> void
|
|
946
|
+
def check_state_order
|
|
947
|
+
@scenarios.group_by(&:uri).each_value do |scenarios|
|
|
948
|
+
States.findings(@usable, scenarios).each do |found|
|
|
949
|
+
findings << Finding.new("error", "state-missing", found[:uri], found[:line], found[:step], found[:message], found[:fix], nil)
|
|
950
|
+
end
|
|
951
|
+
end
|
|
952
|
+
end
|
|
953
|
+
|
|
573
954
|
# Each cycle once, named from the step whose walk first closed it.
|
|
574
955
|
#: () -> Array[Array[singleton(Step)]]
|
|
575
956
|
def part_cycles
|
|
@@ -617,6 +998,7 @@ module Nukadoko
|
|
|
617
998
|
def check_lines
|
|
618
999
|
undefined = []
|
|
619
1000
|
bound = [] #: Array[singleton(Step)]
|
|
1001
|
+
bound_at = [] #: Array[[singleton(Step), String, Integer]]
|
|
620
1002
|
@scenarios.each do |scenario|
|
|
621
1003
|
scenario.steps.each do |line|
|
|
622
1004
|
matches = Engine.matches(@usable, line.text)
|
|
@@ -625,6 +1007,9 @@ module Nukadoko
|
|
|
625
1007
|
when 1
|
|
626
1008
|
step, captures = matches.first
|
|
627
1009
|
bound << step
|
|
1010
|
+
bound_at << [step, scenario.uri, line.line]
|
|
1011
|
+
next check_compat_line(scenario, line, step) if step.respond_to?(:compat?)
|
|
1012
|
+
|
|
628
1013
|
check_fill(scenario, line, step, captures)
|
|
629
1014
|
check_position(scenario, line, step)
|
|
630
1015
|
check_kinds(scenario, line, step, captures)
|
|
@@ -635,12 +1020,18 @@ module Nukadoko
|
|
|
635
1020
|
%("#{line.text}" matches more than one step: #{matches.map { _1.first.step_name }.join(", ")}), Codes.fix("ambiguous-step"), nil)
|
|
636
1021
|
end
|
|
637
1022
|
end
|
|
1023
|
+
# A scenario's findings about the order of its lines follow its
|
|
1024
|
+
# own lines, so a file reads top to bottom.
|
|
1025
|
+
check_from_order(scenario)
|
|
1026
|
+
check_files_order(scenario)
|
|
1027
|
+
check_claim_sources(scenario)
|
|
1028
|
+
judging_nothing(scenario)
|
|
638
1029
|
end
|
|
1030
|
+
check_events_systems(bound.uniq) unless @systems == false
|
|
1031
|
+
check_steps_reach(bound_at) unless @systems == false || @systems.nil?
|
|
639
1032
|
bound.uniq.each { check_transformed(_1) }
|
|
640
|
-
|
|
641
|
-
@scenarios.each { check_claim_sources(_1) }
|
|
1033
|
+
check_state_order
|
|
642
1034
|
suppress_undefined(undefined)
|
|
643
|
-
@scenarios.each { judging_nothing(_1) }
|
|
644
1035
|
end
|
|
645
1036
|
|
|
646
1037
|
# A scenario whose Then lines each bind one step, none of them a claim
|
|
@@ -654,8 +1045,9 @@ module Nukadoko
|
|
|
654
1045
|
return unless steps.all? { _1.size == 1 }
|
|
655
1046
|
return if steps.any? { _1.first.first.claims }
|
|
656
1047
|
|
|
1048
|
+
compat = steps.any? { _1.first.first.respond_to?(:compat?) } ? " A compat step in Then position judges by raising or not, and nukadoko cannot see what it checked." : ""
|
|
657
1049
|
findings << Finding.new("warning", "scenario-without-then", scenario.uri, thens.first.line, nil,
|
|
658
|
-
%(Scenario "#{scenario.name}" judges no claim: none of its Then lines binds a claim step, so it passes whenever its steps run without an error
|
|
1050
|
+
%(Scenario "#{scenario.name}" judges no claim: none of its Then lines binds a claim step, so it passes whenever its steps run without an error.#{compat}),
|
|
659
1051
|
Codes.fix("scenario-without-then"), nil)
|
|
660
1052
|
end
|
|
661
1053
|
|
|
@@ -666,7 +1058,7 @@ module Nukadoko
|
|
|
666
1058
|
@unbound_steps ||= begin
|
|
667
1059
|
bound = @scenarios.flat_map(&:steps).filter_map { |line| (m = Engine.matches(@usable, line.text)).size == 1 ? m.first.first : nil }
|
|
668
1060
|
unread = findings.select { _1.code == "step-file-import-failed" }.map(&:step)
|
|
669
|
-
@steps.
|
|
1061
|
+
@steps.reject { _1.patterns.empty? }.reject { bound.include?(_1) || unread.include?(_1.step_name) }.sort_by(&:file)
|
|
670
1062
|
end
|
|
671
1063
|
end
|
|
672
1064
|
|
|
@@ -678,7 +1070,7 @@ module Nukadoko
|
|
|
678
1070
|
steps = unbound_steps
|
|
679
1071
|
return "" if steps.empty?
|
|
680
1072
|
|
|
681
|
-
named = steps.first(3).map { %(#{_1.step_name} (
|
|
1073
|
+
named = steps.first(3).map { %(#{_1.step_name} (#{_1.patterns.map { |text| %("#{text}") }.join(", ")}, #{_1.file})) }
|
|
682
1074
|
rest = steps.size - named.size
|
|
683
1075
|
"; patterned steps no scanned feature line binds: #{rest.positive? ? "#{named.join(", ")}, and #{rest} more" : named.join(", ")}"
|
|
684
1076
|
end
|
|
@@ -703,6 +1095,18 @@ module Nukadoko
|
|
|
703
1095
|
|
|
704
1096
|
KEYWORD = { "Context" => "Given", "Action" => "When", "Outcome" => "Then" }.freeze
|
|
705
1097
|
|
|
1098
|
+
# A compat step has no contract to hold a line to. In Then position it
|
|
1099
|
+
# judges by raising or not, which nukadoko cannot see.
|
|
1100
|
+
#: (Scenario, PickleStep, untyped) -> void
|
|
1101
|
+
def check_compat_line(scenario, line, step)
|
|
1102
|
+
return unless line.kind.to_s == "Outcome"
|
|
1103
|
+
|
|
1104
|
+
findings << Finding.new("warning", "then-compat-step", scenario.uri, line.line, step.step_name,
|
|
1105
|
+
%(Step "#{step.step_name}" is a compat step bound in Then position. A compat step cannot declare claims, so nukadoko cannot see what it judges; ) +
|
|
1106
|
+
%(this is a static coverage gap, not something the tool caught at run time (docs/ruby/reference.md "Compat steps", docs/spec.md "Claims")),
|
|
1107
|
+
Codes.fix("then-compat-step"), nil)
|
|
1108
|
+
end
|
|
1109
|
+
|
|
706
1110
|
# Only a Then judges, so a claim step elsewhere and a step that runs in
|
|
707
1111
|
# Then position are both mistakes.
|
|
708
1112
|
#: (Scenario, PickleStep, singleton(Step)) -> void
|
|
@@ -831,7 +1235,7 @@ module Nukadoko
|
|
|
831
1235
|
next unless named.is_a?(String) && step.args[key]&.type == :string && Claims.value_kind(named).nil?
|
|
832
1236
|
|
|
833
1237
|
findings << Finding.new("error", "claim-kind-unknown", scenario.uri, line.line, step.step_name,
|
|
834
|
-
%(Step "#{step.step_name}"'s #{entry_label}.expected is args.#{key}, which this line fills with #{
|
|
1238
|
+
%(Step "#{step.step_name}"'s #{entry_label}.expected is args.#{key}, which this line fills with #{JsJson.generate(named)}, and is-a names one of the kinds #{Claims::VALUE_KINDS.join(", ")}, so the claim would always break),
|
|
835
1239
|
Codes.fix("claim-kind-unknown"), nil)
|
|
836
1240
|
end
|
|
837
1241
|
end
|
|
@@ -882,7 +1286,11 @@ module Nukadoko
|
|
|
882
1286
|
|
|
883
1287
|
#: (Array[singleton(Step)], String) -> Array[[singleton(Step), Hash[String, untyped]]]
|
|
884
1288
|
def self.matches(steps, text)
|
|
885
|
-
steps.filter_map
|
|
1289
|
+
steps.filter_map do |step|
|
|
1290
|
+
compat = step #: untyped
|
|
1291
|
+
captures = step.respond_to?(:compat?) ? compat.match_line(text) : step.patterns.lazy.filter_map { Pattern.new(_1).match(text) }.first
|
|
1292
|
+
captures && [step, captures]
|
|
1293
|
+
end
|
|
886
1294
|
end
|
|
887
1295
|
end
|
|
888
1296
|
end
|