nukadoko 0.6.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 +541 -3
- data/README.ja.md +20 -5
- data/README.md +12 -6
- 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 +395 -48
- 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 +1 -1
- data/lib/nukadoko/judgments.rb +4 -4
- 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 +1148 -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 +799 -29
- 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/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 +41 -34
- 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 +1 -1
- data/sig/generated/nukadoko/judgments.rbs +1 -1
- 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/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/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 +12 -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/cli.rb
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
# rbs_inline: enabled
|
|
3
3
|
|
|
4
|
+
require_relative "command_help"
|
|
5
|
+
|
|
4
6
|
# The `nuka` command. With --json it prints one envelope in the shape the
|
|
5
7
|
# TypeScript engine prints, so an agent reads both engines the same way.
|
|
6
8
|
module Nukadoko
|
|
7
9
|
class CLI
|
|
8
|
-
FLAGS = %w[--json --no-check --dry-run --then --replace --allure --records --meets --misses --step --trailer].freeze
|
|
9
|
-
REPEATED = %w[--tag --env --use].freeze
|
|
10
|
+
FLAGS = %w[--json --no-check --dry-run --then --replace --allure --records --meets --misses --step --trailer --codes].freeze
|
|
11
|
+
REPEATED = %w[--tag --env --use --fail-on].freeze
|
|
10
12
|
VALUED = %w[--format --out --base --repeat --concurrency --order --proof-runs --args --pattern --description --feature --command --request --from --cwd --body --argv
|
|
11
13
|
--run --by --because --walk --timeout].freeze
|
|
12
14
|
|
|
@@ -90,6 +92,10 @@ module Nukadoko
|
|
|
90
92
|
message = @command.nil? ? "Not enough non-option arguments: got 0, need at least 1" : "Unknown argument: #{@command}"
|
|
91
93
|
return refuse(Engine::Refusal.new("invalid-arguments", message, run: "nuka --help"))
|
|
92
94
|
end
|
|
95
|
+
if @words.include?("--help") && CommandHelp::COMMANDS.key?(@command)
|
|
96
|
+
@out.write(CommandHelp.text(@command))
|
|
97
|
+
return 0
|
|
98
|
+
end
|
|
93
99
|
return refuse(Engine::Refusal.new("invalid-arguments", "Unknown argument: #{@unknown.first}")) if @unknown.any?
|
|
94
100
|
return verdict if @command == "verdict"
|
|
95
101
|
return Judge.new(@project, @rest, @options, json: @json, out: @out).call if @command == "judge"
|
|
@@ -98,6 +104,10 @@ module Nukadoko
|
|
|
98
104
|
return Walked.new(@project, @rest, @options, json: @json, out: @out).call if @command == "step"
|
|
99
105
|
return skill if @command == "skill"
|
|
100
106
|
return init if @command == "init"
|
|
107
|
+
return codes if @command == "check" && @options.key?("--codes")
|
|
108
|
+
if @command == "check" && (stop = fail_on_refusal)
|
|
109
|
+
return refuse(stop)
|
|
110
|
+
end
|
|
101
111
|
|
|
102
112
|
begin
|
|
103
113
|
Nukadoko.load_project(@project)
|
|
@@ -106,16 +116,27 @@ module Nukadoko
|
|
|
106
116
|
end
|
|
107
117
|
steps = Nukadoko.load_steps(File.join(@project, "features", "steps"))
|
|
108
118
|
problems = []
|
|
109
|
-
|
|
119
|
+
# nuka check with targets reads those feature files alone, and
|
|
120
|
+
# computes no notes: a note is a fact about the whole project.
|
|
121
|
+
targets = @command == "check" ? @rest : []
|
|
122
|
+
begin
|
|
123
|
+
paths = targets.empty? ? "features" : check_targets(targets)
|
|
124
|
+
rescue Engine::Refusal => e
|
|
125
|
+
return refuse(e)
|
|
126
|
+
end
|
|
127
|
+
scenarios = Dir.chdir(@project) { Engine.load_features(paths, problems: problems) }
|
|
110
128
|
declared = (Nukadoko.program_options[:environments] || {}).values.flat_map { (_1[:conditions] || {}).keys.map(&:to_s) }
|
|
111
129
|
# condition-unmet is judged for the selection a run without --env
|
|
112
130
|
# starts; a selection --env names is a choice of where to run.
|
|
113
131
|
selected = (Engine::Program.new(Nukadoko.program_options).environments if Array(@options["--env"]).empty?) rescue nil
|
|
114
|
-
check = Engine::Check.new(steps, scenarios, features: Dir.exist?(File.join(@project, "features")), full: @command == "check"
|
|
115
|
-
conditions: declared, environments: selected, problems: problems, config: env_findings)
|
|
132
|
+
check = Engine::Check.new(steps, scenarios, features: Dir.exist?(File.join(@project, "features")), full: @command == "check" && targets.empty?,
|
|
133
|
+
conditions: declared, environments: selected, problems: problems, config: env_findings, systems: started_systems)
|
|
116
134
|
findings = check.findings.map { relative(_1).to_h }
|
|
135
|
+
# steps and describe print what they could read and name the step
|
|
136
|
+
# files they could not, never the rest of what check reports.
|
|
137
|
+
findings = findings.select { DEFINITION_CODES.include?(_1[:code]) } if %w[steps describe].include?(@command)
|
|
117
138
|
case @command
|
|
118
|
-
when "check" then
|
|
139
|
+
when "check" then checked(check, findings)
|
|
119
140
|
when "sig"
|
|
120
141
|
path = File.join(@project, "sig", "nukadoko", "steps.rbs")
|
|
121
142
|
FileUtils.mkdir_p(File.dirname(path))
|
|
@@ -123,11 +144,25 @@ module Nukadoko
|
|
|
123
144
|
@out.puts "wrote #{path.delete_prefix("#{@project}/")}"
|
|
124
145
|
0
|
|
125
146
|
when "steps"
|
|
126
|
-
entries = check.usable.sort_by(&:
|
|
127
|
-
|
|
147
|
+
entries = check.usable.each_with_index.sort_by { |step, i| [step.file, i] }.map(&:first)
|
|
148
|
+
places = entries.map { [_1, {}] } #: Array[[singleton(Step), Hash[Symbol, untyped]]]
|
|
149
|
+
unbound = [] #: Array[Hash[Symbol, untyped]]
|
|
150
|
+
unless @rest.empty?
|
|
151
|
+
begin
|
|
152
|
+
selection = Engine::Selection.new(@project, @rest, [])
|
|
153
|
+
rescue Engine::Refusal => e
|
|
154
|
+
return refuse(e)
|
|
155
|
+
end
|
|
156
|
+
places, unbound = Vocabulary.of_targets(entries, selection.scenarios)
|
|
157
|
+
end
|
|
158
|
+
if @json
|
|
159
|
+
return finish("steps", unbound.empty?, findings: findings + unbound,
|
|
160
|
+
steps: places.map { |step, place| Vocabulary.entry(step, @project, entries).merge(place) })
|
|
161
|
+
end
|
|
128
162
|
|
|
129
|
-
@out.puts
|
|
130
|
-
|
|
163
|
+
@out.puts places.map { |step, place| Vocabulary.text(step, entries, place) }.join("\n\n")
|
|
164
|
+
emit({}, unbound, "steps", io: $stderr)
|
|
165
|
+
unbound.empty? ? 0 : 1
|
|
131
166
|
when "describe"
|
|
132
167
|
step = check.usable.find { _1.step_name == @rest.first }
|
|
133
168
|
@json = true
|
|
@@ -136,7 +171,7 @@ module Nukadoko
|
|
|
136
171
|
return finish("describe", false, findings: findings + [refusal], verdict: "refused")
|
|
137
172
|
end
|
|
138
173
|
|
|
139
|
-
finish("describe", true, findings: findings, **Vocabulary.describe(step, @project))
|
|
174
|
+
finish("describe", true, findings: findings, **Vocabulary.describe(step, @project, check.usable.sort_by(&:file)))
|
|
140
175
|
when "run" then @options.key?("--step") ? walk(steps) : run(steps)
|
|
141
176
|
when "do" then run_one(check)
|
|
142
177
|
when "scaffold" then scaffold(steps, scenarios)
|
|
@@ -226,8 +261,8 @@ module Nukadoko
|
|
|
226
261
|
raise Engine::Refusal.new("step-needs-one-scenario", "nuka run --step walks one execution of one scenario, and #{reason}", run: again)
|
|
227
262
|
end
|
|
228
263
|
|
|
229
|
-
# A run checks the scenarios it selected, then runs them in each
|
|
230
|
-
# it selected; a target or a
|
|
264
|
+
# A run checks the scenarios it selected, then runs them in each system
|
|
265
|
+
# it selected; a target or a system it cannot reach is refused first.
|
|
231
266
|
#: (Array[singleton(Step)]) -> Integer
|
|
232
267
|
def run(steps)
|
|
233
268
|
repeat = count_flag("--repeat")
|
|
@@ -245,7 +280,7 @@ module Nukadoko
|
|
|
245
280
|
progress = @json ? File.open(File::NULL, "w") : $stderr
|
|
246
281
|
ref = @options["--base"].last
|
|
247
282
|
if @walk && (repeat > 1 || ref)
|
|
248
|
-
why = repeat > 1 ? "--repeat #{repeat} runs it #{repeat} times" : "--base runs it in more than one
|
|
283
|
+
why = repeat > 1 ? "--repeat #{repeat} runs it #{repeat} times" : "--base runs it in more than one system"
|
|
249
284
|
raise Engine::Refusal.new("step-needs-one-scenario", "nuka run --step walks one execution of one scenario, and #{why}",
|
|
250
285
|
run: Engine::Walk.restart_command(@walk_target))
|
|
251
286
|
end
|
|
@@ -262,7 +297,7 @@ module Nukadoko
|
|
|
262
297
|
default = @options["--env"].empty?
|
|
263
298
|
declared = program.declared.values.flat_map { (_1[:conditions] || {}).keys.map(&:to_s) }
|
|
264
299
|
check = Engine::Check.new(steps, default ? selection.scenarios : kept, conditions: declared,
|
|
265
|
-
environments: (environments if default), problems: selection.problems, config: env_findings)
|
|
300
|
+
environments: (environments if default), problems: selection.problems, config: env_findings, systems: started_systems)
|
|
266
301
|
# The TypeScript engine refuses a declaration as its step file loads, so
|
|
267
302
|
# such a step file stops its run even under --no-check, naming the
|
|
268
303
|
# first one.
|
|
@@ -288,6 +323,10 @@ module Nukadoko
|
|
|
288
323
|
fix: "Correct each error the findings name, or pass --no-check to run anyway.", do: check_command }
|
|
289
324
|
return finish("run", false, findings: errors + [stop], verdict: "refused", exit_code: 2)
|
|
290
325
|
end
|
|
326
|
+
# A missing checkout stops the run under --no-check too, before any
|
|
327
|
+
# system builds, as the TypeScript engine stops it.
|
|
328
|
+
rootless = Engine::Program.service_root_refusal(environments.map { [_1.name, program.recipe(_1)] }, @project, Engine::CONFIG)
|
|
329
|
+
return refuse(rootless) if rootless
|
|
291
330
|
if kept.empty? && left_out.any?
|
|
292
331
|
return finish("run", false, findings: [left_out_stop(left_out, program)], verdict: "failed", exit_code: 1)
|
|
293
332
|
end
|
|
@@ -297,7 +336,8 @@ module Nukadoko
|
|
|
297
336
|
base = if commit
|
|
298
337
|
targets = @rest.empty? ? nil : @rest.map { _1.sub(/:\d+\z/, "") }
|
|
299
338
|
Engine::Base.new(project: @project, ref: ref, commit: commit, run_dir: dir, selected: kept.map { Engine::Criteria.key(_1.uri, _1.line) },
|
|
300
|
-
targets: targets, envs: @options["--env"], head_program: Nukadoko.program_options
|
|
339
|
+
targets: targets, envs: @options["--env"], head_program: Nukadoko.program_options,
|
|
340
|
+
paths_wanted: environments.any? { program.writes_events?(_1) })
|
|
301
341
|
end
|
|
302
342
|
# Workers are handed whole feature files, so one file has nothing to
|
|
303
343
|
# spread across them.
|
|
@@ -311,11 +351,12 @@ module Nukadoko
|
|
|
311
351
|
repeat: repeat, concurrency: concurrency, order: order, records: records, walk: @walk,
|
|
312
352
|
rerun: { targets: @rest, tags: @options["--tag"].flat_map { ["--tag", _1] }, whole_files: selection.whole_files }).call
|
|
313
353
|
passed = result.delete(:passed)
|
|
314
|
-
|
|
315
|
-
|
|
354
|
+
teardown = result.delete(:teardown_warnings)
|
|
355
|
+
findings += (@json ? teardown : []) + result.delete(:failures)
|
|
356
|
+
started = result.slice(:run_id, :run_dir, :started_at, :finished_at, :commit, :environments, :systems)
|
|
316
357
|
rest = result.except(*started.keys)
|
|
317
|
-
envelope = { **head("run", passed ? "passed" : "failed", findings,
|
|
318
|
-
**
|
|
358
|
+
envelope = { **head("run", passed ? "passed" : "failed", findings), **started, selection: selection.selection, tag_selection: selection.tag_selection,
|
|
359
|
+
**rest.slice(:order), check: @no_check ? "skipped" : "ran", **rest.except(:order) } #: Hash[Symbol, untyped]
|
|
319
360
|
envelope.delete(:tag_selection) unless envelope[:tag_selection]
|
|
320
361
|
# The limits restate the fields above, so they are read from them,
|
|
321
362
|
# and a run with none has no field.
|
|
@@ -363,28 +404,37 @@ module Nukadoko
|
|
|
363
404
|
end
|
|
364
405
|
|
|
365
406
|
# One pass of a `--base` tree, in the tree's own directory: the plan
|
|
366
|
-
# names the
|
|
407
|
+
# names the system, the environment, and the rows at their place in this
|
|
367
408
|
# tree, and the result goes to the file it names.
|
|
368
409
|
#: (Array[singleton(Step)]) -> Integer
|
|
369
410
|
def tree(steps)
|
|
370
411
|
plan = JSON.parse(File.read(@rest.first), symbolize_names: true)
|
|
371
|
-
found = Dir.chdir(@project) { Engine.load_features(plan[:targets].map { _1[:feature] }.uniq) }
|
|
372
|
-
scenarios = plan[:targets].filter_map { |target| found.find { _1.uri == target[:feature] && _1.line == target[:line] } }
|
|
373
412
|
result = begin
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
413
|
+
program = Engine::Program.new(Nukadoko.program_options)
|
|
414
|
+
environment = program.environments([plan[:environment]]).first
|
|
415
|
+
# Paths are compared only where both sides write execution events:
|
|
416
|
+
# a base that names no {events} would run a pass for nothing to
|
|
417
|
+
# compare.
|
|
418
|
+
targets = plan[:targets] + (program.writes_events?(environment) ? plan[:for_paths] || [] : [])
|
|
419
|
+
found = Dir.chdir(@project) { Engine.load_features(targets.map { _1[:feature] }.uniq) }
|
|
420
|
+
scenarios = targets.filter_map { |target| found.find { _1.uri == target[:feature] && _1.line == target[:line] } }
|
|
421
|
+
if scenarios.empty?
|
|
422
|
+
{ results: [], systems: [] }
|
|
423
|
+
else
|
|
424
|
+
usable = Engine::Check.new(steps, scenarios).usable
|
|
425
|
+
run = Engine::Run.new(@project, usable, scenarios, Nukadoko.program_options, environments: [environment],
|
|
426
|
+
system: plan[:system], dir: plan[:dir], out: @out, head: plan[:head])
|
|
427
|
+
{ results: run.tree_pass, systems: run.system_entries, builds: run.builds }
|
|
428
|
+
end
|
|
379
429
|
rescue Engine::Refusal => e
|
|
380
|
-
{ not_run: "the #{plan[:
|
|
430
|
+
{ not_run: "the #{plan[:system]} tree's program does not give this environment: #{e.message}" }
|
|
381
431
|
end
|
|
382
432
|
File.write(plan[:result], JSON.generate(result))
|
|
383
433
|
0
|
|
384
434
|
end
|
|
385
435
|
|
|
386
436
|
# `nuka do <step>`: one step alone, its args from --args and from the
|
|
387
|
-
# records --use names, in a
|
|
437
|
+
# records --use names, in a system started for it. The step record goes
|
|
388
438
|
# to stdout and to .nukadoko/do/<id>/record.json, where a later
|
|
389
439
|
# `nuka do --use` reads it. A refusal goes to stderr, since stdout is
|
|
390
440
|
# the record's.
|
|
@@ -431,6 +481,10 @@ module Nukadoko
|
|
|
431
481
|
name = @rest.first
|
|
432
482
|
step = check.usable.find { _1.step_name == name }
|
|
433
483
|
return refuse(Engine::Refusal.new("unknown-step", "Unknown step: #{name}", fix: "Name a step that nuka steps lists.", run: "nuka steps")) unless step
|
|
484
|
+
if Vocabulary.compat?(step)
|
|
485
|
+
return refuse(Engine::Refusal.new("compat-step-not-runnable", %(Step "#{name}" is a compat step and has no typed contract, so nuka do cannot run it alone),
|
|
486
|
+
fix: "Promote the step to a Nukadoko::Step to run it with nuka do.", run: "nuka do --help"))
|
|
487
|
+
end
|
|
434
488
|
|
|
435
489
|
describe = "nuka describe #{name}"
|
|
436
490
|
args_fix = "Pass --args as a JSON object with the keys that nuka describe <step> lists."
|
|
@@ -443,30 +497,56 @@ module Nukadoko
|
|
|
443
497
|
end
|
|
444
498
|
return refuse(Engine::Refusal.new("step-args-invalid", "--args must be a JSON object", fix: args_fix, run: describe)) unless given.is_a?(Hash)
|
|
445
499
|
end
|
|
446
|
-
args, origins, used = used_args(step, @options["--use"])
|
|
500
|
+
args, origins, used, files, events, drops = used_args(step, @options["--use"])
|
|
447
501
|
if @options["--args"].empty? && (step.args.required_names - args.keys).any?
|
|
448
502
|
return refuse(Engine::Refusal.new("step-args-invalid", "--args is required unless --use supplies this step's arguments", fix: args_fix, run: describe))
|
|
449
503
|
end
|
|
450
504
|
|
|
451
505
|
args = given.merge(args.reject { |key, _| given.key?(key) })
|
|
452
506
|
given.each_key { origins[_1] = "command_line:#{_1}" }
|
|
453
|
-
|
|
507
|
+
program = Engine::Program.new(Nukadoko.program_options)
|
|
508
|
+
# Without --env, nuka do runs in the environment named default,
|
|
509
|
+
# whatever a run would start.
|
|
510
|
+
environment = program.environments(@options["--env"].last(1).then { _1.empty? ? ["default"] : _1 }).first
|
|
511
|
+
if step.mutating? && program.policy(environment.name) == "read-only"
|
|
512
|
+
return refuse(Engine::Refusal.new("read-only-environment", %(Step "#{step.step_name}" mutates state but environment "#{environment.name}" has policy "read-only")))
|
|
513
|
+
end
|
|
514
|
+
rootless = program.file? ? Engine::Program.service_root_refusal([[environment.name, program.recipe(environment)]], @project, Engine::CONFIG) : nil
|
|
515
|
+
return refuse(rootless) if rootless
|
|
454
516
|
id = "step-#{Time.now.utc.strftime("%Y%m%d-%H%M%S")}-#{SecureRandom.alphanumeric(4).downcase}"
|
|
455
517
|
dir = File.join(@project, ".nukadoko", "do", id)
|
|
456
518
|
run = Engine::Run.new(@project, check.usable, [], Nukadoko.program_options, environments: [environment], dir: dir, out: $stderr)
|
|
457
519
|
texts = given.to_h { |key, value| [key, JSON.generate(value)] }
|
|
458
|
-
record = run.do_step(step, args, origins, texts, environment)
|
|
520
|
+
record = run.do_step(step, args, origins, texts, environment, files, events, drops)
|
|
521
|
+
# A system of more than one service names the service whose log the
|
|
522
|
+
# lines are in.
|
|
523
|
+
named = (record.dig(:program_log, :services) || {}).size > 1
|
|
524
|
+
(record[:program_log_late] || {}).each do |service, late|
|
|
525
|
+
where = late[:file] ? "see #{File.join(".nukadoko", "do", id, late[:file])}" : "they could not be written beside the record"
|
|
526
|
+
whose = named ? "service #{service}'s log" : "the program's log"
|
|
527
|
+
message = "system #{environment.name}: #{late[:lines]} line(s) of #{whose} carry the step's trace id and arrived after the step ended; #{where}"
|
|
528
|
+
$stderr.puts ["note", "program-log-late", "-", message].join("\t"), " fix: #{Engine::Codes.fix("program-log-late")}"
|
|
529
|
+
end
|
|
530
|
+
(record[:events_late] || {}).each do |service, late|
|
|
531
|
+
where = late[:file] ? "see #{File.join(".nukadoko", "do", id, late[:file])}" : "they could not be written beside the record"
|
|
532
|
+
whose = named ? "service #{service}'s execution events" : "the program's execution events"
|
|
533
|
+
message = "system #{environment.name}: #{late[:lines]} line(s) of #{whose} carry the step's trace id and arrived after the step ended; #{where}"
|
|
534
|
+
$stderr.puts ["note", "events-late", "-", message].join("\t"), " fix: #{Engine::Codes.fix("events-late")}"
|
|
535
|
+
end
|
|
459
536
|
written = run.redact(do_record(record, id, step, given, origins, used, environment))
|
|
460
537
|
File.write(File.join(dir, "record.json"), JSON.pretty_generate(written))
|
|
461
538
|
$stdout.puts JSON.pretty_generate(written)
|
|
462
539
|
record[:status] == "passed" ? 0 : 1
|
|
463
540
|
rescue Engine::Refusal => e
|
|
464
541
|
refuse(e)
|
|
542
|
+
rescue Engine::Program::StartFailed => e
|
|
543
|
+
finish("do", false, findings: [{ severity: "failed", code: "program-start-failed", message: e.message, fix: Engine::Codes.fix("program-start-failed") }])
|
|
465
544
|
end
|
|
466
545
|
|
|
467
546
|
# Each from key of the step, from the newest record --use names whose
|
|
468
|
-
# step gives it, and where it came from
|
|
469
|
-
|
|
547
|
+
# step gives it, and where it came from; and for each files key, the
|
|
548
|
+
# record of the one --use value whose step its `of` names.
|
|
549
|
+
#: (singleton(Step), Array[String]) -> [Hash[untyped, untyped], Hash[untyped, String], Array[Hash[Symbol, untyped]], ^(String, untyped) -> Hash[Symbol, untyped], ^(String, untyped) -> Hash[Symbol, untyped], Hash[String, Hash[Symbol, untyped]]]
|
|
470
550
|
def used_args(step, ids)
|
|
471
551
|
records = ids.map do |id|
|
|
472
552
|
path = [File.join(@project, ".nukadoko", "do", id, "record.json"), *Dir.glob(File.join(@project, ".nukadoko", "runs", "*", "steps", id, "record.json"))].find { File.exist?(_1) }
|
|
@@ -474,11 +554,13 @@ module Nukadoko
|
|
|
474
554
|
raise Engine::Refusal.new("step-inputs-invalid", "--use #{id}: no such step record. A step record is removed with its run once the run is older than the newest 20 runs, " \
|
|
475
555
|
"and a nuka do record once it is older than 7 days (retention in nukadoko.config.rb)")
|
|
476
556
|
end
|
|
557
|
+
(@use_dirs ||= {})[id] = File.dirname(path)
|
|
477
558
|
[id, JSON.parse(File.read(path))]
|
|
478
559
|
end
|
|
479
560
|
args = {}
|
|
480
561
|
origins = {}
|
|
481
562
|
used = []
|
|
563
|
+
drops = {}
|
|
482
564
|
step.from.each do |key, sources|
|
|
483
565
|
sources.each do |cls, source_key|
|
|
484
566
|
id, found = records.reverse.find { |_, record| record["step"] == cls.step_name && record["result"].is_a?(Hash) && record["result"].key?(source_key.to_s) }
|
|
@@ -486,11 +568,119 @@ module Nukadoko
|
|
|
486
568
|
|
|
487
569
|
args[key] = found["result"][source_key.to_s]
|
|
488
570
|
origins[key] = "from:#{cls.step_name}@#{id}.#{source_key}"
|
|
571
|
+
# A record the --use value came from says which keys its returns dropped; one written before it did says nothing, and no claim is held back.
|
|
572
|
+
drops[key.to_s] = { step: cls.step_name, key: source_key, dropped: found["returns_dropped"]&.map { { at: _1["at"] || [], keys: _1["keys"] || [] } } }
|
|
489
573
|
used << { step_record_id: id, step: cls.step_name, result: found["result"] } unless used.any? { _1[:step_record_id] == id }
|
|
490
574
|
break
|
|
491
575
|
end
|
|
492
576
|
end
|
|
493
|
-
[args, origins, used]
|
|
577
|
+
[args, origins, used, used_files(step, records), used_events(step, records), drops]
|
|
578
|
+
end
|
|
579
|
+
|
|
580
|
+
# A list is the files of one execution, so two --use records for one
|
|
581
|
+
# files key are refused, and a key no --use supplies is unjudged: under
|
|
582
|
+
# nuka do no earlier line ran, and --use is how a producer is named.
|
|
583
|
+
#: (singleton(Step), Array[untyped]) -> ^(String, untyped) -> Hash[Symbol, untyped]
|
|
584
|
+
def used_files(step, records)
|
|
585
|
+
chosen = {} #: Hash[String, [String, Hash[String, untyped]]]
|
|
586
|
+
step.files.each do |key, entry|
|
|
587
|
+
names = Engine::ChangedFiles.producers(entry).map(&:step_name)
|
|
588
|
+
records.each do |id, record|
|
|
589
|
+
next unless names.include?(record["step"])
|
|
590
|
+
|
|
591
|
+
if (earlier = chosen[key]) && earlier.first != id
|
|
592
|
+
raise Engine::Refusal.new("step-inputs-invalid", %(--use: files key "#{key}" is supplied by both step record #{earlier.first} (step "#{earlier.last["step"]}") and ) +
|
|
593
|
+
%(step record #{id} (step "#{record["step"]}"), and nuka do reads the files of one step record per key))
|
|
594
|
+
end
|
|
595
|
+
chosen[key] = [id, record]
|
|
596
|
+
end
|
|
597
|
+
end
|
|
598
|
+
lambda do |key, entry|
|
|
599
|
+
if (found = chosen[key])
|
|
600
|
+
id, record = found
|
|
601
|
+
processes = record.dig("observed", "processes")
|
|
602
|
+
next { of: "#{record["step"]}@#{id}", record: { step_record_id: id, processes: processes && JSON.parse(JSON.generate(processes), symbolize_names: true) } }
|
|
603
|
+
end
|
|
604
|
+
|
|
605
|
+
names = Engine::ChangedFiles.producers(entry).map(&:step_name)
|
|
606
|
+
{ of: names.join(" or "),
|
|
607
|
+
unchosen: "files.#{key}.of names #{names.map { %("#{_1}") }.join(" or ")}, and no --use value names a step record of #{names.size == 1 ? "it" : "any of them"}, so nuka do has no files to read" }
|
|
608
|
+
end
|
|
609
|
+
end
|
|
610
|
+
|
|
611
|
+
# Each events key reads the record --use named for it, one record per
|
|
612
|
+
# key, since a count is of one execution. A key no --use supplies is
|
|
613
|
+
# unjudged with the reason: under nuka do no earlier line ran, and
|
|
614
|
+
# --use is how a producer is named.
|
|
615
|
+
#: (singleton(Step), Array[untyped]) -> ^(String, untyped) -> Hash[Symbol, untyped]
|
|
616
|
+
def used_events(step, records)
|
|
617
|
+
chosen = {} #: Hash[String, [String, Hash[String, untyped]]]
|
|
618
|
+
step.events.each do |key, entry|
|
|
619
|
+
names = Engine::ChangedFiles.producers(entry).map(&:step_name)
|
|
620
|
+
records.each do |id, record|
|
|
621
|
+
next unless names.include?(record["step"])
|
|
622
|
+
|
|
623
|
+
if (earlier = chosen[key]) && earlier.first != id
|
|
624
|
+
raise Engine::Refusal.new("step-inputs-invalid", %(--use: events key "#{key}" is supplied by both step record #{earlier.first} (step "#{earlier.last["step"]}") and ) +
|
|
625
|
+
%(step record #{id} (step "#{record["step"]}"), and nuka do counts the execution events of one step record per key))
|
|
626
|
+
end
|
|
627
|
+
chosen[key] = [id, record]
|
|
628
|
+
end
|
|
629
|
+
end
|
|
630
|
+
lambda do |key, entry|
|
|
631
|
+
if (found = chosen[key])
|
|
632
|
+
id, record = found
|
|
633
|
+
next { of: "#{record["step"]}@#{id}", producer: recorded_events_producer(id, record) }
|
|
634
|
+
end
|
|
635
|
+
|
|
636
|
+
names = Engine::ChangedFiles.producers(entry).map(&:step_name)
|
|
637
|
+
{ of: names.join(" or "),
|
|
638
|
+
unchosen: "events.#{key}.of names #{names.map { %("#{_1}") }.join(" or ")}, and no --use value names a step record of #{names.size == 1 ? "it" : "any of them"}, " \
|
|
639
|
+
"so nuka do has no execution events to count" }
|
|
640
|
+
end
|
|
641
|
+
end
|
|
642
|
+
|
|
643
|
+
# Where a finished step record's execution events are: its directory
|
|
644
|
+
# with its slice and late lines, whether the late lines are all there,
|
|
645
|
+
# and the system's copy, whose kinds count as reported. A late file
|
|
646
|
+
# whose count no record names may be cut short, so it counts as
|
|
647
|
+
# truncated: an absence then stays unjudged.
|
|
648
|
+
#: (String, Hash[String, untyped]) -> Hash[Symbol, untyped]
|
|
649
|
+
def recorded_events_producer(id, record)
|
|
650
|
+
dir = (@use_dirs || {}).fetch(id)
|
|
651
|
+
symbolized = JSON.parse(JSON.generate(record), symbolize_names: true)
|
|
652
|
+
run_id = symbolized[:run_id]
|
|
653
|
+
run = run_id && begin
|
|
654
|
+
JSON.parse(File.read(File.join(@project, ".nukadoko", "runs", run_id, "run.json")), symbolize_names: true)
|
|
655
|
+
rescue SystemCallError, JSON::ParserError
|
|
656
|
+
nil
|
|
657
|
+
end
|
|
658
|
+
scenario = run && run[:scenarios].find { |entry| entry[:steps].any? { _1[:step_record_id] == id } }
|
|
659
|
+
step = scenario && scenario[:steps].find { _1[:step_record_id] == id }
|
|
660
|
+
of = { step_record_id: id, step: symbolized[:step], line: step && step[:line] }
|
|
661
|
+
observed = symbolized[:observed] || {}
|
|
662
|
+
slice = observed[:events]
|
|
663
|
+
return { source: "unread", of: of, gap: "system-unread" } if observed.key?(:events) && slice.nil?
|
|
664
|
+
log_read = (observed.dig(:program_log, :services) || {}).values.any?
|
|
665
|
+
return { source: "unread", of: of, gap: log_read ? "inlet-unnamed" : "system-unread" } unless slice
|
|
666
|
+
|
|
667
|
+
# Every service whose lines the record holds: its late file is beside
|
|
668
|
+
# the record under its name, and its copy under the system's.
|
|
669
|
+
services = (slice[:services] || {}).keys.map(&:to_s)
|
|
670
|
+
may_miss = lambda do |late|
|
|
671
|
+
next services.any? { File.exist?(File.join(dir, Engine::Events.late_file(_1))) } if late.nil?
|
|
672
|
+
|
|
673
|
+
late.each_value.any? { _1[:truncated] == true || (_1[:lines].to_i.positive? && _1[:file].nil?) }
|
|
674
|
+
end
|
|
675
|
+
if run_id.nil?
|
|
676
|
+
copies = services.map { File.join(dir, "system", _1, Engine::Events::SYSTEM_FILE) }.select { File.exist?(_1) }
|
|
677
|
+
return { source: "recorded", of: of, dir: dir, slice: slice, late_truncated: may_miss.(symbolized[:events_late]), **(copies.empty? ? {} : { system: copies }) }
|
|
678
|
+
end
|
|
679
|
+
|
|
680
|
+
ran = scenario && run[:systems]&.find { _1[:name] == scenario[:environment] && _1[:tree] == (scenario[:system] || "head") }
|
|
681
|
+
# A run.json an earlier build wrote has no services: its copies are not found.
|
|
682
|
+
copies = (ran&.[](:services) || []).filter_map { _1.dig(:events, :file) }.map { File.join(@project, ".nukadoko", "runs", run_id, _1) }
|
|
683
|
+
{ source: "recorded", of: of, dir: dir, slice: slice, late_truncated: may_miss.(step&.[](:events_late)), **(copies.empty? ? {} : { system: copies }) }
|
|
494
684
|
end
|
|
495
685
|
|
|
496
686
|
# The record `nuka do` prints, in the TypeScript engine's shape.
|
|
@@ -506,16 +696,18 @@ module Nukadoko
|
|
|
506
696
|
end
|
|
507
697
|
end
|
|
508
698
|
passed = record[:status] == "passed"
|
|
509
|
-
outcome = passed ? { result: record[:result] || {}, returns_dropped: record[:returns_dropped] || [] } : { error: { message: record[:error], kind: record[:error_kind] } }
|
|
699
|
+
outcome = passed ? { result: record[:result] || {}, **(step.claims ? {} : { returns_dropped: record[:returns_dropped] || [] }) } : { error: { message: record[:error], kind: record[:error_kind] } }
|
|
510
700
|
processes = record[:processes]
|
|
511
701
|
{ schema_version: Engine::RunRecord::SCHEMA_VERSION, nukadoko: VERSION, step_record_id: id, step: step.step_name, kind: "do",
|
|
512
702
|
args: record[:args] || given, args_origin: args_origin, **outcome, status: record[:status], environment: environment.name,
|
|
513
|
-
|
|
703
|
+
system_name: Engine::Program.new(Nukadoko.program_options).file? ? environment.name : nil, **(record[:target_version] ? { target_version: record[:target_version] } : {}),
|
|
704
|
+
scenario_record_id: nil, run_id: nil, started_at: record[:started_at], finished_at: record[:finished_at],
|
|
514
705
|
evidence: { dir: File.join(".nukadoko", "do", id), screenshots: [] },
|
|
515
706
|
observed: { processes: processes&.any? ? processes : nil,
|
|
516
|
-
http: record[:http_count]&.positive? ? record[:http_count] : nil, files: nil, unmeasured: []
|
|
517
|
-
|
|
518
|
-
|
|
707
|
+
http: record[:http_count]&.positive? ? record[:http_count] : nil, files: nil, unmeasured: [],
|
|
708
|
+
**(record.key?(:program_log) ? { program_log: record[:program_log] } : {}), **(record.key?(:events) ? { events: record[:events] } : {}) },
|
|
709
|
+
mutates: record[:mutates], **(used.any? ? { used: used } : {}), **(record[:events_late] ? { events_late: record[:events_late] } : {}),
|
|
710
|
+
**(record[:claim_records] ? { claims: record[:claim_records], observation: record[:observation] || "observed", attempts: 1, **Engine::RunRecord.read_fields(record) } : {}) }
|
|
519
711
|
end
|
|
520
712
|
|
|
521
713
|
#: (Engine::Scenario, Array[Engine::Environment]) -> bool
|
|
@@ -524,6 +716,92 @@ module Nukadoko
|
|
|
524
716
|
environments.any? { Engine::Table.role(tags, _1.conditions) == "required" }
|
|
525
717
|
end
|
|
526
718
|
|
|
719
|
+
# `nuka check --codes`: every code `nuka check` and `nuka run` can print,
|
|
720
|
+
# as findings with no location, and no project read. It answers what
|
|
721
|
+
# could ever be reported, so it holds while the project's config is
|
|
722
|
+
# broken, which is when a reader often reaches for it.
|
|
723
|
+
#: () -> Integer
|
|
724
|
+
def codes
|
|
725
|
+
listed = Engine::Codes.listed
|
|
726
|
+
if @json
|
|
727
|
+
@out.puts JSON.pretty_generate({ **head("check", "passed", []), codes: listed })
|
|
728
|
+
else
|
|
729
|
+
emit({}, listed, "codes")
|
|
730
|
+
end
|
|
731
|
+
0
|
|
732
|
+
end
|
|
733
|
+
|
|
734
|
+
# What makes a step file's definition unreadable, as check names it.
|
|
735
|
+
DEFINITION_CODES = %w[step-file-import-failed duplicate-capture-key invalid-capture-key unknown-parameter-type unnamed-capture unterminated-capture].freeze
|
|
736
|
+
|
|
737
|
+
# `--fail-on` codes, repeated or comma-separated, each once.
|
|
738
|
+
#: () -> Array[String]
|
|
739
|
+
def fail_on = @options["--fail-on"].flat_map { _1.split(",") }.map(&:strip).reject(&:empty?).uniq
|
|
740
|
+
|
|
741
|
+
# The feature files `nuka check <targets>` reads, relative to the
|
|
742
|
+
# project: a file, or each feature file under a directory. A target
|
|
743
|
+
# with a `:line` is refused, since check analyzes whole files.
|
|
744
|
+
#: (Array[String]) -> Array[String]
|
|
745
|
+
def check_targets(targets)
|
|
746
|
+
targets.flat_map do |target|
|
|
747
|
+
absolute = File.expand_path(target, @project)
|
|
748
|
+
relative = absolute.delete_prefix("#{File.expand_path(@project)}/")
|
|
749
|
+
shown = relative.start_with?("/") ? absolute : relative
|
|
750
|
+
unless File.exist?(absolute)
|
|
751
|
+
line = shown.match(/\A(.+):(\d+)\z/)
|
|
752
|
+
if line && File.exist?(File.expand_path(line[1], @project))
|
|
753
|
+
raise Engine::Refusal.new("line-not-supported", "nuka check: #{line[1]}:#{line[2]}: :line is not supported; check analyzes the whole file, not one scenario",
|
|
754
|
+
run: "nuka check #{Engine::Selection.shell_word(line[1])}")
|
|
755
|
+
end
|
|
756
|
+
raise Engine::Refusal.new("target-not-found", "nuka check: feature file not found: #{shown}")
|
|
757
|
+
end
|
|
758
|
+
next [shown] unless File.directory?(absolute)
|
|
759
|
+
|
|
760
|
+
Dir.glob("**/*.feature", base: absolute).sort.map { File.join(shown, _1) }
|
|
761
|
+
end.uniq
|
|
762
|
+
end
|
|
763
|
+
|
|
764
|
+
# A `--fail-on` gate that could never fire is refused before anything
|
|
765
|
+
# is read: a code the check never reports (unknown, or a run or refusal
|
|
766
|
+
# code), and a note under targets, since a note is a fact about the
|
|
767
|
+
# whole project.
|
|
768
|
+
#: () -> Engine::Refusal?
|
|
769
|
+
def fail_on_refusal
|
|
770
|
+
bad = fail_on.reject { Engine::Codes.check?(_1) }
|
|
771
|
+
if bad.any?
|
|
772
|
+
unknown, elsewhere = bad.partition { Engine::Codes.severity(_1).nil? }
|
|
773
|
+
quoted = ->(codes) { codes.map { %("#{_1}") }.join(", ") }
|
|
774
|
+
parts = []
|
|
775
|
+
parts << "#{quoted.(unknown)} #{unknown.size == 1 ? "is not a code" : "are not codes"} nuka check reports" if unknown.any?
|
|
776
|
+
if elsewhere.any?
|
|
777
|
+
parts << "#{quoted.(elsewhere)} #{elsewhere.size == 1 ? "is a nuka run or refusal code" : "are nuka run or refusal codes"}, " \
|
|
778
|
+
"which a check report never contains"
|
|
779
|
+
end
|
|
780
|
+
return Engine::Refusal.new("fail-on-unknown-code", "--fail-on: #{parts.join("; ")}", run: "nuka check --codes")
|
|
781
|
+
end
|
|
782
|
+
notes = @rest.empty? ? [] : fail_on.select { Engine::Codes.severity(_1) == "note" }
|
|
783
|
+
return nil if notes.empty?
|
|
784
|
+
|
|
785
|
+
whole = ["nuka", "check", "--fail-on", fail_on.join(","), *@options["--env"].flat_map { ["--env", _1] }].map { Engine::Selection.shell_word(_1) }.join(" ")
|
|
786
|
+
Engine::Refusal.new("fail-on-note-with-targets",
|
|
787
|
+
"--fail-on: #{notes.map { %("#{_1}") }.join(", ")} #{notes.size == 1 ? "is a note" : "are notes"}, and a nuka check with " \
|
|
788
|
+
"targets computes no notes, since a note is a fact about the whole project", run: whole)
|
|
789
|
+
end
|
|
790
|
+
|
|
791
|
+
# The report, then one line for each `--fail-on` code it holds, so the
|
|
792
|
+
# exit code never changes silently. The finding keeps its severity: what
|
|
793
|
+
# changed is the project's policy, not the finding.
|
|
794
|
+
#: (Engine::Check, Array[Hash[Symbol, untyped]]) -> Integer
|
|
795
|
+
def checked(check, findings)
|
|
796
|
+
hits = fail_on.filter_map do |code|
|
|
797
|
+
count = findings.count { _1[:code] == code }
|
|
798
|
+
{ code: code, count: count } if count.positive?
|
|
799
|
+
end
|
|
800
|
+
exit_code = finish("check", check.passed? && hits.empty?, findings: findings, fail_on_hits: hits)
|
|
801
|
+
hits.each { $stderr.puts "fail-on: #{_1[:code]} reported #{_1[:count]} #{_1[:count] == 1 ? "finding" : "findings"}" } unless @json
|
|
802
|
+
exit_code
|
|
803
|
+
end
|
|
804
|
+
|
|
527
805
|
# The `nuka check` that reports the same errors: the files the targets
|
|
528
806
|
# name, and each --env.
|
|
529
807
|
#: () -> String
|
|
@@ -781,11 +1059,71 @@ module Nukadoko
|
|
|
781
1059
|
#: () -> Array[Engine::Finding]
|
|
782
1060
|
def env_findings
|
|
783
1061
|
Engine::EnvCheck.validate!
|
|
784
|
-
Engine::EnvCheck.findings(@project)
|
|
1062
|
+
Engine::EnvCheck.findings(@project) + placeholder_findings
|
|
785
1063
|
rescue Engine::EnvFile::Unreadable => e
|
|
786
1064
|
raise Engine::Refusal.new("env-file-unreadable", e.message)
|
|
787
1065
|
end
|
|
788
1066
|
|
|
1067
|
+
# A placeholder a system this invocation starts has no value for fails
|
|
1068
|
+
# that system before its program starts, and the program alone says so.
|
|
1069
|
+
# The systems a run with this invocation's --env starts, each with how
|
|
1070
|
+
# it is reached, whether its program names {events}, whether it
|
|
1071
|
+
# declares setup, and what it declares with stepsReach; nil with no
|
|
1072
|
+
# program, and none when --env names no environment.
|
|
1073
|
+
#: () -> Array[Hash[Symbol, untyped]]?
|
|
1074
|
+
def started_systems
|
|
1075
|
+
program = Engine::Program.new(Nukadoko.program_options)
|
|
1076
|
+
return nil unless program.file?
|
|
1077
|
+
|
|
1078
|
+
program.environments(Array(@options["--env"])).map do |environment|
|
|
1079
|
+
recipe = program.recipe(environment)
|
|
1080
|
+
primary = recipe.primary_service
|
|
1081
|
+
# Any served service that names {events} gives the system a file,
|
|
1082
|
+
# so the inlet is there even when the primary names none.
|
|
1083
|
+
{ name: environment.name, kind: primary.reach[:kind], events: program.writes_events?(environment),
|
|
1084
|
+
setup: !recipe.setup.nil?, steps_reach: recipe.steps_reach, services: recipe.services.map { _1.name.to_s } }
|
|
1085
|
+
end
|
|
1086
|
+
rescue Engine::Refusal
|
|
1087
|
+
[]
|
|
1088
|
+
end
|
|
1089
|
+
|
|
1090
|
+
# A system no command of this invocation starts is not checked.
|
|
1091
|
+
#: () -> Array[Engine::Finding]
|
|
1092
|
+
def placeholder_findings
|
|
1093
|
+
program = Engine::Program.new(Nukadoko.program_options)
|
|
1094
|
+
environments = begin
|
|
1095
|
+
program.environments(Array(@options["--env"]))
|
|
1096
|
+
rescue Engine::Refusal
|
|
1097
|
+
[]
|
|
1098
|
+
end
|
|
1099
|
+
# The one old name nukadoko can still see in a config, reported
|
|
1100
|
+
# before the gaps: a field that names it has no gap at all, since
|
|
1101
|
+
# the name is not one nukadoko fills.
|
|
1102
|
+
renamed = environments.flat_map do |environment|
|
|
1103
|
+
Engine::Program.renamed_placeholder_list(program.recipe(environment)).map do |old|
|
|
1104
|
+
Engine::Finding.new("error", "program-placeholder-renamed", Engine::CONFIG, nil, nil,
|
|
1105
|
+
"system #{environment.name}: #{Engine::Program.describe_renamed_placeholder(old)}",
|
|
1106
|
+
Engine::Program.renamed_placeholder_fix(old, Engine::CONFIG), nil)
|
|
1107
|
+
end
|
|
1108
|
+
end
|
|
1109
|
+
gaps = environments.flat_map do |environment|
|
|
1110
|
+
Engine::Program.placeholder_gap_list(program.recipe(environment)).map do |gap|
|
|
1111
|
+
text = "#{gap[:where]} names {#{gap[:name]}}, which has no value here: #{gap[:why]}"
|
|
1112
|
+
fix = Engine::Program.placeholder_gap_fix(gap, environment.name, Engine::CONFIG, Nukadoko.program_options[:environments] || {})
|
|
1113
|
+
Engine::Finding.new("error", "program-placeholder-unfilled", Engine::CONFIG, nil, nil, "system #{environment.name}: #{text}", fix, nil)
|
|
1114
|
+
end
|
|
1115
|
+
end
|
|
1116
|
+
# A checkout this invocation's systems run in and the machine does not
|
|
1117
|
+
# have: an environment that reaches the service at a url names no
|
|
1118
|
+
# root of the top level's, so a run against deployed services never
|
|
1119
|
+
# needs the clone.
|
|
1120
|
+
rootless = Engine::Program.missing_service_roots(environments.map { [_1.name, program.recipe(_1)] }, @project).map do |missing|
|
|
1121
|
+
Engine::Finding.new("error", "program-service-root-missing", Engine::CONFIG, nil, nil, Engine::Program.describe_missing_service_root(missing),
|
|
1122
|
+
Engine::Program.missing_service_root_fix(missing, Engine::CONFIG), nil)
|
|
1123
|
+
end
|
|
1124
|
+
renamed + gaps + rootless
|
|
1125
|
+
end
|
|
1126
|
+
|
|
789
1127
|
#: (Engine::Refusal) -> Integer
|
|
790
1128
|
def refuse(refusal)
|
|
791
1129
|
finish(@command, false, findings: [refusal.to_h(@command)], verdict: refusal.severity, exit_code: refusal.exit_code)
|
|
@@ -806,19 +1144,28 @@ module Nukadoko
|
|
|
806
1144
|
def finish(command, passed, findings:, verdict: passed ? "passed" : "failed", exit_code: passed ? 0 : 1, **rest)
|
|
807
1145
|
# What a walk that stops here ends with.
|
|
808
1146
|
@stopped_with = findings
|
|
809
|
-
|
|
1147
|
+
# A refusal is not the command's output: the TypeScript engine writes
|
|
1148
|
+
# it to stderr, where a shell that keeps stdout for a result leaves it.
|
|
1149
|
+
emit({ **head(command, verdict, findings), **rest }, findings, command, io: verdict == "refused" ? $stderr : @out)
|
|
810
1150
|
exit_code
|
|
811
1151
|
end
|
|
812
1152
|
|
|
1153
|
+
# A finding is one line and its fix and do one line each, so a reader
|
|
1154
|
+
# that splits on newlines and tabs gets the fields back.
|
|
1155
|
+
#: (untyped) -> String
|
|
1156
|
+
def one_line(text)
|
|
1157
|
+
text.to_s.gsub(/\s*[\r\n
]\s*/, " ").tr("\t", " ")
|
|
1158
|
+
end
|
|
1159
|
+
|
|
813
1160
|
#: (Hash[Symbol, untyped], Array[untyped], String?, ?io: IO) -> void
|
|
814
1161
|
def emit(envelope, findings, command, io: @out)
|
|
815
1162
|
if @json
|
|
816
1163
|
@out.puts JSON.pretty_generate(envelope)
|
|
817
1164
|
else
|
|
818
1165
|
findings.each do |f|
|
|
819
|
-
io.puts [f[:severity], f[:code], Engine::Summary.where_of(f), f[:message]].join("\t")
|
|
820
|
-
io.puts " fix: #{f[:fix]}" if f[:fix]
|
|
821
|
-
io.puts " do: #{f[:do]}" if f[:do]
|
|
1166
|
+
io.puts [f[:severity], f[:code], one_line(Engine::Summary.where_of(f)), one_line(f[:message])].join("\t")
|
|
1167
|
+
io.puts " fix: #{one_line(f[:fix])}" if f[:fix]
|
|
1168
|
+
io.puts " do: #{one_line(f[:do])}" if f[:do]
|
|
822
1169
|
end
|
|
823
1170
|
io.puts "ok: no issues found" if command == "check" && findings.empty?
|
|
824
1171
|
end
|
|
@@ -843,7 +1190,7 @@ module Nukadoko
|
|
|
843
1190
|
table = envelope[:table] #: Hash[Symbol, untyped]
|
|
844
1191
|
rows = table[:rows] #: Array[Hash[Symbol, untyped]]
|
|
845
1192
|
based = !table[:base].nil?
|
|
846
|
-
if based || counts[:controls].positive?
|
|
1193
|
+
if based || counts[:controls].positive? || envelope[:scenarios].any? { !_1[:system] && Engine::Underneath.demoting(_1) }
|
|
847
1194
|
count = ->(word) { rows.count { _1[:verdict] == word } }
|
|
848
1195
|
extra = based ? ", #{count.("unproven")} unproven, #{count.("moved")} moved, #{count.("removed")} removed" : ""
|
|
849
1196
|
io.puts "criteria: #{count.("held")} held, #{count.("proven")} proven, #{count.("failed")} failed#{extra}"
|
|
@@ -869,7 +1216,7 @@ module Nukadoko
|
|
|
869
1216
|
#: (Array[Hash[Symbol, untyped]], IO) -> void
|
|
870
1217
|
def repeat_tallies(scenarios, io)
|
|
871
1218
|
named = @options["--env"].size > 1
|
|
872
|
-
scenarios.reject { _1[:
|
|
1219
|
+
scenarios.reject { _1[:system] }.group_by { _1.values_at(:feature, :line, :environment) }.each_value do |runs|
|
|
873
1220
|
passed = runs.count { _1[:status] == "passed" }
|
|
874
1221
|
next if passed == runs.size
|
|
875
1222
|
|