nukadoko 0.1.0 → 0.3.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 +417 -0
- data/README.ja.md +62 -7
- data/README.md +19 -5
- data/exe/nuka +8 -0
- data/lib/nukadoko/aria_snapshot.rb +1008 -0
- data/lib/nukadoko/aria_tree.rb +150 -0
- data/lib/nukadoko/base.rb +294 -0
- data/lib/nukadoko/check.rb +669 -22
- data/lib/nukadoko/claim_check.rb +177 -0
- data/lib/nukadoko/claim_check_run.rb +293 -0
- data/lib/nukadoko/claim_line.rb +381 -0
- data/lib/nukadoko/claim_rules.rb +519 -0
- data/lib/nukadoko/claim_sides.rb +469 -0
- data/lib/nukadoko/claims.rb +576 -37
- data/lib/nukadoko/cli.rb +814 -22
- data/lib/nukadoko/codes.json +947 -0
- data/lib/nukadoko/codes.rb +19 -0
- data/lib/nukadoko/command.rb +214 -12
- data/lib/nukadoko/criteria.rb +172 -0
- data/lib/nukadoko/definition.rb +33 -41
- data/lib/nukadoko/env_check.rb +88 -0
- data/lib/nukadoko/features.rb +80 -10
- data/lib/nukadoko/fixtures.rb +329 -11
- data/lib/nukadoko/http_recording.rb +68 -0
- data/lib/nukadoko/init.rb +129 -0
- data/lib/nukadoko/js_json.rb +274 -0
- data/lib/nukadoko/js_pattern.rb +531 -0
- data/lib/nukadoko/judge.rb +221 -0
- data/lib/nukadoko/judgment_file.rb +78 -0
- data/lib/nukadoko/judgments.rb +256 -0
- data/lib/nukadoko/literal.rb +129 -0
- data/lib/nukadoko/measured.rb +105 -0
- data/lib/nukadoko/order.rb +84 -0
- data/lib/nukadoko/parts.rb +43 -22
- data/lib/nukadoko/pattern.rb +73 -3
- data/lib/nukadoko/poll.rb +21 -8
- data/lib/nukadoko/program.rb +105 -17
- data/lib/nukadoko/project_files.rb +17 -0
- data/lib/nukadoko/project_fixtures.rb +17 -2
- data/lib/nukadoko/project_program.rb +119 -0
- data/lib/nukadoko/report_allure.rb +751 -0
- data/lib/nukadoko/report_messages.rb +167 -0
- data/lib/nukadoko/report_run.rb +169 -0
- data/lib/nukadoko/run.rb +898 -91
- data/lib/nukadoko/run_record.rb +535 -0
- data/lib/nukadoko/scaffold.rb +1015 -0
- data/lib/nukadoko/schema.rb +120 -21
- data/lib/nukadoko/secrets.rb +375 -0
- data/lib/nukadoko/selection.rb +163 -0
- data/lib/nukadoko/signature.rb +4 -1
- data/lib/nukadoko/skill.rb +36 -0
- data/lib/nukadoko/spaces.rb +28 -0
- data/lib/nukadoko/step.rb +68 -21
- data/lib/nukadoko/summary.rb +662 -0
- data/lib/nukadoko/table.rb +34 -2
- data/lib/nukadoko/text_fit.rb +179 -0
- data/lib/nukadoko/trace.rb +244 -0
- data/lib/nukadoko/trace_actions.rb +116 -0
- data/lib/nukadoko/tree_passes.rb +122 -0
- data/lib/nukadoko/verdict.rb +128 -0
- data/lib/nukadoko/version.rb +2 -1
- data/lib/nukadoko/vocabulary.rb +6 -0
- data/lib/nukadoko/walk.rb +305 -0
- data/lib/nukadoko/walk_files.rb +473 -0
- data/lib/nukadoko/walk_step.rb +149 -0
- data/lib/nukadoko.rb +60 -2
- data/llms.txt +297 -0
- data/sig/generated/nukadoko/aria_snapshot.rbs +331 -0
- data/sig/generated/nukadoko/aria_tree.rbs +142 -0
- data/sig/generated/nukadoko/base.rbs +142 -0
- data/sig/generated/nukadoko/check.rbs +255 -0
- data/sig/generated/nukadoko/claim_check.rbs +118 -0
- data/sig/generated/nukadoko/claim_check_run.rbs +88 -0
- data/sig/generated/nukadoko/claim_line.rbs +158 -0
- data/sig/generated/nukadoko/claim_rules.rbs +172 -0
- data/sig/generated/nukadoko/claim_sides.rbs +207 -0
- data/sig/generated/nukadoko/claims.rbs +208 -0
- data/sig/generated/nukadoko/cli.rbs +182 -0
- data/sig/generated/nukadoko/codes.rbs +16 -0
- data/sig/generated/nukadoko/command.rbs +109 -0
- data/sig/generated/nukadoko/criteria.rbs +83 -0
- data/sig/generated/nukadoko/definition.rbs +30 -0
- data/sig/generated/nukadoko/env_check.rbs +34 -0
- data/sig/generated/nukadoko/features.rbs +101 -0
- data/sig/generated/nukadoko/fixtures.rbs +175 -0
- data/sig/generated/nukadoko/http_recording.rbs +29 -0
- data/sig/generated/nukadoko/init.rbs +64 -0
- data/sig/generated/nukadoko/js_json.rbs +109 -0
- data/sig/generated/nukadoko/js_pattern.rbs +194 -0
- data/sig/generated/nukadoko/judge.rbs +64 -0
- data/sig/generated/nukadoko/judgment_file.rbs +39 -0
- data/sig/generated/nukadoko/judgments.rbs +120 -0
- data/sig/generated/nukadoko/literal.rbs +71 -0
- data/sig/generated/nukadoko/measured.rbs +42 -0
- data/sig/generated/nukadoko/order.rbs +54 -0
- data/sig/generated/nukadoko/parts.rbs +35 -0
- data/sig/generated/nukadoko/pattern.rbs +62 -0
- data/sig/generated/nukadoko/poll.rbs +41 -0
- data/sig/generated/nukadoko/program.rbs +101 -0
- data/sig/generated/nukadoko/project_files.rbs +19 -0
- data/sig/generated/nukadoko/project_fixtures.rbs +57 -0
- data/sig/generated/nukadoko/project_program.rbs +55 -0
- data/sig/generated/nukadoko/report_allure.rbs +268 -0
- data/sig/generated/nukadoko/report_messages.rbs +68 -0
- data/sig/generated/nukadoko/report_run.rbs +102 -0
- data/sig/generated/nukadoko/run.rbs +264 -0
- data/sig/generated/nukadoko/run_record.rbs +175 -0
- data/sig/generated/nukadoko/scaffold.rbs +328 -0
- data/sig/generated/nukadoko/schema.rbs +155 -0
- data/sig/generated/nukadoko/secrets.rbs +172 -0
- data/sig/generated/nukadoko/selection.rbs +73 -0
- data/sig/generated/nukadoko/signature.rbs +17 -0
- data/sig/generated/nukadoko/skill.rbs +20 -0
- data/sig/generated/nukadoko/spaces.rbs +31 -0
- data/sig/generated/nukadoko/step.rbs +115 -0
- data/sig/generated/nukadoko/summary.rbs +204 -0
- data/sig/generated/nukadoko/table.rbs +43 -0
- data/sig/generated/nukadoko/text_fit.rbs +70 -0
- data/sig/generated/nukadoko/trace.rbs +127 -0
- data/sig/generated/nukadoko/trace_actions.rbs +40 -0
- data/sig/generated/nukadoko/tree_passes.rbs +48 -0
- data/sig/generated/nukadoko/verdict.rbs +56 -0
- data/sig/generated/nukadoko/version.rbs +5 -0
- data/sig/generated/nukadoko/vocabulary.rbs +25 -0
- data/sig/generated/nukadoko/walk.rbs +139 -0
- data/sig/generated/nukadoko/walk_files.rbs +189 -0
- data/sig/generated/nukadoko/walk_step.rbs +50 -0
- data/sig/generated/nukadoko.rbs +26 -0
- data/sig/nukadoko.rbs +5 -48
- data/skills/nukadoko/SKILL.md +120 -0
- data/skills/nukadoko/references/checking-steps.md +200 -0
- data/skills/nukadoko/references/diagnosing.md +200 -0
- data/skills/nukadoko/references/done.md +99 -0
- data/skills/nukadoko/references/evidence.md +124 -0
- data/skills/nukadoko/references/examples/cli.md +230 -0
- data/skills/nukadoko/references/examples/http-api.md +342 -0
- data/skills/nukadoko/references/examples/workflow.md +173 -0
- data/skills/nukadoko/references/exploring.md +184 -0
- data/skills/nukadoko/references/fixtures.md +198 -0
- data/skills/nukadoko/references/from-prose.md +51 -0
- data/skills/nukadoko/references/judgments.md +95 -0
- data/skills/nukadoko/references/maintenance.md +97 -0
- data/skills/nukadoko/references/merge-risk.md +74 -0
- data/skills/nukadoko/references/parts.md +152 -0
- data/skills/nukadoko/references/perturbed-worlds.md +109 -0
- data/skills/nukadoko/references/program.md +200 -0
- data/skills/nukadoko/references/reviewing.md +200 -0
- data/skills/nukadoko/references/running.md +200 -0
- data/skills/nukadoko/references/scenario-rules.md +188 -0
- data/skills/nukadoko/references/states.md +66 -0
- data/skills/nukadoko/references/step-files.md +200 -0
- data/skills/nukadoko/references/verdicts.md +200 -0
- data/skills/nukadoko/references/writing-steps.md +200 -0
- data/skills/nukadoko/references/writing-the-feature.md +165 -0
- data/skills/nukadoko/scripts/claude-code-verdict-hook.mjs +99 -0
- data/skills/nukadoko/scripts/merge-risk.jq +56 -0
- data/skills/nukadoko-verification/SKILL.md +263 -0
- metadata +133 -1
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
# rbs_inline: enabled
|
|
3
|
+
|
|
4
|
+
require "pathname"
|
|
5
|
+
|
|
6
|
+
# Which scenarios a run executes: the targets on the command line (feature
|
|
7
|
+
# files, `file:line` selections, directories) narrowed by `--tag`. A target
|
|
8
|
+
# that names nothing runnable is refused before anything runs, with the
|
|
9
|
+
# TypeScript engine's code for the same mistake, so a run never quietly
|
|
10
|
+
# does less than its command line asked for.
|
|
11
|
+
module Nukadoko
|
|
12
|
+
module Engine
|
|
13
|
+
class Refusal < StandardError
|
|
14
|
+
attr_reader :code #: String
|
|
15
|
+
attr_reader :severity #: String
|
|
16
|
+
|
|
17
|
+
# `fix` and `run` are this refusal's own way past it; without either,
|
|
18
|
+
# the code's registry fix and the command's --help stand in.
|
|
19
|
+
#: (String, String, ?severity: String, ?fix: String?, ?run: String?) -> void
|
|
20
|
+
def initialize(code, message, severity: "refused", fix: nil, run: nil)
|
|
21
|
+
super(message)
|
|
22
|
+
@code = code
|
|
23
|
+
@severity = severity
|
|
24
|
+
@fix = fix
|
|
25
|
+
@run = run
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# A refusal stops before anything runs (exit 2); a selection that kept
|
|
29
|
+
# no scenario ran and found nothing to do (exit 1).
|
|
30
|
+
#: () -> Integer
|
|
31
|
+
def exit_code = severity == "refused" ? 2 : 1
|
|
32
|
+
|
|
33
|
+
#: (?String) -> Hash[Symbol, untyped]
|
|
34
|
+
def to_h(command = "run")
|
|
35
|
+
own = @fix || @run ? { fix: @fix || Codes.fix(code), do: @run }.compact : { fix: Codes.fix(code), do: "nuka #{command} --help" }
|
|
36
|
+
{ severity: severity, code: code, message: message, **own }
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
class Selection
|
|
41
|
+
TAG = /\A(not )?(@\S+)\z/
|
|
42
|
+
|
|
43
|
+
# `whole_files` are the files a target named whole and --tag left
|
|
44
|
+
# whole, which a rerun line may name as a file.
|
|
45
|
+
attr_reader :scenarios #: Array[Scenario]
|
|
46
|
+
attr_reader :selection #: String
|
|
47
|
+
attr_reader :tag_selection #: Hash[Symbol, untyped]?
|
|
48
|
+
attr_reader :whole_files #: Array[String]
|
|
49
|
+
attr_reader :problems #: Array[FeatureProblem]
|
|
50
|
+
|
|
51
|
+
#: (String, Array[String], Array[String], ?features_dir: String) -> void
|
|
52
|
+
def initialize(project, targets, tags, features_dir: "features")
|
|
53
|
+
@project = project
|
|
54
|
+
@tags = tags.map { parse_tag(_1) }
|
|
55
|
+
lines = Hash.new { |h, k| h[k] = [] }
|
|
56
|
+
whole = []
|
|
57
|
+
named = targets.empty? ? [features_dir] : targets
|
|
58
|
+
named.each { add(_1, whole, lines) }
|
|
59
|
+
line_target = named.find { _1.match?(/:\d+\z/) }
|
|
60
|
+
if @tags.any? && line_target
|
|
61
|
+
raise Refusal.new("invalid-value", "--tag selects among whole files, and #{JSON.generate(line_target)} already names one scenario",
|
|
62
|
+
fix: "Drop --tag to run that scenario, or drop the :line to select by tag in its file.")
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
files = (whole + lines.keys).uniq.sort
|
|
66
|
+
@problems = []
|
|
67
|
+
all = Dir.chdir(@project) { Engine.load_features(files, problems: @problems) }
|
|
68
|
+
by_line = all.select { whole.include?(_1.uri) || lines[_1.uri].include?(_1.line) }
|
|
69
|
+
lines.each do |file, wanted|
|
|
70
|
+
wanted.each do |line|
|
|
71
|
+
next if by_line.any? { _1.uri == file && _1.line == line }
|
|
72
|
+
|
|
73
|
+
starts = all.select { _1.uri == file }.map(&:line).uniq.sort
|
|
74
|
+
fix = starts.empty? ? "Add a scenario to #{file}; nothing in it can run yet." : "Name a line a scenario or an Examples row starts on: #{starts.join(", ")}."
|
|
75
|
+
raise Refusal.new("no-scenario-at-line", "No scenario found at #{file}:#{line}", fix: fix)
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
@scenarios = by_line.select { |s| @tags.all? { |negated, tag| s.tags.include?(tag) != negated } }
|
|
79
|
+
left_out = by_line.size - @scenarios.size
|
|
80
|
+
@whole_files = whole.select { |file| by_line.select { _1.uri == file }.all? { @scenarios.include?(_1) } }
|
|
81
|
+
@tag_selection = { expressions: tags, left_out: left_out } if tags.any?
|
|
82
|
+
@selection = all.size == @scenarios.size ? "full" : "partial"
|
|
83
|
+
return unless @scenarios.empty? && @tags.any?
|
|
84
|
+
|
|
85
|
+
flags = tags.flat_map { ["--tag", Selection.shell_word(_1)] }.join(" ")
|
|
86
|
+
which = by_line.size == 1 ? "the 1 scenario" : "all #{by_line.size} scenarios"
|
|
87
|
+
raise Refusal.new("nothing-selected", "no scenario to run: #{flags} left out #{which} of #{named.join(", ")}, so nothing was checked",
|
|
88
|
+
severity: "failed", fix: "Name a tag a scenario of the targets carries, or run without --tag.")
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
SHELL_SAFE = %r{\A[A-Za-z0-9_./:@%+,-][A-Za-z0-9_./:=@%+,-]*\z}
|
|
92
|
+
|
|
93
|
+
# A word as a POSIX shell reads it back: as it is when it holds no
|
|
94
|
+
# character the shell treats apart, otherwise in single quotes.
|
|
95
|
+
#: (String) -> String
|
|
96
|
+
def self.shell_word(word) = SHELL_SAFE.match?(word) ? word : "'#{word.gsub("'") { %q('\'') }}'"
|
|
97
|
+
|
|
98
|
+
private
|
|
99
|
+
|
|
100
|
+
#: (String) -> [bool, String]
|
|
101
|
+
def parse_tag(expression)
|
|
102
|
+
match = TAG.match(expression)
|
|
103
|
+
unless match
|
|
104
|
+
raise Refusal.new("invalid-value", "--tag #{JSON.generate(expression)} is not an expression nuka run reads: " \
|
|
105
|
+
"give \"@name\" or \"not @name\", and repeat --tag for a scenario that has to meet more than one")
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
[!match[1].nil?, match[2]]
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
#: (String, Array[String], Hash[String, Array[Integer]]) -> void
|
|
112
|
+
def add(target, whole, lines)
|
|
113
|
+
parsed = target.match(/\A(.*?)(?::(\d+))?\z/) #: MatchData
|
|
114
|
+
path = parsed[1].to_s
|
|
115
|
+
line = parsed[2]
|
|
116
|
+
absolute = File.expand_path(path, @project)
|
|
117
|
+
if File.directory?(absolute)
|
|
118
|
+
if line
|
|
119
|
+
raise Refusal.new("line-on-directory", %(":line" has no meaning for a directory: #{target} names a directory, not a feature file),
|
|
120
|
+
fix: "Remove the :line suffix from the directory, or name a feature file.", run: "nuka run #{Selection.shell_word(path)}")
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
found = walk(absolute)
|
|
124
|
+
if found.empty?
|
|
125
|
+
raise Refusal.new("no-feature-files", %(no .feature file was found while scanning "#{path}"; nothing can run), fix: "Add a .feature file under #{path}.")
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
found.each { whole << relative(_1) unless whole.include?(relative(_1)) }
|
|
129
|
+
elsif path.end_with?(".md")
|
|
130
|
+
raise Refusal.new("markdown-target", "#{path} is a Markdown file: Markdown oaths were removed, and nukadoko reads scenarios from .feature files only",
|
|
131
|
+
fix: "Write the scenarios of #{path} as Gherkin in a .feature file, and name that file.")
|
|
132
|
+
elsif !File.file?(absolute)
|
|
133
|
+
raise Refusal.new("target-not-found", "Feature file not found: #{path}")
|
|
134
|
+
elsif line
|
|
135
|
+
lines[relative(absolute)] << Integer(line, 10)
|
|
136
|
+
else
|
|
137
|
+
whole << relative(absolute) unless whole.include?(relative(absolute))
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
# Every .feature file below dir, skipping node_modules and any directory
|
|
142
|
+
# whose name starts with a dot, as step discovery skips them.
|
|
143
|
+
#: (String) -> Array[String]
|
|
144
|
+
def walk(dir)
|
|
145
|
+
Dir.children(dir).sort.flat_map do |name|
|
|
146
|
+
full = File.join(dir, name)
|
|
147
|
+
if File.directory?(full)
|
|
148
|
+
name.start_with?(".") || name == "node_modules" ? [] : walk(full)
|
|
149
|
+
else
|
|
150
|
+
name.end_with?(".feature") ? [full] : []
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
# Two spellings of one file are one file: a target is named by its real
|
|
156
|
+
# path relative to the project, so it is selected once.
|
|
157
|
+
#: (String) -> String
|
|
158
|
+
def relative(absolute)
|
|
159
|
+
Pathname.new(File.realpath(absolute)).relative_path_from(Pathname.new(File.realpath(@project))).to_s
|
|
160
|
+
end
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
end
|
data/lib/nukadoko/signature.rb
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
+
# rbs_inline: enabled
|
|
2
3
|
|
|
3
4
|
# The RBS of each step, written from the same declarations check reads, so a
|
|
4
5
|
# project that runs Steep gets the body checked against its own contract:
|
|
@@ -8,13 +9,15 @@ module Nukadoko
|
|
|
8
9
|
module Signature
|
|
9
10
|
FIXTURE_TYPES = { request: "Nukadoko::Engine::Request", scratch: "Nukadoko::Engine::Scratch", call: "Nukadoko::Engine::Caller", baseURL: "String", page: "untyped", context: "untyped" }.freeze
|
|
10
11
|
|
|
12
|
+
#: (Array[singleton(Nukadoko::Step)]) -> String
|
|
11
13
|
def self.of(steps)
|
|
12
14
|
steps.map { of_step(_1) }.join("\n")
|
|
13
15
|
end
|
|
14
16
|
|
|
17
|
+
#: (singleton(Nukadoko::Step)) -> String
|
|
15
18
|
def self.of_step(step)
|
|
16
19
|
params = step.fixtures.map { "#{_1}: #{FIXTURE_TYPES.fetch(_1, "untyped")}" } + ["args: Args"]
|
|
17
|
-
returns = step.returns ?
|
|
20
|
+
returns = (schema = step.returns) ? schema.rbs_record : "Hash[Symbol, untyped]"
|
|
18
21
|
[
|
|
19
22
|
"class #{step.name} < Nukadoko::Step",
|
|
20
23
|
" class Args",
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
# rbs_inline: enabled
|
|
3
|
+
|
|
4
|
+
# `nuka skill path`: the directory that holds every agent skill this gem
|
|
5
|
+
# ships, one absolute path, as the TypeScript engine prints its own. It is
|
|
6
|
+
# a fact about the installed nukadoko, the one route sure to match the
|
|
7
|
+
# version installed; copying a skill into an agent's own layout is what
|
|
8
|
+
# `gh skill install` and the agent's plugin marketplace already do.
|
|
9
|
+
#
|
|
10
|
+
# The gem ships the skills beside lib/ (bin/stage-shared copies them in
|
|
11
|
+
# before `gem build`). A checkout that has not staged them reads the
|
|
12
|
+
# repository root's, which are the same files.
|
|
13
|
+
module Nukadoko
|
|
14
|
+
module Skill
|
|
15
|
+
module_function
|
|
16
|
+
|
|
17
|
+
#: () -> String
|
|
18
|
+
def dir
|
|
19
|
+
here = __dir__.to_s
|
|
20
|
+
staged = File.expand_path("../../skills", here)
|
|
21
|
+
File.directory?(staged) ? staged : File.expand_path("../../../skills", here)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
#: (IO, IO) -> Integer
|
|
25
|
+
def print_path(out, err)
|
|
26
|
+
found = dir
|
|
27
|
+
unless File.directory?(found)
|
|
28
|
+
err.puts "nuka skill: skill source not found at #{found} (a packaging bug, not a project issue)"
|
|
29
|
+
return 1
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
out.puts found
|
|
33
|
+
0
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
# rbs_inline: enabled
|
|
3
|
+
|
|
4
|
+
# Responsibility: the spaces JavaScript's trim, trimEnd, and \s take, so a
|
|
5
|
+
# text the Ruby engine trims ends where the TypeScript engine's does.
|
|
6
|
+
# Ruby's strip takes a NUL and no Unicode space, and [[:space:]] takes
|
|
7
|
+
# U+0085, which JavaScript keeps; a page's text often ends in a no-break
|
|
8
|
+
# space, so either would judge a claim the other way.
|
|
9
|
+
module Nukadoko
|
|
10
|
+
module Engine
|
|
11
|
+
module Spaces
|
|
12
|
+
CLASS = "\\s\\u00a0\\u1680\\u2000-\\u200a\\u2028\\u2029\\u202f\\u205f\\u3000\\ufeff"
|
|
13
|
+
SPACE = /[#{CLASS}]/
|
|
14
|
+
LEADING = /\A[#{CLASS}]+/
|
|
15
|
+
TRAILING = /[#{CLASS}]+\z/
|
|
16
|
+
BLANK = /\A[#{CLASS}]*\z/
|
|
17
|
+
|
|
18
|
+
#: (String) -> String
|
|
19
|
+
def self.trim(text) = text.sub(LEADING, "").sub(TRAILING, "")
|
|
20
|
+
|
|
21
|
+
#: (String) -> String
|
|
22
|
+
def self.trim_end(text) = text.sub(TRAILING, "")
|
|
23
|
+
|
|
24
|
+
#: (String) -> bool
|
|
25
|
+
def self.blank?(text) = text.match?(BLANK)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
data/lib/nukadoko/step.rb
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
+
# rbs_inline: enabled
|
|
2
3
|
|
|
3
4
|
# A step is a class under features/steps/, one per file, named by its file.
|
|
4
5
|
# Everything except the body is a class-level declaration, so check reads the
|
|
@@ -7,32 +8,53 @@
|
|
|
7
8
|
module Nukadoko
|
|
8
9
|
class Step
|
|
9
10
|
class << self
|
|
10
|
-
|
|
11
|
+
#: () -> String
|
|
12
|
+
def file = @file
|
|
11
13
|
|
|
14
|
+
#: (singleton(Step)) -> void
|
|
12
15
|
def inherited(subclass)
|
|
13
16
|
super
|
|
14
|
-
subclass.instance_variable_set(:@file, caller_locations(1, 1)
|
|
17
|
+
subclass.instance_variable_set(:@file, caller_locations(1, 1)&.first&.absolute_path)
|
|
15
18
|
Step.registry << subclass
|
|
16
19
|
end
|
|
17
20
|
|
|
21
|
+
#: () -> Array[singleton(Step)]
|
|
18
22
|
def registry = (@registry ||= [])
|
|
19
23
|
|
|
24
|
+
#: (String) -> String
|
|
25
|
+
#: () -> String?
|
|
20
26
|
def pattern(text = nil) = text ? (@pattern = text) : @pattern
|
|
27
|
+
#: (String) -> String
|
|
28
|
+
#: () -> String?
|
|
21
29
|
def description(text = nil) = text ? (@description = text) : @description
|
|
30
|
+
#: (bool) -> bool
|
|
31
|
+
#: () -> bool?
|
|
22
32
|
def mutates(value = nil) = value.nil? ? @mutates : (@mutates = value)
|
|
33
|
+
#: (Array[Hash[Symbol, untyped]]) -> Array[Hash[Symbol, untyped]]
|
|
34
|
+
#: () -> Array[Hash[Symbol, untyped]]?
|
|
23
35
|
def claims(list = nil) = list ? (@claims = list) : @claims
|
|
36
|
+
#: (untyped) -> untyped
|
|
37
|
+
#: () -> untyped
|
|
24
38
|
def poll(value = nil) = value.nil? ? @poll : (@poll = value)
|
|
25
39
|
|
|
26
40
|
# The steps this one may run through the `call` fixture. A part with no
|
|
27
41
|
# pattern exists only for calls.
|
|
42
|
+
#: (Array[singleton(Step)]) -> Array[singleton(Step)]
|
|
43
|
+
#: () -> Array[singleton(Step)]
|
|
28
44
|
def parts(list = nil) = list ? (@parts = list.freeze) : (@parts || [])
|
|
29
45
|
|
|
46
|
+
#: () { () [self: Schema] -> void } -> Schema
|
|
47
|
+
#: () -> Schema
|
|
30
48
|
def args(&block) = block ? (@args = Schema.build(&block)) : (@args ||= Schema.new)
|
|
49
|
+
#: () { () [self: Schema] -> void } -> Schema
|
|
50
|
+
#: () -> Schema?
|
|
31
51
|
def returns(&block) = block ? (@returns = Schema.build(&block)) : @returns
|
|
32
52
|
|
|
33
53
|
# Args an earlier step of the scenario returned, by key: one source as
|
|
34
54
|
# `[Step, :field]`, or several as a list of them, where the nearest
|
|
35
55
|
# earlier one that ran gives the value.
|
|
56
|
+
#: (Hash[Symbol | String, untyped]) -> Hash[String, Array[untyped]]
|
|
57
|
+
#: () -> Hash[String, Array[untyped]]
|
|
36
58
|
def from(map = nil)
|
|
37
59
|
return @from || {} unless map
|
|
38
60
|
|
|
@@ -41,54 +63,79 @@ module Nukadoko
|
|
|
41
63
|
|
|
42
64
|
# observe never sees the args a claim compares with, so it cannot pick
|
|
43
65
|
# what to read by the answer it will be judged against.
|
|
44
|
-
|
|
66
|
+
#: () -> Schema
|
|
67
|
+
def inputs
|
|
68
|
+
claims = self.claims
|
|
69
|
+
claims ? args.without(Engine::ClaimRules.withheld_keys(claims, from.keys).keys) : args
|
|
70
|
+
end
|
|
45
71
|
|
|
72
|
+
#: () -> String
|
|
46
73
|
def step_name = File.basename(file, ".rb").tr("_", "-")
|
|
47
74
|
|
|
48
75
|
# A step that runs code may change the world unless it says it does
|
|
49
76
|
# not; a claim step has no action, so it never does.
|
|
77
|
+
#: () -> bool
|
|
50
78
|
def mutating? = claims ? false : mutates != false
|
|
79
|
+
#: () -> Symbol
|
|
51
80
|
def body = claims ? :observe : :run
|
|
81
|
+
#: () -> Integer?
|
|
52
82
|
def line = method_defined?(body) ? instance_method(body).source_location&.last : nil
|
|
53
83
|
|
|
84
|
+
#: () -> Array[Symbol]
|
|
54
85
|
def fixtures
|
|
55
86
|
return [] unless method_defined?(body)
|
|
56
87
|
|
|
57
88
|
instance_method(body).parameters.filter_map { |kind, name| name if kind == :keyreq && name != :args }
|
|
58
89
|
end
|
|
59
90
|
|
|
91
|
+
# What `run` gave back, checked against `returns`, as problems to
|
|
92
|
+
# report. A Ruby method always gives back its last value, so a step
|
|
93
|
+
# with no returns that ends on a call (an Integer, a String, nil)
|
|
94
|
+
# returns nothing; a Hash with keys would lose them from the record,
|
|
95
|
+
# so that is refused, as the TypeScript engine refuses it.
|
|
96
|
+
#: (untyped) -> [untyped, Array[String]]
|
|
97
|
+
def returned(value)
|
|
98
|
+
schema = returns
|
|
99
|
+
# nil is a body that gave back nothing, which zod's "(root): expected
|
|
100
|
+
# object" would leave without its cause or either fix.
|
|
101
|
+
if schema
|
|
102
|
+
nothing = "this step declares returns, but run returned nothing; return a value that matches returns, " \
|
|
103
|
+
"or delete returns if no later step reads from this one"
|
|
104
|
+
return [value, value.nil? ? [nothing] : schema.problems(value)]
|
|
105
|
+
end
|
|
106
|
+
return [{}, []] unless value.is_a?(Hash)
|
|
107
|
+
return [value, []] if value.empty?
|
|
108
|
+
|
|
109
|
+
one = value.size == 1
|
|
110
|
+
[value, ["this step declares no returns, so #{value.keys.join(", ")} would be dropped from the step record; declare returns with #{one ? "that key" : "those keys"}, or stop returning #{one ? "it" : "them"}"]]
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
# The keywords the body is called with: `args` only when it names
|
|
114
|
+
# them, as a TypeScript step that does not destructure `args` never
|
|
115
|
+
# sees them, so `def run(scratch:)` is a whole step.
|
|
116
|
+
#: (Hash[Symbol, untyped], untyped) -> Hash[Symbol, untyped]
|
|
117
|
+
def keywords(fixtures, args)
|
|
118
|
+
params = method_defined?(body) ? instance_method(body).parameters : []
|
|
119
|
+
takes = params.any? { |kind, name| kind == :keyrest || (name == :args && %i[key keyreq].include?(kind)) }
|
|
120
|
+
takes ? fixtures.merge(args: args) : fixtures
|
|
121
|
+
end
|
|
122
|
+
|
|
60
123
|
# The fixtures the engine builds before the body runs: the step's own,
|
|
61
124
|
# and those of every part it can reach, since the bag is closed before
|
|
62
125
|
# any call happens.
|
|
126
|
+
#: (?Array[singleton(Step)]) -> Array[Symbol]
|
|
63
127
|
def bag(seen = [])
|
|
64
128
|
return [] if seen.include?(self)
|
|
65
129
|
|
|
66
130
|
reachable = parts.select { _1.is_a?(Class) && _1 < Step }.flat_map { _1.bag([*seen, self]) }
|
|
67
131
|
(fixtures + reachable - (seen.empty? ? [] : [:call])).uniq
|
|
68
132
|
end
|
|
69
|
-
|
|
70
|
-
private
|
|
71
|
-
|
|
72
|
-
def expected_keys(node)
|
|
73
|
-
case node
|
|
74
|
-
in Array then node.flat_map { expected_keys(_1) }
|
|
75
|
-
in Hash then node.flat_map { |k, v| k.to_s == "expected" ? expected_key(v) : expected_keys(v) }
|
|
76
|
-
else []
|
|
77
|
-
end
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
def expected_key(value)
|
|
81
|
-
case value
|
|
82
|
-
in String then [value]
|
|
83
|
-
in { from: String => key } then [key]
|
|
84
|
-
else []
|
|
85
|
-
end
|
|
86
|
-
end
|
|
87
133
|
end
|
|
88
134
|
end
|
|
89
135
|
|
|
90
136
|
# Each step file is registered for autoload under its class name first, so a
|
|
91
137
|
# step can name another in `from` or `field` whatever order the files load in.
|
|
138
|
+
#: (String) -> Array[singleton(Step)]
|
|
92
139
|
def self.load_steps(dir)
|
|
93
140
|
files = Dir.glob(File.join(dir, "**/*.rb")).sort.map { File.expand_path(_1) }
|
|
94
141
|
files.each { Object.autoload(File.basename(_1, ".rb").split("_").map(&:capitalize).join.to_sym, _1) }
|