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/fixtures.rb
CHANGED
|
@@ -28,7 +28,7 @@ module Nukadoko
|
|
|
28
28
|
class Request
|
|
29
29
|
attr_reader :log #: Array[Hash[Symbol, untyped]]
|
|
30
30
|
|
|
31
|
-
# `base_url` is the
|
|
31
|
+
# `base_url` is the system's URL, which a path joins onto; a project with
|
|
32
32
|
# no program has none. An absolute URL, http or https, goes where it
|
|
33
33
|
# names, so a step can call a third-party API and still have its
|
|
34
34
|
# requests recorded.
|
|
@@ -42,7 +42,7 @@ module Nukadoko
|
|
|
42
42
|
def target(path)
|
|
43
43
|
named = URI(path.to_s)
|
|
44
44
|
return named if named.absolute?
|
|
45
|
-
raise ArgumentError, %(The request fixture needs an absolute URL for "#{path}": this
|
|
45
|
+
raise ArgumentError, %(The request fixture needs an absolute URL for "#{path}": this system has no program, so there is no base URL to join a path onto) unless @base
|
|
46
46
|
|
|
47
47
|
URI.join(@base.to_s, path.to_s)
|
|
48
48
|
end
|
|
@@ -79,13 +79,17 @@ module Nukadoko
|
|
|
79
79
|
req.body = JSON.generate(data)
|
|
80
80
|
end
|
|
81
81
|
req.body = body if body
|
|
82
|
-
# The
|
|
82
|
+
# The system's origin gets the step's traceparent, so the program's
|
|
83
83
|
# log says which step a request came from.
|
|
84
84
|
traceparent = req["traceparent"] ? nil : Trace.current&.stamp(uri)
|
|
85
85
|
req["traceparent"] = traceparent if traceparent
|
|
86
86
|
started = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
87
87
|
entry = { method: verb.upcase, url: uri.to_s, **(path.to_s == uri.to_s ? {} : { declared_url: path.to_s }) }
|
|
88
88
|
stamp = traceparent ? { traceparent: traceparent, traceparent_sent_to: [Trace.origin(uri)] } : {}
|
|
89
|
+
# The service of the system whose origin answers, stamped or not;
|
|
90
|
+
# a request to no service's origin names none.
|
|
91
|
+
reached = Trace.current&.service_at(uri)
|
|
92
|
+
stamp = stamp.merge(service: reached) if reached
|
|
89
93
|
begin
|
|
90
94
|
res = HttpRecording.unrecorded { Net::HTTP.start(uri.host.to_s, uri.port, use_ssl: uri.scheme == "https") { _1.request(req) } }
|
|
91
95
|
rescue StandardError => e
|
|
@@ -106,11 +110,15 @@ module Nukadoko
|
|
|
106
110
|
class Browser
|
|
107
111
|
# `secrets` gives the run's loaded secrets when a screenshot is taken,
|
|
108
112
|
# since an environment's env files are read after the browser is made.
|
|
109
|
-
|
|
110
|
-
|
|
113
|
+
# `stamped` are the URLs of the system's services a page's request to
|
|
114
|
+
# gets the step's traceparent (System#trace_origins); the primary's by
|
|
115
|
+
# default.
|
|
116
|
+
#: (String?, ?Hash[Symbol, untyped], ?secrets: ^() -> Secrets, ?stamped: Array[String]?) -> void
|
|
117
|
+
def initialize(base_url, launch_options = {}, secrets: -> { Secrets.new }, stamped: nil)
|
|
111
118
|
@base_url = base_url
|
|
112
119
|
@launch_options = launch_options
|
|
113
120
|
@secrets = secrets
|
|
121
|
+
@stamped = stamped || [*base_url]
|
|
114
122
|
end
|
|
115
123
|
|
|
116
124
|
# Opaque, so a masked secret leaves no trace of its glyphs.
|
|
@@ -172,14 +180,15 @@ module Nukadoko
|
|
|
172
180
|
@context ||= @browser.new_context(baseURL: @base_url).tap do |context|
|
|
173
181
|
context.tracing.start(screenshots: true, snapshots: true)
|
|
174
182
|
watch_requests(context)
|
|
183
|
+
watch_page(context, nil)
|
|
175
184
|
end
|
|
176
|
-
@page ||= @context.new_page.tap { stamp(_1) }
|
|
185
|
+
@page ||= @context.new_page.tap { stamp(_1, @context) }
|
|
177
186
|
@context.tracing.start_chunk
|
|
178
187
|
@boundary = Trace.current
|
|
179
|
-
listener =
|
|
180
|
-
@page.on("
|
|
188
|
+
listener = page_logger(log, nil)
|
|
189
|
+
@page.on("response", listener)
|
|
181
190
|
finish = lambda do
|
|
182
|
-
@page.off("
|
|
191
|
+
@page.off("response", listener)
|
|
183
192
|
@boundary = nil
|
|
184
193
|
@context.tracing.stop_chunk(path: File.join(step_dir, "trace.zip"))
|
|
185
194
|
end
|
|
@@ -194,7 +203,7 @@ module Nukadoko
|
|
|
194
203
|
# that step's.
|
|
195
204
|
attr_writer :step #: Hash[Symbol, untyped]?
|
|
196
205
|
|
|
197
|
-
# Which requests to the
|
|
206
|
+
# Which requests to the system the page had finished receiving the
|
|
198
207
|
# response of, and which were in flight, around a claim step's
|
|
199
208
|
# reading: an order of the events this process received, never a
|
|
200
209
|
# claim that the page drew from a response. Only a document, a
|
|
@@ -205,7 +214,7 @@ module Nukadoko
|
|
|
205
214
|
@requests = []
|
|
206
215
|
@by_request = {}
|
|
207
216
|
context.on("request", lambda do |request|
|
|
208
|
-
next unless ORDERED_KINDS.include?(request.resource_type) && Trace.stamps?(
|
|
217
|
+
next unless ORDERED_KINDS.include?(request.resource_type) && @stamped.any? { Trace.stamps?(_1, request.url) }
|
|
209
218
|
|
|
210
219
|
entry = { request: request, method: request.method, url: request.url, sent: monotonic, sent_at: Time.now.utc.iso8601(3), step: @step }
|
|
211
220
|
@requests << entry
|
|
@@ -232,8 +241,99 @@ module Nukadoko
|
|
|
232
241
|
@reading ||= [started, monotonic] if started
|
|
233
242
|
end
|
|
234
243
|
|
|
235
|
-
|
|
236
|
-
|
|
244
|
+
# A step's page events start empty, and so does its tally of the
|
|
245
|
+
# page's requests left out of http.jsonl.
|
|
246
|
+
#: () -> void
|
|
247
|
+
def begin_step
|
|
248
|
+
@reading = nil
|
|
249
|
+
@page_events = PAGE_EVENT_KINDS.to_h { [_1, [0, []]] }
|
|
250
|
+
@http_omitted = Hash.new(0)
|
|
251
|
+
end
|
|
252
|
+
|
|
253
|
+
PAGE_EVENT_KINDS = %i[console_errors page_errors failed_requests].freeze
|
|
254
|
+
# A redirect loop or a chatty page can emit thousands of these in one
|
|
255
|
+
# step, so each kind keeps 100 entries and counts the rest under
|
|
256
|
+
# `truncated`, never by changing the kind's own shape.
|
|
257
|
+
PAGE_EVENTS_CAP = 100
|
|
258
|
+
# The page's requests that land in http.jsonl, with their status; a
|
|
259
|
+
# script, a stylesheet, or an image is only counted, by its type.
|
|
260
|
+
PAGE_LOGGED_TYPES = %w[document xhr fetch].freeze
|
|
261
|
+
|
|
262
|
+
# What the page of `context` did that no step asked about: each
|
|
263
|
+
# console.error call, each error it threw that nothing caught (the
|
|
264
|
+
# name an @expects:page-error= tag accepts), and each request that
|
|
265
|
+
# failed at the network level, each with `as` for a named context.
|
|
266
|
+
#: (untyped, String?) -> void
|
|
267
|
+
def watch_page(context, as)
|
|
268
|
+
named_as = as ? { as: as } : {}
|
|
269
|
+
context.on("request", ->(request) { page_started[request] = monotonic })
|
|
270
|
+
context.on("console", lambda do |message|
|
|
271
|
+
next unless message.type == "error"
|
|
272
|
+
|
|
273
|
+
location = message.location || {}
|
|
274
|
+
note_page_event(:console_errors, { text: message.text, location: { url: location["url"], lineNumber: location["lineNumber"], columnNumber: location["columnNumber"] },
|
|
275
|
+
**named_as })
|
|
276
|
+
end)
|
|
277
|
+
context.on("weberror", lambda do |web_error|
|
|
278
|
+
error = web_error.error
|
|
279
|
+
name = error.respond_to?(:name) ? error.name.to_s : ""
|
|
280
|
+
note_page_event(:page_errors, { **(name.empty? ? {} : { name: name }), message: error.respond_to?(:message) ? error.message.to_s : error.to_s, **named_as })
|
|
281
|
+
end)
|
|
282
|
+
context.on("requestfailed", lambda do |request|
|
|
283
|
+
page_started.delete(request)
|
|
284
|
+
failure = request.failure
|
|
285
|
+
note_page_event(:failed_requests, { method: request.method, url: request.url, **(failure ? { failure: failure } : {}), **named_as })
|
|
286
|
+
end)
|
|
287
|
+
end
|
|
288
|
+
|
|
289
|
+
#: (Symbol, Hash[Symbol, untyped]) -> void
|
|
290
|
+
def note_page_event(kind, entry)
|
|
291
|
+
tally = @page_events&.[](kind) or return
|
|
292
|
+
tally[0] += 1
|
|
293
|
+
tally[1] << entry.merge(at: Time.now.utc.iso8601(3)) if tally[1].size < PAGE_EVENTS_CAP
|
|
294
|
+
end
|
|
295
|
+
|
|
296
|
+
# The step's page events as its record holds them, nil when there
|
|
297
|
+
# were none: each kind a bare array, and `truncated` naming each kind
|
|
298
|
+
# that hit the cap with its true total.
|
|
299
|
+
#: () -> Hash[Symbol, untyped]?
|
|
300
|
+
def page_events
|
|
301
|
+
tallies = (@page_events || {}).reject { |_, (total, _)| total.zero? }
|
|
302
|
+
return nil if tallies.empty?
|
|
303
|
+
|
|
304
|
+
truncated = tallies.select { |_, (total, _)| total > PAGE_EVENTS_CAP }.transform_values(&:first)
|
|
305
|
+
{ **tallies.transform_values { _1[1].dup }, **(truncated.empty? ? {} : { truncated: truncated }) }
|
|
306
|
+
end
|
|
307
|
+
|
|
308
|
+
# The page's requests the step's http.jsonl left out, by type, nil
|
|
309
|
+
# when there were none.
|
|
310
|
+
#: () -> Hash[String, Integer]?
|
|
311
|
+
def http_omitted = @http_omitted&.any? ? @http_omitted.to_h : nil
|
|
312
|
+
|
|
313
|
+
# A listener that writes each response the page received to `log`:
|
|
314
|
+
# a document, a fetch, or an XMLHttpRequest with its status, so a
|
|
315
|
+
# failure underneath a step is the server's own answer; any other
|
|
316
|
+
# request is counted by its type.
|
|
317
|
+
#: (Array[Hash[Symbol, untyped]], String?) -> ^(untyped) -> void
|
|
318
|
+
def page_logger(log, as)
|
|
319
|
+
lambda do |response|
|
|
320
|
+
request = response.request
|
|
321
|
+
type = request.resource_type
|
|
322
|
+
unless PAGE_LOGGED_TYPES.include?(type)
|
|
323
|
+
@http_omitted[type] += 1 if @http_omitted
|
|
324
|
+
next
|
|
325
|
+
end
|
|
326
|
+
started = page_started.delete(request)
|
|
327
|
+
traceparent = page_stamps[[request.method, request.url]]&.shift
|
|
328
|
+
# Each hop of a redirect is a request and a line of its own, so
|
|
329
|
+
# the service that answered this one is the one at its URL.
|
|
330
|
+
reached = Trace.current&.service_at(request.url)
|
|
331
|
+
log << { method: request.method, url: request.url, status: response.status, duration_ms: started ? Request.since(started) : 0, via: "page",
|
|
332
|
+
**(as ? { as: as } : {}),
|
|
333
|
+
**(traceparent ? { traceparent: traceparent, traceparent_sent_to: [Trace.origin(URI(request.url))] } : {}),
|
|
334
|
+
**(reached ? { service: reached } : {}) }
|
|
335
|
+
end
|
|
336
|
+
end
|
|
237
337
|
|
|
238
338
|
# A claim step's `pages`, `page_requests`, and `judged_view`, after
|
|
239
339
|
# the reading its claims were judged on, when a page was open.
|
|
@@ -250,7 +350,7 @@ module Nukadoko
|
|
|
250
350
|
before = @requests.select { _1[:finished] && _1[:finished] < started }.max_by { _1[:finished] }
|
|
251
351
|
open = @requests.select { _1[:sent] <= ended && !(_1[:finished] && _1[:finished] < started) && !(_1[:ended] && _1[:ended] < started) }
|
|
252
352
|
page = { as: nil, page: 1, url: @page.url, last_response: before && index.(before), in_flight: open.map { index.(_1) } }
|
|
253
|
-
# What the pages had received is of requests to a
|
|
353
|
+
# What the pages had received is of requests to a system, so a run
|
|
254
354
|
# with none keeps the view alone.
|
|
255
355
|
received = @base_url ? { pages: [page], page_requests: listed.map { request_record(_1, step_record_id) } } : {}
|
|
256
356
|
{ **received, judged_view: view(dir, ended, aria_in_claims) }
|
|
@@ -313,23 +413,29 @@ module Nukadoko
|
|
|
313
413
|
def monotonic = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
314
414
|
|
|
315
415
|
|
|
316
|
-
# A page's documents, fetches, and XMLHttpRequests to
|
|
416
|
+
# A page's documents, fetches, and XMLHttpRequests to a stamped
|
|
417
|
+
# service of the system get
|
|
317
418
|
# the running step's traceparent through the Chrome DevTools
|
|
318
419
|
# Protocol's Fetch domain, on a session of the page's own: a header set
|
|
319
420
|
# on the whole context would reach other origins too, and a route
|
|
320
421
|
# turns the browser's cache off. Images, scripts, and stylesheets are
|
|
321
422
|
# left out, since each paused request costs a round trip. A session
|
|
322
|
-
# that cannot be opened leaves the page's requests unstamped
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
423
|
+
# that cannot be opened leaves the page's requests unstamped, and so
|
|
424
|
+
# does a system with no service to stamp.
|
|
425
|
+
#: (untyped, untyped) -> void
|
|
426
|
+
def stamp(page, context)
|
|
427
|
+
return if @stamped.empty?
|
|
428
|
+
|
|
429
|
+
session = context.new_cdp_session(page)
|
|
326
430
|
session.on("Fetch.requestPaused", lambda do |event|
|
|
327
431
|
request = event["request"]
|
|
328
432
|
headers = nil
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
433
|
+
own = request["headers"].find { |name, _| name.downcase == "traceparent" }&.last
|
|
434
|
+
traceparent = own || @boundary&.stamp(request["url"])
|
|
435
|
+
headers = [*request["headers"].map { |name, value| { name: name, value: value } }, { name: "traceparent", value: traceparent }] if traceparent && !own
|
|
436
|
+
# The page's http.jsonl line for this request names the value it
|
|
437
|
+
# went out with, matched by method and URL in the order sent.
|
|
438
|
+
(page_stamps[[request["method"], request["url"]]] ||= []) << traceparent if traceparent
|
|
333
439
|
# Answered off the thread that delivers the event, which also
|
|
334
440
|
# reads the answer.
|
|
335
441
|
Thread.new do
|
|
@@ -338,9 +444,10 @@ module Nukadoko
|
|
|
338
444
|
nil
|
|
339
445
|
end
|
|
340
446
|
end)
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
447
|
+
patterns = @stamped.flat_map do |url|
|
|
448
|
+
service = URI(url)
|
|
449
|
+
["#{Trace.origin(service).gsub(/[\\*?]/) { "\\#{_1}" }}/*", *("#{service.scheme}://*.localhost:#{service.port}/*" if service.host == "localhost")]
|
|
450
|
+
end
|
|
344
451
|
session.send_message("Fetch.enable", params: { patterns: patterns.product(STAMPED_TYPES).map { |url, type| { urlPattern: url, resourceType: type, requestStage: "Request" } } })
|
|
345
452
|
rescue StandardError
|
|
346
453
|
nil
|
|
@@ -361,12 +468,15 @@ module Nukadoko
|
|
|
361
468
|
return [] unless @page
|
|
362
469
|
|
|
363
470
|
log = File.join(dir, "http.jsonl")
|
|
364
|
-
@held = lambda do |
|
|
365
|
-
|
|
471
|
+
@held = lambda do |response|
|
|
472
|
+
request = response.request
|
|
473
|
+
next unless PAGE_LOGGED_TYPES.include?(request.resource_type)
|
|
474
|
+
|
|
475
|
+
File.open(log, "a") { _1.puts JSON.generate({ method: request.method, url: response.url, status: response.status, via: "page" }) }
|
|
366
476
|
rescue StandardError
|
|
367
477
|
nil
|
|
368
478
|
end
|
|
369
|
-
@page.on("
|
|
479
|
+
@page.on("response", @held)
|
|
370
480
|
# The caret shows, as the person would see the field they type in.
|
|
371
481
|
shot = masked_shot(@page, File.join(dir, "page.png"), monotonic + VIEW_TIMEOUT_MS / 1000.0, caret: "initial") ? "#{recorded_as}/page.png" : nil
|
|
372
482
|
aria = begin
|
|
@@ -383,7 +493,7 @@ module Nukadoko
|
|
|
383
493
|
# The pause is answered: the page's requests are the next step's again.
|
|
384
494
|
#: () -> void
|
|
385
495
|
def release
|
|
386
|
-
@page.off("
|
|
496
|
+
@page.off("response", @held) if @page && @held
|
|
387
497
|
@held = nil
|
|
388
498
|
end
|
|
389
499
|
|
|
@@ -417,6 +527,8 @@ module Nukadoko
|
|
|
417
527
|
held[:context].close rescue nil
|
|
418
528
|
end
|
|
419
529
|
@named = {}
|
|
530
|
+
@page_stamps = {}
|
|
531
|
+
@page_started = nil
|
|
420
532
|
@context&.tracing&.stop
|
|
421
533
|
@context&.close
|
|
422
534
|
@context = @page = nil
|
|
@@ -428,7 +540,7 @@ module Nukadoko
|
|
|
428
540
|
# The page of a browser context of its own, named `name`, so a second
|
|
429
541
|
# person in the scenario has cookies and storage of their own. The
|
|
430
542
|
# context opens on the first call for the name in the scenario, with
|
|
431
|
-
# `options` over the
|
|
543
|
+
# `options` over the system's base URL, and a later call gets the same
|
|
432
544
|
# page. Each step that calls it gets a trace chunk, trace.<name>.zip,
|
|
433
545
|
# and the page's requests go to the step's log with `as`.
|
|
434
546
|
#: (String, Hash[untyped, untyped]?, String, Array[Hash[Symbol, untyped]]) -> untyped
|
|
@@ -448,12 +560,14 @@ module Nukadoko
|
|
|
448
560
|
launch
|
|
449
561
|
context = @browser.new_context(baseURL: @base_url, **(asked || {}))
|
|
450
562
|
context.tracing.start(screenshots: true, snapshots: true)
|
|
451
|
-
|
|
563
|
+
watch_page(context, name)
|
|
564
|
+
held = named[name] = { context: context, page: context.new_page.tap { stamp(_1, context) }, options: asked || {} }
|
|
452
565
|
end
|
|
566
|
+
@boundary = Trace.current
|
|
453
567
|
unless step_named.key?(name)
|
|
454
568
|
held[:context].tracing.start_chunk
|
|
455
|
-
listener =
|
|
456
|
-
held[:page].on("
|
|
569
|
+
listener = page_logger(log, name)
|
|
570
|
+
held[:page].on("response", listener)
|
|
457
571
|
step_named[name] = [step_dir, listener]
|
|
458
572
|
end
|
|
459
573
|
held[:page]
|
|
@@ -468,7 +582,7 @@ module Nukadoko
|
|
|
468
582
|
step_dir, listener = step_named[name]
|
|
469
583
|
next unless step_dir
|
|
470
584
|
|
|
471
|
-
held[:page].off("
|
|
585
|
+
held[:page].off("response", listener)
|
|
472
586
|
file = "trace.#{name}.zip"
|
|
473
587
|
held[:context].tracing.stop_chunk(path: File.join(step_dir, file))
|
|
474
588
|
traces << { as: name, file: file }
|
|
@@ -476,6 +590,7 @@ module Nukadoko
|
|
|
476
590
|
nil
|
|
477
591
|
end
|
|
478
592
|
@step_named = {}
|
|
593
|
+
@boundary = nil
|
|
479
594
|
traces
|
|
480
595
|
end
|
|
481
596
|
|
|
@@ -487,6 +602,16 @@ module Nukadoko
|
|
|
487
602
|
#: () -> Hash[String, [String, untyped]]
|
|
488
603
|
def step_named = (@step_named ||= {})
|
|
489
604
|
|
|
605
|
+
# When each page request started, by the request itself, for its
|
|
606
|
+
# http.jsonl line's duration.
|
|
607
|
+
#: () -> Hash[untyped, Float]
|
|
608
|
+
def page_started = (@page_started ||= {}.compare_by_identity)
|
|
609
|
+
|
|
610
|
+
# The traceparents page requests went out with, by method and URL,
|
|
611
|
+
# oldest first.
|
|
612
|
+
#: () -> Hash[[String, String], Array[String]]
|
|
613
|
+
def page_stamps = (@page_stamps ||= {})
|
|
614
|
+
|
|
490
615
|
public
|
|
491
616
|
|
|
492
617
|
#: () -> void
|
|
@@ -6,7 +6,7 @@ require "net/http"
|
|
|
6
6
|
# Requests a step sends through Net::HTTP itself, without the `request`
|
|
7
7
|
# fixture, measured as the TypeScript engine measures a step's own `fetch`:
|
|
8
8
|
# each lands in the step's http.jsonl with `via: "net/http"`, and one to
|
|
9
|
-
# the
|
|
9
|
+
# the system's origin carries the step's traceparent. It records only while
|
|
10
10
|
# a step runs, on the thread that runs it, so a fixture's setup, the
|
|
11
11
|
# engine's own readiness check, and the `request` fixture (which records
|
|
12
12
|
# its requests itself) go through Net::HTTP untouched.
|
|
@@ -42,9 +42,13 @@ module Nukadoko
|
|
|
42
42
|
|
|
43
43
|
Thread.current[:nukadoko_http_inside] = true
|
|
44
44
|
url = "#{use_ssl? ? "https" : "http"}://#{address}#{":#{port}" unless port == (use_ssl? ? 443 : 80)}#{req.path}"
|
|
45
|
-
traceparent = req["traceparent"] ? nil : Trace.current&.stamp(url)
|
|
45
|
+
traceparent = req["traceparent"] ? nil : McpCalls.traceparent_for(url) || Trace.current&.stamp(url)
|
|
46
46
|
req["traceparent"] = traceparent if traceparent
|
|
47
47
|
stamp = traceparent ? { traceparent: traceparent, traceparent_sent_to: [Trace.origin(URI(url))] } : {}
|
|
48
|
+
# The service of the system whose origin answers, stamped or not;
|
|
49
|
+
# a request to no service's origin names none.
|
|
50
|
+
at = Trace.current&.service_at(url)
|
|
51
|
+
stamp = stamp.merge(service: at) if at
|
|
48
52
|
sent = body || req.body
|
|
49
53
|
started = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
50
54
|
begin
|