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
|
@@ -0,0 +1,469 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
# rbs_inline: enabled
|
|
3
|
+
|
|
4
|
+
require "cucumber/cucumber_expressions/cucumber_expression"
|
|
5
|
+
require "cucumber/cucumber_expressions/regular_expression"
|
|
6
|
+
|
|
7
|
+
# The door a cucumber-ruby suite comes in through: its step definitions and
|
|
8
|
+
# support files load as they are, with `Given`, `When`, `Then`, `Before`,
|
|
9
|
+
# `After`, `World`, and `ParameterType` at the top level, as cucumber-ruby
|
|
10
|
+
# defines them, and each line they bind runs with a measured step record.
|
|
11
|
+
# A compat step has no contract: its arguments are the captures in order,
|
|
12
|
+
# then a table or a docstring, and it is named by its pattern
|
|
13
|
+
# (`compat: <pattern>`). It covers the subset suites use most; anything
|
|
14
|
+
# else fails when the file loads or when the step runs, never by doing
|
|
15
|
+
# something other than what cucumber-ruby did.
|
|
16
|
+
module Nukadoko
|
|
17
|
+
module Compat
|
|
18
|
+
# What the door refuses, named so a migrating suite sees why.
|
|
19
|
+
class Unsupported < StandardError; end
|
|
20
|
+
|
|
21
|
+
# `pending` in a step: cucumber-ruby's Cucumber::Pending. nukadoko has
|
|
22
|
+
# no pending outcome, so the step fails and says so.
|
|
23
|
+
class Pending < StandardError; end
|
|
24
|
+
|
|
25
|
+
# A step definition as the glue registered it.
|
|
26
|
+
Registration = Data.define(:keyword, :pattern, :block, :file, :line)
|
|
27
|
+
|
|
28
|
+
class Registration
|
|
29
|
+
# The pattern's text, as `nuka steps` and the step's name show it.
|
|
30
|
+
#: () -> String
|
|
31
|
+
def source = pattern.is_a?(Regexp) ? pattern.inspect : pattern.to_s
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# A Before, After, AfterStep, BeforeAll, or AfterAll hook.
|
|
35
|
+
Hook = Data.define(:type, :tags, :name, :block, :file, :line)
|
|
36
|
+
|
|
37
|
+
HOOK_TYPES = %i[before after after_step before_all after_all].freeze
|
|
38
|
+
STEP_OPTIONS = %i[].freeze
|
|
39
|
+
PARAMETER_TYPE_KEYS = %i[name regexp type transformer use_for_snippets prefer_for_regexp_match].freeze
|
|
40
|
+
|
|
41
|
+
class << self
|
|
42
|
+
#: () -> Array[Registration]
|
|
43
|
+
def steps = (@steps ||= [])
|
|
44
|
+
#: () -> Array[Hook]
|
|
45
|
+
def hooks = (@hooks ||= [])
|
|
46
|
+
#: () -> Array[Module]
|
|
47
|
+
def world_modules = (@world_modules ||= [])
|
|
48
|
+
#: () -> Proc?
|
|
49
|
+
def world_factory = @world_factory
|
|
50
|
+
|
|
51
|
+
#: (Proc?) -> Proc?
|
|
52
|
+
def world_factory=(value)
|
|
53
|
+
@world_factory = value
|
|
54
|
+
end
|
|
55
|
+
#: () -> Array[Hash[Symbol, untyped]]
|
|
56
|
+
def parameter_types = (@parameter_types ||= [])
|
|
57
|
+
# Each glue file that raised while it loaded, with the first line of
|
|
58
|
+
# what it raised.
|
|
59
|
+
#: () -> Array[[String, String]]
|
|
60
|
+
def load_failures = (@load_failures ||= [])
|
|
61
|
+
|
|
62
|
+
#: () -> void
|
|
63
|
+
def reset
|
|
64
|
+
@steps = @hooks = @world_modules = @parameter_types = @load_failures = nil
|
|
65
|
+
@world_factory = nil
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
#: (Symbol) -> Array[Hook]
|
|
69
|
+
def hooks_of(type) = hooks.select { _1.type == type }
|
|
70
|
+
|
|
71
|
+
# A new World for one scenario: the factory's object, or a plain one,
|
|
72
|
+
# with every `World` module in and the door's own methods on it.
|
|
73
|
+
#: () -> untyped
|
|
74
|
+
def new_world
|
|
75
|
+
factory = world_factory
|
|
76
|
+
world = factory ? factory.call : Object.new
|
|
77
|
+
world.extend(WorldMethods)
|
|
78
|
+
world_modules.each { world.extend(_1) }
|
|
79
|
+
world
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
# A hook's tag expression in the one shape the door reads: `@tag` or
|
|
84
|
+
# `not @tag`. Anything wider would match differently than cucumber-ruby
|
|
85
|
+
# if read loosely, so it is refused.
|
|
86
|
+
TAG = /\A(?:not\s+)?@[^\s()]+\z/
|
|
87
|
+
|
|
88
|
+
#: (String) -> bool
|
|
89
|
+
def self.tag_expression?(text) = TAG.match?(text.strip)
|
|
90
|
+
|
|
91
|
+
# Whether a hook applies to a scenario with `tags`: every one of its
|
|
92
|
+
# expressions holds, as cucumber-ruby ands several of them.
|
|
93
|
+
#: (Hook, Array[String]) -> bool
|
|
94
|
+
def self.applies?(hook, tags)
|
|
95
|
+
hook.tags.all? do |expression|
|
|
96
|
+
raise Unsupported, unsupported_tags(expression) unless tag_expression?(expression)
|
|
97
|
+
|
|
98
|
+
negated, tag = expression.strip.split(/\s+/, 2).then { _2 ? [true, _2] : [false, _1] }
|
|
99
|
+
tags.include?(tag) != negated
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
#: (String) -> String
|
|
104
|
+
def self.unsupported_tags(expression)
|
|
105
|
+
%(Unsupported hook tag expression "#{expression}": the compat door supports only a single "@tag" or its negation "not @tag", ) +
|
|
106
|
+
"not Cucumber's full tag expression grammar (and/or/parentheses); a hook may name several, each of which must hold"
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
# The methods cucumber-ruby's glue calls at the top level of a file.
|
|
110
|
+
module Dsl
|
|
111
|
+
%i[Given When Then And But].each do |keyword|
|
|
112
|
+
define_method(keyword) do |pattern, options = {}, &block|
|
|
113
|
+
Compat.register_step(keyword, pattern, options, block)
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
#: (*String, ?name: String?) { (untyped) -> void } -> void
|
|
118
|
+
def Before(*tags, name: nil, &block) = Compat.register_hook(:before, tags, name, block)
|
|
119
|
+
#: (*String, ?name: String?) { (untyped) -> void } -> void
|
|
120
|
+
def After(*tags, name: nil, &block) = Compat.register_hook(:after, tags, name, block)
|
|
121
|
+
#: (*String, ?name: String?) { (untyped, untyped) -> void } -> void
|
|
122
|
+
def AfterStep(*tags, name: nil, &block) = Compat.register_hook(:after_step, tags, name, block)
|
|
123
|
+
#: (?name: String?) { () -> void } -> void
|
|
124
|
+
def BeforeAll(name: nil, &block) = Compat.register_hook(:before_all, [], name, block)
|
|
125
|
+
#: (?name: String?) { () -> void } -> void
|
|
126
|
+
def AfterAll(name: nil, &block) = Compat.register_hook(:after_all, [], name, block)
|
|
127
|
+
|
|
128
|
+
#: (*untyped) -> void
|
|
129
|
+
def Around(*)
|
|
130
|
+
raise Unsupported, "Around hooks are not part of nukadoko's compat door: split the hook into a Before and an After"
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
#: (*untyped) -> void
|
|
134
|
+
def InstallPlugin(*) = raise(Unsupported, "InstallPlugin is cucumber-ruby's own configuration, which nukadoko does not run")
|
|
135
|
+
#: (*untyped) -> void
|
|
136
|
+
def AfterConfiguration(*) = raise(Unsupported, "AfterConfiguration is cucumber-ruby's own configuration, which nukadoko does not run")
|
|
137
|
+
|
|
138
|
+
# `World(Module, ...)` mixes modules into every scenario's World, and
|
|
139
|
+
# `World { MyWorld.new }` makes the World itself, as cucumber-ruby does.
|
|
140
|
+
#: (*Module, **Module) ?{ () -> untyped } -> void
|
|
141
|
+
def World(*modules, **namespaced, &factory)
|
|
142
|
+
unless namespaced.empty?
|
|
143
|
+
raise Unsupported, "World with namespaced modules (World(#{namespaced.keys.first}: ...)) is not part of nukadoko's compat door: " \
|
|
144
|
+
"mix the module in with World(Module)"
|
|
145
|
+
end
|
|
146
|
+
Compat.world_modules.concat(modules)
|
|
147
|
+
return unless factory
|
|
148
|
+
raise Unsupported, "World was given a block twice: cucumber-ruby takes one World factory" if Compat.world_factory
|
|
149
|
+
|
|
150
|
+
Compat.world_factory = factory
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
#: (**untyped) -> void
|
|
154
|
+
def ParameterType(**options) = Compat.register_parameter_type(options)
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
#: (Symbol, untyped, untyped, Proc?) -> void
|
|
158
|
+
def self.register_step(keyword, pattern, options, block)
|
|
159
|
+
raise ArgumentError, "#{keyword} needs a block, the step's body" unless block
|
|
160
|
+
unless pattern.is_a?(String) || pattern.is_a?(Regexp)
|
|
161
|
+
raise ArgumentError, "#{keyword} takes a String (a cucumber expression) or a Regexp, got #{pattern.class}"
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
unknown = (options || {}).keys.map(&:to_sym) - STEP_OPTIONS
|
|
165
|
+
raise Unsupported, "#{keyword} option #{unknown.first.inspect} is not part of nukadoko's compat door" if unknown.any?
|
|
166
|
+
|
|
167
|
+
file, line = block.source_location
|
|
168
|
+
steps << Registration.new(keyword: keyword, pattern: pattern, block: block, file: File.expand_path(file.to_s), line: line)
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
#: (Symbol, Array[String], String?, Proc?) -> void
|
|
172
|
+
def self.register_hook(type, tags, name, block)
|
|
173
|
+
raise ArgumentError, "a #{type} hook needs a block" unless block
|
|
174
|
+
|
|
175
|
+
file, line = block.source_location
|
|
176
|
+
hooks << Hook.new(type: type, tags: tags.flatten.map(&:to_s), name: name, block: block, file: File.expand_path(file.to_s), line: line)
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
#: (Hash[Symbol, untyped]) -> void
|
|
180
|
+
def self.register_parameter_type(options)
|
|
181
|
+
unknown = options.keys - PARAMETER_TYPE_KEYS
|
|
182
|
+
raise ArgumentError, "ParameterType does not know #{unknown.first.inspect}" if unknown.any?
|
|
183
|
+
raise ArgumentError, "ParameterType needs name: and regexp:" unless options[:name] && options[:regexp]
|
|
184
|
+
|
|
185
|
+
parameter_types << options
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
# The door's own methods on every World.
|
|
189
|
+
module WorldMethods
|
|
190
|
+
# cucumber-ruby's `pending`: the step stops here, and nukadoko, which
|
|
191
|
+
# has no pending outcome, fails it.
|
|
192
|
+
#: (?String) -> bot
|
|
193
|
+
def pending(message = "TODO") = raise(Pending, message)
|
|
194
|
+
|
|
195
|
+
#: (*untyped) -> bot
|
|
196
|
+
def skip_this_scenario(*)
|
|
197
|
+
raise Unsupported, "skip_this_scenario is not part of nukadoko's compat door: a scenario that should not run is left out with a tag"
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
# Runs another step by its text, on this World, as cucumber-ruby's
|
|
201
|
+
# `step` does. The step it runs is part of this step's record.
|
|
202
|
+
#: (String, ?untyped) -> untyped
|
|
203
|
+
def step(text, multiline = nil)
|
|
204
|
+
matched = Compat::Step.compat_steps.filter_map { |step| (found = step.match_line(text)) && [step, found] }
|
|
205
|
+
raise Unsupported, %(step "#{text}" matches no compat step) if matched.empty?
|
|
206
|
+
raise Unsupported, %(step "#{text}" matches more than one compat step: #{matched.map { _1.first.step_name }.join(", ")}) if matched.size > 1
|
|
207
|
+
|
|
208
|
+
step, found = matched.first
|
|
209
|
+
args = step.values(found, self)
|
|
210
|
+
args << (multiline.is_a?(Array) ? DataTable.new(multiline) : multiline) unless multiline.nil?
|
|
211
|
+
instance_exec(*args, &step.registration.block)
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
#: (*untyped) -> bot
|
|
215
|
+
def steps(*)
|
|
216
|
+
raise Unsupported, "steps with Gherkin text is not part of nukadoko's compat door: call step once per line, or write the lines in the scenario"
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
# What cucumber-ruby's `log` and `attach` keep: each goes into the
|
|
220
|
+
# step record's `attachments`, as a typed step's `evidence` does.
|
|
221
|
+
#: (*untyped) -> void
|
|
222
|
+
def log(*messages) = Compat.evidence&.call(:log, messages.map(&:to_s))
|
|
223
|
+
|
|
224
|
+
#: (untyped, ?String?, ?String?) -> void
|
|
225
|
+
def attach(data, media_type = nil, filename = nil) = Compat.evidence&.call(:attach, [data, media_type, filename])
|
|
226
|
+
|
|
227
|
+
# The page nukadoko measures: its trace, screenshots, and requests are
|
|
228
|
+
# the step's. Capybara's `page`, when the glue uses Capybara, is its
|
|
229
|
+
# own and is not measured.
|
|
230
|
+
#: () -> untyped
|
|
231
|
+
def open_page = Compat.open(:page)
|
|
232
|
+
|
|
233
|
+
# The `request` fixture: requests to the world, measured.
|
|
234
|
+
#: () -> untyped
|
|
235
|
+
def open_request = Compat.open(:request)
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
class << self
|
|
239
|
+
# What the running step opens on demand, set by the run around each
|
|
240
|
+
# compat step; nil outside one.
|
|
241
|
+
#: () -> (^(Symbol) -> untyped)?
|
|
242
|
+
def opener = @opener
|
|
243
|
+
|
|
244
|
+
#: ((^(Symbol) -> untyped)?) -> (^(Symbol) -> untyped)?
|
|
245
|
+
def opener=(value)
|
|
246
|
+
@opener = value
|
|
247
|
+
end
|
|
248
|
+
|
|
249
|
+
#: () -> (^(Symbol, Array[untyped]) -> void)?
|
|
250
|
+
def evidence = @evidence
|
|
251
|
+
|
|
252
|
+
#: ((^(Symbol, Array[untyped]) -> void)?) -> (^(Symbol, Array[untyped]) -> void)?
|
|
253
|
+
def evidence=(value)
|
|
254
|
+
@evidence = value
|
|
255
|
+
end
|
|
256
|
+
end
|
|
257
|
+
|
|
258
|
+
#: (Symbol) -> untyped
|
|
259
|
+
def self.open(kind)
|
|
260
|
+
open = opener
|
|
261
|
+
raise Unsupported, "open_#{kind} works inside a step: a hook has no step record for the #{kind} to belong to" unless open
|
|
262
|
+
|
|
263
|
+
open.call(kind)
|
|
264
|
+
end
|
|
265
|
+
|
|
266
|
+
# cucumber-ruby's DataTable, for the calls glue makes most. A table is
|
|
267
|
+
# read, never changed, and `diff!` is refused rather than half done.
|
|
268
|
+
class DataTable
|
|
269
|
+
#: (Array[Array[String]]) -> void
|
|
270
|
+
def initialize(raw)
|
|
271
|
+
@raw = raw.map { |row| row.map(&:to_s).freeze }.freeze
|
|
272
|
+
end
|
|
273
|
+
|
|
274
|
+
#: () -> Array[Array[String]]
|
|
275
|
+
attr_reader :raw
|
|
276
|
+
|
|
277
|
+
#: () -> Array[Array[String]]
|
|
278
|
+
def rows = raw.drop(1)
|
|
279
|
+
|
|
280
|
+
#: () -> Array[Hash[String, String]]
|
|
281
|
+
def hashes
|
|
282
|
+
header, *body = raw
|
|
283
|
+
body.map { header.zip(_1).to_h }
|
|
284
|
+
end
|
|
285
|
+
|
|
286
|
+
#: () -> Array[Hash[Symbol, String]]
|
|
287
|
+
def symbolic_hashes = hashes.map { |row| row.transform_keys { _1.downcase.gsub(/\W+/, "_").to_sym } }
|
|
288
|
+
|
|
289
|
+
#: () -> Hash[String, String]
|
|
290
|
+
def rows_hash
|
|
291
|
+
raise ArgumentError, "rows_hash needs a table of two columns, this one has #{raw.first&.size.to_i}" unless raw.all? { _1.size == 2 }
|
|
292
|
+
|
|
293
|
+
raw.to_h { [_1[0], _1[1]] }
|
|
294
|
+
end
|
|
295
|
+
|
|
296
|
+
#: () -> DataTable
|
|
297
|
+
def transpose = DataTable.new(raw.empty? ? [] : raw.first.zip(*raw.drop(1)).map { _1.map(&:to_s) })
|
|
298
|
+
|
|
299
|
+
#: () -> Array[Array[String]]
|
|
300
|
+
def cells_rows = raw
|
|
301
|
+
|
|
302
|
+
#: () -> Integer
|
|
303
|
+
def size = raw.size
|
|
304
|
+
|
|
305
|
+
#: (untyped) -> bool
|
|
306
|
+
def ==(other) = other.is_a?(DataTable) && other.raw == raw
|
|
307
|
+
|
|
308
|
+
#: () -> String
|
|
309
|
+
def to_s = raw.map { |row| "| #{row.join(" | ")} |" }.join("\n")
|
|
310
|
+
|
|
311
|
+
#: (*untyped) -> bot
|
|
312
|
+
def diff!(*)
|
|
313
|
+
raise Unsupported, "DataTable#diff! is not part of nukadoko's compat door: compare table.hashes with the rows you expect"
|
|
314
|
+
end
|
|
315
|
+
|
|
316
|
+
#: (*untyped) -> bot
|
|
317
|
+
def map_headers!(*) = raise(Unsupported, "DataTable#map_headers! is not part of nukadoko's compat door: read table.hashes and rename the keys")
|
|
318
|
+
#: (*untyped) -> bot
|
|
319
|
+
def map_column!(*) = raise(Unsupported, "DataTable#map_column! is not part of nukadoko's compat door: map the values read from table.hashes")
|
|
320
|
+
end
|
|
321
|
+
|
|
322
|
+
# The scenario a Before or After hook is given, as cucumber-ruby gives it.
|
|
323
|
+
class Scenario
|
|
324
|
+
#: (String, Array[String], String?, ?status: Symbol) -> void
|
|
325
|
+
def initialize(name, tags, location, status: :passed)
|
|
326
|
+
@name = name
|
|
327
|
+
@source_tag_names = tags
|
|
328
|
+
@location = location
|
|
329
|
+
@status = status
|
|
330
|
+
end
|
|
331
|
+
|
|
332
|
+
attr_reader :name, :source_tag_names, :location
|
|
333
|
+
attr_accessor :status
|
|
334
|
+
|
|
335
|
+
#: () -> bool
|
|
336
|
+
def failed? = status == :failed
|
|
337
|
+
#: () -> bool
|
|
338
|
+
def passed? = status == :passed
|
|
339
|
+
end
|
|
340
|
+
|
|
341
|
+
# A step's result as AfterStep is given it.
|
|
342
|
+
StepResult = Data.define(:status, :exception)
|
|
343
|
+
|
|
344
|
+
class StepResult
|
|
345
|
+
#: () -> bool
|
|
346
|
+
def passed? = status == :passed
|
|
347
|
+
#: () -> bool
|
|
348
|
+
def failed? = status == :failed
|
|
349
|
+
end
|
|
350
|
+
|
|
351
|
+
# Each registration as a member of the step vocabulary: a Step
|
|
352
|
+
# subclass named by its pattern, matched with cucumber-expressions or
|
|
353
|
+
# its Regexp, with no contract to check.
|
|
354
|
+
module Step
|
|
355
|
+
#: () -> Array[untyped]
|
|
356
|
+
def self.compat_steps = Nukadoko::Step.registry.select { Vocabulary.compat?(_1) }
|
|
357
|
+
|
|
358
|
+
# One Step subclass for a registration.
|
|
359
|
+
#: (Registration) -> singleton(Nukadoko::Step)
|
|
360
|
+
def self.build(registration)
|
|
361
|
+
klass = Class.new(Nukadoko::Step) #: untyped
|
|
362
|
+
klass.extend(Methods)
|
|
363
|
+
klass.instance_variable_set(:@registration, registration)
|
|
364
|
+
klass.instance_variable_set(:@file, registration.file)
|
|
365
|
+
klass
|
|
366
|
+
end
|
|
367
|
+
|
|
368
|
+
# What a compat step answers where a typed step reads its declarations.
|
|
369
|
+
module Methods
|
|
370
|
+
#: () -> Registration
|
|
371
|
+
def registration = @registration
|
|
372
|
+
#: () -> bool
|
|
373
|
+
def compat? = true
|
|
374
|
+
#: () -> String
|
|
375
|
+
def step_name = "compat: #{registration.source}"
|
|
376
|
+
#: () -> Integer?
|
|
377
|
+
def line = registration.line
|
|
378
|
+
#: () -> String
|
|
379
|
+
def name = step_name
|
|
380
|
+
# No typed pattern: every check of named captures and args passes
|
|
381
|
+
# a compat step by, and `compat_patterns` is what it lists.
|
|
382
|
+
#: (*untyped) -> Array[String]
|
|
383
|
+
def patterns(*) = []
|
|
384
|
+
#: () -> Array[String]
|
|
385
|
+
def compat_patterns = [registration.source]
|
|
386
|
+
#: () -> bool
|
|
387
|
+
def mutating? = true
|
|
388
|
+
#: () -> Symbol
|
|
389
|
+
def body = :run
|
|
390
|
+
#: () -> Array[Symbol]
|
|
391
|
+
def fixtures = []
|
|
392
|
+
#: (?Array[untyped]) -> Array[Symbol]
|
|
393
|
+
def bag(_seen = []) = []
|
|
394
|
+
|
|
395
|
+
# The expression the pattern is read with, against the registry
|
|
396
|
+
# typed patterns read, so a parameter type is one mechanism.
|
|
397
|
+
#: () -> untyped
|
|
398
|
+
def expression
|
|
399
|
+
ce = Cucumber::CucumberExpressions
|
|
400
|
+
@expression ||= if registration.pattern.is_a?(Regexp)
|
|
401
|
+
ce::RegularExpression.new(registration.pattern, Engine::Pattern.registry)
|
|
402
|
+
else
|
|
403
|
+
ce::CucumberExpression.new(registration.pattern, Engine::Pattern.registry)
|
|
404
|
+
end
|
|
405
|
+
end
|
|
406
|
+
|
|
407
|
+
# The arguments a line's text matches, or nil.
|
|
408
|
+
#: (String) -> Array[untyped]?
|
|
409
|
+
def match_line(text)
|
|
410
|
+
return nil if Engine::Pattern.collision
|
|
411
|
+
|
|
412
|
+
expression.match(text)
|
|
413
|
+
rescue StandardError
|
|
414
|
+
nil
|
|
415
|
+
end
|
|
416
|
+
|
|
417
|
+
# Each capture's value, a parameter type's transformer running on
|
|
418
|
+
# the World, as cucumber-ruby runs it.
|
|
419
|
+
#: (Array[untyped], untyped) -> Array[untyped]
|
|
420
|
+
def values(found, world) = found.map { _1.value(world) }
|
|
421
|
+
end
|
|
422
|
+
end
|
|
423
|
+
|
|
424
|
+
# Registers the World methods at the top level and loads `files`, in
|
|
425
|
+
# cucumber-ruby's order: env.rb first, then the rest of support/, then
|
|
426
|
+
# every other file. A file that raises is kept as a load failure and
|
|
427
|
+
# the rest still load, so one broken file does not hide the others.
|
|
428
|
+
#: (Array[String]) -> void
|
|
429
|
+
def self.load(files)
|
|
430
|
+
TOPLEVEL_BINDING.receiver.extend(Dsl)
|
|
431
|
+
files.each do |file|
|
|
432
|
+
before = steps.size
|
|
433
|
+
begin
|
|
434
|
+
require file
|
|
435
|
+
rescue ScriptError, StandardError => e
|
|
436
|
+
load_failures << [file, e.message.lines.first.to_s.chomp]
|
|
437
|
+
steps.slice!(before..)
|
|
438
|
+
end
|
|
439
|
+
end
|
|
440
|
+
steps.drop(@built.to_i).each { Step.build(_1) }
|
|
441
|
+
parameter_types.drop(@registered.to_i).each { |type| register_type(type) }
|
|
442
|
+
@built = steps.size
|
|
443
|
+
@registered = parameter_types.size
|
|
444
|
+
end
|
|
445
|
+
|
|
446
|
+
#: (Hash[Symbol, untyped]) -> void
|
|
447
|
+
def self.register_type(type)
|
|
448
|
+
regexps = Array(type[:regexp])
|
|
449
|
+
transformer = type[:transformer] || ->(*groups) { groups.first }
|
|
450
|
+
Engine::Pattern.registry.define_parameter_type(
|
|
451
|
+
Cucumber::CucumberExpressions::ParameterType.new(type[:name].to_s, regexps, type[:type] || Object, transformer,
|
|
452
|
+
type.fetch(:use_for_snippets, true), type.fetch(:prefer_for_regexp_match, false))
|
|
453
|
+
)
|
|
454
|
+
rescue StandardError => e
|
|
455
|
+
load_failures << [File.expand_path(transformer.source_location&.first.to_s), e.message.lines.first.to_s.chomp]
|
|
456
|
+
end
|
|
457
|
+
|
|
458
|
+
# The glue files under `features`, in the order cucumber-ruby loads
|
|
459
|
+
# them; the typed step files under `steps_dir` are among them.
|
|
460
|
+
#: (String, String) -> Array[String]
|
|
461
|
+
def self.files(features, steps_dir)
|
|
462
|
+
all = Dir.glob(File.join(features, "**/*.rb")).sort.map { File.expand_path(_1) }
|
|
463
|
+
support = File.expand_path(File.join(features, "support"))
|
|
464
|
+
env = File.join(support, "env.rb")
|
|
465
|
+
in_support = all.select { _1.start_with?("#{support}/") }
|
|
466
|
+
[*([env] & all), *(in_support - [env]), *(all - in_support - [env])]
|
|
467
|
+
end
|
|
468
|
+
end
|
|
469
|
+
end
|
data/lib/nukadoko/criteria.rb
CHANGED
|
@@ -14,7 +14,7 @@ require "json"
|
|
|
14
14
|
# content, so a scenario renamed or tagged `@smoke` still says what it said,
|
|
15
15
|
# though a hook or a World could read them, so such a criterion keeps its
|
|
16
16
|
# change and is marked `retagged` or `renamed_from`, and runs in the old
|
|
17
|
-
#
|
|
17
|
+
# system as a changed mapping does.
|
|
18
18
|
#
|
|
19
19
|
# Matching follows the TypeScript engine's order: the same identity and
|
|
20
20
|
# content is unchanged; the same content under another identity, where it
|
data/lib/nukadoko/definition.rb
CHANGED
|
@@ -21,27 +21,177 @@ module Nukadoko
|
|
|
21
21
|
|
|
22
22
|
#: () -> Array[String]
|
|
23
23
|
def problems
|
|
24
|
-
|
|
25
|
-
return []
|
|
24
|
+
problem = timeout_problem
|
|
25
|
+
return ["#{@step.name} #{problem}."] if problem
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
#
|
|
27
|
+
# Named by the class, as the TypeScript engine names its defineStep
|
|
28
|
+
# call, and in the order it meets each refusal: a claim step's
|
|
29
|
+
# options and claims, then the states.
|
|
30
|
+
problem = @step.claims ? claim_step_problem(@step.claims) : run_step_problem
|
|
31
|
+
problem ||= (states = States.read(@step)).is_a?(String) ? states : nil
|
|
29
32
|
problem ? ["#{@step.name} #{problem}."] : []
|
|
30
33
|
end
|
|
31
34
|
|
|
32
35
|
private
|
|
33
36
|
|
|
37
|
+
#: (untyped) -> String?
|
|
38
|
+
def claim_step_problem(claims)
|
|
39
|
+
refused = %i[gives ends].find { @step.public_send(_1).any? }
|
|
40
|
+
return "#{refused} is not an option of a claim step: a claim step has no action, so it leaves no state; it may require one" if refused
|
|
41
|
+
|
|
42
|
+
events_problem || files_problem || ClaimRules.first_problem(claims, shape) || poll_problem
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
#: () -> String?
|
|
46
|
+
def run_step_problem
|
|
47
|
+
option = %i[events files].find { !@step.instance_variable_get(:"@#{_1}").nil? }
|
|
48
|
+
return nil unless option
|
|
49
|
+
|
|
50
|
+
"#{option} belongs to a claim step, and this definition has no claims. A step that acts uses run; a step that judges declares claims"
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
EVENTS_ENTRY_KEYS = %w[of count service].freeze
|
|
54
|
+
|
|
55
|
+
# The characters a service's name takes in a program. Whether the
|
|
56
|
+
# program has a service of that name is `nuka check`'s and the run's
|
|
57
|
+
# (`events-service-unknown`).
|
|
58
|
+
SERVICE_NAME = /\A[a-z0-9_-]+\z/.freeze
|
|
59
|
+
|
|
60
|
+
# Why `events` is not a hash of counts the run can read: each key one
|
|
61
|
+
# word a claim's actual can name, each entry `{ of:, count: }` with
|
|
62
|
+
# `of` a step or a list of distinct ones, and `count` a selection the
|
|
63
|
+
# format can judge, and an optional `service`, the one service of the
|
|
64
|
+
# system whose lines to count.
|
|
65
|
+
#: () -> String?
|
|
66
|
+
def events_problem
|
|
67
|
+
events = @step.instance_variable_get(:@events)
|
|
68
|
+
return nil if events.nil?
|
|
69
|
+
return "events must be an object whose keys name counts, each { of, count }" unless events.is_a?(Hash)
|
|
70
|
+
|
|
71
|
+
events.each do |key, entry|
|
|
72
|
+
unless key.match?(/\A[^.]+\z/)
|
|
73
|
+
return %(events key #{key.to_json} is not one key a claim's actual can name; name it with one word and no dot)
|
|
74
|
+
end
|
|
75
|
+
return "events.#{key} must be an object with of, the step whose events it counts, and count, the lines it counts" unless entry.is_a?(Hash)
|
|
76
|
+
|
|
77
|
+
unknown = entry.keys.map(&:to_s).find { !EVENTS_ENTRY_KEYS.include?(_1) }
|
|
78
|
+
return %(events.#{key} has the key "#{unknown}", which an events entry does not have. It has #{EVENTS_ENTRY_KEYS.join(", ")}) if unknown
|
|
79
|
+
|
|
80
|
+
of = entry[:of] || entry["of"]
|
|
81
|
+
candidates = of.is_a?(Array) ? of : [of]
|
|
82
|
+
if candidates.empty? || !candidates.all? { _1.is_a?(Class) && _1 < Step }
|
|
83
|
+
return "events.#{key}.of must be a step class, or a non-empty list of them; name the step whose events it counts"
|
|
84
|
+
end
|
|
85
|
+
return "events.#{key}.of names one step twice" if candidates.uniq.size != candidates.size
|
|
86
|
+
|
|
87
|
+
service = entry[:service] || entry["service"]
|
|
88
|
+
unless service.nil? || (service.is_a?(String) && service.match?(SERVICE_NAME))
|
|
89
|
+
return %(events.#{key}.service must be the name of a service of the program: lowercase letters, digits, "_", or "-")
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
problems = Events::Selection.problems(Events::Selection.normalize(entry[:count] || entry["count"]), "events.#{key}.count")
|
|
93
|
+
return problems.join("; ") if problems.any?
|
|
94
|
+
end
|
|
95
|
+
nil
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
FILES_ENTRY_KEYS = %w[of change under].freeze
|
|
99
|
+
FILE_CHANGES = %w[added changed removed].freeze
|
|
100
|
+
UNWALKED = %w[node_modules .git].freeze
|
|
101
|
+
|
|
102
|
+
# Why `files` is not a hash of lists the run can read: each key one
|
|
103
|
+
# word a claim's actual can name, each entry `{ of:, change:, under: }`
|
|
104
|
+
# with `of` a step or a list of distinct ones, `change` one of the
|
|
105
|
+
# changes a record lists or a list of them, and `under` a directory
|
|
106
|
+
# relative to the working directory that a walk enters.
|
|
107
|
+
#: () -> String?
|
|
108
|
+
def files_problem
|
|
109
|
+
files = @step.instance_variable_get(:@files)
|
|
110
|
+
return nil if files.nil?
|
|
111
|
+
return "files must be an object whose keys name lists of paths, each { of, change?, under? }" unless files.is_a?(Hash)
|
|
112
|
+
|
|
113
|
+
files.each do |key, entry|
|
|
114
|
+
unless key.match?(/\A[^.]+\z/)
|
|
115
|
+
return %(files key #{key.to_json} is not one key a claim's actual can name; name it with one word and no dot)
|
|
116
|
+
end
|
|
117
|
+
return "files.#{key} must be an object with of, the step whose commands changed the files" unless entry.is_a?(Hash)
|
|
118
|
+
|
|
119
|
+
unknown = entry.keys.map(&:to_s).find { !FILES_ENTRY_KEYS.include?(_1) }
|
|
120
|
+
return %(files.#{key} has the key "#{unknown}", which a files entry does not have. It has #{FILES_ENTRY_KEYS.join(", ")}) if unknown
|
|
121
|
+
|
|
122
|
+
of = entry[:of] || entry["of"]
|
|
123
|
+
candidates = of.is_a?(Array) ? of : [of]
|
|
124
|
+
if candidates.empty? || !candidates.all? { _1.is_a?(Class) && _1 < Step }
|
|
125
|
+
return "files.#{key}.of must be a step class, or a non-empty list of them; name the step whose commands changed the files"
|
|
126
|
+
end
|
|
127
|
+
return "files.#{key}.of names one step twice" if candidates.uniq.size != candidates.size
|
|
128
|
+
|
|
129
|
+
change = entry[:change] || entry["change"]
|
|
130
|
+
unless change.nil?
|
|
131
|
+
changes = change.is_a?(Array) ? change : [change]
|
|
132
|
+
if changes.empty? || !changes.all? { FILE_CHANGES.include?(_1) }
|
|
133
|
+
return "files.#{key}.change must be one of #{FILE_CHANGES.join(", ")}, or a non-empty list of them; leave it out for every change"
|
|
134
|
+
end
|
|
135
|
+
return "files.#{key}.change names one change twice" if changes.uniq.size != changes.size
|
|
136
|
+
end
|
|
137
|
+
under = entry[:under] || entry["under"]
|
|
138
|
+
next if under.nil?
|
|
139
|
+
|
|
140
|
+
problem = under_problem(under)
|
|
141
|
+
return "files.#{key}.under #{problem}" if problem
|
|
142
|
+
end
|
|
143
|
+
nil
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
# A record's paths are relative and `/`-separated, so an absolute
|
|
147
|
+
# path, a backslash, or a `.` or `..` segment matches none of them,
|
|
148
|
+
# and a list under node_modules or .git is empty whatever the command did.
|
|
149
|
+
#: (untyped) -> String?
|
|
150
|
+
def under_problem(under)
|
|
151
|
+
return %(must be a directory relative to the command's working directory, such as "src/"; got #{ClaimRules.describe(under)}) unless under.is_a?(String)
|
|
152
|
+
|
|
153
|
+
segments = under.delete_suffix("/").split("/", -1)
|
|
154
|
+
if under.start_with?("/") || under.include?("\\") || segments.any? { _1.empty? || _1 == "." || _1 == ".." }
|
|
155
|
+
return %(is #{under.to_json}, and a record lists each path relative to the command's working directory, with / between its parts, so no path is under it. Name the directory that way, such as "src/")
|
|
156
|
+
end
|
|
157
|
+
unwalked = segments.find { UNWALKED.include?(_1) }
|
|
158
|
+
unwalked ? %(is #{under.to_json}, inside a #{unwalked} directory, which run_command does not walk, so the list is empty whatever the command did) : nil
|
|
159
|
+
end
|
|
160
|
+
|
|
34
161
|
#: () -> ClaimRules::Shape
|
|
35
162
|
def shape
|
|
36
163
|
fields = @step.args.fields
|
|
37
164
|
ClaimRules::Shape.new(
|
|
38
|
-
patterns:
|
|
165
|
+
patterns: @step.patterns, args_keys: fields.map { _1.name.to_s },
|
|
39
166
|
string_args: fields.select { _1.type == :string }.map { _1.name.to_s },
|
|
40
|
-
from_keys: @step.from.keys.map(&:to_s), capture_keys: @step.
|
|
41
|
-
observe: @observe
|
|
167
|
+
from_keys: @step.from.keys.map(&:to_s), capture_keys: @step.patterns.flat_map { Pattern.new(_1).keys }.uniq,
|
|
168
|
+
observe: @observe, files: @step.files.is_a?(Hash) ? @step.files.keys : [],
|
|
169
|
+
events: @step.events.is_a?(Hash) ? @step.events.keys : [], events_sentence: events_sentence
|
|
42
170
|
)
|
|
43
171
|
end
|
|
44
172
|
|
|
173
|
+
# Each value the step's selections take from the sentence.
|
|
174
|
+
#: () -> Array[Hash[Symbol, String]]
|
|
175
|
+
def events_sentence
|
|
176
|
+
events = @step.events
|
|
177
|
+
return [] unless events.is_a?(Hash)
|
|
178
|
+
|
|
179
|
+
events.flat_map do |key, entry|
|
|
180
|
+
count = entry.is_a?(Hash) ? Events::Selection.normalize(entry[:count] || entry["count"]) : nil
|
|
181
|
+
Events::Selection.sentence_values(count).map { { key: key, field: _1[:field].to_s, name: _1[:name].to_s } }
|
|
182
|
+
end
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
# A deadline the step could never keep is refused when it loads, as
|
|
186
|
+
# the TypeScript engine refuses one Node's timer would clamp.
|
|
187
|
+
#: () -> String?
|
|
188
|
+
def timeout_problem
|
|
189
|
+
timeout = @step.timeout
|
|
190
|
+
return nil if timeout.nil? || (timeout.is_a?(Integer) && timeout.positive? && timeout <= MAX_TIMEOUT_MS)
|
|
191
|
+
|
|
192
|
+
"timeout must be a whole number of milliseconds greater than 0 and at most #{MAX_TIMEOUT_MS}; got #{ClaimRules.describe(timeout)}"
|
|
193
|
+
end
|
|
194
|
+
|
|
45
195
|
#: () -> String?
|
|
46
196
|
def poll_problem
|
|
47
197
|
poll = @step.poll
|