fix: close a proven design after interrupted PCB startup
This commit is contained in:
1 parent
9fa9625dba
commit
b3d69ee722
2 files changed
+40
-12
No files matched your search
@@ -1125,14 +1125,31 @@ def finish_owned_idle_session(path, *, stop=None):
|
||||
and owner.get('force_user_confirmed') is True
|
||||
and _handle_identity(handle) == {k:client[k] for k in ('created_handle','image')}
|
||||
and all(owner.get(k) == client[k] for k in ('owner_sid','session_id')))
|
||||
def empty_target():
|
||||
def idle_target():
|
||||
snapshot = _process_windows({client['pid']}, include_hidden_documents=True)
|
||||
windows = snapshot.get(client['pid'], [])
|
||||
if (any(w.get('desktop') != desktop or w.get('documents')
|
||||
or any(c['class'].casefold().startswith('afx:') and c.get('visible') is False
|
||||
for c in w.get('children',[])) for w in windows)):
|
||||
if any(w.get('desktop') != desktop or any(
|
||||
c['class'].casefold().startswith('afx:') and c.get('visible') is False
|
||||
for c in w.get('children', [])) for w in windows):
|
||||
return None
|
||||
return close_target(client_name, windows, incomplete=_window_error(snapshot,client['pid']))[0]
|
||||
target, _ = close_target(client_name, windows, incomplete=_window_error(snapshot, client['pid']))
|
||||
if target is None or not any(w.get('documents') for w in windows):
|
||||
return target
|
||||
if orphan_client is None:
|
||||
return None
|
||||
# PCB can finish loading after its worker has stopped. Close
|
||||
# only the design independently bound by this launch's logs.
|
||||
from .diagnostic_open import _load_evidence, _target_frame
|
||||
from .failed_session import cancelled_prewrite_startup
|
||||
baseline = cancelled_prewrite_startup(job, client['pid'])
|
||||
if baseline is None:
|
||||
return None
|
||||
frames = _legacy_diagnostic_windows(dict(client, cleanup_desktop=desktop))
|
||||
frame = _target_frame(frames, Path(job['pcb']).stem)
|
||||
if (frame and frame['hwnd'] == target['hwnd']
|
||||
and _load_evidence(job, client['pid'], baseline, require_autosave=False) is not None):
|
||||
return target
|
||||
return None
|
||||
def startup_prompt():
|
||||
from .failed_session import _startup_snapshot, _cancel_target, _tip_target
|
||||
snapshot = _process_windows({client['pid']}, include_hidden_documents=True)
|
||||
@@ -1165,7 +1182,7 @@ def finish_owned_idle_session(path, *, stop=None):
|
||||
if (cancelled_before_write is not None
|
||||
and cancelled_prewrite_startup(job, client['pid']) != cancelled_before_write):
|
||||
return False
|
||||
target = empty_target()
|
||||
target = idle_target()
|
||||
prompt = startup_prompt() if target is None and (cancelled_before_write is not None or orphan_client is not None) else None
|
||||
if (target is None and prompt is None) or stop is not None and stop.is_set(): return False
|
||||
check_active()
|
||||
@@ -1181,7 +1198,7 @@ def finish_owned_idle_session(path, *, stop=None):
|
||||
or latest.get('owned_idle_cleanup') != claim
|
||||
or any(latest.get(k) != v for k,v in session.items() if k != 'recorded_at')
|
||||
or not same_client() or read('request.json') != job
|
||||
or (empty_target() != target if prompt is None else startup_prompt() != prompt)
|
||||
or (idle_target() != target if prompt is None else startup_prompt() != prompt)
|
||||
or (cancelled_before_write is not None
|
||||
and cancelled_prewrite_startup(job, client['pid']) != cancelled_before_write)
|
||||
or read_result() != result or result is None and not recoverable_orphan_session(path)
|
||||
@@ -1204,11 +1221,11 @@ def finish_owned_idle_session(path, *, stop=None):
|
||||
while time.monotonic() < deadline and same_client():
|
||||
if stop is not None and stop.is_set():
|
||||
break
|
||||
target = empty_target()
|
||||
target = idle_target()
|
||||
if target is not None:
|
||||
break
|
||||
time.sleep(.1)
|
||||
if (target is not None and (not same_client() or empty_target() != target
|
||||
if (target is not None and (not same_client() or idle_target() != target
|
||||
or orphan_client is not None and not recoverable_orphan_session(path)
|
||||
or cancelled_before_write is not None
|
||||
and cancelled_prewrite_startup(job, client['pid']) != cancelled_before_write)):
|
||||
|
||||
@@ -182,14 +182,14 @@ def test_cancelled_prewrite_can_dismiss_exact_late_load_failure(qtbot, tmp_path,
|
||||
@pytest.mark.parametrize('obstacle', [None, 'tip', 'cancelled_tip', 'previously_dismissed_tip',
|
||||
'read_write', 'unknown_prompt', 'save',
|
||||
'uncertain_phase', 'live_supervisor', 'live_worker',
|
||||
'wrong_pcb', 'possible_write'])
|
||||
'wrong_pcb', 'possible_write', 'loaded', 'unproved_loaded'])
|
||||
def test_restarted_verify_closes_exact_prewrite_orphan(tmp_path, monkeypatch, obstacle):
|
||||
import json
|
||||
from contextlib import nullcontext
|
||||
from types import SimpleNamespace
|
||||
import win32event
|
||||
from test_owned_idle_cleanup import owned_fixture
|
||||
from cbb_refresh_verify import failed_session, residual_sessions
|
||||
from cbb_refresh_verify import diagnostic_open, failed_session, residual_sessions
|
||||
|
||||
root, job, result, windows, state = owned_fixture(tmp_path, monkeypatch)
|
||||
create_mutex = win32event.CreateMutex
|
||||
@@ -231,6 +231,17 @@ def test_restarted_verify_closes_exact_prewrite_orphan(tmp_path, monkeypatch, ob
|
||||
rows.append(dict(stage='startup_tip_dismissed', pcb_pid=12, hwnd=200))
|
||||
if obstacle == 'possible_write':
|
||||
rows.append(dict(stage='startup_supervisor_write_possible', **binding))
|
||||
if obstacle in ('loaded', 'unproved_loaded'):
|
||||
rows.append(dict(stage='startup_cancelled_prewrite', pcb_pid=12, identity_verified=False,
|
||||
write_admitted=False, **binding))
|
||||
windows[0].update(title='Expedition PCB - Reusable Block - [Bad]', documents=[101])
|
||||
monkeypatch.setattr(residual_sessions, '_legacy_diagnostic_windows', lambda _: [
|
||||
dict(windows[0], text=windows[0]['title'], children=[
|
||||
{'hwnd': 101, 'class': 'MDIClient'},
|
||||
{'hwnd': 102, 'parent': 101, 'class': 'Afx:document', 'text': 'Bad'},
|
||||
])])
|
||||
monkeypatch.setattr(diagnostic_open, '_load_evidence', lambda *a, **kw:
|
||||
{'document_identity': 'native_path_pid_logs'} if obstacle == 'loaded' else None)
|
||||
(root/'events.jsonl').write_text(''.join(json.dumps(row)+'\n' for row in rows), encoding='utf-8')
|
||||
if obstacle == 'save':
|
||||
(root/'save.log').write_text('SAVE_START\n', encoding='utf-8')
|
||||
@@ -267,7 +278,7 @@ def test_restarted_verify_closes_exact_prewrite_orphan(tmp_path, monkeypatch, ob
|
||||
SimpleNamespace(handle=201)) if obstacle == 'read_write' else None)
|
||||
recovered = residual_sessions.finish_owned_idle_session(path)
|
||||
|
||||
assert recovered is (obstacle in (None, 'tip', 'cancelled_tip', 'read_write'))
|
||||
assert recovered is (obstacle in (None, 'tip', 'cancelled_tip', 'read_write', 'loaded'))
|
||||
expected_posts = [(201, 12, 245)] if obstacle in ('tip', 'cancelled_tip', 'read_write') else []
|
||||
if recovered:
|
||||
expected_posts.append((100, 12, 16))
|
||||
|
||||
Reference in new issue
Block a user