vouchington-tooling 0.53.0 → 0.54.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.
- package/README.md +76 -12
- package/dist/agent-blackboard/index.d.mts +0 -1
- package/dist/agent-blackboard/index.mjs +0 -23
- package/dist/cli/commands/agent-blackboard-flags.d.mts +0 -1
- package/dist/cli/commands/agent-blackboard-flags.mjs +0 -9
- package/dist/cli/commands/agent-blackboard.d.mts +0 -2
- package/dist/cli/commands/agent-blackboard.mjs +7 -121
- package/dist/cli/commands/story-coverage.d.mts +2 -0
- package/dist/cli/commands/story-coverage.mjs +56 -0
- package/dist/cli/index.mjs +6 -0
- package/dist/cli/parse-forwarded-commands.d.mts +3 -0
- package/dist/cli/parse-forwarded-commands.mjs +2 -0
- package/dist/cli/parse-story-coverage-fields.d.mts +19 -0
- package/dist/cli/parse-story-coverage-fields.mjs +69 -0
- package/dist/cli/parse-story-coverage.d.mts +8 -0
- package/dist/cli/parse-story-coverage.mjs +34 -0
- package/dist/cli/parse.d.mts +5 -1
- package/dist/cli/parse.mjs +3 -0
- package/dist/cli/usage.d.mts +1 -1
- package/dist/cli/usage.mjs +8 -7
- package/dist/host-storage/check.d.mts +38 -0
- package/dist/host-storage/check.mjs +109 -0
- package/dist/host-storage/cli.d.mts +7 -0
- package/dist/host-storage/cli.mjs +102 -0
- package/dist/host-storage/host-storage.test-helpers.d.mts +26 -0
- package/dist/host-storage/host-storage.test-helpers.mjs +58 -0
- package/dist/host-storage/index.d.mts +3 -0
- package/dist/host-storage/index.mjs +3 -0
- package/dist/host-storage/preflight.d.mts +22 -0
- package/dist/host-storage/preflight.mjs +105 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.mjs +1 -0
- package/dist/playwright/assertions.d.mts +1 -0
- package/dist/playwright/assertions.mjs +5 -0
- package/dist/playwright/blocked-external-network.d.mts +15 -0
- package/dist/playwright/blocked-external-network.mjs +73 -0
- package/dist/playwright/browser-dialog-issues.d.mts +12 -0
- package/dist/playwright/browser-dialog-issues.mjs +29 -0
- package/dist/playwright/browser-errors.d.mts +22 -0
- package/dist/playwright/browser-errors.mjs +130 -0
- package/dist/playwright/browser-issue-monitor.test-helpers.d.mts +31 -0
- package/dist/playwright/browser-issue-monitor.test-helpers.mjs +51 -0
- package/dist/playwright/browser-issue-records.d.mts +42 -0
- package/dist/playwright/browser-issue-records.mjs +148 -0
- package/dist/playwright/browser-test.d.mts +21 -0
- package/dist/playwright/browser-test.mjs +68 -0
- package/dist/playwright/expect-no-broken-images.d.mts +17 -0
- package/dist/playwright/expect-no-broken-images.mjs +39 -0
- package/dist/playwright/index.d.mts +30 -0
- package/dist/playwright/index.mjs +22 -0
- package/dist/playwright/mobile-assertions.d.mts +14 -0
- package/dist/playwright/mobile-assertions.mjs +43 -0
- package/dist/playwright/navigate-to.d.mts +27 -0
- package/dist/playwright/navigate-to.mjs +39 -0
- package/dist/playwright/radix-select.d.mts +18 -0
- package/dist/playwright/radix-select.mjs +19 -0
- package/dist/playwright/random-id.d.mts +34 -0
- package/dist/playwright/random-id.mjs +37 -0
- package/dist/playwright/retry-on-connection-lost.d.mts +7 -0
- package/dist/playwright/retry-on-connection-lost.mjs +107 -0
- package/dist/playwright/scroll-to-load-more.d.mts +37 -0
- package/dist/playwright/scroll-to-load-more.mjs +158 -0
- package/dist/playwright/storybook.d.mts +2 -0
- package/dist/playwright/storybook.mjs +13 -0
- package/dist/playwright/test-fixtures.d.mts +1 -0
- package/dist/playwright/test-fixtures.mjs +2 -0
- package/dist/playwright/test-lifecycle-reporter.d.mts +11 -0
- package/dist/playwright/test-lifecycle-reporter.mjs +35 -0
- package/dist/playwright/totp.d.mts +6 -0
- package/dist/playwright/totp.mjs +37 -0
- package/dist/playwright/turnstile-stub.d.mts +8 -0
- package/dist/playwright/turnstile-stub.mjs +61 -0
- package/dist/playwright/viewport-constants.d.mts +30 -0
- package/dist/playwright/viewport-constants.mjs +9 -0
- package/dist/playwright/virtual-authenticator.d.mts +5 -0
- package/dist/playwright/virtual-authenticator.mjs +15 -0
- package/dist/playwright/wait-for-hydration.d.mts +29 -0
- package/dist/playwright/wait-for-hydration.mjs +81 -0
- package/dist/shell-parse/ansi-c-string.d.mts +12 -0
- package/dist/shell-parse/ansi-c-string.mjs +80 -0
- package/dist/shell-parse/index.d.mts +20 -0
- package/dist/shell-parse/index.mjs +15 -0
- package/dist/shell-parse/shell-command-substitution-reads.d.mts +8 -0
- package/dist/shell-parse/shell-command-substitution-reads.mjs +53 -0
- package/dist/shell-parse/shell-command-substitutions.d.mts +8 -0
- package/dist/shell-parse/shell-command-substitutions.mjs +52 -0
- package/dist/shell-parse/shell-command-wrappers.d.mts +26 -0
- package/dist/shell-parse/shell-command-wrappers.mjs +143 -0
- package/dist/shell-parse/shell-commands.d.mts +24 -0
- package/dist/shell-parse/shell-commands.mjs +155 -0
- package/dist/shell-parse/shell-heredoc-delimiter.d.mts +5 -0
- package/dist/shell-parse/shell-heredoc-delimiter.mjs +52 -0
- package/dist/shell-parse/shell-heredoc-parser.d.mts +7 -0
- package/dist/shell-parse/shell-heredoc-parser.mjs +49 -0
- package/dist/shell-parse/shell-heredoc-quote-state.d.mts +19 -0
- package/dist/shell-parse/shell-heredoc-quote-state.mjs +40 -0
- package/dist/shell-parse/shell-heredoc.d.mts +10 -0
- package/dist/shell-parse/shell-heredoc.mjs +90 -0
- package/dist/shell-parse/shell-redirections.d.mts +5 -0
- package/dist/shell-parse/shell-redirections.mjs +34 -0
- package/dist/shell-parse/shell-script-operand.d.mts +13 -0
- package/dist/shell-parse/shell-script-operand.mjs +103 -0
- package/dist/shell-parse/shell-stdin-script.d.mts +6 -0
- package/dist/shell-parse/shell-stdin-script.mjs +61 -0
- package/dist/shell-parse/shell-token-utils.d.mts +9 -0
- package/dist/shell-parse/shell-token-utils.mjs +33 -0
- package/dist/shell-parse/shell-tokenizer-comments.d.mts +1 -0
- package/dist/shell-parse/shell-tokenizer-comments.mjs +57 -0
- package/dist/shell-parse/shell-tokenizer-operators.d.mts +14 -0
- package/dist/shell-parse/shell-tokenizer-operators.mjs +47 -0
- package/dist/shell-parse/shell-tokenizer.d.mts +12 -0
- package/dist/shell-parse/shell-tokenizer.mjs +104 -0
- package/dist/story-coverage/analyze.d.mts +8 -0
- package/dist/story-coverage/analyze.mjs +24 -0
- package/dist/story-coverage/check.d.mts +11 -0
- package/dist/story-coverage/check.mjs +42 -0
- package/dist/story-coverage/components.d.mts +10 -0
- package/dist/story-coverage/components.mjs +40 -0
- package/dist/story-coverage/coverage.d.mts +10 -0
- package/dist/story-coverage/coverage.mjs +43 -0
- package/dist/story-coverage/index.d.mts +13 -0
- package/dist/story-coverage/index.mjs +7 -0
- package/dist/story-coverage/messages.d.mts +10 -0
- package/dist/story-coverage/messages.mjs +42 -0
- package/dist/story-coverage/options.d.mts +27 -0
- package/dist/story-coverage/options.mjs +51 -0
- package/dist/story-coverage/workspace.d.mts +2 -0
- package/dist/story-coverage/workspace.mjs +27 -0
- package/dist/test-helpers/cancel-runs.test-helpers.d.mts +39 -0
- package/dist/test-helpers/cancel-runs.test-helpers.mjs +124 -0
- package/dist/test-helpers/run-bounded-exit-observer.test-helpers.d.mts +12 -0
- package/dist/test-helpers/run-bounded-exit-observer.test-helpers.mjs +68 -0
- package/dist/test-helpers/run-bounded-output-fixture.test-helpers.d.mts +18 -0
- package/dist/test-helpers/run-bounded-output-fixture.test-helpers.mjs +162 -0
- package/dist/vitest-diagnostics/index.d.mts +9 -1
- package/dist/vitest-diagnostics/index.mjs +5 -1
- package/dist/vitest-diagnostics/vitest-fake-timer-guard.d.mts +6 -0
- package/dist/vitest-diagnostics/vitest-fake-timer-guard.mjs +34 -0
- package/dist/vitest-diagnostics/vitest-fork-leak-detection.d.mts +1 -0
- package/dist/vitest-diagnostics/vitest-fork-leak-detection.mjs +8 -0
- package/dist/vitest-diagnostics/vitest-fork-leak-diagnostics.d.mts +10 -1
- package/dist/vitest-diagnostics/vitest-fork-leak-diagnostics.mjs +43 -2
- package/dist/vitest-diagnostics/vitest-fork-leak-handshake-samples.d.mts +50 -0
- package/dist/vitest-diagnostics/vitest-fork-leak-handshake-samples.mjs +69 -0
- package/dist/vitest-diagnostics/vitest-fork-leak-handshake.d.mts +19 -0
- package/dist/vitest-diagnostics/vitest-fork-leak-handshake.mjs +136 -0
- package/dist/vitest-diagnostics/vitest-network-allowlist-dns.d.mts +7 -0
- package/dist/vitest-diagnostics/vitest-network-allowlist-dns.mjs +54 -0
- package/dist/vitest-diagnostics/vitest-network-allowlist-host.d.mts +8 -0
- package/dist/vitest-diagnostics/vitest-network-allowlist-host.mjs +48 -0
- package/dist/vitest-diagnostics/vitest-network-allowlist-socket.d.mts +14 -0
- package/dist/vitest-diagnostics/vitest-network-allowlist-socket.mjs +39 -0
- package/dist/vitest-diagnostics/vitest-network-allowlist.d.mts +7 -0
- package/dist/vitest-diagnostics/vitest-network-allowlist.mjs +72 -0
- package/dist/vitest-diagnostics/vitest-process-resources.d.mts +6 -0
- package/dist/vitest-diagnostics/vitest-process-resources.mjs +51 -0
- package/dist/vitest-effective-timeout/cap.d.mts +9 -0
- package/dist/vitest-effective-timeout/cap.mjs +28 -0
- package/dist/vitest-effective-timeout/check-profiles.d.mts +15 -0
- package/dist/vitest-effective-timeout/check-profiles.mjs +52 -0
- package/dist/vitest-effective-timeout/config-file.d.mts +6 -0
- package/dist/vitest-effective-timeout/config-file.mjs +23 -0
- package/dist/vitest-effective-timeout/fixtures.d.mts +2 -0
- package/dist/vitest-effective-timeout/fixtures.mjs +18 -0
- package/dist/vitest-effective-timeout/index.d.mts +7 -0
- package/dist/vitest-effective-timeout/index.mjs +4 -0
- package/dist/vitest-effective-timeout/profiles.d.mts +10 -0
- package/dist/vitest-effective-timeout/profiles.mjs +33 -0
- package/dist/vitest-effective-timeout/run-profile.d.mts +31 -0
- package/dist/vitest-effective-timeout/run-profile.mjs +95 -0
- package/docs/mcp-server.md +2 -13
- package/package.json +32 -2
- package/scripts/__pycache__/run_bounded_process.cpython-312.pyc +0 -0
- package/scripts/chromium-launch-probe.d.mts +7 -0
- package/scripts/chromium-launch-probe.mjs +101 -0
- package/scripts/run-bounded-fixtures/run-bounded-backpressure.py +186 -0
- package/scripts/run-bounded-fixtures/run-bounded-merged-output.py +75 -0
- package/scripts/run-bounded-fixtures/run-bounded-reset-socket.py +25 -0
- package/scripts/run-bounded.py +199 -0
- package/scripts/run_bounded_process.py +129 -0
- package/scripts/worktree/git-index-lock.sh +16 -0
- package/scripts/worktree/git-worktrees.sh +23 -20
- package/scripts/worktree/reset-worktree-run.sh +199 -0
- package/scripts/worktree/reset-worktree.sh +122 -0
- package/skills/blackboard/SKILL.md +4 -64
- package/skills/stacked-prs/SKILL.md +1 -1
- package/skills/stacked-prs/references/drain.md +2 -2
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
"""Real CLI fixture: release bounded downstream sockets on owned source-pipe closure."""
|
|
2
|
+
import array
|
|
3
|
+
import json
|
|
4
|
+
import os
|
|
5
|
+
import selectors
|
|
6
|
+
import socket
|
|
7
|
+
import subprocess
|
|
8
|
+
import sys
|
|
9
|
+
import tempfile
|
|
10
|
+
import threading
|
|
11
|
+
|
|
12
|
+
if sys.version_info < (3, 11):
|
|
13
|
+
sys.stderr.write('run-bounded-backpressure.py requires Python 3.11 or newer\n')
|
|
14
|
+
raise SystemExit(1)
|
|
15
|
+
|
|
16
|
+
command = '''
|
|
17
|
+
import array, os, socket, sys
|
|
18
|
+
control = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
|
19
|
+
control.connect(sys.argv[1])
|
|
20
|
+
control.sendmsg([b'owned-source-fds'], [(socket.SOL_SOCKET, socket.SCM_RIGHTS, array.array('i', [1, 2]))])
|
|
21
|
+
assert control.recv(1) == b'r'
|
|
22
|
+
for gate, payload in ((b'r', b'a' * 8191 + b'z'), (b's', b'b' * 4095 + b'y')):
|
|
23
|
+
if gate == b's':
|
|
24
|
+
assert control.recv(1) == gate
|
|
25
|
+
while payload:
|
|
26
|
+
payload = payload[os.write(1, payload):]
|
|
27
|
+
raise SystemExit(3)
|
|
28
|
+
'''
|
|
29
|
+
holder = '''
|
|
30
|
+
import os, sys
|
|
31
|
+
os.write(int(sys.argv[1]), b'ready')
|
|
32
|
+
os.close(int(sys.argv[1]))
|
|
33
|
+
try:
|
|
34
|
+
remaining = 1024 * 1024
|
|
35
|
+
while remaining:
|
|
36
|
+
remaining -= os.write(2, b'x' * min(remaining, 65536))
|
|
37
|
+
raise RuntimeError('Source never backpressured')
|
|
38
|
+
except BrokenPipeError:
|
|
39
|
+
pass
|
|
40
|
+
'''
|
|
41
|
+
with tempfile.TemporaryDirectory(prefix='run-bounded-backpressure-') as directory:
|
|
42
|
+
server = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
|
43
|
+
path = directory + '/control.sock'
|
|
44
|
+
server.bind(path)
|
|
45
|
+
server.listen(1)
|
|
46
|
+
out_read, out_write = socket.socketpair()
|
|
47
|
+
err_read, err_write = socket.socketpair()
|
|
48
|
+
for writer in (out_write, err_write):
|
|
49
|
+
if sys.argv[2:] == ['nonblocking']:
|
|
50
|
+
writer.setblocking(False)
|
|
51
|
+
writer.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 1024)
|
|
52
|
+
assert writer.getsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF) < 8192
|
|
53
|
+
wrapper = None
|
|
54
|
+
source_holder = None
|
|
55
|
+
connection = None
|
|
56
|
+
owned_fds = []
|
|
57
|
+
selector = selectors.DefaultSelector()
|
|
58
|
+
outputs = {'stdout': bytearray(), 'stderr': bytearray()}
|
|
59
|
+
wake_read, wake_write = socket.socketpair()
|
|
60
|
+
disposed = threading.Event()
|
|
61
|
+
wrapper_exited = threading.Event()
|
|
62
|
+
closing = threading.Event()
|
|
63
|
+
waiter = None
|
|
64
|
+
def wake():
|
|
65
|
+
try:
|
|
66
|
+
wake_write.sendall(b'w')
|
|
67
|
+
except OSError:
|
|
68
|
+
if not closing.is_set():
|
|
69
|
+
raise
|
|
70
|
+
def dispose_on_input_eof():
|
|
71
|
+
while os.read(0, 4096):
|
|
72
|
+
pass
|
|
73
|
+
disposed.set()
|
|
74
|
+
wake()
|
|
75
|
+
for reader in (out_read, err_read):
|
|
76
|
+
try:
|
|
77
|
+
reader.shutdown(socket.SHUT_RDWR)
|
|
78
|
+
except OSError:
|
|
79
|
+
pass
|
|
80
|
+
threading.Thread(target=dispose_on_input_eof, daemon=True).start()
|
|
81
|
+
def await_readable(descriptor):
|
|
82
|
+
with selectors.DefaultSelector() as readiness:
|
|
83
|
+
readiness.register(descriptor, selectors.EVENT_READ)
|
|
84
|
+
readiness.register(wake_read, selectors.EVENT_READ)
|
|
85
|
+
while True:
|
|
86
|
+
if disposed.is_set():
|
|
87
|
+
raise RuntimeError('Owned fixture disposed during startup')
|
|
88
|
+
if wrapper_exited.is_set():
|
|
89
|
+
raise RuntimeError('Wrapper exited before fixture readiness')
|
|
90
|
+
events = readiness.select()
|
|
91
|
+
if any(key.fileobj == wake_read for key, _ in events):
|
|
92
|
+
wake_read.recv(64)
|
|
93
|
+
continue
|
|
94
|
+
return
|
|
95
|
+
try:
|
|
96
|
+
wrapper = subprocess.Popen(
|
|
97
|
+
[sys.executable, sys.argv[1], '30', sys.executable, '-c', command, path],
|
|
98
|
+
stdin=subprocess.PIPE, stdout=out_write, stderr=err_write,
|
|
99
|
+
)
|
|
100
|
+
out_write.close()
|
|
101
|
+
err_write.close()
|
|
102
|
+
def observe_wrapper_exit():
|
|
103
|
+
wrapper.wait()
|
|
104
|
+
wrapper_exited.set()
|
|
105
|
+
wake()
|
|
106
|
+
waiter = threading.Thread(target=observe_wrapper_exit)
|
|
107
|
+
waiter.start()
|
|
108
|
+
await_readable(server)
|
|
109
|
+
connection, _ = server.accept()
|
|
110
|
+
await_readable(connection)
|
|
111
|
+
_, controls, _, _ = connection.recvmsg(64, socket.CMSG_SPACE(2 * array.array('i').itemsize))
|
|
112
|
+
for level, kind, data in controls:
|
|
113
|
+
assert (level, kind) == (socket.SOL_SOCKET, socket.SCM_RIGHTS)
|
|
114
|
+
descriptors = array.array('i')
|
|
115
|
+
descriptors.frombytes(data)
|
|
116
|
+
owned_fds.extend(descriptors)
|
|
117
|
+
assert len(owned_fds) == 2
|
|
118
|
+
ready_read, ready_write = os.pipe()
|
|
119
|
+
try:
|
|
120
|
+
source_holder = subprocess.Popen(
|
|
121
|
+
[sys.executable, '-c', holder, str(ready_write)],
|
|
122
|
+
stdin=subprocess.DEVNULL, stdout=owned_fds[0], stderr=owned_fds[1],
|
|
123
|
+
pass_fds=(ready_write,), start_new_session=True,
|
|
124
|
+
)
|
|
125
|
+
os.close(ready_write)
|
|
126
|
+
ready_write = None
|
|
127
|
+
await_readable(ready_read)
|
|
128
|
+
assert os.read(ready_read, 5) == b'ready'
|
|
129
|
+
finally:
|
|
130
|
+
if ready_write is not None:
|
|
131
|
+
os.close(ready_write)
|
|
132
|
+
os.close(ready_read)
|
|
133
|
+
for descriptor in owned_fds:
|
|
134
|
+
os.close(descriptor)
|
|
135
|
+
owned_fds.clear()
|
|
136
|
+
connection.sendall(b'r')
|
|
137
|
+
# Readability proves the relay has consumed the first source chunk.
|
|
138
|
+
# Leave that output unread so its bounded target remains backpressured.
|
|
139
|
+
await_readable(out_read)
|
|
140
|
+
connection.sendall(b's')
|
|
141
|
+
# No elapsed-time wait: the native source write returns EPIPE only when its reader closes.
|
|
142
|
+
holder_status = source_holder.wait()
|
|
143
|
+
assert holder_status == 0
|
|
144
|
+
for reader, name in ((out_read, 'stdout'), (err_read, 'stderr')):
|
|
145
|
+
selector.register(reader, selectors.EVENT_READ, name)
|
|
146
|
+
while selector.get_map():
|
|
147
|
+
for key, _ in selector.select():
|
|
148
|
+
chunk = key.fileobj.recv(65536)
|
|
149
|
+
if chunk:
|
|
150
|
+
outputs[key.data].extend(chunk)
|
|
151
|
+
else:
|
|
152
|
+
selector.unregister(key.fileobj)
|
|
153
|
+
status = wrapper.wait()
|
|
154
|
+
print(json.dumps({'status': status, 'stdout': outputs['stdout'].decode(),
|
|
155
|
+
'sourceHolderStatus': holder_status, 'wrapperDrained': True}))
|
|
156
|
+
finally:
|
|
157
|
+
# Every owned resource gets a cleanup attempt, even after an earlier failure.
|
|
158
|
+
primary = sys.exception()
|
|
159
|
+
cleanup_errors = []
|
|
160
|
+
def settle(operation):
|
|
161
|
+
try:
|
|
162
|
+
operation()
|
|
163
|
+
except BaseException as err:
|
|
164
|
+
cleanup_errors.append(err)
|
|
165
|
+
for descriptor in owned_fds:
|
|
166
|
+
settle(lambda descriptor=descriptor: os.close(descriptor))
|
|
167
|
+
# Closing the listener also rejects queued, not-yet-accepted handshakes.
|
|
168
|
+
settle(server.close)
|
|
169
|
+
if connection is not None:
|
|
170
|
+
settle(connection.close)
|
|
171
|
+
for reader in (out_read, err_read):
|
|
172
|
+
settle(reader.close)
|
|
173
|
+
if wrapper is not None:
|
|
174
|
+
if wrapper.stdin is not None:
|
|
175
|
+
settle(wrapper.stdin.close)
|
|
176
|
+
settle(wrapper.wait)
|
|
177
|
+
if source_holder is not None:
|
|
178
|
+
settle(source_holder.wait)
|
|
179
|
+
if waiter is not None:
|
|
180
|
+
settle(waiter.join)
|
|
181
|
+
closing.set()
|
|
182
|
+
for resource in (wake_read, wake_write, selector, out_write, err_write):
|
|
183
|
+
settle(resource.close)
|
|
184
|
+
if cleanup_errors:
|
|
185
|
+
failures = ([primary] if primary is not None else []) + cleanup_errors
|
|
186
|
+
raise BaseExceptionGroup('Fixture failure and owned cleanup', failures) from failures[0]
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"""Exercise native merged sinks and independent regular-file open descriptions."""
|
|
2
|
+
import errno
|
|
3
|
+
import json
|
|
4
|
+
import os
|
|
5
|
+
import pty
|
|
6
|
+
import socket
|
|
7
|
+
import subprocess
|
|
8
|
+
import sys
|
|
9
|
+
import tempfile
|
|
10
|
+
import tty
|
|
11
|
+
|
|
12
|
+
script, mode = sys.argv[1:]
|
|
13
|
+
command = 'import os; os.write(1, b"a" * 1048576); os.write(2, b"Z"); raise SystemExit(3)'
|
|
14
|
+
if mode == 'terminal':
|
|
15
|
+
command = 'import os; assert os.isatty(1) and os.isatty(2); ' + command.removeprefix('import os; ')
|
|
16
|
+
with tempfile.TemporaryDirectory(prefix='bounded-merged-') as directory:
|
|
17
|
+
if mode == 'independent-files':
|
|
18
|
+
path = directory + '/output'
|
|
19
|
+
with open(path, 'w+b') as out, open(path, 'r+b') as err:
|
|
20
|
+
err.seek(1048576)
|
|
21
|
+
proc = subprocess.Popen([sys.executable, script, '5', sys.executable, '-c', command],
|
|
22
|
+
stdout=out, stderr=err)
|
|
23
|
+
status = proc.wait()
|
|
24
|
+
positions = [out.tell(), err.tell()]
|
|
25
|
+
data = open(path, 'rb').read()
|
|
26
|
+
elif mode == 'regular':
|
|
27
|
+
path = directory + '/output'
|
|
28
|
+
with open(path, 'w+b') as target:
|
|
29
|
+
proc = subprocess.Popen([sys.executable, script, '5', sys.executable, '-c', command],
|
|
30
|
+
stdout=target, stderr=target)
|
|
31
|
+
status = proc.wait()
|
|
32
|
+
data = open(path, 'rb').read()
|
|
33
|
+
positions = None
|
|
34
|
+
else:
|
|
35
|
+
if mode == 'socket':
|
|
36
|
+
reader, writer = socket.socketpair()
|
|
37
|
+
writer.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 1024)
|
|
38
|
+
read_fd, write_fd = reader.fileno(), writer.fileno()
|
|
39
|
+
elif mode == 'terminal':
|
|
40
|
+
read_fd, write_fd = pty.openpty()
|
|
41
|
+
tty.setraw(write_fd)
|
|
42
|
+
else:
|
|
43
|
+
read_fd, write_fd = os.pipe()
|
|
44
|
+
proc = None
|
|
45
|
+
try:
|
|
46
|
+
proc = subprocess.Popen([sys.executable, script, '5', sys.executable, '-c', command],
|
|
47
|
+
stdout=write_fd, stderr=write_fd)
|
|
48
|
+
if mode == 'socket':
|
|
49
|
+
writer.close()
|
|
50
|
+
else:
|
|
51
|
+
os.close(write_fd)
|
|
52
|
+
chunks = []
|
|
53
|
+
while True:
|
|
54
|
+
try:
|
|
55
|
+
chunk = os.read(read_fd, 128)
|
|
56
|
+
except OSError as err:
|
|
57
|
+
if mode != 'terminal' or err.errno != errno.EIO:
|
|
58
|
+
raise
|
|
59
|
+
break
|
|
60
|
+
if not chunk:
|
|
61
|
+
break
|
|
62
|
+
chunks.append(chunk)
|
|
63
|
+
data = b''.join(chunks)
|
|
64
|
+
status = proc.wait()
|
|
65
|
+
positions = None
|
|
66
|
+
finally:
|
|
67
|
+
if mode == 'socket':
|
|
68
|
+
reader.close()
|
|
69
|
+
writer.close()
|
|
70
|
+
else:
|
|
71
|
+
os.close(read_fd)
|
|
72
|
+
if proc is not None:
|
|
73
|
+
proc.wait()
|
|
74
|
+
print(json.dumps(dict(status=status, length=len(data), marker=data.find(b'Z'),
|
|
75
|
+
allBytes=data == b'a' * 1048576 + b'Z', positions=positions)))
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"""A genuine peer RST must not replace the completed command status."""
|
|
2
|
+
import json
|
|
3
|
+
import select
|
|
4
|
+
import socket
|
|
5
|
+
import struct
|
|
6
|
+
import subprocess
|
|
7
|
+
import sys
|
|
8
|
+
|
|
9
|
+
command = 'import os; os.write(1, b"x" * 70000); os.write(2, b"err\\n"); raise SystemExit(3)'
|
|
10
|
+
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as server:
|
|
11
|
+
server.bind(('127.0.0.1', 0))
|
|
12
|
+
server.listen(1)
|
|
13
|
+
with socket.create_connection(server.getsockname(), timeout=5) as downstream:
|
|
14
|
+
peer, _ = server.accept()
|
|
15
|
+
with peer:
|
|
16
|
+
peer.setsockopt(socket.SOL_SOCKET, socket.SO_LINGER, struct.pack('ii', 1, 0))
|
|
17
|
+
# Observe peer-close readiness without consuming the pending native reset error.
|
|
18
|
+
if not select.select([downstream], [], [], 5)[0]:
|
|
19
|
+
raise RuntimeError('Owned reset socket never became readable')
|
|
20
|
+
downstream.settimeout(None)
|
|
21
|
+
result = subprocess.run(
|
|
22
|
+
[sys.executable, sys.argv[1], '5', sys.executable, '-c', command],
|
|
23
|
+
stdout=downstream, stderr=subprocess.PIPE, text=True,
|
|
24
|
+
)
|
|
25
|
+
print(json.dumps(dict(status=result.returncode, stderr=result.stderr)))
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Run a command until it exits or the deadline elapses, then kill its process group."""
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
import array
|
|
7
|
+
import fcntl
|
|
8
|
+
import os
|
|
9
|
+
import select
|
|
10
|
+
import signal
|
|
11
|
+
import subprocess
|
|
12
|
+
import sys
|
|
13
|
+
import threading
|
|
14
|
+
import termios
|
|
15
|
+
import time
|
|
16
|
+
|
|
17
|
+
from run_bounded_process import (
|
|
18
|
+
WrapperSignal,
|
|
19
|
+
arm_termination,
|
|
20
|
+
command_outputs,
|
|
21
|
+
output_sinks,
|
|
22
|
+
reap_terminated_group,
|
|
23
|
+
run,
|
|
24
|
+
signal_group,
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
RELAY_JOIN_SECONDS = 3
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class Relay(threading.Thread):
|
|
31
|
+
def __init__(self, source, target: int | None) -> None:
|
|
32
|
+
super().__init__()
|
|
33
|
+
self.source = source
|
|
34
|
+
self.target = target
|
|
35
|
+
self.lock = threading.Lock()
|
|
36
|
+
self.pending: list[bytes] = []
|
|
37
|
+
self.closed = False
|
|
38
|
+
self.error: BaseException | None = None
|
|
39
|
+
os.set_blocking(source.fileno(), False)
|
|
40
|
+
self.wake_read, self.wake_write = os.pipe()
|
|
41
|
+
|
|
42
|
+
def cut_source(self) -> None:
|
|
43
|
+
try:
|
|
44
|
+
with self.lock:
|
|
45
|
+
if not self.closed:
|
|
46
|
+
try:
|
|
47
|
+
available = array.array('i', [0])
|
|
48
|
+
fcntl.ioctl(self.source.fileno(), termios.FIONREAD, available, True)
|
|
49
|
+
remaining = available[0]
|
|
50
|
+
while remaining:
|
|
51
|
+
data = os.read(self.source.fileno(), min(remaining, 65536))
|
|
52
|
+
if not data:
|
|
53
|
+
break
|
|
54
|
+
self.pending.append(data)
|
|
55
|
+
remaining -= len(data)
|
|
56
|
+
finally:
|
|
57
|
+
self.closed = True
|
|
58
|
+
self.source.close()
|
|
59
|
+
finally:
|
|
60
|
+
os.write(self.wake_write, b'close')
|
|
61
|
+
|
|
62
|
+
def next_chunk(self) -> bytes:
|
|
63
|
+
while True:
|
|
64
|
+
with self.lock:
|
|
65
|
+
if self.pending:
|
|
66
|
+
return self.pending.pop(0)
|
|
67
|
+
if self.closed:
|
|
68
|
+
return b''
|
|
69
|
+
source_fd = self.source.fileno()
|
|
70
|
+
try:
|
|
71
|
+
select.select([source_fd, self.wake_read], [], [])
|
|
72
|
+
except (OSError, ValueError):
|
|
73
|
+
with self.lock:
|
|
74
|
+
if not self.closed:
|
|
75
|
+
raise
|
|
76
|
+
continue # Take cutoff-buffered bytes under the lock.
|
|
77
|
+
with self.lock:
|
|
78
|
+
if self.closed:
|
|
79
|
+
continue
|
|
80
|
+
try:
|
|
81
|
+
data = os.read(source_fd, 65536)
|
|
82
|
+
except BlockingIOError:
|
|
83
|
+
continue
|
|
84
|
+
if not data:
|
|
85
|
+
self.closed = True
|
|
86
|
+
self.source.close()
|
|
87
|
+
return data
|
|
88
|
+
|
|
89
|
+
def run(self) -> None:
|
|
90
|
+
target = self.target
|
|
91
|
+
try:
|
|
92
|
+
while data := self.next_chunk():
|
|
93
|
+
if target is None:
|
|
94
|
+
continue
|
|
95
|
+
try:
|
|
96
|
+
while data:
|
|
97
|
+
try:
|
|
98
|
+
written = os.write(target, data)
|
|
99
|
+
except BlockingIOError:
|
|
100
|
+
select.select([], [target], [])
|
|
101
|
+
continue
|
|
102
|
+
if written == 0:
|
|
103
|
+
raise RuntimeError('Output write made no progress')
|
|
104
|
+
data = data[written:]
|
|
105
|
+
except (BrokenPipeError, ConnectionResetError):
|
|
106
|
+
target = None # Downstream closed; drain without leaking a sink FD.
|
|
107
|
+
except BaseException as err:
|
|
108
|
+
self.error = err
|
|
109
|
+
finally:
|
|
110
|
+
with self.lock:
|
|
111
|
+
self.closed = True
|
|
112
|
+
try:
|
|
113
|
+
self.source.close()
|
|
114
|
+
except BaseException as err:
|
|
115
|
+
if self.error is None:
|
|
116
|
+
self.error = err
|
|
117
|
+
else:
|
|
118
|
+
failure = RuntimeError(f'Relay failed: {self.error!r}; source close: {err!r}')
|
|
119
|
+
failure.__cause__ = self.error
|
|
120
|
+
self.error = failure
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def main() -> None:
|
|
124
|
+
if len(sys.argv) < 3:
|
|
125
|
+
print('usage: run-bounded.py <seconds> <command> [args...]', file=sys.stderr)
|
|
126
|
+
raise SystemExit(2)
|
|
127
|
+
try:
|
|
128
|
+
seconds = int(sys.argv[1])
|
|
129
|
+
except ValueError:
|
|
130
|
+
print('timeout seconds must be an integer', file=sys.stderr)
|
|
131
|
+
raise SystemExit(2) from None
|
|
132
|
+
if seconds < 1:
|
|
133
|
+
print('timeout seconds must be positive', file=sys.stderr)
|
|
134
|
+
raise SystemExit(2)
|
|
135
|
+
|
|
136
|
+
with output_sinks() as targets:
|
|
137
|
+
execute(seconds, targets)
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def execute(seconds: int, targets: list[int | None]) -> None:
|
|
141
|
+
proc = subprocess.Popen(
|
|
142
|
+
sys.argv[2:], **command_outputs(targets), start_new_session=True
|
|
143
|
+
)
|
|
144
|
+
relays: list[Relay] = []
|
|
145
|
+
started: list[Relay] = []
|
|
146
|
+
errors: list[BaseException] = []
|
|
147
|
+
status = 1
|
|
148
|
+
try:
|
|
149
|
+
arm_termination()
|
|
150
|
+
for stream, fd in zip((proc.stdout, proc.stderr), targets):
|
|
151
|
+
if stream is not None:
|
|
152
|
+
relays.append(Relay(stream, fd))
|
|
153
|
+
for thread in relays:
|
|
154
|
+
thread.start()
|
|
155
|
+
started.append(thread)
|
|
156
|
+
status = run(proc, seconds)
|
|
157
|
+
except WrapperSignal as err:
|
|
158
|
+
status = reap_terminated_group(proc, err.signum)
|
|
159
|
+
except BaseException as err:
|
|
160
|
+
errors.append(err)
|
|
161
|
+
for sig in (signal.SIGTERM, signal.SIGKILL):
|
|
162
|
+
try:
|
|
163
|
+
signal_group(proc.pid, sig)
|
|
164
|
+
proc.wait(timeout=10)
|
|
165
|
+
except BaseException as cleanup_err:
|
|
166
|
+
errors.append(cleanup_err)
|
|
167
|
+
finally:
|
|
168
|
+
deadline = time.monotonic() + RELAY_JOIN_SECONDS
|
|
169
|
+
for thread in started:
|
|
170
|
+
thread.join(max(0.0, deadline - time.monotonic()))
|
|
171
|
+
# Sever descendant sources, never abandon a write to the downstream consumer.
|
|
172
|
+
for thread in relays:
|
|
173
|
+
try:
|
|
174
|
+
thread.cut_source()
|
|
175
|
+
except BaseException as err:
|
|
176
|
+
errors.append(err)
|
|
177
|
+
for thread in started:
|
|
178
|
+
thread.join()
|
|
179
|
+
if thread.error is not None:
|
|
180
|
+
errors.append(thread.error)
|
|
181
|
+
for stream in (proc.stdout, proc.stderr):
|
|
182
|
+
try:
|
|
183
|
+
if stream is not None:
|
|
184
|
+
stream.close()
|
|
185
|
+
except BaseException as err:
|
|
186
|
+
errors.append(err)
|
|
187
|
+
for thread in relays:
|
|
188
|
+
for descriptor in (thread.wake_read, thread.wake_write):
|
|
189
|
+
try:
|
|
190
|
+
os.close(descriptor)
|
|
191
|
+
except BaseException as err:
|
|
192
|
+
errors.append(err)
|
|
193
|
+
if errors:
|
|
194
|
+
raise RuntimeError('Command/relay cleanup failed: ' + '; '.join(map(repr, errors))) from errors[0]
|
|
195
|
+
raise SystemExit(status)
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
if __name__ == '__main__':
|
|
199
|
+
main()
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"""Own downstream descriptors and command process-group lifetime."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import errno
|
|
6
|
+
import fcntl
|
|
7
|
+
import os
|
|
8
|
+
import signal
|
|
9
|
+
import stat
|
|
10
|
+
import subprocess
|
|
11
|
+
from contextlib import contextmanager
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
@contextmanager
|
|
15
|
+
def output_sinks():
|
|
16
|
+
targets: list[int | None] = []
|
|
17
|
+
primary: BaseException | None = None
|
|
18
|
+
try:
|
|
19
|
+
for fd in (1, 2):
|
|
20
|
+
try:
|
|
21
|
+
targets.append(fcntl.fcntl(fd, fcntl.F_DUPFD_CLOEXEC, 3))
|
|
22
|
+
except OSError as err:
|
|
23
|
+
if err.errno != errno.EBADF:
|
|
24
|
+
raise
|
|
25
|
+
targets.append(None) # Absent at entry, before Popen allocates source pipes.
|
|
26
|
+
# Keep the closed number occupied so a child pipe cannot become stderr.
|
|
27
|
+
occupy_closed_fd(fd)
|
|
28
|
+
yield targets
|
|
29
|
+
except BaseException as err:
|
|
30
|
+
primary = err
|
|
31
|
+
raise
|
|
32
|
+
finally:
|
|
33
|
+
errors: list[BaseException] = []
|
|
34
|
+
for fd in targets:
|
|
35
|
+
if fd is not None:
|
|
36
|
+
try:
|
|
37
|
+
os.close(fd)
|
|
38
|
+
except BaseException as err:
|
|
39
|
+
errors.append(err)
|
|
40
|
+
if errors:
|
|
41
|
+
details = ([repr(primary)] if primary is not None else []) + list(map(repr, errors))
|
|
42
|
+
raise RuntimeError('Output descriptor cleanup failed: ' + '; '.join(details)) from (primary or errors[0])
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
class WrapperSignal(BaseException):
|
|
46
|
+
def __init__(self, signum: int) -> None:
|
|
47
|
+
super().__init__(signum)
|
|
48
|
+
self.signum = signum
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def occupy_closed_fd(fd: int) -> None:
|
|
52
|
+
null = os.open(os.devnull, os.O_WRONLY)
|
|
53
|
+
try:
|
|
54
|
+
if null != fd:
|
|
55
|
+
os.dup2(null, fd)
|
|
56
|
+
finally:
|
|
57
|
+
if null != fd:
|
|
58
|
+
os.close(null)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def exit_status(code: int) -> int:
|
|
62
|
+
if code < 0:
|
|
63
|
+
return 128 - code
|
|
64
|
+
return code
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def signal_group(pid: int, sig: int) -> None:
|
|
68
|
+
try:
|
|
69
|
+
os.killpg(pid, sig)
|
|
70
|
+
except ProcessLookupError:
|
|
71
|
+
return
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def arm_termination() -> None:
|
|
75
|
+
def handle(signum: int, _frame: object) -> None:
|
|
76
|
+
signal.signal(signum, signal.SIG_DFL)
|
|
77
|
+
raise WrapperSignal(signum)
|
|
78
|
+
|
|
79
|
+
signal.signal(signal.SIGTERM, handle)
|
|
80
|
+
signal.signal(signal.SIGINT, handle)
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def reap_terminated_group(proc: subprocess.Popen[bytes], signum: int) -> int:
|
|
84
|
+
signal_group(proc.pid, signal.SIGTERM)
|
|
85
|
+
try:
|
|
86
|
+
proc.wait(timeout=10)
|
|
87
|
+
except subprocess.TimeoutExpired:
|
|
88
|
+
pass
|
|
89
|
+
# A TERM-resistant descendant can outlive the parent; finish the group.
|
|
90
|
+
signal_group(proc.pid, signal.SIGKILL)
|
|
91
|
+
proc.wait()
|
|
92
|
+
return 128 + signum
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def run(proc: subprocess.Popen[bytes], seconds: int) -> int:
|
|
96
|
+
try:
|
|
97
|
+
return exit_status(proc.wait(timeout=seconds))
|
|
98
|
+
except subprocess.TimeoutExpired:
|
|
99
|
+
signal_group(proc.pid, signal.SIGTERM)
|
|
100
|
+
try:
|
|
101
|
+
proc.wait(timeout=10)
|
|
102
|
+
except subprocess.TimeoutExpired:
|
|
103
|
+
pass
|
|
104
|
+
# The parent can exit on SIGTERM while a descendant keeps running.
|
|
105
|
+
# Finish cleaning the group even when waiting for the parent succeeded.
|
|
106
|
+
signal_group(proc.pid, signal.SIGKILL)
|
|
107
|
+
proc.wait()
|
|
108
|
+
return 124
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def command_outputs(targets: list[int | None]):
|
|
113
|
+
"""Inherit non-stream descriptors; share one pipe for merged stream sinks."""
|
|
114
|
+
outputs = [
|
|
115
|
+
subprocess.PIPE
|
|
116
|
+
if fd is None or stat.S_ISFIFO(os.fstat(fd).st_mode) or stat.S_ISSOCK(os.fstat(fd).st_mode)
|
|
117
|
+
else fd
|
|
118
|
+
for fd in targets
|
|
119
|
+
]
|
|
120
|
+
if all(fd is not None for fd in targets):
|
|
121
|
+
left, right = (os.fstat(fd) for fd in targets)
|
|
122
|
+
stream = stat.S_ISFIFO(left.st_mode) or stat.S_ISSOCK(left.st_mode)
|
|
123
|
+
same_endpoint = (left.st_dev, left.st_ino, left.st_mode) == (
|
|
124
|
+
right.st_dev, right.st_ino, right.st_mode
|
|
125
|
+
)
|
|
126
|
+
same_flags = fcntl.fcntl(targets[0], fcntl.F_GETFL) == fcntl.fcntl(targets[1], fcntl.F_GETFL)
|
|
127
|
+
if stream and same_endpoint and same_flags:
|
|
128
|
+
outputs[1] = subprocess.STDOUT
|
|
129
|
+
return dict(stdout=outputs[0], stderr=outputs[1])
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Removes a 0-byte index.lock left by an interrupted git write.
|
|
3
|
+
# A non-empty index.lock means a git process is mid-write, so it stays.
|
|
4
|
+
# Git creates a 0-byte lock briefly before writing. Call this only when no
|
|
5
|
+
# concurrent git write is expected.
|
|
6
|
+
|
|
7
|
+
clear_stale_index_lock() {
|
|
8
|
+
local git_dir=$1
|
|
9
|
+
if [ -z "$git_dir" ]; then
|
|
10
|
+
return 1
|
|
11
|
+
fi
|
|
12
|
+
if [ -f "$git_dir/index.lock" ] && [ ! -s "$git_dir/index.lock" ]; then
|
|
13
|
+
rm -f "$git_dir/index.lock"
|
|
14
|
+
printf 'Cleared stale empty index.lock at %s/index.lock\n' "$git_dir"
|
|
15
|
+
fi
|
|
16
|
+
}
|