fix: acknowledge each legacy tip once per cleanup intent

This commit is contained in:
阿白叔 committed 2026-11-17 11:33:49 +08:00
1 parent 701e5cd3b4
commit 8818fa9841
3 files changed
+48 -16

No files matched your search

+23 -10
View File
@@ -218,34 +218,47 @@ def test_independent_backup_job_registration_retains_descendants_after_caller_ha
def test_common_admission_refusal_publishes_bound_receipt_and_ui_can_reopen(qtbot, tmp_path, monkeypatch):
import win32api
import subprocess,sys
from threading import Event, Thread
from test_native_backup import project_fixture
from test_ui_filters import load_window
from cbb_refresh_verify import native_backup as native, desktop_worker
from cbb_refresh_verify.application import main
request, _ = project_fixture(tmp_path)
monkeypatch.setattr(native, 'native_backup_executable', lambda *_: tmp_path/'native.exe')
monkeypatch.setattr(native.subprocess, 'Popen', lambda *a, **k:
SimpleNamespace(pid=os.getpid(), handle=win32api.GetCurrentProcess(), poll=lambda: None))
session = native.launch_native_backup(request)
# A cold observer reads kernel identity: poll=exited on pytest's live PID
# cannot represent a released worker. Use a real, harmless refused child.
invoke = tmp_path/'invoke-refusal.signal'
child = tmp_path/'refused_worker.py'
child.write_text('import sys,time\nfrom pathlib import Path\n'
f'gate=Path({str(invoke)!r})\ndeadline=time.monotonic()+10\n'
'while not gate.exists() and time.monotonic()<deadline:time.sleep(.01)\n'
'assert gate.exists()\n'
'from cbb_refresh_verify import native_backup\n'
'def forbidden(*args):raise AssertionError("refused action entered")\n'
'native_backup.native_backup_worker_main=forbidden\n'
'from cbb_refresh_verify.application import main\n'
'raise SystemExit(main(["--native-backup-worker",sys.argv[1]]))\n')
popen = subprocess.Popen
with monkeypatch.context() as launch:
launch.setattr(native.subprocess, 'Popen', lambda command, **kwargs:
popen([sys.executable,str(child),command[-1]], **kwargs))
session = native.launch_native_backup(request)
entered, release = Event(), Event()
monkeypatch.setattr(desktop_worker, '_automation_clients', [])
def held_writer():
with desktop_worker.worker_native_channel():
entered.set(); release.wait(5)
entered.set(); release.wait(10)
holder = Thread(target=held_writer); holder.start()
assert entered.wait(2)
monkeypatch.setattr(native, 'native_backup_worker_main', lambda *a: pytest.fail('refused action entered'))
try:
assert main(['--native-backup-worker', str(session.job)]) == 1
invoke.touch()
assert session.process.wait(timeout=8) == 1
finally:
release.set(); holder.join(3)
record = json.loads(session.job.with_name('result.json').read_text('utf-8'))
assert record['safe_to_continue'] is True and record['native_started'] is False
assert record['operation_id'] == json.loads(session.job.read_text('utf-8'))['operation_id']
assert record['worker_identity']['pid'] == os.getpid()
session.process.poll = lambda: 1
assert record['worker_identity']['pid'] == session.process.pid != os.getpid()
launched = []
window = load_window(qtbot, tmp_path, monkeypatch,
native_backup_launcher=lambda req: (launched.append(req) or session),