fix: require a durable boundary before native add submission

This commit is contained in:
阿白叔 committed 2026-11-06 16:41:36 +08:00
1 parent d9a79b6535
commit 051498ba57
4 files changed
+54 -7

No files matched your search

+9 -3
View File
@@ -53,7 +53,8 @@ def test_add_timeout_publishes_cancellation_without_killing_native_owner(tmp_pat
@pytest.mark.parametrize('cancel', [True, False])
def test_cancellation_and_phase_at_native_add_submit(tmp_path, monkeypatch, cancel):
@pytest.mark.parametrize('journal_error', [False, True])
def test_cancellation_and_phase_at_native_add_submit(tmp_path, monkeypatch, cancel, journal_error):
import os,sys
from types import SimpleNamespace
import win32gui,win32process
@@ -95,9 +96,14 @@ def test_cancellation_and_phase_at_native_add_submit(tmp_path, monkeypatch, canc
'operation_id':'test-add-phase','session_record_path':str(root/'session.json')}
from cbb_refresh_verify.session_record import write_session_record
write_session_record(root/'worker-state.json', {'operation_id': 'test-add-phase', 'phase':'POSTCALL', 'processes':[]})
with pytest.raises(RuntimeError,match='NATIVE_ADD_CANCELLED' if cancel else 'unsafe OK posted'):
if journal_error:
def fail(*a, **kw): raise OSError('phase journal unavailable')
monkeypatch.setattr('cbb_refresh_verify.session_record.write_session_record', fail)
expected = OSError if journal_error and not cancel else RuntimeError
message = 'NATIVE_ADD_CANCELLED' if cancel else 'phase journal unavailable' if journal_error else 'unsafe OK posted'
with pytest.raises(expected, match=message):
native._probe_add_dialog_impl(SimpleNamespace(OnReusableBlocksEditor=lambda:None),job,desktop,{99},root)
assert state['posted']==([110] if cancel else [110,210])
assert state['posted']==([110] if cancel or journal_error else [110,210])
def test_unknown_pending_add_does_not_send_cleanup_dialog_actions(tmp_path, monkeypatch):
+15
View File
@@ -169,3 +169,18 @@ def test_reused_pid_keeps_observing_resources_and_unblocks_only_after_proof(tmp_
assert sessions.library_available(tmp_path/'lib.lmc')
finally:
stop.set()
def test_retained_live_worker_with_stale_postcall_phase_is_still_protected(tmp_path, child):
import threading
path = record(tmp_path, [dict(role='worker', **sessions.process_identity(child.pid))])
sessions.write_session_record(tmp_path/'worker-state.json', dict(operation_id='test-session',
processes=[], phase='POSTCALL'))
stop = threading.Event()
sessions.handoff_session(path, evidence_root=tmp_path, stop=stop)
try:
writes = sessions.active_write_records(tmp_path/'lib.lmc')
assert writes and writes[0]['phase'] == 'UNCONFIRMED'
assert child.poll() is None
finally:
stop.set()