Preserve tested Verify source, authoritative READY checks, bounded bridge retries, diagnostics and failure-only reporting. Include 336-test suite and packaging assets; exclude live Mentor samples, field logs, backups and distributions.
84 lines
3.3 KiB
Python
84 lines
3.3 KiB
Python
from pathlib import Path
|
|
|
|
|
|
def test_smoke_arguments_exit_zero_and_write_lifecycle_log(tmp_path: Path):
|
|
import subprocess, sys
|
|
result = subprocess.run([sys.executable, '-m', 'cbb_refresh_verify', '--smoke-test', '--data-root', str(tmp_path)], timeout=30)
|
|
assert result.returncode == 0
|
|
text = (tmp_path / "logs" / "application.log").read_text(encoding="utf-8")
|
|
assert "application_start" in text
|
|
assert "application_clean_shutdown" in text
|
|
assert "gui_smoke_window_created" in text
|
|
|
|
|
|
def test_module_entrypoint_propagates_main_exit_code():
|
|
import subprocess, sys
|
|
code = (
|
|
"import cbb_refresh_verify.application as a; a.main=lambda: 7; "
|
|
"import runpy; runpy.run_module('cbb_refresh_verify.__main__', run_name='__main__')"
|
|
)
|
|
result = subprocess.run([sys.executable, '-c', code], capture_output=True, text=True)
|
|
assert result.returncode == 7
|
|
|
|
|
|
def test_batch_cli_acquires_unc_lease_before_directory_scan(tmp_path, monkeypatch):
|
|
import cbb_refresh_verify.application as application
|
|
import cbb_refresh_verify.library_reader as library_reader
|
|
import cbb_refresh_verify.network_path as network_path
|
|
|
|
events = []
|
|
|
|
class Lease:
|
|
display_path = r'\\server\share\library'
|
|
mentor_path = tmp_path
|
|
drive = 'Z:'
|
|
remote_root = r'\\server\share'
|
|
created = True
|
|
def __enter__(self):
|
|
events.append('enter')
|
|
return self
|
|
def __exit__(self, *_args):
|
|
events.append('exit')
|
|
def close(self):
|
|
events.append('close')
|
|
|
|
class Library:
|
|
error = 'stop after path setup'
|
|
records = ()
|
|
|
|
monkeypatch.setattr(application, 'configure', lambda *_args: type('C', (), {
|
|
'root': tmp_path,
|
|
'logger': type('L', (), {'info': lambda *a, **k: None,
|
|
'exception': lambda *a, **k: None,
|
|
'handlers': ()})(),
|
|
})())
|
|
monkeypatch.setattr(network_path, 'LibraryPathLease', type('LP', (), {
|
|
'acquire': staticmethod(lambda path: (events.append(('acquire', path)) or Lease()))
|
|
}))
|
|
monkeypatch.setattr(network_path, 'select_library_file', lambda path: (
|
|
events.append(('select', path)) or path
|
|
))
|
|
|
|
# The command exits after the fake reader reports an empty/error library;
|
|
# ordering is the contract under test.
|
|
monkeypatch.setattr(library_reader, 'read_library_fast', lambda path, **kwargs: Library())
|
|
result = application.main(['--batch-lmc', r'\\server\share\library'])
|
|
|
|
assert result == 1
|
|
assert events[:3] == [('acquire', Path(r'\\server\share\library')), 'enter',
|
|
('select', tmp_path)]
|
|
|
|
|
|
def test_native_log_helper_mode_does_not_load_ui_or_mgcpcb(tmp_path, monkeypatch):
|
|
import json
|
|
import cbb_refresh_verify.application as application
|
|
request = tmp_path/'request.json'
|
|
pcb = tmp_path/'Work/PCB/test.pcb'
|
|
pcb.parent.mkdir(parents=True)
|
|
request.write_text(json.dumps({'root': str(tmp_path), 'pcb': str(pcb)}), encoding='utf-8')
|
|
monkeypatch.setattr(application, 'configure', lambda *_: (_ for _ in ()).throw(
|
|
AssertionError('log capture must not create a GUI/logger session')))
|
|
result = application.main(['--collect-failure-logs', str(request)])
|
|
assert result == 0
|
|
assert (tmp_path/'diagnostics/native-logs.json').is_file()
|