capybara-lightpanda 0.17.0 → 0.17.1
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 +12 -0
- data/lib/capybara/lightpanda/browser/modals.rb +26 -1
- data/lib/capybara/lightpanda/browser.rb +19 -7
- data/lib/capybara/lightpanda/client/web_socket.rb +14 -2
- data/lib/capybara/lightpanda/driver.rb +9 -1
- data/lib/capybara/lightpanda/javascripts/turbo.js +71 -13
- data/lib/capybara/lightpanda/keyboard.rb +37 -18
- data/lib/capybara/lightpanda/network.rb +10 -2
- data/lib/capybara/lightpanda/process.rb +46 -14
- data/lib/capybara/lightpanda/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f73305ebb70a014b9b5345eade37ec044e2b07cbe99cf30a9eaa2bdbdb80eca5
|
|
4
|
+
data.tar.gz: '095323a36971553487cfa1517df1e08bf67f7a188599e5d93c7db4d44d58868b'
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: eba98666f4f06a68d008bd04248aa8be99a0b2f03ec5d214cd3f2b02fee2f2685085c5fe44c2045faa2e992a090f8b25c13a21e8a703e799d079461aa20bb5ac
|
|
7
|
+
data.tar.gz: 483d3b13353f17e76378a3a0d991a1d5951779a4ea9f4e51b7b6c99485ca66ff1b3efecbdce65c51bb49e49ee11a83e2d7a5da0c7ec2d79d93de0c036e029118
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.17.1] - 2026-11-08
|
|
4
|
+
|
|
5
|
+
### Fixed
|
|
6
|
+
|
|
7
|
+
- **Clicks no longer stall after Turbo cancels a request.** When Turbo aborted a fetch (a newer click or visit replacing it), or a Turbo Stream render was cancelled or raised, the driver kept thinking the page was busy. Every later `click`, `send_keys` or `go_back` then waited the full driver timeout. Each request and each stream render is now counted out exactly once, whatever way it ends.
|
|
8
|
+
- **A crashed browser is restarted instead of failing the next test.** If Lightpanda died during a navigation, the driver didn't notice, and the next `visit` raised `DeadBrowserError`. It now detects the crash and starts a fresh browser. Each restart also used to leave the dead browser's process tracked and running; it is now cleaned up, and a browser that fails partway through startup no longer leaves a process behind.
|
|
9
|
+
- **`accept_alert` / `accept_confirm` only match a dialog opened inside their block.** An earlier, unhandled alert could satisfy a later `accept_alert` whose block opened nothing, so the test passed when it should have failed. And after an `accept_confirm` that timed out, the next unwrapped `confirm` was silently accepted; it is now dismissed and reported like any unexpected dialog.
|
|
10
|
+
- **`status_code` and `response_headers` describe the page, not an iframe.** A page that embedded an iframe returning 404 reported `status_code == 404`, along with the iframe's headers. They now always come from the top-level page.
|
|
11
|
+
- **A failing key in `send_keys` no longer leaves modifiers held down.** If a key in a chord like `[:shift, "a"]` raised, Shift stayed pressed for the rest of the test.
|
|
12
|
+
- **Commands cut off by a dying browser raise `DeadBrowserError`, not `TimeoutError`.** And shutting down a browser that has stopped responding now always finishes, instead of raising partway through.
|
|
13
|
+
- **Lightpanda release candidates are accepted.** An RC build (for example `1.0.4-rc1`) was rejected as "too old" even when it was newer than the required version.
|
|
14
|
+
|
|
3
15
|
## [0.17.0] - 2026-11-05
|
|
4
16
|
|
|
5
17
|
> **Update Lightpanda before upgrading.** This release requires Lightpanda **1.0.3** or a nightly build ≥ 11647. The driver refuses anything older and names the version it found. Pin `1.0.3` for a reproducible browser.
|
|
@@ -93,16 +93,41 @@ module Capybara
|
|
|
93
93
|
end
|
|
94
94
|
claimed[:message]
|
|
95
95
|
rescue TimeoutError
|
|
96
|
+
disarm_modal
|
|
96
97
|
raise_modal_not_found(type, text, last_seen_message)
|
|
97
98
|
end
|
|
98
99
|
|
|
99
100
|
private
|
|
100
101
|
|
|
102
|
+
# The dialog find_modal claims must come from the block about to run,
|
|
103
|
+
# so anything queued before the arm (a dialog nobody wrapped, already
|
|
104
|
+
# reported as unhandled) is dropped here. Kept, it satisfied the next
|
|
105
|
+
# accept_* even when that block opened no dialog at all.
|
|
101
106
|
def arm_modal
|
|
102
|
-
@modal_messages_mutex.synchronize
|
|
107
|
+
@modal_messages_mutex.synchronize do
|
|
108
|
+
@modal_messages.clear
|
|
109
|
+
@modal_armed = true
|
|
110
|
+
end
|
|
103
111
|
yield
|
|
104
112
|
end
|
|
105
113
|
|
|
114
|
+
# find_modal gave up while still armed: the block opened no dialog, and
|
|
115
|
+
# Lightpanda still holds the pre-armed answer for the next one — a
|
|
116
|
+
# dialog nobody wrapped would get it silently. LP has no command to
|
|
117
|
+
# clear the slot, so overwrite it with Lightpanda's own default
|
|
118
|
+
# (confirm false, prompt null) and stop claiming it: that next dialog
|
|
119
|
+
# then behaves, and is reported, exactly as if nothing had been armed.
|
|
120
|
+
def disarm_modal
|
|
121
|
+
armed = @modal_messages_mutex.synchronize do
|
|
122
|
+
was = @modal_armed
|
|
123
|
+
@modal_armed = false
|
|
124
|
+
was
|
|
125
|
+
end
|
|
126
|
+
page_command("LP.handleJavaScriptDialog", accept: false) if armed
|
|
127
|
+
rescue Error
|
|
128
|
+
nil # the session is gone; ModalNotFound is the error worth raising
|
|
129
|
+
end
|
|
130
|
+
|
|
106
131
|
LIGHTPANDA_DIALOG_DEFAULTS = {
|
|
107
132
|
"confirm" => "cancelled it",
|
|
108
133
|
"prompt" => "answered null",
|
|
@@ -122,9 +122,27 @@ module Capybara
|
|
|
122
122
|
start
|
|
123
123
|
end
|
|
124
124
|
|
|
125
|
+
# A step that fails after the process or the connection is up (an old
|
|
126
|
+
# ws_url browser, a command timing out on a slow machine) must not leave
|
|
127
|
+
# them behind: Browser.new raises, nobody holds this object to quit it,
|
|
128
|
+
# and the next attempt would compete with the orphan for the port. The
|
|
129
|
+
# `ensure` covers Interrupt too.
|
|
125
130
|
def start
|
|
126
131
|
return if @started
|
|
127
132
|
|
|
133
|
+
begin
|
|
134
|
+
connect
|
|
135
|
+
create_browser_context
|
|
136
|
+
create_page
|
|
137
|
+
@started = true
|
|
138
|
+
ensure
|
|
139
|
+
quit unless @started
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
self.class.track(self)
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
def connect
|
|
128
146
|
if @options.ws_url?
|
|
129
147
|
@client = Client.new(@options.ws_url, @options)
|
|
130
148
|
check_remote_version
|
|
@@ -133,12 +151,6 @@ module Capybara
|
|
|
133
151
|
@process.start
|
|
134
152
|
@client = Client.new(@process.ws_url, @options)
|
|
135
153
|
end
|
|
136
|
-
|
|
137
|
-
create_browser_context
|
|
138
|
-
create_page
|
|
139
|
-
|
|
140
|
-
@started = true
|
|
141
|
-
self.class.track(self)
|
|
142
154
|
end
|
|
143
155
|
|
|
144
156
|
# Per-session BrowserContext (Chrome's incognito-profile primitive).
|
|
@@ -521,7 +533,7 @@ module Capybara
|
|
|
521
533
|
|
|
522
534
|
# Internal lifecycle steps defined above near their topical groups —
|
|
523
535
|
# calling them out of order corrupts session state, so they are not API.
|
|
524
|
-
private :create_browser_context, :create_page, :clear_session_state,
|
|
536
|
+
private :connect, :create_browser_context, :create_page, :clear_session_state,
|
|
525
537
|
:enable_page_events
|
|
526
538
|
|
|
527
539
|
private
|
|
@@ -56,19 +56,31 @@ module Capybara
|
|
|
56
56
|
# connection (status :closed or :error) without closing the socket,
|
|
57
57
|
# and an early return here then left the TCPSocket — one descriptor
|
|
58
58
|
# per crashed browser — open until GC finalized it (ferrum #639).
|
|
59
|
+
#
|
|
60
|
+
# A close frame that cannot be written (buffers full, browser not
|
|
61
|
+
# reading) is given up on, not raised: abandon_stalled_write already
|
|
62
|
+
# marked the connection dead, and an error escaping here would cut
|
|
63
|
+
# Client#close short before it released its thread and pending commands.
|
|
59
64
|
def close
|
|
60
65
|
unless @status == :closed
|
|
61
66
|
@status = :closing
|
|
62
67
|
@messages.close
|
|
63
|
-
|
|
68
|
+
begin
|
|
69
|
+
@driver_mutex.synchronize { @driver&.close }
|
|
70
|
+
rescue DeadBrowserError
|
|
71
|
+
nil
|
|
72
|
+
end
|
|
64
73
|
@thread&.join(1) || @thread&.kill
|
|
65
74
|
end
|
|
66
75
|
close_socket
|
|
67
76
|
@status = :closed
|
|
68
77
|
end
|
|
69
78
|
|
|
79
|
+
# :closing counts: no reply can arrive once close has begun, and a
|
|
80
|
+
# command released by it must report the connection gone
|
|
81
|
+
# (DeadBrowserError), not a timeout that never happened.
|
|
70
82
|
def closed?
|
|
71
|
-
|
|
83
|
+
%i[closed closing error].include?(@status)
|
|
72
84
|
end
|
|
73
85
|
|
|
74
86
|
# Called by websocket-driver, always under @driver_mutex. A browser
|
|
@@ -20,8 +20,16 @@ module Capybara
|
|
|
20
20
|
@started = false
|
|
21
21
|
end
|
|
22
22
|
|
|
23
|
+
# A browser whose CDP connection died still owns a process (running, or a
|
|
24
|
+
# zombie after a crash), its output pipes and an at_exit registry slot.
|
|
25
|
+
# Quit it before spawning the replacement, or every respawn leaves one
|
|
26
|
+
# more Lightpanda running until the suite exits.
|
|
23
27
|
def browser
|
|
24
|
-
|
|
28
|
+
if @browser && !browser_alive?
|
|
29
|
+
dead = @browser
|
|
30
|
+
@browser = nil
|
|
31
|
+
dead.quit
|
|
32
|
+
end
|
|
25
33
|
@browser ||= Browser.new(@options)
|
|
26
34
|
end
|
|
27
35
|
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
// Pages without Turbo never trigger _turboStart, so no sentinels fire and the
|
|
13
13
|
// Ruby Event stays set (idle by default) — wait_for_turbo returns immediately.
|
|
14
14
|
var _pendingTurboOps = 0;
|
|
15
|
+
var _turboGeneration = 0;
|
|
15
16
|
function _signalTurbo(state) {
|
|
16
17
|
try { console.debug('__lightpanda_turbo_' + state); } catch (e) {}
|
|
17
18
|
}
|
|
@@ -26,10 +27,50 @@ function _turboEnd() {
|
|
|
26
27
|
}
|
|
27
28
|
}
|
|
28
29
|
|
|
29
|
-
// Fetch requests (covers Drive, Frames, and Form submission fetches)
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
// Fetch requests (covers Drive, Frames, and Form submission fetches).
|
|
31
|
+
//
|
|
32
|
+
// A fetch ends in one of three ways, and must be counted out exactly once:
|
|
33
|
+
// a response (turbo:before-fetch-response), a network error
|
|
34
|
+
// (turbo:fetch-request-error) or an abort. Turbo aborts fetches routinely — a
|
|
35
|
+
// frame whose src is removed or replaced, a visit superseded by another, a
|
|
36
|
+
// stopped form submission — and swallows the AbortError without dispatching
|
|
37
|
+
// either event (FetchRequest#perform), so the abort signal is the only trace.
|
|
38
|
+
// Counting on the two events alone left the counter stuck above zero and every
|
|
39
|
+
// later driver action waiting out its full timeout.
|
|
40
|
+
//
|
|
41
|
+
// Each fetch gets a token. The response and error events carry the request's
|
|
42
|
+
// target, not the request, so they close the oldest open token for that target;
|
|
43
|
+
// the abort listener closes its own token, and a token closes once — an abort
|
|
44
|
+
// after the response has been counted is a no-op.
|
|
45
|
+
var _turboFetches = [];
|
|
46
|
+
function _turboFetchEnd(token) {
|
|
47
|
+
if (!token.open) return;
|
|
48
|
+
token.open = false;
|
|
49
|
+
var index = _turboFetches.indexOf(token);
|
|
50
|
+
if (index !== -1) _turboFetches.splice(index, 1);
|
|
51
|
+
_turboEnd();
|
|
52
|
+
}
|
|
53
|
+
function _turboFetchSettled(event) {
|
|
54
|
+
for (var i = 0; i < _turboFetches.length; i++) {
|
|
55
|
+
if (_turboFetches[i].target === event.target) return _turboFetchEnd(_turboFetches[i]);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
document.addEventListener('turbo:before-fetch-request', function(event) {
|
|
59
|
+
var token = { target: event.target, open: true };
|
|
60
|
+
_turboFetches.push(token);
|
|
61
|
+
_turboStart();
|
|
62
|
+
var options = event.detail && event.detail.fetchOptions;
|
|
63
|
+
var signal = options && options.signal;
|
|
64
|
+
if (signal && typeof signal.addEventListener === 'function') {
|
|
65
|
+
if (signal.aborted) {
|
|
66
|
+
_turboFetchEnd(token);
|
|
67
|
+
} else {
|
|
68
|
+
signal.addEventListener('abort', function() { _turboFetchEnd(token); });
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
document.addEventListener('turbo:before-fetch-response', _turboFetchSettled);
|
|
73
|
+
document.addEventListener('turbo:fetch-request-error', _turboFetchSettled);
|
|
33
74
|
|
|
34
75
|
// Form submissions (can outlast their underlying fetch)
|
|
35
76
|
document.addEventListener('turbo:submit-start', _turboStart);
|
|
@@ -39,21 +80,33 @@ document.addEventListener('turbo:submit-end', _turboEnd);
|
|
|
39
80
|
document.addEventListener('turbo:before-frame-render', _turboStart);
|
|
40
81
|
document.addEventListener('turbo:frame-render', _turboEnd);
|
|
41
82
|
|
|
42
|
-
//
|
|
83
|
+
// Only count renders that actually run: Turbo skips the renderer when the
|
|
84
|
+
// before-stream-render event is canceled. Each invocation owns its completion,
|
|
85
|
+
// and a completion from before turbo:load must not decrement newer activity.
|
|
43
86
|
document.addEventListener('turbo:before-stream-render', function(event) {
|
|
44
|
-
_turboStart();
|
|
45
87
|
if (event.detail && event.detail.render) {
|
|
46
88
|
var originalRender = event.detail.render;
|
|
47
89
|
event.detail.render = function(streamElement) {
|
|
48
|
-
var
|
|
49
|
-
|
|
50
|
-
|
|
90
|
+
var generation = _turboGeneration;
|
|
91
|
+
var open = true;
|
|
92
|
+
function finish() {
|
|
93
|
+
if (!open) return;
|
|
94
|
+
open = false;
|
|
95
|
+
if (generation === _turboGeneration) _turboEnd();
|
|
96
|
+
}
|
|
97
|
+
_turboStart();
|
|
98
|
+
try {
|
|
99
|
+
var result = originalRender(streamElement);
|
|
100
|
+
if (result && typeof result.then === 'function') {
|
|
101
|
+
return Promise.resolve(result).finally(finish);
|
|
102
|
+
}
|
|
103
|
+
finish();
|
|
104
|
+
return result;
|
|
105
|
+
} catch (error) {
|
|
106
|
+
finish();
|
|
107
|
+
throw error;
|
|
51
108
|
}
|
|
52
|
-
_turboEnd();
|
|
53
|
-
return result;
|
|
54
109
|
};
|
|
55
|
-
} else {
|
|
56
|
-
_turboEnd();
|
|
57
110
|
}
|
|
58
111
|
});
|
|
59
112
|
|
|
@@ -62,6 +115,11 @@ document.addEventListener('turbo:before-stream-render', function(event) {
|
|
|
62
115
|
// Always re-signal idle so the Ruby Event re-arms even if some `_turboEnd`
|
|
63
116
|
// call dropped on the floor mid-navigation.
|
|
64
117
|
document.addEventListener('turbo:load', function() {
|
|
118
|
+
_turboGeneration++;
|
|
65
119
|
_pendingTurboOps = 0;
|
|
120
|
+
// Forget open fetches too: their late abort/response must not count down
|
|
121
|
+
// operations that started after this reset.
|
|
122
|
+
for (var i = 0; i < _turboFetches.length; i++) _turboFetches[i].open = false;
|
|
123
|
+
_turboFetches = [];
|
|
66
124
|
_signalTurbo('idle');
|
|
67
125
|
});
|
|
@@ -104,25 +104,43 @@ module Capybara
|
|
|
104
104
|
# only the Tab went out.
|
|
105
105
|
def type(*keys)
|
|
106
106
|
active_mods = []
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
107
|
+
holding_modifiers(active_mods) do
|
|
108
|
+
keys.each do |key|
|
|
109
|
+
case key
|
|
110
|
+
when Symbol
|
|
111
|
+
if MODIFIERS.key?(key)
|
|
112
|
+
press_modifier(key, active_mods)
|
|
113
|
+
else
|
|
114
|
+
dispatch_key_with_mods(key, active_mods)
|
|
115
|
+
end
|
|
116
|
+
when Array
|
|
117
|
+
type_with_modifiers(key)
|
|
112
118
|
else
|
|
113
|
-
|
|
119
|
+
type_text(key, active_mods)
|
|
114
120
|
end
|
|
115
|
-
when Array
|
|
116
|
-
type_with_modifiers(key)
|
|
117
|
-
else
|
|
118
|
-
type_text(key, active_mods)
|
|
119
121
|
end
|
|
120
122
|
end
|
|
121
|
-
release_modifiers(active_mods)
|
|
122
123
|
end
|
|
123
124
|
|
|
124
125
|
private
|
|
125
126
|
|
|
127
|
+
# Every modifier keyDown gets its keyUp, even when a key in the chord
|
|
128
|
+
# raises (an unknown key name, a CDP timeout): otherwise page code that
|
|
129
|
+
# tracks modifier state sees Shift or Ctrl stuck down. A release that
|
|
130
|
+
# fails too must not replace the error that explains the failure.
|
|
131
|
+
def holding_modifiers(active_mods)
|
|
132
|
+
yield
|
|
133
|
+
rescue StandardError
|
|
134
|
+
begin
|
|
135
|
+
release_modifiers(active_mods)
|
|
136
|
+
rescue StandardError
|
|
137
|
+
nil
|
|
138
|
+
end
|
|
139
|
+
raise
|
|
140
|
+
else
|
|
141
|
+
release_modifiers(active_mods)
|
|
142
|
+
end
|
|
143
|
+
|
|
126
144
|
def press_modifier(mod, active_mods)
|
|
127
145
|
return if active_mods.include?(mod)
|
|
128
146
|
|
|
@@ -166,15 +184,16 @@ module Capybara
|
|
|
166
184
|
modifiers, rest = keys.partition { |k| k.is_a?(Symbol) && MODIFIERS.key?(k) }
|
|
167
185
|
|
|
168
186
|
active_mods = []
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
187
|
+
holding_modifiers(active_mods) do
|
|
188
|
+
modifiers.each { |m| press_modifier(m, active_mods) }
|
|
189
|
+
rest.each do |key|
|
|
190
|
+
if key.is_a?(Symbol)
|
|
191
|
+
dispatch_key_with_mods(key, active_mods)
|
|
192
|
+
else
|
|
193
|
+
type_text(key, active_mods)
|
|
194
|
+
end
|
|
175
195
|
end
|
|
176
196
|
end
|
|
177
|
-
release_modifiers(active_mods)
|
|
178
197
|
end
|
|
179
198
|
|
|
180
199
|
def type_text(key, active_mods)
|
|
@@ -10,7 +10,7 @@ module Capybara
|
|
|
10
10
|
|
|
11
11
|
attr_reader :browser
|
|
12
12
|
|
|
13
|
-
# Status/headers of the last
|
|
13
|
+
# Status/headers of the last main-frame document navigation; nil before
|
|
14
14
|
# the first navigation completes. Backs Browser#status_code /
|
|
15
15
|
# #response_headers. Captured by #subscribe's handlers.
|
|
16
16
|
attr_reader :last_navigation_response
|
|
@@ -176,7 +176,7 @@ module Capybara
|
|
|
176
176
|
# hop, and the redirected requestWillBeSent resets it below anyway.
|
|
177
177
|
def build_request_handler
|
|
178
178
|
lambda do |params|
|
|
179
|
-
if params
|
|
179
|
+
if main_frame_document?(params)
|
|
180
180
|
@document_request_id = params["requestId"]
|
|
181
181
|
@last_navigation_response = nil
|
|
182
182
|
end
|
|
@@ -235,6 +235,14 @@ module Capybara
|
|
|
235
235
|
end
|
|
236
236
|
end
|
|
237
237
|
|
|
238
|
+
# Iframes load by default (Browser#configure_loading) and their document
|
|
239
|
+
# requests are typed "Document" too; counting them made the last iframe's
|
|
240
|
+
# response the page's status_code. The main frame shares the target's id,
|
|
241
|
+
# the same test Browser#main_frame_document_request? applies.
|
|
242
|
+
def main_frame_document?(params)
|
|
243
|
+
params["type"] == "Document" && params["frameId"] == browser.target_id
|
|
244
|
+
end
|
|
245
|
+
|
|
238
246
|
# Caller holds @traffic_mutex.
|
|
239
247
|
def last_open_entry(request_id)
|
|
240
248
|
@traffic.reverse_each.find { |t| t[:request_id] == request_id && open?(t) }
|
|
@@ -337,25 +337,36 @@ module Capybara
|
|
|
337
337
|
# silently accept a binary the nightly channel rejects.
|
|
338
338
|
MINIMUM_RELEASE = Gem::Version.new("1.0.3")
|
|
339
339
|
|
|
340
|
+
# A release-candidate binary: "<x.y.z>-rc<N>.<git rev-list --count>+<hash>".
|
|
341
|
+
# Captures the commit counter.
|
|
342
|
+
RC_VERSION = /\A\d+\.\d+\.\d+-rc\d+\.(\d+)\+\h+\z/
|
|
343
|
+
|
|
340
344
|
class << self
|
|
341
|
-
# `lightpanda version` prints one of
|
|
342
|
-
#
|
|
343
|
-
# release:
|
|
345
|
+
# `lightpanda version` prints one of three shapes, and the gem supports
|
|
346
|
+
# all of them so a suite can track nightly, try a release candidate or
|
|
347
|
+
# pin a reproducible release:
|
|
344
348
|
#
|
|
345
349
|
# "1.0.0-nightly.8285+de85a51d" rolling nightly (also "dev.NNNN" for
|
|
346
350
|
# a locally compiled tree — same
|
|
347
351
|
# `git rev-list --count HEAD` counter,
|
|
348
352
|
# different label). Checked against
|
|
349
353
|
# MINIMUM_NIGHTLY_BUILD.
|
|
354
|
+
# "1.0.4-rc1.11801+1b60dcc7a" a release candidate (tag x.y.z-rcN,
|
|
355
|
+
# upstream #4480). build.zig's
|
|
356
|
+
# resolveVersion enriches any
|
|
357
|
+
# pre-release tag with the same commit
|
|
358
|
+
# counter, so it is checked against
|
|
359
|
+
# MINIMUM_NIGHTLY_BUILD like a nightly
|
|
360
|
+
# — its x.y.z is the release it leads
|
|
361
|
+
# up to, not one that exists yet.
|
|
350
362
|
# "0.3.5" a tagged release: bare semver, no
|
|
351
363
|
# build metadata. Checked against
|
|
352
364
|
# MINIMUM_RELEASE.
|
|
353
365
|
#
|
|
354
|
-
# The release
|
|
355
|
-
#
|
|
356
|
-
#
|
|
357
|
-
#
|
|
358
|
-
# enough.
|
|
366
|
+
# The release and RC forms are matched anchored, so a stray "1.2.3" or
|
|
367
|
+
# "rc1.99999" inside some other string can never be mistaken for one.
|
|
368
|
+
# Anything that matches none of the shapes stays a hard failure: a
|
|
369
|
+
# version we cannot identify is never assumed to be new enough.
|
|
359
370
|
#
|
|
360
371
|
# Lives on the class, not the instance, because there are two ways to
|
|
361
372
|
# learn a version and only one of them involves a Process: the spawn
|
|
@@ -371,7 +382,7 @@ module Capybara
|
|
|
371
382
|
def check_version!(raw)
|
|
372
383
|
version = raw.to_s.strip
|
|
373
384
|
|
|
374
|
-
if (build = version[/(?:nightly|dev)\.(\d+)/, 1])
|
|
385
|
+
if (build = version[/(?:nightly|dev)\.(\d+)/, 1] || version[RC_VERSION, 1])
|
|
375
386
|
nightly_build = Gem::Version.new(build)
|
|
376
387
|
return [version, nightly_build, nil] if nightly_build >= MINIMUM_NIGHTLY_BUILD
|
|
377
388
|
elsif (tag = version[/\A\d+\.\d+\.\d+\z/])
|
|
@@ -401,6 +412,7 @@ module Capybara
|
|
|
401
412
|
@stderr_r = nil
|
|
402
413
|
@stderr_w = nil
|
|
403
414
|
@finalizer_registered = false
|
|
415
|
+
@reaped = false
|
|
404
416
|
@output = []
|
|
405
417
|
@output_partial = {}
|
|
406
418
|
@output_mutex = Mutex.new
|
|
@@ -426,20 +438,34 @@ module Capybara
|
|
|
426
438
|
attempt_start(binary_path)
|
|
427
439
|
end
|
|
428
440
|
|
|
441
|
+
# A reaped pid is never signalled: the kernel may already have handed it
|
|
442
|
+
# (and its process group id) to an unrelated process. The finalizer is
|
|
443
|
+
# disarmed for the same reason — left armed, it TERMed whatever owned the
|
|
444
|
+
# stale pid whenever GC got round to this object.
|
|
429
445
|
def stop
|
|
430
446
|
return unless @pid
|
|
431
447
|
|
|
432
|
-
self.class.send(:terminate, @pid)
|
|
448
|
+
self.class.send(:terminate, @pid) unless @reaped
|
|
449
|
+
disarm_finalizer
|
|
433
450
|
cleanup_pipes
|
|
434
451
|
@pid = nil
|
|
435
452
|
end
|
|
436
453
|
|
|
454
|
+
# A crashed Lightpanda is a zombie until someone reaps it, and `kill(0)`
|
|
455
|
+
# succeeds on a zombie, so probing with a signal reported a dead browser
|
|
456
|
+
# as alive and Browser#restart_process_if_dead never restarted it. Reap
|
|
457
|
+
# instead: `waitpid(WNOHANG)` returns the pid once the child has exited.
|
|
458
|
+
# ECHILD means it was already reaped elsewhere — gone either way.
|
|
437
459
|
def alive?
|
|
438
460
|
return false unless @pid
|
|
461
|
+
return false if @reaped
|
|
462
|
+
|
|
463
|
+
return true unless ::Process.wait(@pid, ::Process::WNOHANG)
|
|
439
464
|
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
rescue Errno::
|
|
465
|
+
@reaped = true
|
|
466
|
+
false
|
|
467
|
+
rescue Errno::ECHILD
|
|
468
|
+
@reaped = true
|
|
443
469
|
false
|
|
444
470
|
end
|
|
445
471
|
|
|
@@ -460,6 +486,7 @@ module Capybara
|
|
|
460
486
|
@stderr_r, @stderr_w = IO.pipe
|
|
461
487
|
|
|
462
488
|
@pid = spawn_process(binary_path)
|
|
489
|
+
@reaped = false
|
|
463
490
|
register_finalizer(@pid)
|
|
464
491
|
|
|
465
492
|
@stdout_w.close
|
|
@@ -716,11 +743,16 @@ module Capybara
|
|
|
716
743
|
# `undefine_finalizer + define_finalizer` so the finalizer always
|
|
717
744
|
# references the most recently started process.
|
|
718
745
|
def register_finalizer(pid)
|
|
719
|
-
|
|
746
|
+
disarm_finalizer
|
|
720
747
|
ObjectSpace.define_finalizer(self, self.class.send(:weak_kill, pid))
|
|
721
748
|
@finalizer_registered = true
|
|
722
749
|
end
|
|
723
750
|
|
|
751
|
+
def disarm_finalizer
|
|
752
|
+
ObjectSpace.undefine_finalizer(self) if @finalizer_registered
|
|
753
|
+
@finalizer_registered = false
|
|
754
|
+
end
|
|
755
|
+
|
|
724
756
|
def cleanup_pipes
|
|
725
757
|
[@stdout_r, @stdout_w, @stderr_r, @stderr_w].each do |pipe|
|
|
726
758
|
pipe&.close unless pipe&.closed?
|