perf(execution): consolidate full checks at commit boundaries
This commit is contained in:
1 parent
196c84b0d3
commit
0714c7753f
4 files changed
+241
-24
No files matched your search
@@ -1,5 +1,6 @@
|
||||
import ast
|
||||
from pathlib import Path
|
||||
import re
|
||||
import subprocess
|
||||
|
||||
import pytest
|
||||
@@ -229,6 +230,103 @@ Require QP_App.TransactionCount=0,"identity failure must precede CAD writes"
|
||||
''', after=change)
|
||||
|
||||
|
||||
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.
|
||||
routines = re.sub(r'(?ms)^Function QPReadCommand\([^\n]*\n.*?^End Function', '''Function QPReadCommand(ByVal Path)
|
||||
Set QPReadCommand=Command
|
||||
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
|
||||
QP_OwnedProject=True
|
||||
QP_OwnedProjectPath=TargetPath
|
||||
''' + ('Set Attr=Other.FindAttribute("Value"): Attr.Value="DRIFT"' if fault == 'after_reopen' else '') + '''
|
||||
End Sub''', routines)
|
||||
injection = 'FullChecks=FullChecks+1\n'
|
||||
if fault == 'before_save':
|
||||
injection += 'If FullChecks=1 Then Other.FindAttribute("Value").Value="DRIFT"\n'
|
||||
return routines.replace('Sub QPVerifyUntouched(ByRef Records)\n',
|
||||
'Sub QPVerifyUntouched(ByRef Records)\n' + injection)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('fault', ['', 'before_save', 'after_reopen'])
|
||||
def test_owned_batch_checks_full_state_at_save_and_disk_boundaries(tmp_path, fault):
|
||||
run_vbs(tmp_path, 'part_number', '''
|
||||
Dim FullChecks
|
||||
FullChecks=0
|
||||
Command.Add "project_path",QPProjectPath()
|
||||
QP_BatchMode=True: QP_SessionMode=True
|
||||
QP_SessionToken=String(32,"b")
|
||||
QP_OwnedProject=True: QP_OwnedProjectPath=QPProjectPath()
|
||||
QPRestoreAfterOperatorReplace Command,SnapshotPath
|
||||
Require FullChecks=0,"full scans repeated before the commit boundary"
|
||||
On Error Resume Next
|
||||
QPFinishBatchItem
|
||||
Failure=Err.Number
|
||||
Err.Clear
|
||||
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"
|
||||
''' 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 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='''
|
||||
Dim Other
|
||||
Set Other=New ValueComponent
|
||||
Other.UID="unselected": Other.Refdes="R2": Other.Orientation=0: Other.Scale=1
|
||||
Set Ignored=AddValueAttr(Other,"Value","SAFE")
|
||||
QP_App.Components.Add Other,True
|
||||
QPWriteUtf8 SnapshotPath,QPReadUtf8(SnapshotPath) & QPUntouchedComponent(Other)
|
||||
''', routines_transform=lambda routines: _batch_readback_fixture(routines, fault=fault))
|
||||
|
||||
|
||||
@pytest.mark.parametrize('refuse_close', [False, True])
|
||||
def test_verified_disk_recovery_closes_without_saving_or_reopening(tmp_path, refuse_close):
|
||||
run_vbs(tmp_path, 'part_number', '''
|
||||
Command.Add "recovery_part_name","NEW_NAME"
|
||||
Command.Add "recovery_part_label","NEW_LABEL"
|
||||
Command.Add "project_path",QPProjectPath()
|
||||
QPRestoreAfterOperatorReplace Command,SnapshotPath
|
||||
QPWriteUtf8 QP_Fso.BuildPath(QP_Root,"status.tsv"),"job_id" & vbTab & "state" & vbTab & "code" & vbTab & "message" & vbCrLf
|
||||
QP_BatchMode=True
|
||||
QP_OwnedProject=True: QP_OwnedProjectPath=QPProjectPath()
|
||||
QP_App.RefuseClose=''' + ('True' if refuse_close else 'False') + '''
|
||||
On Error Resume Next
|
||||
QPRecoverSavedJob Command,SnapshotPath
|
||||
Failure=Err.Number
|
||||
Err.Clear
|
||||
On Error GoTo 0
|
||||
Require Not QP_App.SaveCalled,"read-only disk recovery saved again"
|
||||
''' + ('''
|
||||
Require Failure<>0,"unconfirmed recovery close was accepted"
|
||||
Require InStr(QPReadUtf8(QP_Fso.BuildPath(QP_Root,"status.tsv")),"recovery_saved_verified")=0,"failure published proof"
|
||||
''' if refuse_close else '''
|
||||
Require Failure=0,"valid disk recovery failed"
|
||||
Require Not QP_BatchMode,"read-only recovery will trigger a duplicate finish/save"
|
||||
Require QP_App.CloseCount=1 And Len(QP_App.ProjectPath)=0,"verified recovery did not close"
|
||||
Require Not QP_OwnedProject,"closed recovery retains stale ownership"
|
||||
Require InStr(QPReadUtf8(QP_Fso.BuildPath(QP_Root,"status.tsv")),"recovery_saved_verified")>0,"missing disk proof"
|
||||
'''))
|
||||
|
||||
|
||||
def test_command_snapshot_validation_reads_the_file_once(tmp_path):
|
||||
def count_reads(routines):
|
||||
return routines.replace('Function QPReadSnapshot(ByVal Path)\n',
|
||||
'Function QPReadSnapshot(ByVal Path)\n SnapshotReads=SnapshotReads+1\n')
|
||||
run_vbs(tmp_path, 'part_number', '''
|
||||
Dim SnapshotReads
|
||||
SnapshotReads=0
|
||||
QPRequireCommandSnapshot Command,SnapshotPath
|
||||
Require SnapshotReads=1,"same boundary parsed its snapshot twice"
|
||||
''', routines_transform=count_reads)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('mode', ['preserve', 'part_label', 'part_number'])
|
||||
def test_recovery_repairs_attributes_without_native_replace(tmp_path, mode):
|
||||
run_vbs(tmp_path, mode, '''
|
||||
|
||||
Reference in new issue
Block a user