fix: preserve native calls on stop and keep status reads observational

This commit is contained in:
阿白叔 committed 2026-11-06 15:42:33 +08:00
1 parent 97a3de20c9
commit 8d3eab1164
19 files changed
+631 -290

No files matched your search

+116
View File
@@ -85,3 +85,119 @@ End Class
assert completed.returncode == 4, completed.stderr
assert 'SAVE_OK' not in parsed['markers']
assert 'CLOSE_OK' not in parsed['markers']
def run_helper(tmp_path, *, save_body='Save = True', close_body='Close = True',
is_saved='True', gated=False, cancelled=False):
source = Path('src/cbb_refresh_verify/save_verified_block.vbs').read_text('utf-8')
classes = '''
Class FakePi
Public ProjectFile, ForwardAnnotationStatus, SynchCESStatus, LoadCESStatus, BackAnnotationStatus
Private Sub Class_Initialize
ProjectFile = WScript.Arguments(0)
ForwardAnnotationStatus = 2
SynchCESStatus = 2
LoadCESStatus = 2
BackAnnotationStatus = 2
End Sub
End Class
Class FakeDoc
Public Name
Private Sub Class_Initialize
Name = "CBB.pcb"
End Sub
Public Property Get ProjectIntegration
Set ProjectIntegration = New FakePi
End Property
Public Function Validate(token)
Validate = 17
End Function
Public Function Save()
WScript.Echo "TEST_SAVE_CALLED"
SAVE_BODY
End Function
Public Function IsSaved()
IsSaved = IS_SAVED_VALUE
End Function
Public Function Close(saveChanges)
CLOSE_BODY
closedDoc = True
End Function
End Class
Class FakeApp
Public Property Get ActiveDocument
If closedDoc Then
Set ActiveDocument = Nothing
Else
Set ActiveDocument = New FakeDoc
End If
End Property
Public Sub Quit()
WScript.Echo "TEST_QUIT"
End Sub
End Class
Class FakeLic
Public Function GetToken(value)
GetToken = value
End Function
End Class
'''.replace('SAVE_BODY', save_body).replace('CLOSE_BODY', close_body).replace('IS_SAVED_VALUE', is_saved)
source = source.replace('Option Explicit', 'Option Explicit\nDim closedDoc\n' + classes)
source = source.replace('GetObject(, "MGCPCB.Application")', 'New FakeApp')
source = source.replace('CreateObject("MGCPCBAutomationLicensing.Application")', 'New FakeLic')
harness = tmp_path/'facts.vbs'
harness.write_text(source, encoding='ascii')
cancel = tmp_path/'cancel.signal'
if cancelled:
cancel.touch()
args = [str(Path(os.environ['WINDIR'])/'SysWOW64/cscript.exe'), '//nologo',
str(harness), 'expected.prj', 'CBB.pcb', str(cancel)]
if gated:
args.append(str(tmp_path/'start.signal'))
return subprocess.run(args, capture_output=True, text=True, timeout=35)
@pytest.mark.parametrize('body,marker', [('Close = False', 'CLOSE_FAILED'),
('Err.Raise 5, "FakeDoc", "close failed"', 'CLOSE_FAILED')])
def test_close_failure_keeps_successful_save_fact(tmp_path, body, marker):
result = run_helper(tmp_path, close_body=body)
assert 'SAVE_OK' in result.stdout
assert marker in result.stdout
assert 'CLOSE_OK' not in result.stdout
assert result.returncode != 0
def test_save_exception_has_unknown_result_marker(tmp_path):
result = run_helper(tmp_path, save_body='Err.Raise 5, "FakeDoc", "save failed"')
assert 'SAVE_RESULT_UNKNOWN|5|' in result.stdout
assert 'CLOSE_START' not in result.stdout
assert result.returncode != 0
def test_saved_document_postcheck_failure_does_not_discard_save_fact(tmp_path):
result = run_helper(tmp_path, is_saved='False')
assert 'SAVE_OK' in result.stdout
assert 'POST_SAVE_FAILED' in result.stdout
assert 'CLOSE_START' not in result.stdout
def test_cancellation_in_save_allows_identity_checked_saved_close(tmp_path):
result = run_helper(tmp_path, save_body='''
Dim fso, flag
Set fso = CreateObject("Scripting.FileSystemObject")
Set flag = fso.CreateTextFile(WScript.Arguments(2), True)
flag.Close
Save = True
''')
assert 'SAVE_OK' in result.stdout
assert 'CLOSE_OK' in result.stdout
assert 'QUIT_OK' in result.stdout
assert result.returncode == 0, result.stderr
def test_unopened_gate_cancellation_exits_before_com(tmp_path):
result = run_helper(tmp_path, gated=True, cancelled=True)
assert 'CANCELLED_BEFORE_SAVE' in result.stdout
assert 'TEST_SAVE_CALLED' not in result.stdout
assert 'VALIDATE_START' not in result.stdout
assert result.returncode == 9