fix: reject native source renames before management writes

This commit is contained in:
阿白叔 committed 2026-11-17 01:22:57 +08:00
1 parent 36ff964230
commit d40fa3a750
7 files changed
+102 -20

No files matched your search

+10 -5
View File
@@ -68,7 +68,8 @@ def test_add_timeout_publishes_cancellation_without_killing_native_owner(tmp_pat
@pytest.mark.parametrize('cancel', [True, False])
@pytest.mark.parametrize('journal_error', [False, True])
def test_cancellation_and_phase_at_native_add_submit(tmp_path, monkeypatch, cancel, journal_error, owned_add_process):
@pytest.mark.parametrize('changed_name', [False, True])
def test_cancellation_and_phase_at_native_add_submit(tmp_path, monkeypatch, cancel, journal_error, changed_name, owned_add_process):
import os,sys
from types import SimpleNamespace
import win32gui,win32process
@@ -90,7 +91,10 @@ def test_cancellation_and_phase_at_native_add_submit(tmp_path, monkeypatch, canc
monkeypatch.setattr(win32gui,'GetWindowText',lambda h:{100:'Reusable Blocks',200:'New Reusable Block'}[int(h)])
monkeypatch.setattr(win32gui,'GetDlgItem',lambda h,c:110 if h==100 else 210 if c==1083 else c+1000)
monkeypatch.setattr(win32gui,'GetClassName',lambda h:'Edit')
monkeypatch.setattr(native,'_set_probe_field',lambda *a:None)
def field(*args, read_only=False):
if read_only and args[1] == 1215 and changed_name:
raise RuntimeError('NATIVE_ADD_NAME_CHANGED')
monkeypatch.setattr(native,'_set_probe_field',field)
def post(h,*args):
state['posted'].append(h)
if h==110:state['new']=True
@@ -113,11 +117,12 @@ def test_cancellation_and_phase_at_native_add_submit(tmp_path, monkeypatch, canc
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'
expected = OSError if journal_error and not cancel and not changed_name else RuntimeError
message = ('NATIVE_ADD_NAME_CHANGED' if changed_name else '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,{owned_add_process.pid},root)
assert state['posted']==([110] if cancel or journal_error else [110,210])
assert state['posted']==([110] if cancel or journal_error or changed_name else [110,210])
def test_unknown_pending_add_does_not_send_cleanup_dialog_actions(tmp_path, monkeypatch):