test: separate passive release preview from observer cleanup

This commit is contained in:
阿白叔 committed 2026-11-25 13:47:03 +08:00
1 parent a63861f0e2
commit 9fa9625dba
1 file changed
+11 -4
+11 -4
View File
@@ -13,12 +13,12 @@ from cbb_refresh_verify import session_record as sessions
from test_session_record import child, record from test_session_record import child, record
def retain_unconfirmed(root, library): def retain_unconfirmed(root, library, *, observe_only=False):
root.mkdir(parents=True) root.mkdir(parents=True)
path = root/'session.json' path = root/'session.json'
sessions.write_session_record(path, dict(operation_id=root.name, library=str(library), processes=[])) sessions.write_session_record(path, dict(operation_id=root.name, library=str(library), processes=[]))
done = Event() done = Event()
sessions.handoff_session(path, evidence_root=root, progress=lambda _: done.set()) sessions.handoff_session(path, evidence_root=root, observe_only=observe_only, progress=lambda _: done.set())
assert done.wait(3) assert done.wait(3)
with sessions._observer_guard: with sessions._observer_guard:
observer = sessions._observers.get(str(path.absolute()).casefold()) observer = sessions._observers.get(str(path.absolute()).casefold())
@@ -157,16 +157,23 @@ def test_residual_dialog_refresh_shows_runtime_blocker_without_releasing(qtbot,
library = tmp_path/'library/lib.lmc' library = tmp_path/'library/lib.lmc'
library.parent.mkdir(); library.touch() library.parent.mkdir(); library.touch()
monkeypatch.setattr(locks, 'inspect_residual_sessions', lambda *_: {'library': str(library), 'sessions': []}) monkeypatch.setattr(locks, 'inspect_residual_sessions', lambda *_: {'library': str(library), 'sessions': []})
monkeypatch.setattr(locks, 'release_retained_library', lambda *a, **kw: pytest.fail('preview mutated library')) releases = []
def unexpected_release(*args, **kwargs):
releases.append((args, kwargs))
raise OSError('Preview started a release')
monkeypatch.setattr(locks, 'release_retained_library', unexpected_release)
dialog = ResidualReleaseDialog(library, tmp_path/'release-checks') dialog = ResidualReleaseDialog(library, tmp_path/'release-checks')
qtbot.addWidget(dialog) qtbot.addWidget(dialog)
qtbot.waitUntil(lambda: not dialog.busy) qtbot.waitUntil(lambda: not dialog.busy)
retain_unconfirmed(tmp_path/'late-session', library) retain_unconfirmed(tmp_path/'late-session', library, observe_only=True)
dialog.refresh_button.click() dialog.refresh_button.click()
qtbot.waitUntil(lambda: not dialog.busy) qtbot.waitUntil(lambda: not dialog.busy)
assert dialog.plan['runtime_sessions'][0]['status'] == 'UNCONFIRMED' assert dialog.plan['runtime_sessions'][0]['status'] == 'UNCONFIRMED'
assert '待核对' in dialog.runtime_label.text() assert '待核对' in dialog.runtime_label.text()
assert not sessions.library_available(library) assert not sessions.library_available(library)
assert releases == []
def test_passive_handoff_reports_final_unconfirmed_state_without_proof(tmp_path, child, monkeypatch): def test_passive_handoff_reports_final_unconfirmed_state_without_proof(tmp_path, child, monkeypatch):