Fix arq quoting to work in runInTerminal (#1981)
Some checks failed
Code scanning - action / CodeQL-Build (push) Has been cancelled

* Fix arq quoting to work in runInTerminal

* Default was backwards

* Fix ruff errors

* Fix failing tests

* Only strip quotes on the exe

* Try fixing gw worker failures

* Skip certain test because of cmd limitations

* Need to skip all 'code' based tests on windows
This commit is contained in:
Rich Chiodo 2025-12-10 10:39:27 -08:00 committed by GitHub
parent 1e3fd91306
commit e5017d7360
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 144 additions and 18 deletions

View file

@ -27,6 +27,7 @@ class BackChannel(object):
self._server_socket = sockets.create_server("127.0.0.1", 0, self.TIMEOUT)
_, self.port = sockets.get_address(self._server_socket)
self._server_socket.listen(0)
log.info("{0} created server socket on port {1}", self, self.port)
def accept_worker():
log.info(
@ -67,8 +68,14 @@ class BackChannel(object):
self._established.set()
def receive(self):
self._established.wait()
return self._stream.read_json()
log.info("{0} waiting for connection to be established...", self)
if not self._established.wait(timeout=self.TIMEOUT):
log.error("{0} timed out waiting for connection after {1} seconds", self, self.TIMEOUT)
raise TimeoutError(f"{self} timed out waiting for debuggee to connect")
log.info("{0} connection established, reading JSON...", self)
result = self._stream.read_json()
log.info("{0} received: {1}", self, result)
return result
def send(self, value):
self.session.timeline.unfreeze()

View file

@ -281,7 +281,11 @@ class Session(object):
if self.adapter_endpoints is not None and self.expected_exit_code is not None:
log.info("Waiting for {0} to close listener ports ...", self.adapter_id)
timeout_start = time.time()
while self.adapter_endpoints.check():
if time.time() - timeout_start > 10:
log.warning("{0} listener ports did not close within 10 seconds", self.adapter_id)
break
time.sleep(0.1)
if self.adapter is not None:
@ -290,8 +294,20 @@ class Session(object):
self.adapter_id,
self.adapter.pid,
)
self.adapter.wait()
watchdog.unregister_spawn(self.adapter.pid, self.adapter_id)
try:
self.adapter.wait(timeout=10)
except Exception:
log.warning("{0} did not exit gracefully within 10 seconds, force-killing", self.adapter_id)
try:
self.adapter.kill()
self.adapter.wait(timeout=5)
except Exception as e:
log.error("Failed to force-kill {0}: {1}", self.adapter_id, e)
try:
watchdog.unregister_spawn(self.adapter.pid, self.adapter_id)
except Exception as e:
log.warning("Failed to unregister adapter spawn: {0}", e)
self.adapter = None
if self.backchannel is not None:
@ -366,9 +382,23 @@ class Session(object):
return env
def _make_python_cmdline(self, exe, *args):
return [
str(s.strpath if isinstance(s, py.path.local) else s) for s in [exe, *args]
]
def normalize(s, strip_quotes=False):
# Convert py.path.local to string
if isinstance(s, py.path.local):
s = s.strpath
else:
s = str(s)
# Strip surrounding quotes if requested
if strip_quotes and len(s) >= 2 and " " in s and (s[0] == s[-1] == '"' or s[0] == s[-1] == "'"):
s = s[1:-1]
return s
# Strip quotes from exe
result = [normalize(exe, strip_quotes=True)]
for arg in args:
# Don't strip quotes on anything except the exe
result.append(normalize(arg, strip_quotes=False))
return result
def spawn_debuggee(self, args, cwd=None, exe=sys.executable, setup=None):
assert self.debuggee is None