From 264fee5127ae77d92409c126710c16dc0343d0dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=98=BF=E7=99=BD=E5=8F=94?= <11794527+absfan@user.noreply.gitee.com> Date: Fri, 23 Oct 2026 16:39:26 +0800 Subject: [PATCH] fix: detect owned CAD exit during startup without waiting for probe timeout --- .../trial_task_center/isolated_cad.py | 3 +++ tests/v1_1/test_isolated_cad.py | 20 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/dx_productivity/trial_task_center/isolated_cad.py b/src/dx_productivity/trial_task_center/isolated_cad.py index b675b07..bb3916a 100644 --- a/src/dx_productivity/trial_task_center/isolated_cad.py +++ b/src/dx_productivity/trial_task_center/isolated_cad.py @@ -128,6 +128,9 @@ class IsolatedCadSession: deadline = time.monotonic() + 120 while probe.poll() is None: self._check_abort() + cad_exit = self.cad.poll() + if cad_exit is not None: + raise WorkerMonitorError(f'owned private CAD exited during startup: exit code {cad_exit}') if time.monotonic() >= deadline: raise WorkerMonitorError('private CAD bootstrap timed out') time.sleep(0.05) diff --git a/tests/v1_1/test_isolated_cad.py b/tests/v1_1/test_isolated_cad.py index 1b5e9e8..69c9ac1 100644 --- a/tests/v1_1/test_isolated_cad.py +++ b/tests/v1_1/test_isolated_cad.py @@ -236,6 +236,26 @@ def test_slow_startup_is_bounded_and_cleanup_remains_owned(monkeypatch, tmp_path assert ('release', False) in events +def test_owned_cad_exit_does_not_wait_for_unresponsive_startup_probe(monkeypatch, tmp_path): + events, cad = fake_desktop(monkeypatch, tmp_path) + clock = [0.0] + monkeypatch.setattr(runtime.time, 'monotonic', lambda: clock[0]) + monkeypatch.setattr(runtime.time, 'sleep', lambda seconds: clock.__setitem__(0, clock[0] + seconds)) + original = runtime.PrivateDesktop.start_process + def start(self, command, **kwargs): + process = original(self, command, **kwargs) + if command[0] == 'probe': + cad.returncode = 73 + process.poll = lambda: None + return process + monkeypatch.setattr(runtime.PrivateDesktop, 'start_process', start) + with pytest.raises(runtime.PrivateCadStartupError, match='exited during startup.*73'): + with runtime.IsolatedCadSession(tmp_path): + pytest.fail('exited CAD must never enter project work') + assert clock[0] < 1 + assert events.index('close-helper') < events.index(('release', False)) + + def test_repeated_session_preserves_prior_release_evidence(monkeypatch, tmp_path): fake_desktop(monkeypatch, tmp_path) with runtime.IsolatedCadSession(tmp_path) as first: