fix: isolate ICDB checks and recover scoped native sessions
This commit is contained in:
1 parent
1acfbd6374
commit
1bd7589fef
82 files changed
+7770
-1583
No files matched your search
@@ -31,12 +31,28 @@ def test_diagnostic_worker_closes_without_integration_save_or_config_edit(tmp_pa
|
||||
def forbidden(*args, **kwargs):
|
||||
pytest.fail('diagnosis attempted integration/save/config rewrite')
|
||||
monkeypatch.setattr(adapter, 'ensure_pcb_central_library', forbidden)
|
||||
monkeypatch.setattr(adapter, 'pcb_log_reports_integration_error', forbidden)
|
||||
original_read = Path.read_bytes
|
||||
def read_bytes(path):
|
||||
if path.name in ('ForwardAnnotation.txt', 'MsgBoxResponse.log', 'PartPkg.log'):
|
||||
pytest.fail('opening check read unrelated integration history')
|
||||
return original_read(path)
|
||||
monkeypatch.setattr(Path, 'read_bytes', read_bytes)
|
||||
monkeypatch.setattr('cbb_refresh_verify.integration.refresh_integration', forbidden)
|
||||
monkeypatch.setattr('cbb_refresh_verify.desktop_worker.launch_save_helper', forbidden)
|
||||
monkeypatch.setattr('cbb_refresh_verify.pcb_bridge.wait_for_target_document', forbidden)
|
||||
monkeypatch.setattr('cbb_refresh_verify.failed_session.close_failed_document', forbidden)
|
||||
closes = []
|
||||
monkeypatch.setattr('cbb_refresh_verify.failed_session.close_failed_document',
|
||||
lambda job, **kw: closes.append(job) or {'status': 'CLOSED'})
|
||||
def check(job, pid, **kw):
|
||||
assert pid == 2 and kw['launcher_process'].pid == 1
|
||||
assert job['diagnostic_log_baseline']['started_ns']
|
||||
closes.append(job)
|
||||
kw['emit'](stage='diagnostic_wm_close')
|
||||
return {'status': 'PASS', 'native_processes_exited': True}
|
||||
monkeypatch.setattr('cbb_refresh_verify.diagnostic_open.check_target_window', check)
|
||||
result = execute()
|
||||
from cbb_refresh_verify.verify_runner import VerifyResult
|
||||
assert VerifyResult(**result).status == 'PASS'
|
||||
assert result['status'] == 'PASS'
|
||||
assert len(closes) == 1
|
||||
assert not any(e['stage'] in ('save_start', 'saved_and_closed') for e in events)
|
||||
@@ -47,8 +63,13 @@ def test_diagnostic_close_failure_never_returns_healthy(tmp_path, monkeypatch):
|
||||
job, events, execute = diagnostic_worker(tmp_path, monkeypatch)
|
||||
job['diagnostic_only'] = True
|
||||
closes = []
|
||||
monkeypatch.setattr('cbb_refresh_verify.failed_session.close_failed_document',
|
||||
lambda *a, **kw: closes.append(a) or {'status': 'RETAINED'})
|
||||
def check(*a, **kw):
|
||||
closes.append(a)
|
||||
kw['emit'](stage='diagnostic_wm_close')
|
||||
raise RuntimeError('DIAGNOSTIC_CLOSE_UNCONFIRMED')
|
||||
monkeypatch.setattr('cbb_refresh_verify.diagnostic_open.check_target_window', check)
|
||||
monkeypatch.setattr('cbb_refresh_verify.failed_session.close_failed_startup',
|
||||
lambda *a, **kw: pytest.fail('must not send another close after WM_CLOSE'))
|
||||
with pytest.raises(RuntimeError, match='DIAGNOSTIC_CLOSE_UNCONFIRMED'):
|
||||
execute()
|
||||
assert len(closes) == 1
|
||||
@@ -71,6 +92,8 @@ def diagnostic_worker(tmp_path, monkeypatch):
|
||||
job, events, execute = exercise_worker(tmp_path, monkeypatch)
|
||||
(Path(job['pcb']).parent/'pcb.prj').write_text(
|
||||
'KEY CentralLibrary "' + job['lmc_file'] + '"\n', encoding='utf-8')
|
||||
monkeypatch.setattr('cbb_refresh_verify.diagnostic_open.check_target_window',
|
||||
lambda *a, **kw: {'status': 'PASS', 'native_processes_exited': True})
|
||||
return job, events, execute
|
||||
|
||||
|
||||
@@ -98,19 +121,14 @@ def test_diagnostic_runner_skips_importer_and_ready_verification(tmp_path, monke
|
||||
assert captured['diagnostic_only'] is True
|
||||
|
||||
|
||||
def test_diagnostic_waits_for_normal_exit_after_close_returns(tmp_path, monkeypatch):
|
||||
def test_diagnostic_cannot_pass_with_unconfirmed_process_exit(tmp_path, monkeypatch):
|
||||
from cbb_refresh_verify import mentor_adapter as adapter
|
||||
job, events, execute = diagnostic_worker(tmp_path, monkeypatch)
|
||||
job['diagnostic_only'] = True
|
||||
observations = []
|
||||
def release(*a, **kw):
|
||||
observations.append(True)
|
||||
return {'safe_to_continue': len(observations) > 1}
|
||||
monkeypatch.setattr(adapter, 'cleanup_verify_processes', release)
|
||||
monkeypatch.setattr('cbb_refresh_verify.failed_session.close_failed_document',
|
||||
lambda *a, **kw: {'status': 'CLOSED'})
|
||||
assert execute()['status'] == 'PASS'
|
||||
assert len(observations) >= 2
|
||||
monkeypatch.setattr(adapter, 'cleanup_verify_processes',
|
||||
lambda *a, **kw: {'safe_to_continue': False, 'remaining_pids': [2]})
|
||||
with pytest.raises(RuntimeError, match='DIAGNOSTIC_CLOSE_UNCONFIRMED'):
|
||||
execute()
|
||||
|
||||
|
||||
@pytest.mark.parametrize('when', ['document_ready', 'closing'])
|
||||
@@ -123,17 +141,31 @@ def test_diagnostic_checks_late_startup_errors_before_declaring_healthy(tmp_path
|
||||
source.parent.mkdir(exist_ok=True)
|
||||
source.write_text("The last server session on different server machine lost the connection to the database. "
|
||||
f"Machine:[fixture] Path:[{Path(job['project']).parent/'database'}] session:[current]", encoding='utf-8')
|
||||
def document(*a, **kw):
|
||||
if when == 'document_ready': late_fault()
|
||||
return None, None, object()
|
||||
closes = []
|
||||
def close(*a, **kw):
|
||||
def check(*a, **kw):
|
||||
if when == 'document_ready':
|
||||
late_fault()
|
||||
raise RuntimeError(kw['error_reader']())
|
||||
closes.append(True)
|
||||
if when == 'closing': late_fault()
|
||||
return {'status': 'CLOSED'}
|
||||
monkeypatch.setattr('cbb_refresh_verify.pcb_bridge.wait_for_target_document', document)
|
||||
monkeypatch.setattr('cbb_refresh_verify.failed_session.close_failed_document', close)
|
||||
kw['emit'](stage='diagnostic_wm_close')
|
||||
late_fault()
|
||||
return {'status': 'PASS', 'native_processes_exited': True}
|
||||
monkeypatch.setattr('cbb_refresh_verify.diagnostic_open.check_target_window', check)
|
||||
monkeypatch.setattr('cbb_refresh_verify.failed_session.close_failed_startup',
|
||||
lambda *a, **kw: {'status': 'CLOSED'})
|
||||
with pytest.raises(RuntimeError, match='ICDB_REPAIR_REQUIRED'):
|
||||
execute()
|
||||
assert len(closes) == 1
|
||||
assert len(closes) == (1 if when == 'closing' else 0)
|
||||
assert not any(e['stage'] == 'diagnostic_complete' for e in events)
|
||||
|
||||
|
||||
def test_diagnostic_snapshot_is_before_launch(tmp_path, monkeypatch):
|
||||
from cbb_refresh_verify import mentor_adapter as adapter
|
||||
job, events, execute = diagnostic_worker(tmp_path, monkeypatch)
|
||||
job['diagnostic_only'] = True
|
||||
def launch(*a):
|
||||
assert job.get('diagnostic_log_baseline', {}).get('started_ns')
|
||||
from types import SimpleNamespace
|
||||
return SimpleNamespace(pid=1)
|
||||
monkeypatch.setattr(adapter, 'launch_pcb_process', launch)
|
||||
assert execute()['status'] == 'PASS'
|
||||
Reference in new issue
Block a user