Verify desktop disappearance and finish private session feedback and native probes
This commit is contained in:
1 parent
fee1aff557
commit
48ad7b3592
13 files changed
+470
-25
No files matched your search
@@ -23,3 +23,15 @@ def test_feedback_uses_executing_child_and_ignores_previous_run_progress(tmp_pat
|
||||
path.write_text('incomplete JSON')
|
||||
assert service.execution_feedback(None, started_after=0).stage == ''
|
||||
store.close()
|
||||
def test_private_startup_and_shutdown_override_stale_worker_phase(tmp_path):
|
||||
import json
|
||||
from dx_productivity.trial_task_center.execution_feedback import read_feedback
|
||||
root = tmp_path / 'quick-run'
|
||||
root.mkdir()
|
||||
(root / 'worker-progress.json').write_text(json.dumps({'stage': 'capture'}))
|
||||
private = root / 'private-desktop.json'
|
||||
for state, expected in [('starting', 'private_startup'), ('closing', 'private_shutdown')]:
|
||||
private.write_text(json.dumps({'state': state}))
|
||||
assert read_feedback('task', 1, 1, 'running', tmp_path, 0).stage == expected
|
||||
private.write_text(json.dumps({'state': 'released'}))
|
||||
assert read_feedback('task', 1, 1, 'running', tmp_path, 0).stage == 'capture'
|
||||
@@ -54,6 +54,32 @@ def test_success_quits_owned_cad_before_releasing_desktop(monkeypatch, tmp_path)
|
||||
assert record['state'] == 'released' and record['clean']
|
||||
|
||||
|
||||
def test_repeated_session_preserves_prior_release_evidence(monkeypatch, tmp_path):
|
||||
fake_desktop(monkeypatch, tmp_path)
|
||||
with runtime.IsolatedCadSession(tmp_path) as first:
|
||||
first_token = first.token
|
||||
fake_desktop(monkeypatch, tmp_path)
|
||||
with runtime.IsolatedCadSession(tmp_path):
|
||||
pass
|
||||
records = [json.loads(path.read_text()) for path in (tmp_path / 'private-desktop-sessions').glob('*.json')]
|
||||
assert len(records) == 2 and first_token in {row['token'] for row in records}
|
||||
assert all(row['state'] == 'released' and row['clean'] for row in records)
|
||||
|
||||
|
||||
def test_hidden_private_action_dispatches_without_opening_gui(monkeypatch, tmp_path):
|
||||
from dx_productivity.trial_task_center import application
|
||||
def forbidden(*args, **kwargs):
|
||||
pytest.fail('private CAD helper must not initialize the GUI')
|
||||
monkeypatch.setattr(application, 'QApplication', forbidden)
|
||||
calls = []
|
||||
monkeypatch.setattr(runtime, 'native_action', lambda *args: calls.append(args) or 0)
|
||||
path = tmp_path / 'evidence.json'
|
||||
assert application.main(['--private-cad-action', 'probe', '--private-cad-evidence', str(path),
|
||||
'--private-cad-pid', '123']) == 0
|
||||
assert calls == [('probe', path, 123)]
|
||||
assert application.main(['--private-cad-action', 'probe']) == 2
|
||||
|
||||
|
||||
def test_startup_cancellation_releases_without_waiting_for_com_timeout(monkeypatch, tmp_path):
|
||||
abort = Event()
|
||||
events, _ = fake_desktop(monkeypatch, tmp_path, abort=abort)
|
||||
@@ -76,6 +102,21 @@ def test_startup_cleanup_failure_keeps_uncertain_lock(monkeypatch, tmp_path):
|
||||
assert (tmp_path / 'uncertain.flag').exists()
|
||||
|
||||
|
||||
def test_released_startup_failure_returns_retryable_pre_mutation_code(monkeypatch, tmp_path):
|
||||
class FailedStartup:
|
||||
def __init__(self, *args, **kwargs):
|
||||
pass
|
||||
def __enter__(self):
|
||||
raise runtime.PrivateCadStartupError('startup cancelled before project launch')
|
||||
def __exit__(self, *args):
|
||||
pytest.fail('failed enter must not enter execution')
|
||||
monkeypatch.setattr(runtime, 'IsolatedCadSession', FailedStartup)
|
||||
result = runtime.run_isolated_process(('cscript.exe', '//nologo', 'helper.vbs', str(tmp_path)), 1)
|
||||
assert result.returncode == 2
|
||||
assert 'before project launch' in result.stderr
|
||||
assert not (tmp_path / 'uncertain.flag').exists()
|
||||
|
||||
|
||||
@pytest.mark.parametrize('failure', ['quit', 'cad_exit', 'unexpected_exit'])
|
||||
def test_uncertain_cleanup_is_durable_before_forced_owned_release(monkeypatch, tmp_path, failure):
|
||||
events, cad = fake_desktop(monkeypatch, tmp_path,
|
||||
|
||||
@@ -11,6 +11,24 @@ from dx_productivity.trial_task_center.isolated_desktop import PrivateDesktop, b
|
||||
from dx_productivity.trial_task_center.isolated_desktop import _Win32Api, _Win32Process
|
||||
|
||||
|
||||
@pytest.mark.skipif(os.name != 'nt', reason='native Windows desktop lifetime')
|
||||
def test_release_does_not_report_success_while_another_handle_keeps_desktop_alive():
|
||||
desktop = PrivateDesktop('dx-test-' + uuid4().hex, enabled=True)
|
||||
desktop.__enter__()
|
||||
retained = subprocess.Popen((sys.executable, '-u', '-c',
|
||||
'import win32service,sys,time; h=win32service.OpenDesktop(sys.argv[1],0,False,1); print("ready",flush=True); time.sleep(30)',
|
||||
desktop.name), stdout=subprocess.PIPE)
|
||||
try:
|
||||
assert retained.stdout.readline() == b'ready\r\n'
|
||||
with pytest.raises(TaskCenterError, match='still exists'):
|
||||
desktop.close()
|
||||
finally:
|
||||
retained.terminate()
|
||||
retained.wait(timeout=5)
|
||||
retained.stdout.close()
|
||||
desktop.close()
|
||||
|
||||
|
||||
def test_startup_info_always_targets_private_desktop():
|
||||
info = build_startup_info('dx-private-test')
|
||||
assert info.lpDesktop == 'winsta0\\dx-private-test'
|
||||
|
||||
Reference in new issue
Block a user