fix: stabilize ICDB preflight and organize UI into tabs
This commit is contained in:
1 parent
29959e2988
commit
223655fe00
10 files changed
+352
-57
No files matched your search
@@ -90,6 +90,26 @@ def test_requested_close_without_exit_is_not_reported_closed(tmp_path, monkeypat
|
||||
assert records
|
||||
|
||||
|
||||
@pytest.mark.parametrize('exits', [True, False])
|
||||
def test_after_owned_close_transient_empty_command_waits_for_exit(tmp_path, monkeypatch, exits):
|
||||
from types import SimpleNamespace
|
||||
import win32gui
|
||||
job, records, messages = startup_fixture(tmp_path, monkeypatch)
|
||||
ticks = [0.0]
|
||||
def post(hwnd, message, *_):
|
||||
messages.append((hwnd, message))
|
||||
records[0] = (12, '', '', 11) # WMI during process teardown.
|
||||
def advance(seconds):
|
||||
ticks[0] += seconds
|
||||
if exits: records.clear()
|
||||
monkeypatch.setattr(win32gui, 'PostMessage', post)
|
||||
monkeypatch.setattr(failed_session, 'time', SimpleNamespace(monotonic=lambda: ticks[0], sleep=advance))
|
||||
result = failed_session.close_failed_startup(job, 12, timeout_seconds=1)
|
||||
assert ticks[0] > 0 and len(messages) == 1
|
||||
assert result['status'] == ('CLOSED' if exits else 'RETAINED')
|
||||
assert 'STARTUP_PROCESS_UNCONFIRMED' not in result.get('detail', '')
|
||||
|
||||
|
||||
@pytest.mark.parametrize('obstacle', ['address', 'dialog', 'process'])
|
||||
def test_startup_close_waits_for_native_state_transitions(tmp_path, monkeypatch, obstacle):
|
||||
from types import SimpleNamespace
|
||||
|
||||
@@ -115,6 +115,33 @@ def test_addressless_target_binds_unique_project_and_rejects_new_address(case):
|
||||
with maintenance_target_guard(request, context): pass
|
||||
|
||||
|
||||
def test_guard_reuses_full_tree_scan_but_still_refreshes_before_yield(case, monkeypatch):
|
||||
from cbb_refresh_verify.maintenance_entry import maintenance_target_guard
|
||||
import cbb_refresh_verify.scoped_manifest as manifests
|
||||
request, _, _ = case
|
||||
scans = []
|
||||
original = manifests.scan_tree
|
||||
def scan(root, **kwargs):
|
||||
scans.append(Path(root))
|
||||
return original(root, **kwargs)
|
||||
monkeypatch.setattr(manifests, 'scan_tree', scan)
|
||||
with maintenance_target_guard(request): pass
|
||||
assert scans.count(request.lmc_file.parent) == 2
|
||||
|
||||
|
||||
def test_guard_rejects_new_native_database_appearing_during_checks(case, monkeypatch):
|
||||
import cbb_refresh_verify.maintenance_entry as entry
|
||||
request, _, _ = case
|
||||
calls = []
|
||||
def idle():
|
||||
calls.append(1)
|
||||
if len(calls) == 2:
|
||||
(request.lmc_file.parent/'new.lmc').write_bytes(b'new native store')
|
||||
monkeypatch.setattr(entry, 'assert_native_idle', idle)
|
||||
with pytest.raises(ValueError, match='MAINTENANCE_SOURCE_CHANGED'):
|
||||
with entry.maintenance_target_guard(request): pass
|
||||
|
||||
|
||||
@pytest.mark.parametrize('reference', ['', 'KEY ProjectFile "../Other.prj"\n',
|
||||
'KEY ProjectFile "../IP101GR.prj"\nKEY ProjectFile "../IP101GR.prj"\n'])
|
||||
def test_addressless_target_requires_exact_pcb_back_reference(case, reference):
|
||||
@@ -284,7 +311,8 @@ def test_explicit_worker_requires_positive_native_idle_before_repair(tmp_path, m
|
||||
values['maintenance_context'] = {'library': str(tmp_path/'lib.lmc'), 'block': 'CBB1'}
|
||||
job.write_text(json.dumps(values))
|
||||
@contextmanager
|
||||
def guard(*args):
|
||||
def guard(*args, stop=None):
|
||||
assert stop is not None
|
||||
yield {'target': RepairTarget(Path(values['project']), Path(values['database']))}
|
||||
monkeypatch.setattr(entry, 'maintenance_target_guard', guard)
|
||||
monkeypatch.setattr(ui, '_native_output', lambda windows: output)
|
||||
@@ -293,7 +321,7 @@ def test_explicit_worker_requires_positive_native_idle_before_repair(tmp_path, m
|
||||
assert any(message == win32con.WM_COMMAND for _, message in actions) is expected
|
||||
|
||||
|
||||
def test_worker_rechecks_address_after_complete_backup_before_native_launch(tmp_path, monkeypatch):
|
||||
def test_worker_rechecks_address_after_access_probe_before_native_launch(tmp_path, monkeypatch):
|
||||
from test_native_repair import repair_worker_fixture
|
||||
import cbb_refresh_verify.maintenance_entry as entry
|
||||
from cbb_refresh_verify.native_repair import RepairTarget
|
||||
@@ -301,15 +329,19 @@ def test_worker_rechecks_address_after_complete_backup_before_native_launch(tmp_
|
||||
values = json.loads(job.read_text()); values['maintenance_context'] = {'library': str(tmp_path/'lib.lmc'), 'block': 'CBB1'}
|
||||
job.write_text(json.dumps(values))
|
||||
calls = []
|
||||
monkeypatch.setattr('cbb_refresh_verify.native_repair.check_repair_access',
|
||||
lambda *_: calls.append('access'))
|
||||
@contextmanager
|
||||
def guard(*args):
|
||||
def guard(*args, stop=None):
|
||||
assert stop is not None
|
||||
calls.append('guard')
|
||||
if len(calls) == 2: raise ValueError('address changed during complete backup')
|
||||
assert calls == ['access', 'guard']
|
||||
raise ValueError('address changed after access probe')
|
||||
yield {'target': RepairTarget(Path(values['project']), Path(values['database']))}
|
||||
monkeypatch.setattr(entry, 'maintenance_target_guard', guard)
|
||||
monkeypatch.setattr(ui.subprocess, 'Popen', lambda *a, **k: pytest.fail('mutation must stop native launch'))
|
||||
ui.repair_worker_main(job)
|
||||
assert calls == ['guard', 'guard']
|
||||
assert calls == ['access', 'guard']
|
||||
assert 'address changed' in json.loads((root/'repair-result.json').read_text())['detail']
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
import json
|
||||
from pathlib import Path
|
||||
import sys
|
||||
from uuid import uuid4
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
def test_empty_private_desktop_does_not_inherit_stale_windows_error(tmp_path):
|
||||
from cbb_refresh_verify.desktop_worker import DesktopWorker
|
||||
script = tmp_path/'enumerate.py'
|
||||
result = tmp_path/'result.json'
|
||||
script.write_text(
|
||||
'import sys,json,win32api,win32gui,win32process\nfrom pathlib import Path\n'
|
||||
f'sys.path.insert(0,{str(Path("src").resolve())!r})\n'
|
||||
'from cbb_refresh_verify.native_repair_ui import _windows\n'
|
||||
'win32api.SetLastError(2)\n'
|
||||
'try:\n record={"windows":_windows(999999)}\n'
|
||||
'except Exception as error:\n record={"error":str(error)}\n'
|
||||
f'Path({str(result)!r}).write_text(json.dumps(record))\n', encoding='utf-8')
|
||||
worker = DesktopWorker([sys.executable, str(script)], 'CbbProbe_' + uuid4().hex[:12])
|
||||
try:
|
||||
assert worker.wait(timeout=20) == 0
|
||||
finally:
|
||||
worker.close()
|
||||
assert json.loads(result.read_text()) == {'windows': []}
|
||||
|
||||
|
||||
def test_real_window_enumeration_errors_still_propagate(monkeypatch):
|
||||
import win32gui, pywintypes
|
||||
from cbb_refresh_verify.native_repair_ui import _windows
|
||||
def denied(*args): raise pywintypes.error(5, 'EnumWindows', 'denied')
|
||||
monkeypatch.setattr(win32gui, 'EnumWindows', denied)
|
||||
with pytest.raises(pywintypes.error): _windows(123)
|
||||
|
||||
|
||||
def test_cancel_reaches_prelaunch_scan(tmp_path, monkeypatch):
|
||||
from contextlib import contextmanager
|
||||
from test_native_repair import repair_worker_fixture
|
||||
from cbb_refresh_verify.native_repair import RepairTarget
|
||||
ui, root, job, actions = repair_worker_fixture(tmp_path, monkeypatch, 'active')
|
||||
data = json.loads(job.read_text('utf-8'))
|
||||
data['maintenance_context'] = {'library': str(tmp_path/'lib.lmc'), 'block': 'CBB1'}
|
||||
job.write_text(json.dumps(data), encoding='utf-8')
|
||||
calls, interrupted = [], []
|
||||
@contextmanager
|
||||
def guard(*args, stop=None, **kwargs):
|
||||
calls.append(1)
|
||||
assert stop is not None, 'worker scan has no cancellation input'
|
||||
if len(calls) == 1:
|
||||
Path(data['cancel_signal']).touch()
|
||||
assert stop.is_set()
|
||||
interrupted.append(1)
|
||||
raise ValueError('MAINTENANCE_CANCELLED')
|
||||
yield {'target': RepairTarget(Path(data['project']), Path(data['database']))}
|
||||
monkeypatch.setattr('cbb_refresh_verify.maintenance_entry.maintenance_target_guard', guard)
|
||||
monkeypatch.setattr(ui.subprocess, 'Popen', lambda *a, **kw: pytest.fail('cancelled native launch'))
|
||||
assert ui.repair_worker_main(job) == 1
|
||||
assert interrupted == [1] and not actions
|
||||
|
||||
|
||||
def test_worker_uses_one_complete_guard_immediately_before_native_launch(tmp_path, monkeypatch):
|
||||
from contextlib import contextmanager
|
||||
from test_native_repair import repair_worker_fixture
|
||||
from cbb_refresh_verify.native_repair import RepairTarget
|
||||
ui, root, job, actions = repair_worker_fixture(tmp_path, monkeypatch, 'active')
|
||||
data = json.loads(job.read_text('utf-8'))
|
||||
data['maintenance_context'] = {'library': str(tmp_path/'lib.lmc'), 'block': 'CBB1'}
|
||||
job.write_text(json.dumps(data), encoding='utf-8')
|
||||
order = []
|
||||
@contextmanager
|
||||
def guard(*args, stop=None, **kwargs):
|
||||
assert stop is not None
|
||||
order.append('guard')
|
||||
yield {'target': RepairTarget(Path(data['project']), Path(data['database']))}
|
||||
order.append('guard_complete')
|
||||
monkeypatch.setattr('cbb_refresh_verify.maintenance_entry.maintenance_target_guard', guard)
|
||||
popen = ui.subprocess.Popen
|
||||
def launch(*args, **kwargs):
|
||||
order.append('launch')
|
||||
return popen(*args, **kwargs)
|
||||
monkeypatch.setattr(ui.subprocess, 'Popen', launch)
|
||||
ui.repair_worker_main(job)
|
||||
assert order == ['guard', 'guard_complete', 'launch']
|
||||
|
||||
|
||||
def test_file_cancellation_polling_is_bounded_and_latches_cancel(tmp_path, monkeypatch):
|
||||
from types import SimpleNamespace
|
||||
import cbb_refresh_verify.native_repair_ui as ui
|
||||
now = [1.0]
|
||||
monkeypatch.setattr(ui, 'time', SimpleNamespace(monotonic=lambda: now[0]))
|
||||
signal = ui._CancellationFile(tmp_path/'cancel.signal')
|
||||
reads = []
|
||||
signal.path = SimpleNamespace(exists=lambda: reads.append(1) or len(reads) > 1)
|
||||
for _ in range(50000):
|
||||
assert not signal.is_set()
|
||||
assert len(reads) == 1
|
||||
now[0] += .11
|
||||
assert signal.is_set()
|
||||
signal.path = SimpleNamespace(exists=lambda: pytest.fail('cancel must stay latched'))
|
||||
now[0] += 1
|
||||
assert signal.is_set()
|
||||
@@ -164,11 +164,11 @@ def test_cancel_during_final_guard_cannot_launch_native_tool(tmp_path, monkeypat
|
||||
def guard(*a, **kw):
|
||||
calls.append(True)
|
||||
yield {'target': RepairTarget(Path(data['project']), Path(data['database']))}
|
||||
if len(calls) == 2: Path(data['cancel_signal']).touch()
|
||||
Path(data['cancel_signal']).touch()
|
||||
monkeypatch.setattr('cbb_refresh_verify.maintenance_entry.maintenance_target_guard', guard)
|
||||
monkeypatch.setattr(ui.subprocess, 'Popen', lambda *a, **kw: pytest.fail('late native launch'))
|
||||
assert ui.repair_worker_main(job) == 1
|
||||
assert len(calls) == 2 and not actions
|
||||
assert len(calls) == 1 and not actions
|
||||
|
||||
|
||||
def test_verified_cbb_refusal_is_not_hidden_by_secondary_release_failure():
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
from PySide6.QtCore import Qt
|
||||
|
||||
|
||||
def test_three_horizontal_sections_keep_one_catalog_and_only_their_actions(qtbot, tmp_path, monkeypatch):
|
||||
from test_ui_filters import load_window
|
||||
window = load_window(qtbot, tmp_path, monkeypatch)
|
||||
window.show()
|
||||
assert [window.section_tabs.tabText(i) for i in range(window.section_tabs.count())] == [
|
||||
'检验', 'ICDB 维护', '中心库管理']
|
||||
window.search_edit.setText('Beta')
|
||||
window.select_visible_button.click()
|
||||
for index, visible, hidden in (
|
||||
(0, window.batch_button, window.icdb_repair_button),
|
||||
(1, window.icdb_repair_button, window.add_button),
|
||||
(2, window.add_button, window.batch_button),
|
||||
):
|
||||
window.section_tabs.setCurrentIndex(index)
|
||||
assert visible.isVisible() and not hidden.isVisible()
|
||||
assert window.cbb_table.isVisible()
|
||||
assert window.search_edit.text() == 'Beta'
|
||||
assert [record.name for record in window.selected_records()] == ['Beta']
|
||||
assert window.minimumSizeHint().height() <= 650
|
||||
|
||||
|
||||
def test_long_status_does_not_expand_the_window(qtbot, tmp_path):
|
||||
from cbb_refresh_verify.ui.main_window import MainWindow
|
||||
window = MainWindow(data_root=tmp_path)
|
||||
qtbot.addWidget(window)
|
||||
window.resize(1000, 650); window.show()
|
||||
window.status_label.setText('错误说明\n' * 80)
|
||||
qtbot.wait(20)
|
||||
assert window.height() <= 650
|
||||
assert window.status_label.height() <= window.status_label.fontMetrics().lineSpacing() * 3 + 4
|
||||
Reference in new issue
Block a user