nukadoko 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +541 -3
- data/README.ja.md +20 -5
- data/README.md +12 -6
- data/docs/ci.ja.md +542 -0
- data/docs/ci.md +635 -0
- data/docs/commands.ja.md +1524 -0
- data/docs/commands.md +1281 -0
- data/docs/engines.json +19 -0
- data/docs/execution-events.ja.md +336 -0
- data/docs/execution-events.md +423 -0
- data/docs/glossary.json +1348 -0
- data/docs/guide.ja.md +733 -0
- data/docs/guide.md +815 -0
- data/docs/intent.ja.md +133 -0
- data/docs/intent.md +156 -0
- data/docs/layout.ja.md +442 -0
- data/docs/layout.md +399 -0
- data/docs/releasing.ja.md +186 -0
- data/docs/releasing.md +237 -0
- data/docs/ruby/reference.ja.md +302 -0
- data/docs/ruby/reference.md +368 -0
- data/docs/spec.ja.md +8916 -0
- data/docs/spec.md +11250 -0
- data/docs/tutorial.ja.md +451 -0
- data/docs/tutorial.md +458 -0
- data/docs/typescript/adopting.ja.md +231 -0
- data/docs/typescript/adopting.md +251 -0
- data/docs/typescript/doors.ja.md +301 -0
- data/docs/typescript/doors.md +329 -0
- data/docs/typescript/migration-playwright-test.ja.md +189 -0
- data/docs/typescript/migration-playwright-test.md +212 -0
- data/docs/typescript/migration.ja.md +391 -0
- data/docs/typescript/migration.md +505 -0
- data/docs/typescript/reference.ja.md +176 -0
- data/docs/typescript/reference.md +197 -0
- data/docs/typescript/upgrading.ja.md +1774 -0
- data/docs/typescript/upgrading.md +2224 -0
- data/docs/web-app.ja.md +627 -0
- data/docs/web-app.md +659 -0
- data/docs/writing-scenarios.ja.md +544 -0
- data/docs/writing-scenarios.md +563 -0
- data/lib/nukadoko/base.rb +12 -5
- data/lib/nukadoko/changed_files.rb +95 -0
- data/lib/nukadoko/check.rb +459 -51
- data/lib/nukadoko/claim_drops.rb +271 -0
- data/lib/nukadoko/claim_line.rb +24 -4
- data/lib/nukadoko/claim_rules.rb +143 -1
- data/lib/nukadoko/claim_sides.rb +157 -9
- data/lib/nukadoko/cli.rb +395 -48
- data/lib/nukadoko/codes.json +246 -21
- data/lib/nukadoko/codes.rb +21 -4
- data/lib/nukadoko/command.rb +120 -13
- data/lib/nukadoko/command_help.rb +128 -0
- data/lib/nukadoko/compat.rb +469 -0
- data/lib/nukadoko/criteria.rb +1 -1
- data/lib/nukadoko/definition.rb +157 -7
- data/lib/nukadoko/error_frames.rb +6 -3
- data/lib/nukadoko/events/count.rb +146 -0
- data/lib/nukadoko/events/counted.rb +114 -0
- data/lib/nukadoko/events/format.rb +257 -0
- data/lib/nukadoko/events/lists.rb +154 -0
- data/lib/nukadoko/events/path.rb +285 -0
- data/lib/nukadoko/events/read.rb +284 -0
- data/lib/nukadoko/events/reader.rb +490 -0
- data/lib/nukadoko/events/selection.rb +252 -0
- data/lib/nukadoko/events/tally.rb +438 -0
- data/lib/nukadoko/features.rb +2 -2
- data/lib/nukadoko/fixtures.rb +160 -35
- data/lib/nukadoko/http_recording.rb +6 -2
- data/lib/nukadoko/intent.rb +364 -0
- data/lib/nukadoko/intent_file.rb +81 -0
- data/lib/nukadoko/intent_view.rb +190 -0
- data/lib/nukadoko/js_json.rb +2 -1
- data/lib/nukadoko/judge.rb +2 -2
- data/lib/nukadoko/judgment_file.rb +1 -1
- data/lib/nukadoko/judgments.rb +4 -4
- data/lib/nukadoko/measure_mcp.rb +202 -0
- data/lib/nukadoko/parts.rb +8 -2
- data/lib/nukadoko/path_view.rb +252 -0
- data/lib/nukadoko/place_rows.rb +161 -0
- data/lib/nukadoko/program.rb +1265 -51
- data/lib/nukadoko/program_log.rb +122 -0
- data/lib/nukadoko/program_shape.rb +385 -0
- data/lib/nukadoko/project_fixtures.rb +43 -10
- data/lib/nukadoko/project_program.rb +5 -4
- data/lib/nukadoko/repeated_prefix.rb +310 -0
- data/lib/nukadoko/report_run.rb +3 -3
- data/lib/nukadoko/run.rb +1148 -159
- data/lib/nukadoko/run_record.rb +70 -46
- data/lib/nukadoko/scaffold.rb +24 -6
- data/lib/nukadoko/schema.rb +15 -2
- data/lib/nukadoko/secrets.rb +55 -5
- data/lib/nukadoko/states.rb +478 -0
- data/lib/nukadoko/step.rb +71 -2
- data/lib/nukadoko/step_fixtures.rb +52 -3
- data/lib/nukadoko/summary.rb +799 -29
- data/lib/nukadoko/table.rb +4 -2
- data/lib/nukadoko/text_fit.rb +20 -7
- data/lib/nukadoko/trace.rb +152 -45
- data/lib/nukadoko/tree_passes.rb +95 -33
- data/lib/nukadoko/underneath.rb +311 -0
- data/lib/nukadoko/version.rb +1 -1
- data/lib/nukadoko/vocabulary.rb +166 -23
- data/lib/nukadoko/walk.rb +2 -2
- data/lib/nukadoko/walk_step.rb +1 -1
- data/lib/nukadoko.rb +23 -0
- data/llms.txt +41 -34
- data/sig/generated/nukadoko/base.rbs +4 -4
- data/sig/generated/nukadoko/changed_files.rbs +42 -0
- data/sig/generated/nukadoko/check.rbs +147 -10
- data/sig/generated/nukadoko/claim_drops.rbs +135 -0
- data/sig/generated/nukadoko/claim_line.rbs +11 -0
- data/sig/generated/nukadoko/claim_rules.rbs +49 -4
- data/sig/generated/nukadoko/claim_sides.rbs +63 -12
- data/sig/generated/nukadoko/cli.rbs +80 -7
- data/sig/generated/nukadoko/codes.rbs +19 -4
- data/sig/generated/nukadoko/command.rbs +68 -1
- data/sig/generated/nukadoko/command_help.rbs +18 -0
- data/sig/generated/nukadoko/compat.rbs +392 -0
- data/sig/generated/nukadoko/criteria.rbs +1 -1
- data/sig/generated/nukadoko/definition.rbs +50 -0
- data/sig/generated/nukadoko/error_frames.rbs +1 -1
- data/sig/generated/nukadoko/events/count.rbs +69 -0
- data/sig/generated/nukadoko/events/counted.rbs +70 -0
- data/sig/generated/nukadoko/events/format.rbs +163 -0
- data/sig/generated/nukadoko/events/lists.rbs +47 -0
- data/sig/generated/nukadoko/events/path.rbs +161 -0
- data/sig/generated/nukadoko/events/read.rbs +109 -0
- data/sig/generated/nukadoko/events/reader.rbs +226 -0
- data/sig/generated/nukadoko/events/selection.rbs +100 -0
- data/sig/generated/nukadoko/events/tally.rbs +227 -0
- data/sig/generated/nukadoko/features.rbs +6 -4
- data/sig/generated/nukadoko/fixtures.rbs +67 -11
- data/sig/generated/nukadoko/http_recording.rbs +1 -1
- data/sig/generated/nukadoko/intent.rbs +132 -0
- data/sig/generated/nukadoko/intent_file.rbs +46 -0
- data/sig/generated/nukadoko/intent_view.rbs +69 -0
- data/sig/generated/nukadoko/judgment_file.rbs +1 -1
- data/sig/generated/nukadoko/judgments.rbs +1 -1
- data/sig/generated/nukadoko/measure_mcp.rbs +104 -0
- data/sig/generated/nukadoko/parts.rbs +2 -2
- data/sig/generated/nukadoko/path_view.rbs +105 -0
- data/sig/generated/nukadoko/place_rows.rbs +43 -0
- data/sig/generated/nukadoko/program.rbs +627 -23
- data/sig/generated/nukadoko/program_log.rbs +67 -0
- data/sig/generated/nukadoko/program_shape.rbs +147 -0
- data/sig/generated/nukadoko/project_fixtures.rbs +16 -3
- data/sig/generated/nukadoko/project_program.rbs +2 -1
- data/sig/generated/nukadoko/repeated_prefix.rbs +172 -0
- data/sig/generated/nukadoko/report_run.rbs +1 -1
- data/sig/generated/nukadoko/run.rbs +286 -41
- data/sig/generated/nukadoko/run_record.rbs +20 -12
- data/sig/generated/nukadoko/scaffold.rbs +3 -0
- data/sig/generated/nukadoko/schema.rbs +5 -0
- data/sig/generated/nukadoko/secrets.rbs +26 -3
- data/sig/generated/nukadoko/states.rbs +214 -0
- data/sig/generated/nukadoko/step.rbs +58 -1
- data/sig/generated/nukadoko/step_fixtures.rbs +39 -0
- data/sig/generated/nukadoko/summary.rbs +256 -2
- data/sig/generated/nukadoko/table.rbs +3 -2
- data/sig/generated/nukadoko/trace.rbs +108 -33
- data/sig/generated/nukadoko/tree_passes.rbs +36 -8
- data/sig/generated/nukadoko/underneath.rbs +141 -0
- data/sig/generated/nukadoko/vocabulary.rbs +45 -6
- data/skills/nukadoko/SKILL.md +18 -18
- data/skills/nukadoko/references/checking-steps.md +16 -83
- data/skills/nukadoko/references/diagnosing.md +6 -6
- data/skills/nukadoko/references/evidence.md +19 -6
- data/skills/nukadoko/references/exploring.md +22 -7
- data/skills/nukadoko/references/fixtures.md +12 -32
- data/skills/nukadoko/references/judgments.md +12 -0
- data/skills/nukadoko/references/maintenance.md +1 -1
- data/skills/nukadoko/references/merge-risk.md +1 -1
- data/skills/nukadoko/references/parts.md +46 -23
- data/skills/nukadoko/references/{perturbed-worlds.md → perturbed-systems.md} +30 -12
- data/skills/nukadoko/references/program.md +168 -169
- data/skills/nukadoko/references/reviewing.md +20 -20
- data/skills/nukadoko/references/ruby/checking-steps.md +106 -0
- data/skills/nukadoko/references/ruby/examples/cli.md +212 -0
- data/skills/nukadoko/references/ruby/fixtures.md +34 -0
- data/skills/nukadoko/references/ruby/program.md +112 -0
- data/skills/nukadoko/references/ruby/step-files.md +115 -0
- data/skills/nukadoko/references/running.md +34 -34
- data/skills/nukadoko/references/scenario-rules.md +7 -6
- data/skills/nukadoko/references/states.md +7 -1
- data/skills/nukadoko/references/step-files.md +41 -120
- data/skills/nukadoko/references/typescript/checking-steps.md +129 -0
- data/skills/nukadoko/references/{examples → typescript/examples}/cli.md +1 -1
- data/skills/nukadoko/references/{examples → typescript/examples}/http-api.md +6 -6
- data/skills/nukadoko/references/{examples → typescript/examples}/workflow.md +1 -1
- data/skills/nukadoko/references/typescript/fixtures.md +56 -0
- data/skills/nukadoko/references/typescript/program.md +111 -0
- data/skills/nukadoko/references/typescript/step-files.md +104 -0
- data/skills/nukadoko/references/verdicts.md +10 -10
- data/skills/nukadoko/references/writing-steps.md +67 -67
- data/skills/nukadoko/references/writing-the-feature.md +1 -1
- data/skills/nukadoko-verification/SKILL.md +13 -8
- metadata +103 -7
- data/skills/nukadoko/references/ruby.md +0 -80
data/lib/nukadoko/judgments.rb
CHANGED
|
@@ -68,10 +68,10 @@ module Nukadoko
|
|
|
68
68
|
# judgment, once per Then, claim, and value.
|
|
69
69
|
#: (Hash[Symbol, untyped], Array[Hash[Symbol, untyped]]) -> Array[Hash[Symbol, untyped]]
|
|
70
70
|
def judged_values(row, scenarios)
|
|
71
|
-
required = row[:cells].select { _1[:
|
|
71
|
+
required = row[:cells].select { _1[:system] == "head" && _1[:role] == "required" }.map { _1[:environment] }
|
|
72
72
|
values = [] #: Array[Hash[Symbol, untyped]]
|
|
73
73
|
scenarios.each do |scenario|
|
|
74
|
-
next if scenario[:
|
|
74
|
+
next if scenario[:system] || scenario[:feature] != row[:feature] || scenario[:line] != row[:line]
|
|
75
75
|
next if scenario[:role] == "control" || scenario[:status] != "passed" || !required.include?(scenario[:environment])
|
|
76
76
|
|
|
77
77
|
scenario[:steps].each do |step|
|
|
@@ -176,7 +176,7 @@ module Nukadoko
|
|
|
176
176
|
#: (Array[Hash[Symbol, untyped]], Array[Hash[Symbol, untyped]], ^(String) -> Array[Hash[Symbol, untyped]]) -> Array[Hash[Symbol, untyped]]
|
|
177
177
|
def with_judgments(rows, scenarios, entries_of)
|
|
178
178
|
rows.map do |row|
|
|
179
|
-
required = row[:cells].select { _1[:
|
|
179
|
+
required = row[:cells].select { _1[:system] == "head" && _1[:role] == "required" }
|
|
180
180
|
next row if required.empty? || required.any? { _1[:outcome] != "pass" }
|
|
181
181
|
|
|
182
182
|
judgment = row_judgment(row, scenarios, entries_of.(row[:feature]))
|
|
@@ -188,7 +188,7 @@ module Nukadoko
|
|
|
188
188
|
# the base's file already held that very judgment (the same claim,
|
|
189
189
|
# value, verdict, judge, reason, and time), false when the change
|
|
190
190
|
# brought it. A change cannot be trusted to judge its own output any
|
|
191
|
-
# more than to rewrite its own Thens, and the old
|
|
191
|
+
# more than to rewrite its own Thens, and the old system covers only
|
|
192
192
|
# the Thens. `base_entries_of` answers nil for a feature whose base
|
|
193
193
|
# file could not be read, and its reads stay unmarked.
|
|
194
194
|
#: (Array[Hash[Symbol, untyped]], ^(String) -> Array[Hash[Symbol, untyped]]?) -> Array[Hash[Symbol, untyped]]
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
# rbs_inline: enabled
|
|
3
|
+
|
|
4
|
+
require "delegate"
|
|
5
|
+
require "json"
|
|
6
|
+
|
|
7
|
+
# `Nukadoko.measure_mcp`, which makes the MCP calls a step sends through a
|
|
8
|
+
# client's transport part of the step record (docs/spec.md "MCP calls"):
|
|
9
|
+
# each request and notification becomes a line of the step's mcp.jsonl
|
|
10
|
+
# with the answer it got, and carries the step's trace context in
|
|
11
|
+
# `params._meta.traceparent`, so the server's log lines and execution
|
|
12
|
+
# events for the call are the step's. It decides no verdict: an `isError`
|
|
13
|
+
# result or a JSON-RPC error is an answer the step reads.
|
|
14
|
+
#
|
|
15
|
+
# It wraps the transport, not the client. The mcp gem's client calls only
|
|
16
|
+
# `send_request(request:)`, which returns the answer, and
|
|
17
|
+
# `send_notification(notification:)` on its transport, so the wrapper
|
|
18
|
+
# measures those two and hands every other method to the transport as it
|
|
19
|
+
# is: a project keeps the official client, and nukadoko requires no MCP
|
|
20
|
+
# gem.
|
|
21
|
+
#
|
|
22
|
+
# It finds the step at each send, on the thread that sends, as the
|
|
23
|
+
# requests a step sends through Net::HTTP are found. A client is usually
|
|
24
|
+
# made in a scenario fixture, outside every step, and called from several
|
|
25
|
+
# steps, so a step bound when the transport was wrapped would be the wrong
|
|
26
|
+
# one. A message sent outside every step (the client's `initialize`, or a
|
|
27
|
+
# request the client sends from a thread of its own) goes as it was given
|
|
28
|
+
# and is recorded nowhere.
|
|
29
|
+
#
|
|
30
|
+
# Over HTTP to the system, the request the transport sends for a call goes
|
|
31
|
+
# out with the call's traceparent as its header, and counts as a stamped
|
|
32
|
+
# request with the call's span, so the program's `request` line for it
|
|
33
|
+
# closes the call. Over stdio no line can close a call: that is the
|
|
34
|
+
# `mcp-unbounded` gap.
|
|
35
|
+
module Nukadoko
|
|
36
|
+
# `transport`, measured: give it to the MCP client in its place.
|
|
37
|
+
#: [T] (T) -> T
|
|
38
|
+
def self.measure_mcp(transport) = Engine::McpCalls::Measured.new(transport) # steep:ignore
|
|
39
|
+
|
|
40
|
+
module Engine
|
|
41
|
+
module McpCalls
|
|
42
|
+
FILE = "mcp.jsonl"
|
|
43
|
+
|
|
44
|
+
# The params member that names each method's target, by the line
|
|
45
|
+
# field that keeps it. A method MCP adds later is one more row.
|
|
46
|
+
TARGETS = {
|
|
47
|
+
"tools/call" => [:tool, "name"],
|
|
48
|
+
"prompts/get" => [:prompt, "name"],
|
|
49
|
+
"resources/read" => [:uri, "uri"],
|
|
50
|
+
"resources/subscribe" => [:uri, "uri"],
|
|
51
|
+
"resources/unsubscribe" => [:uri, "uri"],
|
|
52
|
+
}.freeze #: Hash[String, [Symbol, String]]
|
|
53
|
+
|
|
54
|
+
#: [T] (Array[Hash[Symbol, untyped]]) { () -> T } -> T
|
|
55
|
+
def self.collect(log)
|
|
56
|
+
Thread.current[:nukadoko_mcp] = log
|
|
57
|
+
yield
|
|
58
|
+
ensure
|
|
59
|
+
Thread.current[:nukadoko_mcp] = nil
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# The call whose transport is sending now: the traceparent its HTTP
|
|
63
|
+
# request takes, and the origins that got it.
|
|
64
|
+
#: () -> Hash[Symbol, untyped]?
|
|
65
|
+
def self.sending = Thread.current[:nukadoko_mcp_sending]
|
|
66
|
+
|
|
67
|
+
#: [T] (Hash[Symbol, untyped]) { () -> T } -> T
|
|
68
|
+
def self.sending_as(call)
|
|
69
|
+
Thread.current[:nukadoko_mcp_sending] = call
|
|
70
|
+
yield
|
|
71
|
+
ensure
|
|
72
|
+
Thread.current[:nukadoko_mcp_sending] = nil
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
# The header an MCP call's own HTTP request to a service of the system
|
|
76
|
+
# takes: the call's traceparent, so the header and `params._meta`
|
|
77
|
+
# carry one value. Nil outside a call, or to another origin.
|
|
78
|
+
#: (String) -> String?
|
|
79
|
+
def self.traceparent_for(url)
|
|
80
|
+
call = sending
|
|
81
|
+
boundary = Trace.current
|
|
82
|
+
return nil unless call && call[:traceparent] && boundary&.stamps?(url)
|
|
83
|
+
|
|
84
|
+
boundary.mcp_sent(call, url)
|
|
85
|
+
call[:traceparent]
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
# A member of a message, whichever kind of key it was written with.
|
|
89
|
+
#: (untyped, String) -> untyped
|
|
90
|
+
def self.member(message, key)
|
|
91
|
+
return nil unless message.is_a?(Hash)
|
|
92
|
+
|
|
93
|
+
message.key?(key) ? message[key] : message[key.to_sym]
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
#: (untyped) -> String?
|
|
97
|
+
def self.traceparent_in(message)
|
|
98
|
+
meta = member(member(message, "params"), "_meta")
|
|
99
|
+
value = member(meta, "traceparent")
|
|
100
|
+
value.is_a?(String) ? value : nil
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
# `message` with `traceparent` in `params._meta`, as a new Hash with
|
|
104
|
+
# keys of the kind the message has. A message that already carries a
|
|
105
|
+
# traceparent keeps it, as a request that sets its own header does,
|
|
106
|
+
# and one whose `params` is not a Hash goes as it was: JSON-RPC allows
|
|
107
|
+
# positional params, and an Array has no place for the key.
|
|
108
|
+
#: (Hash[untyped, untyped], String) -> Hash[untyped, untyped]
|
|
109
|
+
def self.stamp(message, traceparent)
|
|
110
|
+
params = member(message, "params")
|
|
111
|
+
return message unless traceparent_in(message).nil? && (params.nil? || params.is_a?(Hash))
|
|
112
|
+
|
|
113
|
+
key = message.keys.first.is_a?(Symbol) ? ->(name) { name.to_sym } : ->(name) { name }
|
|
114
|
+
params ||= {}
|
|
115
|
+
meta = member(params, "_meta")
|
|
116
|
+
meta = {} unless meta.is_a?(Hash)
|
|
117
|
+
params = params.except("_meta", :_meta).merge(key.("_meta") => meta.merge(key.("traceparent") => traceparent))
|
|
118
|
+
message.except("params", :params).merge(key.("params") => params)
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
# A call as it starts: the message as it goes out, and the
|
|
122
|
+
# traceparent nukadoko gave it, nil when it kept the step's own or
|
|
123
|
+
# the run has no system.
|
|
124
|
+
#: (Hash[untyped, untyped]) -> Hash[Symbol, untyped]
|
|
125
|
+
def self.start(message)
|
|
126
|
+
boundary = Trace.current
|
|
127
|
+
traceparent = boundary&.mcp_traceparent if traceparent_in(message).nil?
|
|
128
|
+
sent = traceparent ? stamp(message, traceparent) : message
|
|
129
|
+
{ message: sent, traceparent: traceparent, span: traceparent&.split("-")&.at(2), sent_to: [], counted: false }
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
# The mcp.jsonl line of a call and how it ended. The params and the
|
|
133
|
+
# result are their JSON text, kept as a body is; a JSON-RPC error
|
|
134
|
+
# keeps its code and the first line of its message, which can carry
|
|
135
|
+
# a stack. The record redacts the line as it writes it.
|
|
136
|
+
#: (Hash[Symbol, untyped], **untyped) -> Hash[Symbol, untyped]
|
|
137
|
+
def self.line(call, **ended)
|
|
138
|
+
message = call[:message]
|
|
139
|
+
method = member(message, "method").to_s
|
|
140
|
+
id = member(message, "id")
|
|
141
|
+
params = member(message, "params")
|
|
142
|
+
answer = ended[:answer]
|
|
143
|
+
result = member(answer, "result") if answer
|
|
144
|
+
error = member(answer, "error") if answer
|
|
145
|
+
field, param = TARGETS[method]
|
|
146
|
+
target = field && member(params, param.to_s)
|
|
147
|
+
traceparent = traceparent_in(message)
|
|
148
|
+
sent_to = call[:sent_to] #: Array[String]
|
|
149
|
+
{ method: method, **(id.is_a?(String) || id.is_a?(Integer) ? { id: id } : {}),
|
|
150
|
+
**(ended[:notification] ? { notification: true } : {}),
|
|
151
|
+
**(target.is_a?(String) && field ? { field => target } : {}),
|
|
152
|
+
**(params.nil? ? {} : { params: kept(params) }),
|
|
153
|
+
**(traceparent ? { traceparent: traceparent } : {}),
|
|
154
|
+
**(sent_to.empty? ? {} : { header_sent_to: sent_to.dup }),
|
|
155
|
+
**(ended.key?(:duration_ms) ? { duration_ms: ended[:duration_ms] } : {}),
|
|
156
|
+
**(answer.is_a?(Hash) && (answer.key?("result") || answer.key?(:result)) ? { result: kept(result) } : {}),
|
|
157
|
+
**(member(result, "isError") == true ? { is_error: true } : {}),
|
|
158
|
+
**(error ? { error: { code: (code = member(error, "code")).is_a?(Integer) ? code : nil, message: member(error, "message").to_s.lines.first.to_s.chomp } } : {}),
|
|
159
|
+
**(ended[:send_error] ? { send_error: ended[:send_error] } : {}) }
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
#: (untyped) -> Hash[Symbol, untyped]
|
|
163
|
+
def self.kept(value)
|
|
164
|
+
Request.body(:value, JSON.generate(value))[:value] || { text: "", bytes: 0 }
|
|
165
|
+
rescue JSON::GeneratorError
|
|
166
|
+
{ unread: "not JSON text" }
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
# The transport, measured. Recording never breaks the call: the
|
|
170
|
+
# transport's own error goes on to the client unchanged.
|
|
171
|
+
class Measured < SimpleDelegator
|
|
172
|
+
#: (request: Hash[untyped, untyped]) ?{ () -> void } -> untyped
|
|
173
|
+
def send_request(request:, &block)
|
|
174
|
+
log = ::Thread.current[:nukadoko_mcp] #: Array[Hash[Symbol, untyped]]?
|
|
175
|
+
return __getobj__.send_request(request: request, &block) unless log && request.is_a?(Hash)
|
|
176
|
+
|
|
177
|
+
call = McpCalls.start(request)
|
|
178
|
+
started = ::Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
179
|
+
begin
|
|
180
|
+
answer = McpCalls.sending_as(call) { __getobj__.send_request(request: call[:message], &block) }
|
|
181
|
+
rescue StandardError => e
|
|
182
|
+
log << McpCalls.line(call, send_error: e.message.lines.first.to_s.chomp, duration_ms: Request.since(started))
|
|
183
|
+
::Kernel.raise e
|
|
184
|
+
end
|
|
185
|
+
log << McpCalls.line(call, answer: answer, duration_ms: Request.since(started))
|
|
186
|
+
answer
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
# A notification has no answer, so its line is written as it goes.
|
|
190
|
+
#: (notification: Hash[untyped, untyped]) -> untyped
|
|
191
|
+
def send_notification(notification:)
|
|
192
|
+
log = ::Thread.current[:nukadoko_mcp] #: Array[Hash[Symbol, untyped]]?
|
|
193
|
+
return __getobj__.send_notification(notification: notification) unless log && notification.is_a?(Hash)
|
|
194
|
+
|
|
195
|
+
call = McpCalls.start(notification)
|
|
196
|
+
log << McpCalls.line(call, notification: true)
|
|
197
|
+
McpCalls.sending_as(call) { __getobj__.send_notification(notification: call[:message]) }
|
|
198
|
+
end
|
|
199
|
+
end
|
|
200
|
+
end
|
|
201
|
+
end
|
|
202
|
+
end
|
data/lib/nukadoko/parts.rb
CHANGED
|
@@ -16,9 +16,12 @@ module Nukadoko
|
|
|
16
16
|
|
|
17
17
|
attr_reader :calls
|
|
18
18
|
|
|
19
|
-
#: (singleton(Nukadoko::Step), Hash[Symbol, untyped]) -> void
|
|
20
|
-
def initialize(step, fixtures)
|
|
19
|
+
#: (singleton(Nukadoko::Step), Hash[Symbol, untyped], ?refuse: ^(untyped) -> String?) -> void
|
|
20
|
+
def initialize(step, fixtures, refuse: ->(_) {})
|
|
21
21
|
@fixtures = fixtures
|
|
22
|
+
# Why a part may not run here: a part that mutates in a read-only
|
|
23
|
+
# environment is refused as its caller would be.
|
|
24
|
+
@refuse = refuse
|
|
22
25
|
@stack = [step]
|
|
23
26
|
@calls = []
|
|
24
27
|
@into = [@calls]
|
|
@@ -40,6 +43,9 @@ module Nukadoko
|
|
|
40
43
|
%(built from that list before "run" is called, so a part the list does not name has nothing to run with.)
|
|
41
44
|
end
|
|
42
45
|
|
|
46
|
+
refused = @refuse.(part)
|
|
47
|
+
raise Refused, refused if refused
|
|
48
|
+
|
|
43
49
|
args = args.merge(keywords).transform_keys(&:to_s)
|
|
44
50
|
entry = { step: part.step_name, args: args }
|
|
45
51
|
started = Time.now.utc.iso8601(3)
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
# rbs_inline: enabled
|
|
3
|
+
|
|
4
|
+
require "json"
|
|
5
|
+
|
|
6
|
+
# Responsibility: run.json's `paths` (docs/spec.md "Execution events"):
|
|
7
|
+
# for each pair of sides the run can compare, what each criterion's steps
|
|
8
|
+
# did differently on one side than on the other, as their paths say
|
|
9
|
+
# (events/path.rb), so a person about to turn a change on for everyone
|
|
10
|
+
# reads what changed in what the program did. Pure: it reads run.json's
|
|
11
|
+
# own fields and nothing else. Boundary: a path, and the range a count on
|
|
12
|
+
# it lies in, are events/path.rb's; the cells and their outcomes are the
|
|
13
|
+
# table's; this module adds no verdict.
|
|
14
|
+
#
|
|
15
|
+
# A pair is two sides of one criterion. Under `nuka run --base`, each
|
|
16
|
+
# environment's base system is paired with its head system, for the rows
|
|
17
|
+
# whose head cell there is required and ran. Otherwise it is two head
|
|
18
|
+
# environments whose declared `conditions` differ in exactly one
|
|
19
|
+
# condition. Steps align by their line in head's feature file, and a
|
|
20
|
+
# criterion whose two step lists differ is not compared. A side is read
|
|
21
|
+
# from its cell's first execution, since repeats and proof runs add more.
|
|
22
|
+
#
|
|
23
|
+
# Two counts are the same when both are exact and equal, changed when
|
|
24
|
+
# their ranges cannot meet, and open otherwise: a count a side's missing
|
|
25
|
+
# lines could still reach never reads as a change. A criterion whose every
|
|
26
|
+
# open count reads the same on both sides, under the same gap words, is
|
|
27
|
+
# `same_so_far`. In a pair of environments, a flag's side differing is the
|
|
28
|
+
# switch the pair was made to compare, so a kind PATH_KINDS marks as the
|
|
29
|
+
# premise is never among what changed. Against the base, it is compared as
|
|
30
|
+
# any kind is.
|
|
31
|
+
#
|
|
32
|
+
# A write to a table the tables list marks is compared too, and its
|
|
33
|
+
# difference carries what the table holds. A criterion's `result` reads
|
|
34
|
+
# the other differences alone, and one whose only differences are on
|
|
35
|
+
# marked tables is `marked_only`, never `same`: something did differ.
|
|
36
|
+
#
|
|
37
|
+
# Against the base, a changed criterion says what accounts for it: on a
|
|
38
|
+
# new or changed criterion, the new sentences a person approves; on an
|
|
39
|
+
# unchanged one, nothing in the feature files, which is the one a reader
|
|
40
|
+
# is sent to first.
|
|
41
|
+
module Nukadoko
|
|
42
|
+
module Engine
|
|
43
|
+
module PathView
|
|
44
|
+
RESULTS = %w[changed open same_so_far marked_only same].freeze
|
|
45
|
+
|
|
46
|
+
module_function
|
|
47
|
+
|
|
48
|
+
# One comparison per pair of sides the run can compare: each base
|
|
49
|
+
# pair, then each pair of environments, in the run's order of
|
|
50
|
+
# environments; [] when there is none.
|
|
51
|
+
#: (Hash[Symbol, untyped]) -> Array[Hash[Symbol, untyped]]
|
|
52
|
+
def compare(doc)
|
|
53
|
+
(base_pairs(doc) + condition_pairs(doc[:environments])).filter_map { compare_pair(doc, _1) }
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
#: (Hash[Symbol, untyped]) -> Array[Hash[Symbol, untyped]]
|
|
57
|
+
def base_pairs(doc)
|
|
58
|
+
return [] if doc.dig(:table, :base).nil?
|
|
59
|
+
|
|
60
|
+
doc[:environments].map { |e| { between: { kind: "base" }, a: { system: "base", environment: e[:name] }, b: { system: "head", environment: e[:name] } } }
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# Every two environments whose declared conditions differ in exactly
|
|
64
|
+
# one: side `a` holds false or no value where `b` holds true, and
|
|
65
|
+
# otherwise the earlier environment.
|
|
66
|
+
#: (Array[Hash[Symbol, untyped]]) -> Array[Hash[Symbol, untyped]]
|
|
67
|
+
def condition_pairs(environments)
|
|
68
|
+
pairs = [] #: Array[Hash[Symbol, untyped]]
|
|
69
|
+
environments.each_with_index do |first, index|
|
|
70
|
+
environments.drop(index + 1).each do |second|
|
|
71
|
+
one = (first[:conditions] || {}).transform_keys(&:to_s)
|
|
72
|
+
other = (second[:conditions] || {}).transform_keys(&:to_s)
|
|
73
|
+
differ = (one.keys | other.keys).reject { one[_1] == other[_1] && one.key?(_1) == other.key?(_1) }
|
|
74
|
+
next unless differ.size == 1
|
|
75
|
+
|
|
76
|
+
name = differ.first
|
|
77
|
+
flipped = one[name] == true && (other[name] == false || !other.key?(name))
|
|
78
|
+
a, b = flipped ? [[second, other], [first, one]] : [[first, one], [second, other]]
|
|
79
|
+
pairs << { between: { kind: "condition", name: name, a: a.last.fetch(name, nil), b: b.last.fetch(name, nil) },
|
|
80
|
+
a: { system: "head", environment: a.first[:name] }, b: { system: "head", environment: b.first[:name] } }
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
pairs
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# Whether a side's system read its events: "read", "none" when no
|
|
87
|
+
# base system started in the environment, or why it gave no paths.
|
|
88
|
+
#: (Hash[Symbol, untyped], Hash[Symbol, untyped]) -> (String | Hash[Symbol, String])
|
|
89
|
+
def reading_of(doc, side)
|
|
90
|
+
system = (doc[:systems] || []).find { (_1[:tree] || "head") == side[:system] && _1[:name] == side[:environment] }
|
|
91
|
+
base = side[:system] == "base"
|
|
92
|
+
return "none" if system.nil? && base
|
|
93
|
+
|
|
94
|
+
named = base ? "the base system" : "system #{side[:environment]}"
|
|
95
|
+
return { unread: "the program did not start for #{named}" } if system.nil? || !system[:error].nil?
|
|
96
|
+
# A step's path holds the lines of every service whose events are
|
|
97
|
+
# read, so one service that names {events} is enough to compare.
|
|
98
|
+
named_events = (system[:services] || []).select { _1.key?(:events) }
|
|
99
|
+
if named_events.empty?
|
|
100
|
+
return { unread: base ? "the base's program names no {events}, so the base system wrote no execution events" : "the program of #{named} names no {events}, so it wrote no execution events" }
|
|
101
|
+
end
|
|
102
|
+
return { unread: "#{named} runs at #{system[:url] || "a url"}, which nukadoko did not start, so it read no execution events there" } if named_events.all? { _1[:events].nil? }
|
|
103
|
+
|
|
104
|
+
"read"
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
#: (Hash[Symbol, untyped], Hash[Symbol, untyped]) -> String
|
|
108
|
+
def side_where(pair, side)
|
|
109
|
+
return side[:system] == "base" ? "at the base" : "at head" if pair.dig(:between, :kind) == "base"
|
|
110
|
+
|
|
111
|
+
"in #{side[:environment]}"
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
# A side's first execution of a row, with what its cell came to, or
|
|
115
|
+
# what it came to itself when the base ran it for paths alone.
|
|
116
|
+
#: (Hash[Symbol, untyped], Hash[Symbol, untyped], Hash[Symbol, untyped]) -> Hash[Symbol, untyped]?
|
|
117
|
+
def side_of(doc, row, side)
|
|
118
|
+
scenario = doc[:scenarios].find do |entry|
|
|
119
|
+
at = entry[:row] || entry
|
|
120
|
+
(entry[:system] || "head") == side[:system] && entry[:environment] == side[:environment] && at[:feature] == row[:feature] && at[:line] == row[:line]
|
|
121
|
+
end
|
|
122
|
+
came = row[:cells].find { _1[:system] == side[:system] && _1[:environment] == side[:environment] } || scenario&.dig(:for_paths)
|
|
123
|
+
return nil if scenario.nil? || came.nil?
|
|
124
|
+
|
|
125
|
+
{ scenario: scenario, execution: { scenario_record_id: scenario[:scenario_record_id], outcome: came[:outcome], line: came[:line] }.compact }
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
#: (Hash[Symbol, untyped], Hash[Symbol, untyped]) -> bool
|
|
129
|
+
def pair_compares?(pair, row)
|
|
130
|
+
return true if pair.dig(:between, :kind) == "condition"
|
|
131
|
+
|
|
132
|
+
head = row[:cells].find { _1[:system] == "head" && _1[:environment] == pair.dig(:b, :environment) }
|
|
133
|
+
!head.nil? && head[:role] == "required" && head[:outcome] != "not-run"
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
#: (Hash[Symbol, untyped]) -> bool
|
|
137
|
+
def exact?(range) = range[:at_most] == range[:at_least]
|
|
138
|
+
|
|
139
|
+
#: (Hash[Symbol, untyped], Hash[Symbol, untyped]) -> bool
|
|
140
|
+
def apart?(one, other)
|
|
141
|
+
(!one[:at_most].nil? && one[:at_most] < other[:at_least]) || (!other[:at_most].nil? && other[:at_most] < one[:at_least])
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
#: (Array[Hash[Symbol, untyped]]) -> Array[String]
|
|
145
|
+
def gap_words(gaps) = gaps.map { _1[:gap] }.uniq.sort
|
|
146
|
+
|
|
147
|
+
#: (Array[Hash[Symbol, untyped]]) -> Array[Hash[Symbol, untyped]]
|
|
148
|
+
def unmarked(differences) = differences.select { _1[:holds].nil? }
|
|
149
|
+
|
|
150
|
+
#: (Hash[Symbol, untyped]) -> bool
|
|
151
|
+
def same_so_far?(step)
|
|
152
|
+
unmarked(step[:open]).all? { _1[:a] == _1[:b] } && gap_words(step[:gaps][:a]) == gap_words(step[:gaps][:b])
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
# A path as events/path.rb reads it, from run.json's own shape or
|
|
156
|
+
# from one read back with symbol keys: entries and requests keyed by
|
|
157
|
+
# strings, gaps by symbols.
|
|
158
|
+
#: (Hash[Symbol, untyped]) -> Hash[Symbol, untyped]
|
|
159
|
+
def path_of(path)
|
|
160
|
+
{ requests: JSON.parse(JSON.generate(path[:requests] || [])), entries: JSON.parse(JSON.generate(path[:entries] || [])),
|
|
161
|
+
maybe: path[:maybe] || 0, open: JSON.parse(JSON.generate(path[:open] || []), symbolize_names: true) }
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
#: (Hash[Symbol, untyped], Hash[Symbol, untyped], ^(String) -> bool) -> Hash[Symbol, untyped]
|
|
165
|
+
def step_difference(one, other, compared)
|
|
166
|
+
changed = [] #: Array[Hash[Symbol, untyped]]
|
|
167
|
+
open = [] #: Array[Hash[Symbol, untyped]]
|
|
168
|
+
Events.keys_of(one, other).select { compared.(_1["kind"]) }.each do |key|
|
|
169
|
+
ranges = { a: Events.range_on(one, key), b: Events.range_on(other, key) }
|
|
170
|
+
next if exact?(ranges[:a]) && exact?(ranges[:b]) && ranges[:a][:at_least] == ranges[:b][:at_least]
|
|
171
|
+
|
|
172
|
+
holds = Events.holds_on(other, key) || Events.holds_on(one, key)
|
|
173
|
+
(apart?(ranges[:a], ranges[:b]) ? changed : open) << { **key.transform_keys(&:to_sym), **(holds.nil? ? {} : { holds: holds }), **ranges }
|
|
174
|
+
end
|
|
175
|
+
{ changed: changed, open: open }
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
#: (Hash[Symbol, untyped], Hash[Symbol, untyped], Array[Hash[Symbol, untyped]], ^(String) -> bool) -> Hash[Symbol, untyped]
|
|
179
|
+
def compare_criterion(pair, row, sides, compared)
|
|
180
|
+
steps_a = sides[0][:scenario][:steps] || []
|
|
181
|
+
steps_b = sides[1][:scenario][:steps] || []
|
|
182
|
+
if steps_a.size != steps_b.size || steps_a.each_with_index.any? { |step, index| step[:line] != steps_b[index][:line] }
|
|
183
|
+
return { reason: "ran steps that differ between the two sides, which run one pickle, a bug in nukadoko" }
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
steps = [] #: Array[Hash[Symbol, untyped]]
|
|
187
|
+
steps_a.each_with_index do |step_a, index|
|
|
188
|
+
step_b = steps_b[index]
|
|
189
|
+
ran_a = !step_a[:record].nil?
|
|
190
|
+
ran_b = !step_b[:record].nil?
|
|
191
|
+
if ran_a != ran_b
|
|
192
|
+
steps << { line: step_a[:line], text: step_a[:text], ran: ran_a ? "a" : "b" }
|
|
193
|
+
next
|
|
194
|
+
end
|
|
195
|
+
next unless ran_a
|
|
196
|
+
if step_a[:path].nil? || step_b[:path].nil?
|
|
197
|
+
return { reason: "kept no path of its step at line #{step_a[:line] || "unknown"} #{side_where(pair, step_a[:path].nil? ? pair[:a] : pair[:b])}" }
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
path_a = path_of(step_a[:path])
|
|
201
|
+
path_b = path_of(step_b[:path])
|
|
202
|
+
found = step_difference(path_a, path_b, compared)
|
|
203
|
+
next if found[:changed].empty? && found[:open].empty?
|
|
204
|
+
|
|
205
|
+
steps << { line: step_a[:line], text: step_a[:text], ran: "both", **found, gaps: { a: Events.bounding_gaps(path_a), b: Events.bounding_gaps(path_b) } }
|
|
206
|
+
end
|
|
207
|
+
changed = steps.any? { _1[:ran] != "both" || unmarked(_1[:changed]).any? }
|
|
208
|
+
read = steps.select { _1[:ran] != "both" || (unmarked(_1[:changed]) + unmarked(_1[:open])).any? }
|
|
209
|
+
result = if changed then "changed"
|
|
210
|
+
elsif read.any? then read.all? { _1[:ran] == "both" && same_so_far?(_1) } ? "same_so_far" : "open"
|
|
211
|
+
elsif steps.any? then "marked_only"
|
|
212
|
+
else "same"
|
|
213
|
+
end
|
|
214
|
+
explained = pair.dig(:between, :kind) == "base" && result == "changed" ? { explained_by: %w[new changed].include?(row[:change]) ? "criterion_change" : nil } : {}
|
|
215
|
+
{ criterion: { feature: row[:feature], line: row[:line], name: row[:name], result: result, **explained,
|
|
216
|
+
a: sides[0][:execution], b: sides[1][:execution], **(result == "same" ? {} : { steps: steps }) } }
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
#: (Hash[Symbol, untyped], Hash[Symbol, untyped]) -> Hash[Symbol, untyped]?
|
|
220
|
+
def compare_pair(doc, pair)
|
|
221
|
+
readings = [reading_of(doc, pair[:a]), reading_of(doc, pair[:b])]
|
|
222
|
+
# Neither side read events: a run of a program that reports none
|
|
223
|
+
# says nothing about paths.
|
|
224
|
+
return nil unless readings.include?("read")
|
|
225
|
+
|
|
226
|
+
empty = RESULTS.to_h { [_1.to_sym, 0] }.merge(not_compared: 0)
|
|
227
|
+
why = readings.find { _1.is_a?(Hash) }
|
|
228
|
+
return { **pair, unread: why[:unread], counts: empty, criteria: [], not_compared: [] } if why.is_a?(Hash)
|
|
229
|
+
|
|
230
|
+
compared = ->(kind) { !(pair.dig(:between, :kind) == "condition" && Events.kind_rule(kind)[:condition_premise] == true) }
|
|
231
|
+
criteria = [] #: Array[Hash[Symbol, untyped]]
|
|
232
|
+
not_compared = [] #: Array[Hash[Symbol, untyped]]
|
|
233
|
+
doc.dig(:table, :rows).each do |row|
|
|
234
|
+
next if row[:verdict] == "removed" || !pair_compares?(pair, row)
|
|
235
|
+
|
|
236
|
+
sides = [side_of(doc, row, pair[:a]), side_of(doc, row, pair[:b])]
|
|
237
|
+
missing = [pair[:a], pair[:b]].each_with_index.find { |_, index| sides[index].nil? }&.first
|
|
238
|
+
if missing
|
|
239
|
+
not_compared << { feature: row[:feature], line: row[:line], reason: "did not run #{side_where(pair, missing)}" }
|
|
240
|
+
next
|
|
241
|
+
end
|
|
242
|
+
found = compare_criterion(pair, row, sides.compact, compared)
|
|
243
|
+
if found[:reason] then not_compared << { feature: row[:feature], line: row[:line], reason: found[:reason] }
|
|
244
|
+
else criteria << found[:criterion]
|
|
245
|
+
end
|
|
246
|
+
end
|
|
247
|
+
counts = RESULTS.to_h { |result| [result.to_sym, criteria.count { _1[:result] == result }] }.merge(not_compared: not_compared.size)
|
|
248
|
+
{ **pair, unread: nil, counts: counts, criteria: criteria, not_compared: not_compared }
|
|
249
|
+
end
|
|
250
|
+
end
|
|
251
|
+
end
|
|
252
|
+
end
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
# rbs_inline: enabled
|
|
3
|
+
|
|
4
|
+
# Responsibility: run.json's `flags` and `routes` (docs/spec.md "Execution
|
|
5
|
+
# events" and "Lists"): the verdict table read once per place of the
|
|
6
|
+
# program the head executions' paths reached, a flag's side or a route,
|
|
7
|
+
# with each criterion's verdict and its cells there. Pure: it reads the
|
|
8
|
+
# scenarios and the table run.json already holds. Boundary: a step's path
|
|
9
|
+
# is the system's stop's (events/path.rb), the table is run.rb's, and what
|
|
10
|
+
# a system's lists hold is the system's start; this module adds no verdict.
|
|
11
|
+
#
|
|
12
|
+
# Only head's executions are read: the base system runs the ref's code, and
|
|
13
|
+
# the old system the ref's criteria, so their cells are read in the table.
|
|
14
|
+
# A criterion counts under its row's verdict only where it has a required
|
|
15
|
+
# cell at the place, so a red count is never hidden; one seen at the place
|
|
16
|
+
# only in controls counts as `controls`.
|
|
17
|
+
#
|
|
18
|
+
# A flag's side is the one its line names, so one execution that switches
|
|
19
|
+
# a flag for one actor stands under both sides. When a head system read the
|
|
20
|
+
# flags list, every side it declares has a row, and every row names the
|
|
21
|
+
# environments whose list declares it. A request line names the route the
|
|
22
|
+
# program matched, never what a step claimed on the answer, so a route
|
|
23
|
+
# entry says requested, never checked.
|
|
24
|
+
|
|
25
|
+
module Nukadoko
|
|
26
|
+
module Engine
|
|
27
|
+
module PlaceRows
|
|
28
|
+
COUNTED = %i[held proven failed unproven moved].freeze
|
|
29
|
+
|
|
30
|
+
module_function
|
|
31
|
+
|
|
32
|
+
# Each place the head executions' visits reached, by key, in the order
|
|
33
|
+
# of its first visit: its criteria in the table's row order, each with
|
|
34
|
+
# its head cells there in the table's column order. `visits` gives an
|
|
35
|
+
# execution's visits as [key, place, detail]; `cell_of` what a cell
|
|
36
|
+
# holds beyond the table's fields, from its visits' details.
|
|
37
|
+
#: (Array[Hash[Symbol, untyped]], Array[Hash[Symbol, untyped]], ^(Hash[Symbol, untyped]) -> Array[[String, untyped, untyped]], ^(Array[untyped]) -> Hash[Symbol, untyped]) -> Hash[String, Hash[Symbol, untyped]]
|
|
38
|
+
def criteria_by_place(scenarios, rows, visits, cell_of)
|
|
39
|
+
index_of = rows.each_with_index.to_h { |row, index| [[row[:feature], row[:line]], index] }
|
|
40
|
+
reached = {} #: Hash[String, Hash[Symbol, untyped]]
|
|
41
|
+
scenarios.each do |scenario|
|
|
42
|
+
next if scenario[:system]
|
|
43
|
+
|
|
44
|
+
index = index_of[[scenario[:feature], scenario[:line]]]
|
|
45
|
+
next unless index
|
|
46
|
+
|
|
47
|
+
visits.(scenario).each do |key, place, detail|
|
|
48
|
+
at = reached[key] ||= { place: place, rows: {} }
|
|
49
|
+
((at[:rows][index] ||= {})[scenario[:environment]] ||= []) << detail
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
reached.transform_values do |at|
|
|
53
|
+
criteria = at[:rows].sort_by(&:first).filter_map do |index, cells|
|
|
54
|
+
row = rows[index]
|
|
55
|
+
next nil if row[:verdict] == "removed"
|
|
56
|
+
|
|
57
|
+
here = row[:cells].filter_map do |cell|
|
|
58
|
+
details = cell[:system] == "head" ? cells[cell[:environment]] : nil
|
|
59
|
+
next nil unless details
|
|
60
|
+
|
|
61
|
+
{ environment: cell[:environment], role: cell[:role], outcome: cell[:outcome], line: cell[:line] }.compact.merge(cell_of.(details || []))
|
|
62
|
+
end
|
|
63
|
+
here.empty? ? nil : { feature: row[:feature], line: row[:line], name: row[:name], verdict: row[:verdict], cells: here }
|
|
64
|
+
end
|
|
65
|
+
{ place: at[:place], criteria: criteria }
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
#: (Array[Hash[Symbol, untyped]]) -> Hash[Symbol, Integer]
|
|
70
|
+
def counts_of(criteria)
|
|
71
|
+
counts = { held: 0, proven: 0, failed: 0, unproven: 0, moved: 0, controls: 0 }
|
|
72
|
+
criteria.each do |criterion|
|
|
73
|
+
key = criterion[:cells].any? { _1[:role] == "required" } ? criterion[:verdict].to_sym : :controls
|
|
74
|
+
counts[key] += 1
|
|
75
|
+
end
|
|
76
|
+
counts
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
#: (Hash[Symbol, untyped]) -> Array[Hash[String, untyped]]
|
|
80
|
+
def paths_of(scenario) = scenario[:steps].filter_map { _1[:path] }
|
|
81
|
+
|
|
82
|
+
#: (String?, String, String) -> String
|
|
83
|
+
def flag_key(service, name, side) = JSON.generate([service, name, side])
|
|
84
|
+
|
|
85
|
+
# One row per service, flag, and side the head paths' flag entries
|
|
86
|
+
# name, and per side a read flags list declares, by service, then
|
|
87
|
+
# flag name, then side. Each service of the system evaluates its own
|
|
88
|
+
# flags, so a row is one (service, name, side): two services can hold
|
|
89
|
+
# a flag of the same name and decide it apart. A read flags list is
|
|
90
|
+
# the primary service's, so the sides it declares are rows of that
|
|
91
|
+
# service, which `listed` names beside each environment.
|
|
92
|
+
#: (Array[Hash[Symbol, untyped]], Array[Hash[Symbol, untyped]], ?Array[Hash[Symbol, untyped]]) -> Array[Hash[Symbol, untyped]]
|
|
93
|
+
def flag_rows(scenarios, rows, listed = [])
|
|
94
|
+
place_of = ->(service, name, side) { { **(service ? { service: service } : {}), name: name, side: side } }
|
|
95
|
+
visits = lambda do |scenario|
|
|
96
|
+
paths_of(scenario).flat_map do |path|
|
|
97
|
+
path[:entries].select { _1["kind"] == "flag" }.flat_map do |entry|
|
|
98
|
+
place = place_of.(entry["service"], entry["name"], entry["side"])
|
|
99
|
+
(entry["gates"] || []).map { [flag_key(entry["service"], entry["name"], entry["side"]), place, _1] }
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
cell_of = ->(gates) { { gates: gates.uniq.sort { |a, b| Events.by_gate(a, b) } } }
|
|
104
|
+
evaluated = criteria_by_place(scenarios, rows, visits, cell_of)
|
|
105
|
+
sides = {} #: Hash[String, Hash[Symbol, untyped]]
|
|
106
|
+
evaluated.each { |key, at| sides[key] = { **at[:place], listed_in: [] } if at[:criteria].any? }
|
|
107
|
+
listed.each do |list|
|
|
108
|
+
list[:flags].each do |flag|
|
|
109
|
+
flag[:sides].each do |side|
|
|
110
|
+
entry = sides[flag_key(list[:service], flag[:name], side)] ||= { **place_of.(list[:service], flag[:name], side), listed_in: [] }
|
|
111
|
+
entry[:listed_in] << list[:environment] unless entry[:listed_in].include?(list[:environment])
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
# A flag of one service, named by its service, so one service's only
|
|
116
|
+
# side is not read as another's.
|
|
117
|
+
sides_evaluated = evaluated.values.select { _1[:criteria].any? }.map { [_1[:place][:service], _1[:place][:name]] }.tally
|
|
118
|
+
sides.sort_by { |_, entry| [entry[:service].to_s, entry[:name], entry[:side]] }.map do |key, entry|
|
|
119
|
+
criteria = evaluated.dig(key, :criteria) || []
|
|
120
|
+
{ **(entry[:service] ? { service: entry[:service] } : {}), name: entry[:name], side: entry[:side], criteria: criteria, counts: counts_of(criteria),
|
|
121
|
+
**(listed.empty? ? {} : { listed_in: entry[:listed_in] }),
|
|
122
|
+
**(criteria.any? && sides_evaluated[[entry[:service], entry[:name]]] == 1 ? { only_side_evaluated: true } : {}) }
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
# One entry per method and route a head system's routes list or a head
|
|
127
|
+
# step's request line names, by route (a route no line matched last),
|
|
128
|
+
# then by method. `listed` is each environment whose routes list was
|
|
129
|
+
# read, in the run's order.
|
|
130
|
+
#: (Array[Hash[Symbol, untyped]], Array[Hash[Symbol, untyped]], Array[Hash[Symbol, untyped]]) -> Array[Hash[Symbol, untyped]]
|
|
131
|
+
def route_rows(scenarios, rows, listed)
|
|
132
|
+
key_of = ->(method, route) { JSON.generate([method, route]) }
|
|
133
|
+
entries = {} #: Hash[String, Hash[Symbol, untyped]]
|
|
134
|
+
entry_of = ->(method, route) { entries[key_of.(method, route)] ||= { method: method, route: route, handlers: [], listed_in: [], requests: 0, statuses: [] } }
|
|
135
|
+
listed.each do |list|
|
|
136
|
+
list[:routes].each do |route|
|
|
137
|
+
entry = entry_of.(route[:method], route[:route])
|
|
138
|
+
entry[:listed_in] << list[:environment] unless entry[:listed_in].include?(list[:environment])
|
|
139
|
+
entry[:handlers] |= route[:handlers]
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
served = ->(scenario) { paths_of(scenario).flat_map { _1[:requests] } }
|
|
143
|
+
scenarios.each do |scenario|
|
|
144
|
+
next if scenario[:system]
|
|
145
|
+
|
|
146
|
+
served.(scenario).each do |request|
|
|
147
|
+
entry = entry_of.(request["method"], request["route"])
|
|
148
|
+
entry[:requests] += 1
|
|
149
|
+
entry[:statuses] |= [request["status"]]
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
visits = ->(scenario) { served.(scenario).map { [key_of.(_1["method"], _1["route"]), nil, _1["status"]] } } #: ^(Hash[Symbol, untyped]) -> Array[[String, untyped, untyped]]
|
|
153
|
+
reached = criteria_by_place(scenarios, rows, visits, ->(statuses) { { requests: statuses.size, statuses: statuses.uniq.sort } })
|
|
154
|
+
entries.map do |key, entry|
|
|
155
|
+
criteria = reached.dig(key, :criteria) || []
|
|
156
|
+
{ **entry, handlers: entry[:handlers].sort, statuses: entry[:statuses].sort, criteria: criteria, counts: counts_of(criteria) }
|
|
157
|
+
end.sort_by { [_1[:route].nil? ? 1 : 0, _1[:route].to_s, _1[:method]] }
|
|
158
|
+
end
|
|
159
|
+
end
|
|
160
|
+
end
|
|
161
|
+
end
|