feat: add confirmed client release with durable consent and server protection
This commit is contained in:
1 parent
282be7be7f
commit
173dee1980
54 files changed
+3909
-14
No files matched your search
@@ -60,6 +60,18 @@ def test_unconfirmed_open_is_amber_and_does_not_claim_icdb_damage(qtbot, tmp_pat
|
||||
assert cell.background().color().name() == '#fff8e1'
|
||||
|
||||
|
||||
def test_completed_old_library_result_does_not_release_new_library(qtbot, tmp_path, monkeypatch):
|
||||
from test_ui_filters import load_window
|
||||
from cbb_refresh_verify.verify_runner import VerifyResult
|
||||
from pathlib import Path
|
||||
window = load_window(qtbot, tmp_path, monkeypatch, verifier=lambda _: VerifyResult('FAIL', safe_to_continue=False))
|
||||
window._run(['Beta'], maintenance=True)
|
||||
qtbot.waitUntil(lambda: not window._icdb_active())
|
||||
summary = window.icdb_summary
|
||||
window.lmc_edit.setText('other.lmc')
|
||||
next(button for button in summary.buttons() if '释放' in button.text()).click()
|
||||
assert getattr(window, 'release_dialog', None) is None
|
||||
assert '切' in window.status_label.text()
|
||||
|
||||
|
||||
def test_later_management_invalidates_old_recovery_offer(qtbot, tmp_path, monkeypatch):
|
||||
|
||||
@@ -23,6 +23,46 @@ def test_only_confirmed_maintenance_sets_explicit_flag(qtbot, tmp_path, monkeypa
|
||||
assert len(calls) == 2 and calls[-1].maintenance is True
|
||||
|
||||
|
||||
@pytest.mark.parametrize('marker_kind', ['valid', 'foreign', 'malformed'])
|
||||
def test_old_checkpoint_does_not_force_maintenance_or_disable_verify(qtbot, tmp_path, monkeypatch, marker_kind):
|
||||
from cbb_refresh_verify.library_lock import LibraryLock, blocker_path, _owners, _guard
|
||||
from cbb_refresh_verify.ui.main_window import MainWindow
|
||||
from cbb_refresh_verify.verify_runner import VerifyResult
|
||||
from cbb_refresh_verify.models import LibraryReadResult, CbbRecord
|
||||
import cbb_refresh_verify.ui.main_window as ui
|
||||
library = tmp_path/'library/mentor.lmc'; library.parent.mkdir(); library.touch()
|
||||
(library.parent/'ReusableBlocksLP/IP101GR').mkdir(parents=True)
|
||||
with LibraryLock(library, safe_to_release=lambda: False) as lock: pass
|
||||
with _guard:
|
||||
owner = _owners.pop(lock.key, None)
|
||||
if owner: owner['handle'].Close()
|
||||
marker = blocker_path(library)
|
||||
if marker_kind == 'malformed': marker.write_text('{}')
|
||||
if marker_kind == 'foreign':
|
||||
record = json.loads(marker.read_text()); record['library'] = str(tmp_path/'foreign/mentor.lmc')
|
||||
marker.write_text(json.dumps(record))
|
||||
monkeypatch.setattr(ui, 'preflight_skip_reason', lambda *a: None)
|
||||
calls = []
|
||||
window = MainWindow(reader=lambda *a: LibraryReadResult((CbbRecord('IP101GR', 'Reusable Blocks', status='PENDING'),)),
|
||||
verifier=lambda req: (calls.append(req) or VerifyResult('BLOCKED', safe_to_continue=False)),
|
||||
status_refresher=lambda *a: {'IP101GR': 'PENDING'}, data_root=tmp_path/'data')
|
||||
qtbot.addWidget(window)
|
||||
window.lmc_edit.setText(str(library)); window.load_library()
|
||||
qtbot.waitUntil(lambda: not window.busy)
|
||||
assert window.release_library_button.isEnabled()
|
||||
assert window.visible_records()[0].name == 'IP101GR'
|
||||
assert window.visible_records()[0].status == 'PENDING'
|
||||
assert not window._maintenance_recovery_view
|
||||
window.select_visible_button.click()
|
||||
assert window.icdb_repair_button.isEnabled()
|
||||
assert window.batch_button.isEnabled() and window.selected_batch_button.isEnabled()
|
||||
monkeypatch.setattr(QMessageBox, 'question', lambda *a, **k: QMessageBox.Yes)
|
||||
window.verify_selected(); qtbot.waitUntil(lambda: not window.busy)
|
||||
assert len(calls) == 1 and calls[0].maintenance is False
|
||||
assert window.selected_batch_button.isEnabled()
|
||||
window.repair_icdb_all(); qtbot.waitUntil(lambda: not window._icdb_active())
|
||||
assert len(calls) == 2 and calls[1].maintenance is True
|
||||
assert marker.exists()
|
||||
|
||||
|
||||
def test_maintenance_summary_exposes_first_failure_reason(qtbot, tmp_path):
|
||||
|
||||
@@ -72,6 +72,20 @@ def test_busy_execution_channel_does_not_create_unreleased_management_owner(setu
|
||||
assert result.evidence_path.is_file()
|
||||
|
||||
|
||||
def test_management_rechecks_retained_verify_lease_without_checkpoint(setup, monkeypatch, isolated_mutex):
|
||||
import cbb_refresh_verify.library_lock as locks
|
||||
from cbb_refresh_verify.residual_sessions import inspect_residual_sessions
|
||||
request, adapter, _ = setup
|
||||
with locks.LibraryLock(request.library, checkpoint=False, safe_to_release=lambda: False):
|
||||
pass
|
||||
assert not locks.blocker_path(request.library).exists()
|
||||
monkeypatch.setattr('cbb_refresh_verify.owner_probe.query_owners', lambda *_: [])
|
||||
monkeypatch.setattr('cbb_refresh_verify.residual_sessions.query_process_snapshot', lambda: [])
|
||||
preview = inspect_residual_sessions(request.library)
|
||||
assert preview['sessions'] == [] and any(r.get('kind') == 'in_memory' for r in preview['previous_records'])
|
||||
result = execute(request, adapter)
|
||||
assert result.status == 'REMOVED' and result.release_proof['status'] == 'RELEASE_CONFIRMED'
|
||||
assert not locks.has_retained_library(request.library)
|
||||
|
||||
|
||||
def test_management_worker_prelaunch_failure_is_safe(tmp_path, monkeypatch):
|
||||
|
||||
@@ -111,3 +111,31 @@ def test_previous_unsafe_result_allows_retry_and_requires_matching_release_proof
|
||||
window.management_dialog.reject()
|
||||
|
||||
|
||||
def test_historical_record_does_not_prevent_catalog_load_and_offers_checked_release(qtbot, tmp_path, monkeypatch):
|
||||
import pytest
|
||||
import cbb_refresh_verify.library_lock as locks
|
||||
from cbb_refresh_verify.ui.main_window import MainWindow
|
||||
library = tmp_path/'library/lib.lmc'; library.parent.mkdir(); library.touch()
|
||||
locks.blocker_path(library).write_text('{}', encoding='utf-8')
|
||||
reads = []
|
||||
window = MainWindow(reader=lambda path: (reads.append(path) or LibraryReadResult(())), data_root=tmp_path/'data')
|
||||
qtbot.addWidget(window)
|
||||
window.lmc_edit.setText(str(library)); window.load_library()
|
||||
qtbot.waitUntil(lambda: not window.busy)
|
||||
assert window.loaded_path == str(library) and reads
|
||||
assert window.release_library_button.isEnabled()
|
||||
assert locks.blocker_path(library).read_text() == '{}'
|
||||
calls = []
|
||||
monkeypatch.setattr(locks, 'inspect_residual_sessions', lambda *a:
|
||||
{'library': str(library), 'sessions': []})
|
||||
monkeypatch.setattr(locks, 'release_residual_sessions', lambda *a, **kw:
|
||||
(calls.append(a) or {'status': 'RELEASE_CONFIRMED', 'sessions': [], 'proof':
|
||||
{'status': 'RELEASE_CONFIRMED', 'library': str(library), 'evidence_path': 'proof.json'}}))
|
||||
window.release_library_button.click()
|
||||
qtbot.waitUntil(lambda: not window.release_dialog.busy)
|
||||
assert not calls
|
||||
window.release_dialog.confirm_button.click()
|
||||
qtbot.waitUntil(lambda: not window.release_dialog.busy)
|
||||
window.release_dialog.close()
|
||||
qtbot.waitUntil(lambda: not window.busy)
|
||||
assert len(calls) == 1 and 'proof.json' in window.output.toPlainText()
|
||||
@@ -0,0 +1,156 @@
|
||||
from pathlib import Path
|
||||
from PySide6.QtCore import Qt
|
||||
|
||||
|
||||
def test_preview_lists_residuals_and_does_not_close_before_confirmation(qtbot, tmp_path, monkeypatch):
|
||||
from cbb_refresh_verify import library_lock
|
||||
from cbb_refresh_verify.ui.residual_release_dialog import ResidualReleaseDialog
|
||||
plan = {'library': str(tmp_path/'lib.lmc'), 'sessions': [
|
||||
{'project': 'A', 'name': 'iCDBProjectBackup.exe', 'pid': 10, 'detail': '可正常关闭'}]}
|
||||
monkeypatch.setattr(library_lock, 'inspect_residual_sessions', lambda *_: plan)
|
||||
calls = []
|
||||
monkeypatch.setattr(library_lock, 'release_residual_sessions', lambda *a, **k: calls.append(a))
|
||||
dialog = ResidualReleaseDialog(tmp_path/'lib.lmc', tmp_path/'evidence')
|
||||
qtbot.addWidget(dialog); dialog.show()
|
||||
qtbot.waitUntil(lambda: not dialog.busy)
|
||||
assert dialog.table.item(0, 0).text() == 'A'
|
||||
assert dialog.table.item(0, 2).text() == '10'
|
||||
assert not calls
|
||||
dialog.close()
|
||||
assert not calls
|
||||
|
||||
|
||||
def test_empty_process_list_explains_historical_records_without_claiming_activity(qtbot, tmp_path, monkeypatch):
|
||||
from cbb_refresh_verify import library_lock
|
||||
from cbb_refresh_verify.ui.residual_release_dialog import ResidualReleaseDialog
|
||||
monkeypatch.setattr(library_lock, 'inspect_residual_sessions', lambda *_: {
|
||||
'library': str(tmp_path/'lib.lmc'), 'sessions': [], 'previous_records': [
|
||||
{'path': 'old-record.json', 'time': '2026-11-04T09:43:50+00:00', 'pid': 57076}]})
|
||||
dialog = ResidualReleaseDialog(tmp_path/'lib.lmc', tmp_path/'evidence')
|
||||
qtbot.addWidget(dialog)
|
||||
qtbot.waitUntil(lambda: not dialog.busy)
|
||||
assert '未发现活跃会话' in dialog.message.text()
|
||||
assert '历史操作记录' in dialog.message.text() and '2026-11-04' in dialog.message.text()
|
||||
assert dialog.confirm_button.isEnabled() and not dialog.force_button.isEnabled()
|
||||
dialog.close()
|
||||
|
||||
|
||||
def test_confirm_releases_full_plan_and_only_emits_actual_library_proof(qtbot, tmp_path, monkeypatch):
|
||||
from cbb_refresh_verify import library_lock
|
||||
from cbb_refresh_verify.ui.residual_release_dialog import ResidualReleaseDialog
|
||||
plan = {'library': str(tmp_path/'lib.lmc'), 'sessions': [
|
||||
{'project': name, 'name': 'iCDBProjectBackup.exe', 'pid': pid, 'detail': '可正常关闭'}
|
||||
for name, pid in [('A', 10), ('B', 20)]]}
|
||||
monkeypatch.setattr(library_lock, 'inspect_residual_sessions', lambda *_: plan)
|
||||
proof = {'status': 'RELEASE_CONFIRMED', 'library': plan['library'], 'evidence_path': 'proof.json'}
|
||||
calls = []
|
||||
def release(actual, *a, **kw):
|
||||
calls.append(actual)
|
||||
return {'status': 'RELEASE_CONFIRMED', 'proof': proof, 'sessions': [
|
||||
{**row, 'release_status': 'RELEASED', 'detail': '已正常退出'} for row in actual['sessions']]}
|
||||
monkeypatch.setattr(library_lock, 'release_residual_sessions', release)
|
||||
dialog = ResidualReleaseDialog(tmp_path/'lib.lmc', tmp_path/'evidence')
|
||||
qtbot.addWidget(dialog); dialog.show()
|
||||
released = []
|
||||
dialog.released.connect(released.append)
|
||||
qtbot.waitUntil(lambda: not dialog.busy)
|
||||
qtbot.mouseClick(dialog.confirm_button, Qt.LeftButton)
|
||||
qtbot.waitUntil(lambda: not dialog.busy)
|
||||
assert calls == [plan] and released == [proof]
|
||||
assert '已释放 2' in dialog.message.text()
|
||||
assert not dialog.confirm_button.isEnabled()
|
||||
|
||||
|
||||
def test_main_window_opens_confirmation_list_and_returns_to_idle_when_closed(qtbot, tmp_path, monkeypatch):
|
||||
from test_ui_filters import load_window
|
||||
from cbb_refresh_verify import library_lock
|
||||
monkeypatch.setattr(library_lock, 'inspect_residual_sessions', lambda library, **kw:
|
||||
{'library': str(library), 'sessions': []})
|
||||
window = load_window(qtbot, tmp_path, monkeypatch)
|
||||
window.check_library_release()
|
||||
dialog = getattr(window, 'release_dialog', None)
|
||||
assert dialog is not None, 'Release entry must preview sessions before cleanup'
|
||||
qtbot.waitUntil(lambda: not dialog.busy)
|
||||
assert window.busy and dialog.confirm_button.isEnabled()
|
||||
dialog.close()
|
||||
qtbot.waitUntil(lambda: not window.busy)
|
||||
|
||||
|
||||
def test_force_close_is_explicit_and_cancel_does_not_release(qtbot, tmp_path, monkeypatch):
|
||||
from PySide6.QtWidgets import QMessageBox
|
||||
from cbb_refresh_verify import library_lock
|
||||
from cbb_refresh_verify.ui.residual_release_dialog import ResidualReleaseDialog
|
||||
plan = {'library': str(tmp_path/'lib.lmc'), 'sessions': [
|
||||
{'project': 'A', 'name': 'ExpeditionPCB.exe', 'pid': 10, 'detail': '窗口无响应',
|
||||
'scope_confirmed': True, 'owner_sid': 'S-1-current', 'session_id': 1, 'force_user_confirmed': True, 'image': 'C:/Mentor/ExpeditionPCB.exe', 'created_handle': 'creation'}]}
|
||||
monkeypatch.setattr(library_lock, 'inspect_residual_sessions', lambda *_: plan)
|
||||
calls = []
|
||||
def release(actual, *a, **kw):
|
||||
calls.append(kw['force'])
|
||||
return {'status': 'PARTIAL', 'sessions': [{**plan['sessions'][0], 'release_status': 'WAITING'}]}
|
||||
monkeypatch.setattr(library_lock, 'release_residual_sessions', release)
|
||||
dialog = ResidualReleaseDialog(tmp_path/'lib.lmc', tmp_path/'evidence')
|
||||
qtbot.addWidget(dialog)
|
||||
qtbot.waitUntil(lambda: not dialog.busy)
|
||||
monkeypatch.setattr(QMessageBox, 'warning', lambda *a: QMessageBox.Cancel)
|
||||
dialog.force_button.click()
|
||||
assert not calls
|
||||
monkeypatch.setattr(QMessageBox, 'warning', lambda *a: QMessageBox.Yes)
|
||||
dialog.force_button.click()
|
||||
qtbot.waitUntil(lambda: not dialog.busy)
|
||||
assert calls == [True]
|
||||
|
||||
|
||||
def test_force_confirmation_excludes_shared_servers(qtbot, tmp_path, monkeypatch):
|
||||
from PySide6.QtWidgets import QMessageBox
|
||||
from cbb_refresh_verify import library_lock
|
||||
from cbb_refresh_verify.ui.residual_release_dialog import ResidualReleaseDialog
|
||||
rows = [{'project': 'A', 'name': name, 'pid': pid, 'scope_confirmed': True, 'owner_sid': 'S-1-current', 'session_id': 1, 'force_user_confirmed': True,
|
||||
'image': 'C:/Mentor/'+name, 'created_handle': str(pid), 'detail': 'waiting'}
|
||||
for name, pid in [('icdbserver.exe', 10), ('ExpeditionPCB.exe', 20)]]
|
||||
monkeypatch.setattr(library_lock, 'inspect_residual_sessions', lambda *_: {
|
||||
'library': str(tmp_path/'lib.lmc'), 'sessions': rows})
|
||||
dialog = ResidualReleaseDialog(tmp_path/'lib.lmc', tmp_path/'evidence')
|
||||
qtbot.addWidget(dialog)
|
||||
qtbot.waitUntil(lambda: not dialog.busy)
|
||||
messages = []
|
||||
monkeypatch.setattr(QMessageBox, 'warning', lambda parent, title, text, *args:
|
||||
messages.append(text) or QMessageBox.Cancel)
|
||||
dialog.force_button.click()
|
||||
assert len(messages) == 1
|
||||
assert 'ExpeditionPCB.exe' in messages[0]
|
||||
assert 'icdbserver.exe' not in messages[0]
|
||||
assert '服务器' in messages[0]
|
||||
dialog.plan['sessions'] = [rows[0]]
|
||||
dialog._finished()
|
||||
assert not dialog.force_button.isEnabled()
|
||||
|
||||
|
||||
def test_released_batch_can_resume_only_its_unexecuted_items(qtbot, tmp_path, monkeypatch):
|
||||
from test_ui_filters import load_window
|
||||
from cbb_refresh_verify.verify_runner import VerifyResult
|
||||
window = load_window(qtbot, tmp_path, monkeypatch,
|
||||
verifier=lambda _: VerifyResult('FAIL', stderr='release unconfirmed', safe_to_continue=False))
|
||||
window._run(['Beta', 'Gamma'])
|
||||
qtbot.waitUntil(lambda: not window.busy)
|
||||
action = getattr(window, '_resume_batch_action', None)
|
||||
assert action is not None and not action.isEnabled()
|
||||
library = Path(window.mentor_lmc_path or window.loaded_path)
|
||||
from cbb_refresh_verify import library_lock
|
||||
monkeypatch.setattr(library_lock, 'inspect_residual_sessions', lambda *_:
|
||||
{'library': str(library), 'sessions': []})
|
||||
monkeypatch.setattr(library_lock, 'release_residual_sessions', lambda *a, **kw:
|
||||
{'status': 'RELEASE_CONFIRMED', 'sessions': [], 'proof': {'status': 'RELEASE_CONFIRMED',
|
||||
'library': str(library), 'evidence_path': str(tmp_path/'proof.json')}})
|
||||
window._residual_release_action.click()
|
||||
qtbot.waitUntil(lambda: not window.release_dialog.busy)
|
||||
window.release_dialog.confirm_button.click()
|
||||
qtbot.waitUntil(lambda: not window.release_dialog.busy)
|
||||
window.release_dialog.close()
|
||||
qtbot.waitUntil(lambda: not window.busy)
|
||||
assert window.summary.isVisible()
|
||||
assert action.isEnabled()
|
||||
calls = []
|
||||
monkeypatch.setattr(window, '_run', lambda names, **kw: calls.append((names, kw)))
|
||||
action.click()
|
||||
assert calls == [(['Gamma'], {'maintenance': False})]
|
||||
@@ -0,0 +1,363 @@
|
||||
from pathlib import Path
|
||||
from types import SimpleNamespace
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
OWNERSHIP = {"owner_sid": "S-1-current", "session_id": 1, "force_user_confirmed": True}
|
||||
|
||||
|
||||
def api():
|
||||
from cbb_refresh_verify import library_lock
|
||||
inspect = getattr(library_lock, 'inspect_residual_sessions', None)
|
||||
release = getattr(library_lock, 'release_residual_sessions', None)
|
||||
assert callable(inspect) and callable(release), 'Missing confirmed residual-session release workflow'
|
||||
return inspect, release
|
||||
|
||||
|
||||
def row(pid, project, *, name='iCDBProjectBackup.exe'):
|
||||
return {'pid': pid, 'name': name, 'parent': 1, 'created': f'created-{pid}',
|
||||
'executable': 'C:/Mentor/'+name, 'command': f'{name} -p "{project}"'}
|
||||
|
||||
|
||||
def test_preview_limits_to_selected_projects_and_keeps_process_identity(tmp_path, monkeypatch):
|
||||
inspect, _ = api()
|
||||
from cbb_refresh_verify import residual_sessions as sessions
|
||||
library = tmp_path/'lib.lmc'; library.touch()
|
||||
a = library.parent/'ReusableBlocksLP/A/Work/A.prj'
|
||||
b = library.parent/'ReusableBlocksLP/B/Work/B.prj'
|
||||
monkeypatch.setattr(sessions, 'query_process_snapshot', lambda: [row(10, a), row(20, b)])
|
||||
monkeypatch.setattr(sessions, '_process_identity', lambda r: {**OWNERSHIP, 'created_handle': r['created'], 'image': r['executable']})
|
||||
monkeypatch.setattr(sessions, '_process_windows', lambda pids: {p: [] for p in pids})
|
||||
result = inspect(library, block_names=('A',))
|
||||
assert [r['pid'] for r in result['sessions']] == [10]
|
||||
assert result['sessions'][0]['created'] == 'created-10'
|
||||
|
||||
|
||||
def test_unknown_scope_is_visible_but_never_closed_even_with_force(tmp_path, monkeypatch):
|
||||
from cbb_refresh_verify import residual_sessions as sessions
|
||||
library = tmp_path/'lib.lmc'; library.touch()
|
||||
process = row(10, ''); process['command'] = 'LibraryManager.exe'
|
||||
process['name'] = 'LibraryManager.exe'
|
||||
monkeypatch.setattr(sessions, 'query_process_snapshot', lambda: [process])
|
||||
monkeypatch.setattr(sessions, '_process_windows', lambda _: {})
|
||||
monkeypatch.setattr(sessions, '_process_identity', lambda r: {**OWNERSHIP, 'created_handle': 'old', 'image': r['executable']})
|
||||
plan = sessions.inspect_residual_sessions(library)
|
||||
assert plan['sessions'] and plan['sessions'][0]['scope_confirmed'] is False
|
||||
monkeypatch.setattr(sessions, '_request_close', lambda *a, **kw: pytest.fail('closed unknown scope'))
|
||||
monkeypatch.setattr(sessions, '_force_close', lambda *a, **kw: pytest.fail('ended unknown scope'))
|
||||
for force in (False, True):
|
||||
result = sessions.release_residual_sessions(plan, tmp_path.parent/'release-evidence'/tmp_path.name, force=force)
|
||||
assert result['status'] == 'PARTIAL'
|
||||
# A request file becoming readable must not expand the user's consent list.
|
||||
monkeypatch.setattr('cbb_refresh_verify.library_lock._owner_matches_scope', lambda *a: True)
|
||||
result = sessions.release_residual_sessions(plan, tmp_path.parent/'release-evidence'/tmp_path.name, force=True)
|
||||
assert result['status'] == 'PARTIAL'
|
||||
|
||||
|
||||
@pytest.mark.parametrize('name,title,children,expected', [
|
||||
('iCDBProjectBackup.exe', 'iCDB Project Backup - test', [], True),
|
||||
('ExpeditionPCB.exe', 'Expedition PCB - Reusable Block', [], True),
|
||||
('ExpeditionPCB.exe', 'Design.pcb - Expedition PCB', [], True),
|
||||
('iCDBProjectBackup.exe', 'iCDB Project Backup - test', [{'class': 'msctls_progress32', 'text': ''}], False),
|
||||
])
|
||||
def test_only_idle_supported_native_windows_are_offered_for_close(name, title, children, expected):
|
||||
api()
|
||||
from cbb_refresh_verify.residual_sessions import close_target
|
||||
windows = [{'hwnd': 100, 'class': 'Afx:main', 'title': title, 'enabled': True,
|
||||
'children': children, 'documents': [], 'output': 'Backup information loaded correctly.'}]
|
||||
target, reason = close_target(name, windows)
|
||||
assert bool(target) is expected
|
||||
if not expected: assert reason
|
||||
|
||||
|
||||
def test_confirmation_rechecks_pid_reuse_and_never_posts_to_replacement(tmp_path, monkeypatch):
|
||||
inspect, release = api()
|
||||
from cbb_refresh_verify import residual_sessions as sessions
|
||||
library = tmp_path/'lib.lmc'; library.touch()
|
||||
process = row(10, tmp_path/'ReusableBlocksLP/A/Work/A.prj')
|
||||
monkeypatch.setattr(sessions, 'query_process_snapshot', lambda: [process.copy()])
|
||||
monkeypatch.setattr(sessions, '_process_identity', lambda r: {**OWNERSHIP, 'created_handle': 'old', 'image': r['executable']})
|
||||
monkeypatch.setattr(sessions, '_process_windows', lambda _: {10: []})
|
||||
plan = inspect(library)
|
||||
process['created'] = 'replacement'
|
||||
monkeypatch.setattr(sessions, '_request_close', lambda *_: pytest.fail('closed replacement PID'))
|
||||
monkeypatch.setattr(sessions, '_finish_library_release', lambda *_: {'status': 'RELEASE_CONFIRMED'})
|
||||
result = release(plan, tmp_path.parent/'release-evidence'/tmp_path.name)
|
||||
assert result['sessions'][0]['release_status'] == 'IDENTITY_CHANGED'
|
||||
assert result['status'] == 'PARTIAL'
|
||||
|
||||
|
||||
def test_close_requests_cover_whole_preview_and_failures_remain_per_item(tmp_path, monkeypatch):
|
||||
inspect, release = api()
|
||||
from cbb_refresh_verify import residual_sessions as sessions
|
||||
library = tmp_path/'lib.lmc'; library.touch()
|
||||
rows = [row(p, tmp_path/f'ReusableBlocksLP/{p}/Work/{p}.prj') for p in (10, 20)]
|
||||
monkeypatch.setattr(sessions, 'query_process_snapshot', lambda: rows)
|
||||
monkeypatch.setattr(sessions, '_process_identity', lambda r: {**OWNERSHIP, 'created_handle': r['created'], 'image': r['executable']})
|
||||
monkeypatch.setattr(sessions, '_process_windows', lambda _: {})
|
||||
calls = []
|
||||
monkeypatch.setattr(sessions, '_request_close', lambda r, *_, **kw: calls.append(r['pid']) or
|
||||
{'release_status': 'RELEASED' if r['pid'] == 10 else 'WAITING', 'detail': 'native window pending'})
|
||||
monkeypatch.setattr(sessions, '_finish_library_release', lambda *_: pytest.fail('partial release cleared library marker'))
|
||||
result = release(inspect(library), tmp_path.parent/'release-evidence'/tmp_path.name)
|
||||
assert calls == [10, 20]
|
||||
assert result['status'] == 'PARTIAL'
|
||||
assert [r['release_status'] for r in result['sessions']] == ['RELEASED', 'WAITING']
|
||||
|
||||
|
||||
def test_no_remaining_processes_rechecks_and_clears_old_metadata(tmp_path, monkeypatch):
|
||||
inspect, release = api()
|
||||
from cbb_refresh_verify import residual_sessions as sessions
|
||||
library = tmp_path/'lib.lmc'; library.touch()
|
||||
monkeypatch.setattr(sessions, 'query_process_snapshot', lambda: [])
|
||||
monkeypatch.setattr(sessions, '_process_windows', lambda _: {})
|
||||
proof = {'status': 'RELEASE_CONFIRMED', 'library': str(library), 'evidence_path': 'proof.json'}
|
||||
monkeypatch.setattr(sessions, '_finish_library_release', lambda *_: proof)
|
||||
result = release(inspect(library), tmp_path.parent/'release-evidence'/tmp_path.name)
|
||||
assert result['status'] == 'RELEASE_CONFIRMED' and result['proof'] == proof
|
||||
|
||||
|
||||
def test_empty_session_scan_still_exposes_historical_operation_record(tmp_path, monkeypatch):
|
||||
import json
|
||||
from cbb_refresh_verify import residual_sessions as sessions
|
||||
from cbb_refresh_verify.library_lock import blocker_path
|
||||
library = tmp_path/'lib.lmc'; library.touch()
|
||||
marker = blocker_path(library)
|
||||
marker.write_text(json.dumps({'protocol': 'cbb-refresh-verify-library-lease', 'version': 1,
|
||||
'library': str(library), 'lease_id': 'a'*32, 'pid': 57076,
|
||||
'status': 'OWNER_RELEASE_UNCONFIRMED', 'time': '2026-11-04T09:43:50+00:00'}))
|
||||
monkeypatch.setattr(sessions, 'query_process_snapshot', lambda: [])
|
||||
result = sessions.inspect_residual_sessions(library)
|
||||
assert result['sessions'] == []
|
||||
assert result['previous_records'][0]['path'] == str(marker)
|
||||
assert result['previous_records'][0]['time'].startswith('2026-11-04')
|
||||
assert marker.exists()
|
||||
|
||||
|
||||
@pytest.mark.parametrize('output', [None, 'Repairing project\nRepair backup created successfully.',
|
||||
'Repairing project\nBackup information loaded correctly.\nRestoring project'])
|
||||
def test_backup_intermediate_success_does_not_allow_cooperative_close(output):
|
||||
from cbb_refresh_verify.residual_sessions import close_target
|
||||
window = {'hwnd': 10, 'class': 'Afx:main', 'title': 'iCDB Project Backup - test',
|
||||
'children': [], 'enabled': True, 'output': output}
|
||||
assert close_target('iCDBProjectBackup.exe', [window])[0] is None
|
||||
|
||||
|
||||
def test_force_requires_separate_explicit_argument_and_rechecks_identity(tmp_path, monkeypatch):
|
||||
from cbb_refresh_verify import residual_sessions as sessions
|
||||
library = tmp_path/'lib.lmc'; library.touch()
|
||||
process = row(10, tmp_path/'ReusableBlocksLP/A/Work/A.prj')
|
||||
monkeypatch.setattr(sessions, 'query_process_snapshot', lambda: [process.copy()])
|
||||
monkeypatch.setattr(sessions, '_process_identity', lambda r: {**OWNERSHIP, 'created_handle': 'old', 'image': r['executable']})
|
||||
monkeypatch.setattr(sessions, '_process_windows', lambda _: {})
|
||||
monkeypatch.setattr(sessions, '_request_close', lambda *a, **k: {'release_status': 'WAITING', 'detail': 'hung'})
|
||||
forced = []
|
||||
monkeypatch.setattr(sessions, '_force_close', lambda r, **kw: forced.append(r['pid']) or
|
||||
{'release_status': 'WAITING', 'detail': 'exiting'})
|
||||
plan = sessions.inspect_residual_sessions(library)
|
||||
evidence = tmp_path.parent/'release-evidence'/tmp_path.name
|
||||
sessions.release_residual_sessions(plan, evidence)
|
||||
assert not forced
|
||||
sessions.release_residual_sessions(plan, evidence, force=True)
|
||||
assert forced == [10]
|
||||
process['created'] = 'reused'
|
||||
sessions.release_residual_sessions(plan, evidence, force=True)
|
||||
assert forced == [10]
|
||||
|
||||
|
||||
@pytest.mark.parametrize('name', ['icdbnetserver.exe', 'icdbserver.exe',
|
||||
'ReuseBlockImporter.exe', 'wscript.exe'])
|
||||
def test_force_preserves_servers_and_unsupported_processes_even_with_confirmed_scope(tmp_path, monkeypatch, name):
|
||||
from cbb_refresh_verify import residual_sessions as sessions
|
||||
library = tmp_path/'lib.lmc'; library.touch()
|
||||
process = row(10, tmp_path/'ReusableBlocksLP/A/Work/A.prj', name=name)
|
||||
monkeypatch.setattr(sessions, 'query_process_snapshot', lambda: [process.copy()])
|
||||
monkeypatch.setattr(sessions, '_process_identity', lambda r: {**OWNERSHIP, 'created_handle': 'old', 'image': r['executable']})
|
||||
monkeypatch.setattr(sessions, '_process_windows', lambda _: {})
|
||||
monkeypatch.setattr(sessions, '_force_close', lambda *a, **kw: pytest.fail('protected process was force terminated'))
|
||||
plan = sessions.inspect_residual_sessions(library)
|
||||
assert plan['sessions'][0]['scope_confirmed']
|
||||
result = sessions.release_residual_sessions(plan, tmp_path.parent/'release-evidence'/tmp_path.name, force=True)
|
||||
assert result['status'] == 'PARTIAL'
|
||||
assert result['sessions'][0]['release_status'] == 'WAITING'
|
||||
assert result['sessions'][0]['force_allowed'] is False
|
||||
|
||||
|
||||
@pytest.mark.parametrize('name', ['icdbserver.exe', 'cdbsvr.exe', 'python.exe'])
|
||||
def test_direct_force_cannot_request_a_terminate_handle_for_database_server(monkeypatch, name):
|
||||
from cbb_refresh_verify import residual_sessions as sessions
|
||||
process = {'pid': 10, 'name': name, 'scope_confirmed': True,
|
||||
'image': 'C:/Mentor/'+name, 'created_handle': 'creation'}
|
||||
monkeypatch.setattr(sessions, '_process_handle', lambda *a, **kw: pytest.fail('opened terminate-capable server handle'))
|
||||
assert sessions._force_close(process)['release_status'] == 'WAITING'
|
||||
|
||||
|
||||
def test_force_writes_exact_consent_before_any_native_action(tmp_path, monkeypatch):
|
||||
import json
|
||||
from cbb_refresh_verify import residual_sessions as sessions
|
||||
library = tmp_path/'lib.lmc'; library.touch()
|
||||
process = row(10, tmp_path/'ReusableBlocksLP/A/Work/A.prj', name='ExpeditionPCB.exe')
|
||||
monkeypatch.setattr(sessions, 'query_process_snapshot', lambda: [process.copy()])
|
||||
monkeypatch.setattr(sessions, '_process_identity', lambda r: {**OWNERSHIP, 'created_handle': 'old', 'image': r['executable']})
|
||||
monkeypatch.setattr(sessions, '_process_windows', lambda _: {})
|
||||
evidence = tmp_path.parent/'release-evidence'/tmp_path.name
|
||||
def force(actual, **kwargs):
|
||||
consent = json.loads(next(evidence.glob('sessions-*/consent.json')).read_text(encoding='utf-8'))
|
||||
assert consent['library'] == str(library.resolve())
|
||||
assert consent['mode'] == 'force_document_clients'
|
||||
assert consent['sessions'][0]['pid'] == actual['pid']
|
||||
assert consent['sessions'][0]['created_handle'] == actual['created_handle']
|
||||
return {'release_status': 'WAITING', 'detail': 'not exited'}
|
||||
monkeypatch.setattr(sessions, '_force_close', force)
|
||||
plan = sessions.inspect_residual_sessions(library)
|
||||
result = sessions.release_residual_sessions(plan, evidence, force=True)
|
||||
assert Path(result['consent_path']).is_file()
|
||||
assert result['status'] == 'PARTIAL'
|
||||
|
||||
|
||||
def test_unwritable_force_consent_prevents_all_native_actions(tmp_path, monkeypatch):
|
||||
from cbb_refresh_verify import residual_sessions as sessions
|
||||
library = tmp_path/'lib.lmc'; library.touch()
|
||||
process = row(10, tmp_path/'ReusableBlocksLP/A/Work/A.prj', name='ExpeditionPCB.exe')
|
||||
monkeypatch.setattr(sessions, 'query_process_snapshot', lambda: [process.copy()])
|
||||
monkeypatch.setattr(sessions, '_process_identity', lambda r: {**OWNERSHIP, 'created_handle': 'old', 'image': r['executable']})
|
||||
monkeypatch.setattr(sessions, '_process_windows', lambda _: {})
|
||||
plan = sessions.inspect_residual_sessions(library)
|
||||
original = Path.open
|
||||
def deny(path, *args, **kwargs):
|
||||
if path.name == 'consent.json': raise PermissionError('cannot record consent')
|
||||
return original(path, *args, **kwargs)
|
||||
monkeypatch.setattr(Path, 'open', deny)
|
||||
monkeypatch.setattr(sessions, '_force_close', lambda *a, **kw: pytest.fail('termination preceded durable consent'))
|
||||
with pytest.raises(PermissionError, match='cannot record consent'):
|
||||
sessions.release_residual_sessions(plan, tmp_path.parent/'release-evidence'/tmp_path.name, force=True)
|
||||
|
||||
|
||||
def test_current_process_handle_identity_uses_real_windows_api():
|
||||
import os
|
||||
from cbb_refresh_verify.residual_sessions import _process_identity
|
||||
identity = _process_identity({'pid': os.getpid()})
|
||||
assert identity['created_handle'] and Path(identity['image']).is_file()
|
||||
assert identity['owner_sid'].startswith('S-1-')
|
||||
assert isinstance(identity['session_id'], int)
|
||||
assert identity['force_user_confirmed'] is True
|
||||
|
||||
|
||||
@pytest.mark.parametrize('ownership', [{}, {'owner_sid': 'S-1-other', 'session_id': 1,
|
||||
'force_user_confirmed': False}])
|
||||
def test_force_never_opens_terminate_handle_without_current_user_and_session(monkeypatch, ownership):
|
||||
from cbb_refresh_verify import residual_sessions as sessions
|
||||
process = {'pid': 10, 'name': 'ExpeditionPCB.exe', 'scope_confirmed': True,
|
||||
'created_handle': 'creation', 'image': 'C:/Mentor/ExpeditionPCB.exe', **ownership}
|
||||
monkeypatch.setattr(sessions, '_process_handle', lambda *a, **kw: pytest.fail('opened unowned process'))
|
||||
assert sessions._force_close(process)['release_status'] == 'WAITING'
|
||||
|
||||
|
||||
@pytest.mark.parametrize('other_user,other_session', [(True, False), (False, True), (False, False)])
|
||||
def test_force_ownership_checks_user_sid_and_windows_session(monkeypatch, other_user, other_session):
|
||||
import os
|
||||
import win32api, win32process, win32security, win32ts
|
||||
from cbb_refresh_verify import residual_sessions as sessions
|
||||
closed = []
|
||||
monkeypatch.setattr(win32process, 'GetProcessId', lambda _: 10)
|
||||
monkeypatch.setattr(win32api, 'GetCurrentProcess', lambda: 999)
|
||||
monkeypatch.setattr(win32security, 'OpenProcessToken', lambda process, access:
|
||||
SimpleNamespace(process=process, Close=lambda: closed.append(process)))
|
||||
monkeypatch.setattr(win32security, 'GetTokenInformation', lambda token, kind:
|
||||
('other' if other_user and token.process == 123 else 'current', 0))
|
||||
monkeypatch.setattr(win32security, 'ConvertSidToStringSid', lambda sid: 'S-1-'+sid)
|
||||
monkeypatch.setattr(win32ts, 'ProcessIdToSessionId', lambda pid:
|
||||
2 if other_session and pid != os.getpid() else 1)
|
||||
assert sessions._force_ownership(123, 10)['force_user_confirmed'] is (not other_user and not other_session)
|
||||
assert closed == [123, 999]
|
||||
|
||||
|
||||
def test_unreadable_force_ownership_does_not_hide_cooperative_identity(monkeypatch):
|
||||
from contextlib import nullcontext
|
||||
from cbb_refresh_verify import residual_sessions as sessions
|
||||
monkeypatch.setattr(sessions, '_process_handle', lambda _: nullcontext(123))
|
||||
monkeypatch.setattr(sessions, '_handle_identity', lambda _: {'created_handle': 'creation', 'image': 'pcb.exe'})
|
||||
def denied(*args): raise PermissionError('token inaccessible')
|
||||
monkeypatch.setattr(sessions, '_force_ownership', denied)
|
||||
identity = sessions._process_identity({'pid': 10})
|
||||
assert identity['created_handle'] == 'creation' and identity['force_user_confirmed'] is False
|
||||
|
||||
|
||||
def test_force_refuses_actual_unsupported_test_helper():
|
||||
import subprocess
|
||||
import sys
|
||||
from cbb_refresh_verify.residual_sessions import _process_identity, _force_close
|
||||
child = subprocess.Popen([sys.executable, '-c', 'import time; time.sleep(30)'],
|
||||
creationflags=subprocess.CREATE_NO_WINDOW)
|
||||
try:
|
||||
process = {'pid': child.pid, **_process_identity({'pid': child.pid})}
|
||||
assert _force_close(process)['release_status'] == 'WAITING'
|
||||
assert child.poll() is None
|
||||
finally:
|
||||
if child.poll() is None:
|
||||
child.terminate(); child.wait(3) # This test's sleep-only helper.
|
||||
|
||||
|
||||
def test_supported_force_revalidates_exact_handle_before_termination(monkeypatch):
|
||||
from contextlib import nullcontext
|
||||
import win32api, win32con, win32event
|
||||
from cbb_refresh_verify import residual_sessions as sessions
|
||||
process = {'pid': 10, 'name': 'ExpeditionPCB.exe', 'scope_confirmed': True,
|
||||
'created_handle': 'creation', 'image': 'C:/Mentor/ExpeditionPCB.exe', **OWNERSHIP}
|
||||
monkeypatch.setattr(sessions, '_process_handle', lambda *a, **kw: nullcontext(123))
|
||||
monkeypatch.setattr(sessions, '_handle_identity', lambda _: {
|
||||
'created_handle': 'creation', 'image': 'C:/Mentor/ExpeditionPCB.exe'})
|
||||
monkeypatch.setattr(win32event, 'WaitForSingleObject', lambda handle, timeout:
|
||||
win32con.WAIT_OBJECT_0 if timeout else win32con.WAIT_TIMEOUT)
|
||||
monkeypatch.setattr(sessions, '_force_ownership', lambda *args: dict(OWNERSHIP))
|
||||
calls = []
|
||||
monkeypatch.setattr(win32api, 'TerminateProcess', lambda handle, code: calls.append((handle, code)))
|
||||
assert sessions._force_close({**process, 'created_handle': 'reused'})['release_status'] == 'IDENTITY_CHANGED'
|
||||
assert not calls
|
||||
assert sessions._force_close({**process, 'session_id': 2})['release_status'] == 'IDENTITY_CHANGED'
|
||||
assert sessions._force_close({**process, 'owner_sid': 'S-1-other'})['release_status'] == 'IDENTITY_CHANGED'
|
||||
assert not calls
|
||||
assert sessions._force_close(process)['release_status'] == 'RELEASED'
|
||||
assert calls == [(123, 1)]
|
||||
|
||||
|
||||
def test_partial_desktop_enumeration_never_offers_normal_close(monkeypatch):
|
||||
import win32gui, win32service
|
||||
from cbb_refresh_verify.residual_sessions import _process_windows, close_target
|
||||
def failed(*_): raise OSError('desktop disappeared')
|
||||
monkeypatch.setattr(win32gui, 'EnumWindows', failed)
|
||||
monkeypatch.setattr(win32service, 'GetProcessWindowStation', lambda: SimpleNamespace(EnumDesktops=lambda: []))
|
||||
windows = _process_windows({10})[10]
|
||||
assert any(w['class'] == 'UNCONFIRMED' for w in windows)
|
||||
windows.append({'hwnd': 100, 'class': 'Afx:main', 'title': 'Design - Expedition PCB',
|
||||
'children': [], 'enabled': True})
|
||||
assert close_target('ExpeditionPCB.exe', windows)[0] is None
|
||||
|
||||
|
||||
@pytest.mark.parametrize('choice', [6, 7, 2])
|
||||
def test_save_answers_require_current_exact_prompt_and_process(monkeypatch, choice):
|
||||
import win32con, win32gui, win32process
|
||||
from contextlib import nullcontext
|
||||
from cbb_refresh_verify import residual_sessions as sessions
|
||||
process = row(10, 'C:/Lib/ReusableBlocksLP/A/Work/A.prj')
|
||||
process.update(created_handle='creation', image='pcb.exe')
|
||||
dialog = {'hwnd': 100, 'class': '#32770', 'title': 'Expedition PCB', 'children': [
|
||||
{'class': 'Static', 'text': 'Save changes to the modified design?'},
|
||||
*[{'class': 'Button', 'text': text, 'enabled': True, 'id': code, 'hwnd': code}
|
||||
for code, text in ((6, 'Yes'), (7, 'No'), (2, 'Cancel'))]]}
|
||||
windows = [dialog]
|
||||
process['prompt'] = sessions._save_question(windows)
|
||||
monkeypatch.setattr(sessions, 'query_process_snapshot', lambda: [process])
|
||||
monkeypatch.setattr(sessions, '_process_handle', lambda _: nullcontext(123))
|
||||
monkeypatch.setattr(sessions, '_handle_identity', lambda _: {'created_handle': 'creation', 'image': 'pcb.exe'})
|
||||
monkeypatch.setattr(sessions, '_process_windows', lambda _: {10: windows})
|
||||
monkeypatch.setattr(win32process, 'GetWindowThreadProcessId', lambda _: (1, 10))
|
||||
clicked = []
|
||||
monkeypatch.setattr(win32gui, 'PostMessage', lambda *a: clicked.append(a))
|
||||
sessions._answer_save_question(process, choice)
|
||||
assert clicked == [(choice, win32con.BM_CLICK, 0, 0)]
|
||||
dialog['children'][0]['text'] = 'Save changes to another modified design?'
|
||||
with pytest.raises(ValueError, match='提示已变化'):
|
||||
sessions._answer_save_question(process, choice)
|
||||
assert len(clicked) == 1
|
||||
@@ -204,6 +204,34 @@ def test_batch_report_failure_preserves_ui_outcomes(qtbot, tmp_path, monkeypatch
|
||||
assert window.batch_button.isEnabled()
|
||||
|
||||
|
||||
def test_release_check_clears_only_its_own_management_library(qtbot, tmp_path, monkeypatch):
|
||||
from test_ui_filters import load_window
|
||||
from cbb_refresh_verify.management import Capability
|
||||
adapter = SimpleNamespace(capabilities=lambda: {op: Capability(True, 'available')
|
||||
for op in ('add', 'update', 'remove')})
|
||||
window = load_window(qtbot, tmp_path, monkeypatch, management_adapter=adapter)
|
||||
window.path_lease_factory = lambda path: SimpleNamespace(mentor_path=path, close=lambda: None,
|
||||
retain_for_recovery=lambda: None)
|
||||
library_a, library_b = tmp_path/'a.lmc', tmp_path/'b.lmc'
|
||||
for library in (library_a, library_b):
|
||||
window._management_unsafe = True
|
||||
window._management_unsafe_library = library
|
||||
window._update()
|
||||
monkeypatch.setattr('cbb_refresh_verify.library_lock.release_retained_library',
|
||||
lambda *_: {'status': 'RELEASE_CONFIRMED', 'library': str(library_a),
|
||||
'evidence_path': str(tmp_path/'release.json')})
|
||||
window.lmc_edit.setText(str(library_a))
|
||||
window.load_library()
|
||||
qtbot.waitUntil(lambda: not window.busy)
|
||||
window._complete_library_release(library_a, {'status': 'RELEASE_CONFIRMED',
|
||||
'library': str(library_a), 'evidence_path': str(tmp_path/'release.json')})
|
||||
qtbot.waitUntil(lambda: not window.busy)
|
||||
assert not window._management_block_reason('add')
|
||||
window.lmc_edit.setText(str(library_b))
|
||||
window.load_library()
|
||||
qtbot.waitUntil(lambda: not window.busy)
|
||||
assert window._management_library_unsafe(library_b)
|
||||
assert not window._management_block_reason('add')
|
||||
|
||||
|
||||
@pytest.mark.parametrize('alias', ['absolute', 'mapped'])
|
||||
@@ -231,6 +259,39 @@ def test_native_backup_session_matches_library_alias_without_network_resolution(
|
||||
window._native_backup_session = None
|
||||
|
||||
|
||||
@pytest.mark.parametrize('proof_kind', ['valid', 'foreign', 'invalid', 'lease_error'])
|
||||
def test_release_check_restores_current_mapping_only_after_matching_proof(qtbot, tmp_path, monkeypatch, proof_kind):
|
||||
from test_ui_filters import load_window
|
||||
from cbb_refresh_verify import network_path
|
||||
window = load_window(qtbot, tmp_path, monkeypatch)
|
||||
library = Path('test.lmc').absolute()
|
||||
current = network_path.LibraryPathLease(library, library)
|
||||
current.retain_for_recovery()
|
||||
window.library_lease = current
|
||||
window.mentor_lmc_path = library
|
||||
window._management_unsafe = True
|
||||
window._management_unsafe_library = library
|
||||
session = SimpleNamespace(library=library, path_lease=current, process=SimpleNamespace(poll=lambda: 0))
|
||||
window._native_backup_session = session
|
||||
proof = {'status': 'UNCONFIRMED' if proof_kind == 'invalid' else 'RELEASE_CONFIRMED',
|
||||
'library': str(tmp_path/'foreign.lmc') if proof_kind == 'foreign' else str(library),
|
||||
'evidence_path': str(tmp_path/'release.json')}
|
||||
monkeypatch.setattr('cbb_refresh_verify.library_lock.release_retained_library', lambda *_: proof)
|
||||
if proof_kind == 'lease_error':
|
||||
def failed_release(*_a, **_k):
|
||||
raise network_path.NetworkPathError('mapping release failed')
|
||||
monkeypatch.setattr(network_path, 'release_retained_path_leases', failed_release)
|
||||
try:
|
||||
window._complete_library_release(library, proof)
|
||||
qtbot.waitUntil(lambda: window._mapping_busy == 0)
|
||||
qtbot.waitUntil(lambda: window._lease_pending == 0)
|
||||
assert current._retained_for_recovery is (proof_kind != 'valid')
|
||||
assert not current._closed
|
||||
assert window._management_unsafe is (proof_kind != 'valid')
|
||||
assert (window._native_backup_session is session) is (proof_kind != 'valid')
|
||||
finally:
|
||||
window._native_backup_session = None
|
||||
network_path._retained_path_leases.pop(id(current), None)
|
||||
|
||||
|
||||
def test_opening_evidence_failure_does_not_retain_library(qtbot, tmp_path, monkeypatch):
|
||||
|
||||
@@ -78,6 +78,28 @@ def test_management_dialog_finish_waits_for_mapping_cleanup_without_freezing_fil
|
||||
qtbot.waitUntil(lambda: window.pool.activeThreadCount() == 0)
|
||||
|
||||
|
||||
def test_release_dialog_finish_cannot_clear_busy_before_mapping_cleanup(qtbot, tmp_path, monkeypatch):
|
||||
window = load_window(qtbot, tmp_path, monkeypatch)
|
||||
library = Path(window.mentor_lmc_path)
|
||||
entered, release = Event(), Event()
|
||||
main_thread = get_ident()
|
||||
def restore(*args, **kwargs):
|
||||
assert get_ident() != main_thread, 'mapping release blocked the Qt thread'
|
||||
entered.set()
|
||||
assert release.wait(3)
|
||||
monkeypatch.setattr('cbb_refresh_verify.network_path.release_retained_path_leases', restore)
|
||||
window.busy = True
|
||||
try:
|
||||
window._complete_library_release(library, {'status': 'RELEASE_CONFIRMED',
|
||||
'library': str(library), 'evidence_path': 'proof.json'})
|
||||
window._release_dialog_finished(0)
|
||||
qtbot.waitUntil(entered.is_set)
|
||||
assert window.busy and window.search_edit.isEnabled()
|
||||
release.set()
|
||||
qtbot.waitUntil(lambda: not window.busy)
|
||||
finally:
|
||||
release.set()
|
||||
qtbot.waitUntil(lambda: window.pool.activeThreadCount() == 0)
|
||||
|
||||
|
||||
def test_window_close_waits_asynchronously_for_retain_and_all_pool_work(qtbot, tmp_path, monkeypatch):
|
||||
@@ -131,3 +153,14 @@ def test_duplicate_dialog_finish_schedules_only_one_catalog_reload(qtbot, tmp_pa
|
||||
qtbot.waitUntil(lambda: window.pool.activeThreadCount() == 0)
|
||||
|
||||
|
||||
def test_window_close_tolerates_fake_and_deleted_dialog_pools(qtbot, tmp_path, monkeypatch):
|
||||
from PySide6.QtCore import QThreadPool
|
||||
from shiboken6 import delete
|
||||
window = load_window(qtbot, tmp_path, monkeypatch)
|
||||
deleted_pool = QThreadPool()
|
||||
delete(deleted_pool)
|
||||
window.release_dialog = SimpleNamespace()
|
||||
window.management_dialog = SimpleNamespace(pool=deleted_pool)
|
||||
window.show()
|
||||
window.close()
|
||||
qtbot.waitUntil(lambda: not window.isVisible())
|
||||
Reference in new issue
Block a user