fix: close batch execution and recovery lifecycle

This commit is contained in:
阿白叔 committed 2026-11-17 16:56:29 +08:00
1 parent b19afc6a53
commit d9cf6a07e9
91 files changed
+5779 -454

No files matched your search

+21 -6
View File
@@ -90,6 +90,7 @@ Class ValueApp
End Function
Public Sub Close(ByVal SaveChanges,ByVal FileName)
CloseCount=CloseCount+1
DocumentCount=DocumentCount-1
If SaveChanges Then
SaveCalled=True
SaveCount=SaveCount+1
@@ -149,6 +150,9 @@ End Function
SETUP = r'''
Dim Comp, Pin, Attr, Ignored, Command, Snapshot, SnapshotPath, Failure, Saved
Set QP_Fso=CreateObject("Scripting.FileSystemObject")
Set QP_SessionItems=CreateObject("Scripting.Dictionary")
Set QP_SessionSheets=CreateObject("Scripting.Dictionary")
Set QP_SessionDocuments=CreateObject("Scripting.Dictionary")
QP_Root="__ROOT__"
QP_CurrentJobId="value-job"
Set QP_App=New ValueApp
@@ -220,7 +224,7 @@ Require QP_App.UndoCount=0,"recovery undid prior CAD work"
''')
@pytest.mark.parametrize('change', ['Comp.UID="imposter"', 'Comp.Refdes="R99"'])
@pytest.mark.parametrize('change', ['Comp.Refdes="R99"'])
def test_restore_rejects_changed_component_identity_before_any_write(tmp_path, change):
run_vbs(tmp_path, 'part_number', '''
On Error Resume Next
@@ -233,6 +237,16 @@ Require QP_App.TransactionCount=0,"identity failure must precede CAD writes"
''', after=change)
def test_restore_accepts_uid_churn_without_changing_reference_or_replaying_replace(tmp_path):
run_vbs(tmp_path, 'part_number', '''
QPRestoreAfterOperatorReplace Command,SnapshotPath
Require QP_App.TransactionCount=1,"restoration did not use exactly one transaction"
Require Comp.Refdes="R1","reference identity changed"
Require Comp.FindAttribute("Value").InstanceValue="NEW","Value policy was not verified"
Require QP_App.UndoCount=0,"UID churn replayed or undid the native replacement"
''', after='Comp.UID="changed-native-uid"')
def _batch_readback_fixture(routines, *, fault=''):
# Exercise real restore/finish/guards, replacing only the external open and
# command transport with an in-memory CAD-shaped application.
@@ -242,6 +256,7 @@ End Function''', routines)
routines = re.sub(r'(?ms)^Sub QPEnsureProject\([^\n]*\n.*?^End Sub', '''Sub QPEnsureProject(ByRef App, ByVal TargetPath)
App.ProjectPath=TargetPath
App.CloseCount=0
App.DocumentCount=1
QP_OwnedProject=True
QP_OwnedProjectPath=TargetPath
''' + ('Set Attr=Other.FindAttribute("Value"): Attr.Value="DRIFT"' if fault == 'after_reopen' else '') + '''
@@ -258,7 +273,7 @@ def test_save_then_project_close_refusal_retains_save_boundary(tmp_path):
Dim FullChecks
FullChecks=0
Command.Add "project_path",QPProjectPath()
QP_BatchMode=True: QP_SessionMode=True
QP_BatchMode=True: QP_SessionMode=False
QP_SessionToken=String(32,"b")
QP_OwnedProject=True: QP_OwnedProjectPath=QPProjectPath()
QPRestoreAfterOperatorReplace Command,SnapshotPath
@@ -274,7 +289,7 @@ QP_App.RefuseClose=False
QPDiscardFailedBatchProject CloseError
Require Len(CloseError)>0,"uncertain save must not discard the open project"
Require Len(QPProjectPath())>0,"failed saved project was silently discarded"
Require Not QP_Fso.FileExists(QP_Fso.BuildPath(QP_Root,"project-session-result.tsv")),"failure published success"
Require Not QP_Fso.FileExists(QP_Fso.BuildPath(QP_Root,"status.tsv")),"failure published success"
''', routines_transform=_batch_readback_fixture)
@@ -284,7 +299,7 @@ def test_owned_batch_checks_full_state_at_save_and_disk_boundaries(tmp_path, fau
Dim FullChecks
FullChecks=0
Command.Add "project_path",QPProjectPath()
QP_BatchMode=True: QP_SessionMode=True
QP_BatchMode=True: QP_SessionMode=False
QP_SessionToken=String(32,"b")
QP_OwnedProject=True: QP_OwnedProjectPath=QPProjectPath()
QPRestoreAfterOperatorReplace Command,SnapshotPath
@@ -298,10 +313,10 @@ On Error GoTo 0
Require Failure=0,"valid batch failed"
Require FullChecks=2,"expected one full check before save and one after reopen"
Require QP_App.SaveCalled,"valid batch did not save"
Require InStr(QPReadUtf8(QP_Fso.BuildPath(QP_Root,"project-session-result.tsv")),"saved_ok")>0,"no verified result"
Require InStr(QPReadUtf8(QP_Fso.BuildPath(QP_Root,"status.tsv")),"saved_ok")>0,"no verified result"
''' if not fault else '''
Require Failure<>0,"unselected drift passed the commit guard"
Require Not QP_Fso.FileExists(QP_Fso.BuildPath(QP_Root,"project-session-result.tsv")),"failure published a completion"
Require Not QP_Fso.FileExists(QP_Fso.BuildPath(QP_Root,"status.tsv")),"failure published a completion"
Require QP_App.SaveCalled=''' + ('True' if fault == 'after_reopen' else 'False') + ''',"wrong save boundary"
Require QP_BatchSaveCommitted=''' + ('True' if fault == 'after_reopen' else 'False') + ''',"saved uncertainty marker is wrong"
'''), after='''