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,310 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
# rbs_inline: enabled
|
|
3
|
+
|
|
4
|
+
require "json"
|
|
5
|
+
require "time"
|
|
6
|
+
|
|
7
|
+
# The `repeated-scenario-prefix` notes of a finished run: the scenarios of
|
|
8
|
+
# this run that open with the same steps. It reads the run's own scenario
|
|
9
|
+
# entries and the step records they cite, and writes nothing; `nuka run`
|
|
10
|
+
# adds the notes to the run's findings before run.json is written, so
|
|
11
|
+
# run.json, the summary, and `--json` carry the same notes. A note never
|
|
12
|
+
# changes the exit code. Boundary: it judges nothing about a verdict.
|
|
13
|
+
#
|
|
14
|
+
# It reports measured repetition, and names a process-scope fixture as the
|
|
15
|
+
# place to lift an opening only when every shared step declares `mutates
|
|
16
|
+
# false`. An opening ends at the first When or Then, since a step there is
|
|
17
|
+
# what the scenario exercises, not its setup; and two steps are the same
|
|
18
|
+
# step only when their docstring or table is the same too. Both facts come
|
|
19
|
+
# from the scenario as the run's features hold it. An entry whose scenario
|
|
20
|
+
# the features do not hold with the same step texts is keyed by its texts
|
|
21
|
+
# alone.
|
|
22
|
+
#
|
|
23
|
+
# Which opening a note names depends on the scenarios alone: within one
|
|
24
|
+
# family of nested openings, the one that covers the most step executions,
|
|
25
|
+
# then the longer one, then the one that comes first in the feature files.
|
|
26
|
+
# Measured time only decides whether an opening clears the 2% floor.
|
|
27
|
+
# Ranking by time named a different opening from run to run on a fast
|
|
28
|
+
# suite, where the differences were timing noise. The same as the
|
|
29
|
+
# TypeScript engine.
|
|
30
|
+
module Nukadoko
|
|
31
|
+
module Engine
|
|
32
|
+
module RepeatedPrefix
|
|
33
|
+
# Under this share of the run's summed scenario time an opening is noise.
|
|
34
|
+
FLOOR = 0.02
|
|
35
|
+
|
|
36
|
+
# A step that exercises what the scenario is about, where an opening ends.
|
|
37
|
+
EXERCISES = %w[Action Outcome].freeze
|
|
38
|
+
|
|
39
|
+
# Where a scenario is written, as the note names the earliest one.
|
|
40
|
+
Place = Data.define(:feature, :line)
|
|
41
|
+
|
|
42
|
+
# One opening, and what the records that walked it add up to.
|
|
43
|
+
class Node
|
|
44
|
+
attr_reader :texts #: Array[String]
|
|
45
|
+
attr_reader :parent #: Node?
|
|
46
|
+
attr_reader :children #: Hash[String, Node]
|
|
47
|
+
# True once a step on the way to this node carries a docstring or table.
|
|
48
|
+
attr_accessor :with_argument #: bool
|
|
49
|
+
attr_accessor :count #: Integer
|
|
50
|
+
attr_accessor :ms #: Integer
|
|
51
|
+
# True once a record reached this node's own step from a scenario's
|
|
52
|
+
# own steps, not from a Background, or from a scenario the features
|
|
53
|
+
# do not hold.
|
|
54
|
+
attr_accessor :outside_background #: bool
|
|
55
|
+
# The earliest scenario, in source order, that opens with this prefix.
|
|
56
|
+
attr_accessor :first #: Place?
|
|
57
|
+
# True once a record of this node's own step lacks `mutates false`:
|
|
58
|
+
# it declares `mutates true`, is a compat step with no declaration,
|
|
59
|
+
# or has no step record to read the declaration from.
|
|
60
|
+
attr_accessor :may_write #: bool
|
|
61
|
+
|
|
62
|
+
#: (Array[String], bool, Node?) -> void
|
|
63
|
+
def initialize(texts, with_argument, parent)
|
|
64
|
+
@texts = texts
|
|
65
|
+
@with_argument = with_argument
|
|
66
|
+
@parent = parent
|
|
67
|
+
@children = {}
|
|
68
|
+
@count = 0
|
|
69
|
+
@ms = 0
|
|
70
|
+
@outside_background = false
|
|
71
|
+
@first = nil
|
|
72
|
+
@may_write = false
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
# The run's notes. `dir` is the run directory, which each step entry's
|
|
77
|
+
# `record` is relative to; `scenarios` are head's own executions, and
|
|
78
|
+
# `features` the scenarios the run selected.
|
|
79
|
+
#: (String, Array[Hash[Symbol, untyped]], Array[Scenario]) -> Array[Hash[Symbol, untyped]]
|
|
80
|
+
def self.findings(dir, scenarios, features)
|
|
81
|
+
records = one_per_scenario(scenarios)
|
|
82
|
+
return [] if records.empty?
|
|
83
|
+
|
|
84
|
+
total = records.sum { elapsed(_1[:started_at], _1[:finished_at]) }
|
|
85
|
+
return [] if total.zero?
|
|
86
|
+
|
|
87
|
+
without_overlaps(candidates(trie(dir, records, features), total * FLOOR)).map { note(_1, total) }
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
# One record per scenario, the latest started: a `--repeat` run holds
|
|
91
|
+
# several records for one scenario, and a run over several
|
|
92
|
+
# environments one per environment. Counting them would report the
|
|
93
|
+
# scenario's own repetition as an opening shared between scenarios
|
|
94
|
+
# that are the same one, and a process fixture is built once per
|
|
95
|
+
# environment anyway, so lifting it would save nothing across them.
|
|
96
|
+
#: (Array[Hash[Symbol, untyped]]) -> Array[Hash[Symbol, untyped]]
|
|
97
|
+
def self.one_per_scenario(scenarios)
|
|
98
|
+
latest = {} #: Hash[Array[untyped], Hash[Symbol, untyped]]
|
|
99
|
+
scenarios.each do |record|
|
|
100
|
+
key = [record[:feature], record[:line]]
|
|
101
|
+
kept = latest.fetch(key, nil)
|
|
102
|
+
next latest[key] = record unless kept
|
|
103
|
+
|
|
104
|
+
started = moment(record[:started_at])
|
|
105
|
+
before = moment(kept[:started_at])
|
|
106
|
+
latest[key] = record if started && before && started >= before
|
|
107
|
+
end
|
|
108
|
+
latest.values
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
#: (untyped) -> Float?
|
|
112
|
+
def self.moment(text)
|
|
113
|
+
Time.iso8601(text.to_s).to_f
|
|
114
|
+
rescue ArgumentError
|
|
115
|
+
nil
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
#: (untyped, untyped) -> Integer
|
|
119
|
+
def self.elapsed(started_at, finished_at)
|
|
120
|
+
from = moment(started_at)
|
|
121
|
+
to = moment(finished_at)
|
|
122
|
+
return 0 unless from && to
|
|
123
|
+
|
|
124
|
+
ms = ((to - from) * 1000).round
|
|
125
|
+
ms.positive? ? ms : 0
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
# Every opening the records walked, each with how many scenarios
|
|
129
|
+
# walked it and how long their steps up to it took.
|
|
130
|
+
#: (String, Array[Hash[Symbol, untyped]], Array[Scenario]) -> Node
|
|
131
|
+
def self.trie(dir, records, features)
|
|
132
|
+
root = Node.new([], false, nil)
|
|
133
|
+
held = features.to_h { [[_1.uri, _1.line], _1] }
|
|
134
|
+
records.each do |record|
|
|
135
|
+
node = root
|
|
136
|
+
prefix_ms = 0
|
|
137
|
+
place = Place.new(feature: record[:feature], line: record[:line])
|
|
138
|
+
lines = opening_lines(record, held[[record[:feature], record[:line]]])
|
|
139
|
+
(record[:steps] || []).each_with_index do |step, index|
|
|
140
|
+
line = lines&.[](index)
|
|
141
|
+
break if line && EXERCISES.include?(line.kind.to_s)
|
|
142
|
+
|
|
143
|
+
read = step[:record] ? step_record(File.join(dir, step[:record].to_s)) : nil
|
|
144
|
+
prefix_ms += elapsed(read[:started_at], read[:finished_at]) if read
|
|
145
|
+
node = reached(node, step, line, place, prefix_ms, read)
|
|
146
|
+
end
|
|
147
|
+
end
|
|
148
|
+
root
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
# The node one record reached through one step, with that record counted.
|
|
152
|
+
#: (Node, Hash[Symbol, untyped], PickleStep?, Place, Integer, Hash[Symbol, untyped]?) -> Node
|
|
153
|
+
def self.reached(node, step, line, place, prefix_ms, read)
|
|
154
|
+
argument = !line.nil? && !(line.doc_string.nil? && line.table.nil?)
|
|
155
|
+
key = JSON.generate([step[:text], line&.doc_string, line&.doc_string_media_type, line&.table])
|
|
156
|
+
child = node.children[key] ||= Node.new([*node.texts, step[:text].to_s], node.with_argument || argument, node)
|
|
157
|
+
child.count += 1
|
|
158
|
+
child.ms += prefix_ms
|
|
159
|
+
first = child.first
|
|
160
|
+
child.first = place if first.nil? || before?(place, first)
|
|
161
|
+
child.may_write = true if read.nil? || read[:mutates] != false
|
|
162
|
+
child.outside_background = true unless line&.background
|
|
163
|
+
child
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
# The steps of the scenario a record ran, when the run's features hold
|
|
167
|
+
# that scenario with the same step texts.
|
|
168
|
+
#: (Hash[Symbol, untyped], Scenario?) -> Array[PickleStep]?
|
|
169
|
+
def self.opening_lines(record, scenario)
|
|
170
|
+
entries = (record[:steps] || []) #: Array[Hash[Symbol, untyped]]
|
|
171
|
+
return nil unless scenario && scenario.steps.size == entries.size
|
|
172
|
+
return nil unless scenario.steps.each_with_index.all? { |line, index| line.text == entries[index][:text] }
|
|
173
|
+
|
|
174
|
+
scenario.steps
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
# A record that is not there, or not readable, says nothing about the
|
|
178
|
+
# step's own time or what it declares; the node reads as a step that
|
|
179
|
+
# may write, so no fixture is named for it.
|
|
180
|
+
#: (String) -> Hash[Symbol, untyped]?
|
|
181
|
+
def self.step_record(dir)
|
|
182
|
+
JSON.parse(File.read(File.join(dir, "record.json"), encoding: "UTF-8"), symbolize_names: true)
|
|
183
|
+
rescue StandardError
|
|
184
|
+
nil
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
#: (Place, Place) -> bool
|
|
188
|
+
def self.before?(one, other)
|
|
189
|
+
one.feature < other.feature || (one.feature == other.feature && one.line < other.line)
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
# Each opening two or more scenarios walked that clears the floor.
|
|
193
|
+
#: (Node, Float, ?Array[Node]) -> Array[Node]
|
|
194
|
+
def self.candidates(node, minimum, found = [])
|
|
195
|
+
node.children.each_value do |child|
|
|
196
|
+
found << child if child.count >= 2 && child.ms >= minimum
|
|
197
|
+
candidates(child, minimum, found)
|
|
198
|
+
end
|
|
199
|
+
found
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
#: (Node, Node) -> bool
|
|
203
|
+
def self.ancestor?(ancestor, descendant)
|
|
204
|
+
node = descendant.parent
|
|
205
|
+
while node
|
|
206
|
+
return true if node.equal?(ancestor)
|
|
207
|
+
|
|
208
|
+
node = node.parent
|
|
209
|
+
end
|
|
210
|
+
false
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
# True when `one` names a better opening than `other`: it covers more
|
|
214
|
+
# step executions, or as many with more steps, or comes first in
|
|
215
|
+
# source order. Every candidate has a place, since a record reached it.
|
|
216
|
+
#: (Node, Node) -> bool
|
|
217
|
+
def self.ranks_above?(one, other)
|
|
218
|
+
executions = [one, other].map { _1.count * _1.texts.size }
|
|
219
|
+
return executions[0] > executions[1] if executions[0] != executions[1]
|
|
220
|
+
return one.texts.size > other.texts.size if one.texts.size != other.texts.size
|
|
221
|
+
|
|
222
|
+
place = one.first
|
|
223
|
+
place_of_other = other.first
|
|
224
|
+
!place.nil? && !place_of_other.nil? && before?(place, place_of_other)
|
|
225
|
+
end
|
|
226
|
+
|
|
227
|
+
# One note per family of nested openings: the best of the family, and
|
|
228
|
+
# none of the openings it holds or sits inside.
|
|
229
|
+
#: (Array[Node]) -> Array[Node]
|
|
230
|
+
def self.without_overlaps(found)
|
|
231
|
+
remaining = found.dup
|
|
232
|
+
selected = [] #: Array[Node]
|
|
233
|
+
until remaining.empty?
|
|
234
|
+
best = remaining.fetch(0)
|
|
235
|
+
remaining.drop(1).each { best = _1 if ranks_above?(_1, best) }
|
|
236
|
+
selected << best
|
|
237
|
+
remaining.reject! { _1.equal?(best) || ancestor?(_1, best) || ancestor?(best, _1) }
|
|
238
|
+
end
|
|
239
|
+
selected
|
|
240
|
+
end
|
|
241
|
+
|
|
242
|
+
# The first shared step, in order, that may write.
|
|
243
|
+
#: (Node) -> String?
|
|
244
|
+
def self.first_writing_step(node)
|
|
245
|
+
chain(node).find(&:may_write)&.texts&.last
|
|
246
|
+
end
|
|
247
|
+
|
|
248
|
+
# True when every record reached every shared step from a Background.
|
|
249
|
+
#: (Node) -> bool
|
|
250
|
+
def self.all_from_background?(node)
|
|
251
|
+
chain(node).none?(&:outside_background)
|
|
252
|
+
end
|
|
253
|
+
|
|
254
|
+
# The shared steps, in order, as the nodes that hold them.
|
|
255
|
+
#: (Node) -> Array[Node]
|
|
256
|
+
def self.chain(node)
|
|
257
|
+
steps = [] #: Array[Node]
|
|
258
|
+
current = node #: Node?
|
|
259
|
+
while current && current.parent
|
|
260
|
+
steps.unshift(current)
|
|
261
|
+
current = current.parent
|
|
262
|
+
end
|
|
263
|
+
steps
|
|
264
|
+
end
|
|
265
|
+
|
|
266
|
+
# A number with at most `digits` after the point and no trailing zero,
|
|
267
|
+
# as JavaScript writes one.
|
|
268
|
+
#: (Float, Integer) -> String
|
|
269
|
+
def self.number(value, digits)
|
|
270
|
+
rounded = value.round(digits)
|
|
271
|
+
rounded == rounded.to_i ? rounded.to_i.to_s : rounded.to_s
|
|
272
|
+
end
|
|
273
|
+
|
|
274
|
+
#: (Node, Integer) -> Hash[Symbol, untyped]
|
|
275
|
+
def self.note(node, total)
|
|
276
|
+
# One decimal on the seconds: a wall-clock measurement of a whole
|
|
277
|
+
# scenario opening carries nowhere near millisecond accuracy, and
|
|
278
|
+
# three decimals would claim it does.
|
|
279
|
+
seconds = number(node.ms / 1000.0, 1)
|
|
280
|
+
share = number(node.ms.to_f / total * 100, 1)
|
|
281
|
+
steps = node.texts.map { %("#{_1}") }.join(", ")
|
|
282
|
+
# Advice to move steps into a Background they already sit in sends
|
|
283
|
+
# the reader to change nothing.
|
|
284
|
+
in_background = all_from_background?(node)
|
|
285
|
+
{ severity: "note", code: "repeated-scenario-prefix", **(node.first ? { file: node.first.feature } : {}),
|
|
286
|
+
message: "#{node.count} scenarios begin with the same #{node.texts.size} step#{"s" unless node.texts.size == 1}, " \
|
|
287
|
+
"which took #{seconds} seconds across them, #{share}% of this run's summed scenario time. " \
|
|
288
|
+
"The shared steps: #{steps}. " \
|
|
289
|
+
"#{"The shared steps take the same docstring or table. " if node.with_argument}#{lift(node, in_background)}",
|
|
290
|
+
fix: in_background ? IN_BACKGROUND : Codes.fix("repeated-scenario-prefix").to_s }
|
|
291
|
+
end
|
|
292
|
+
|
|
293
|
+
IN_BACKGROUND = "No change is necessary. The shared steps already sit in a Background. " \
|
|
294
|
+
"A process-scope fixture fits only an opening whose steps all declare mutates: false."
|
|
295
|
+
|
|
296
|
+
# Where the opening can go. `mutates` is the step's own declaration,
|
|
297
|
+
# so this trusts it rather than guessing from the trace whether the
|
|
298
|
+
# opening wrote anything.
|
|
299
|
+
#: (Node, bool) -> String
|
|
300
|
+
def self.lift(node, in_background)
|
|
301
|
+
writer = first_writing_step(node)
|
|
302
|
+
return %(Every shared step declares mutates: false, so a "process"-scope fixture (nukadoko.config.rb fixtures) can build this opening once for all of them.) unless writer
|
|
303
|
+
|
|
304
|
+
%("#{writer}" does not declare mutates: false, so a later scenario may read what this opening writes: ) +
|
|
305
|
+
%(a "process"-scope fixture would share that state between scenarios.) +
|
|
306
|
+
(in_background ? " The shared steps already sit in a Background." : " A Background keeps the shared steps in one place and still runs them for each scenario.")
|
|
307
|
+
end
|
|
308
|
+
end
|
|
309
|
+
end
|
|
310
|
+
end
|
data/lib/nukadoko/report_run.rb
CHANGED
|
@@ -128,13 +128,13 @@ module Nukadoko
|
|
|
128
128
|
end
|
|
129
129
|
end
|
|
130
130
|
|
|
131
|
-
# An execution of the base or the old
|
|
131
|
+
# An execution of the base or the old system is a cell of the table,
|
|
132
132
|
# not a test result, so the formats render head's executions alone.
|
|
133
133
|
#: () -> Array[Scenario]
|
|
134
134
|
def read_scenarios
|
|
135
135
|
pickles = @features.flat_map { |feature| feature.pickles.map { [[feature.path, _1.dig("location", "line")], [feature, _1]] } }.to_h
|
|
136
136
|
@document[:scenarios].filter_map do |scenario|
|
|
137
|
-
next if scenario[:
|
|
137
|
+
next if scenario[:system]
|
|
138
138
|
|
|
139
139
|
feature, pickle = pickles[[scenario[:feature], scenario[:line]]]
|
|
140
140
|
unless feature && pickle
|
|
@@ -161,7 +161,7 @@ module Nukadoko
|
|
|
161
161
|
#: (Hash[Symbol, untyped]) -> Hash[Symbol, untyped]?
|
|
162
162
|
def verdict_of(scenario)
|
|
163
163
|
row = @document.dig(:table, :rows)&.find { _1[:feature] == scenario[:feature] && _1[:line] == scenario[:line] }
|
|
164
|
-
cell = row && row[:cells].find { _1[:
|
|
164
|
+
cell = row && row[:cells].find { _1[:system] == "head" && _1[:environment] == scenario[:environment] }
|
|
165
165
|
row && cell ? { verdict: row[:verdict], reason: row[:reason], role: cell[:role] } : nil
|
|
166
166
|
end
|
|
167
167
|
end
|