fix(execution): verify exact identity connections and untouched state
This commit is contained in:
1 parent
b646a9a88a
commit
11810eca4c
7 files changed
+673
-133
No files matched your search
@@ -1059,7 +1059,8 @@ Sub QPRollbackNativeReplacement(ByVal SnapshotPath)
|
||||
Expected = ""
|
||||
For LineIndex = 1 To UBound(Lines)
|
||||
If Len(Replace(Lines(LineIndex), vbCr, "")) > 0 Then
|
||||
If Left(CStr(Lines(LineIndex)), 2) <> "U" & vbTab Then _
|
||||
If Left(CStr(Lines(LineIndex)), 2) = "C" & vbTab Or _
|
||||
Left(CStr(Lines(LineIndex)), 2) = "A" & vbTab Then _
|
||||
Expected = Expected & Replace(Lines(LineIndex), vbCr, "") & vbCrLf
|
||||
End If
|
||||
Next
|
||||
@@ -1087,7 +1088,7 @@ Sub QPCaptureAndSelect(ByRef Command, ByVal SnapshotPath)
|
||||
Dim PartAttr
|
||||
Dim Snapshot
|
||||
Dim Index
|
||||
Dim Selectors, Selector, Uid, ValueAttr, ValueText
|
||||
Dim Selectors, Selector, Uid, ValueAttr, ValueText, MatchedUids, UntouchedCount
|
||||
|
||||
If StrComp(CStr(Command("old_part_number")), CStr(Command("new_part_number")), vbTextCompare) = 0 Then _
|
||||
Err.Raise vbObjectError + 829, "QuickPartReplace", "source and target must differ"
|
||||
@@ -1152,12 +1153,23 @@ Sub QPCaptureAndSelect(ByRef Command, ByVal SnapshotPath)
|
||||
Snapshot = Snapshot & QPSnapshotComponent(Comp)
|
||||
QPProgress "capture", Index + 1, Matches.Count
|
||||
Next
|
||||
If Not Selectors Is Nothing Then
|
||||
For Each Comp In Components
|
||||
If Not Selectors.Exists(CStr(Comp.UID)) Then _
|
||||
Snapshot = Snapshot & QPUntouchedComponent(Comp)
|
||||
Next
|
||||
End If
|
||||
' U remains the seven-field native-helper identity baseline. X/G extend it
|
||||
' with complete unselected state for every scope, including all-match jobs.
|
||||
Snapshot = Snapshot & "X" & vbTab & "untouched_full_v1" & vbCrLf
|
||||
Set MatchedUids = CreateObject("Scripting.Dictionary")
|
||||
For Index = 0 To Matches.Count - 1
|
||||
Set Comp = Matches.Item(CStr(Index))
|
||||
MatchedUids.Add CStr(Comp.UID), True
|
||||
Next
|
||||
UntouchedCount = 0
|
||||
For Each Comp In Components
|
||||
If Not MatchedUids.Exists(CStr(Comp.UID)) Then
|
||||
QPProgress "capture_untouched", UntouchedCount, Components.Count - Matches.Count
|
||||
Snapshot = Snapshot & QPUntouchedComponent(Comp)
|
||||
UntouchedCount = UntouchedCount + 1
|
||||
QPProgress "capture_untouched", UntouchedCount, Components.Count - Matches.Count
|
||||
End If
|
||||
Next
|
||||
QPWriteUtf8 SnapshotPath, Snapshot
|
||||
|
||||
For Each Comp In Components
|
||||
@@ -1179,6 +1191,30 @@ Function QPUntouchedComponent(ByRef Comp)
|
||||
QPEncode(QPEffectiveComponentAttribute(Comp, "Value")) & vbTab & _
|
||||
QPEncode(QPEffectiveComponentAttribute(Comp, "Part Name")) & vbTab & _
|
||||
QPEncode(QPEffectiveComponentAttribute(Comp, "Part Label")) & vbCrLf
|
||||
QPUntouchedComponent = QPUntouchedComponent & "G" & vbTab & QPEncode(CStr(Comp.UID)) & _
|
||||
vbTab & QPEncode(QPUntouchedFullState(Comp)) & vbCrLf
|
||||
End Function
|
||||
|
||||
Function QPUntouchedFullState(ByRef Comp)
|
||||
Dim Point, Pins, Connections, Attr, AttributeText, Result
|
||||
Set Point = Comp.GetLocation()
|
||||
Set Pins = QPComponentPins(Comp)
|
||||
If Pins.Count = 0 Then
|
||||
' A genuinely empty query is valid for annotation symbols; COM errors
|
||||
' still propagate. Selected replacement symbols continue to require pins.
|
||||
Connections = "NO_PINS"
|
||||
Else
|
||||
Connections = QPConnectionSignature(Comp)
|
||||
End If
|
||||
Result = "C" & vbTab & QPEncode(CStr(Comp.UID)) & vbTab & QPEncode(CStr(Comp.Refdes)) & _
|
||||
vbTab & QPEncode(CStr(Point.X)) & vbTab & QPEncode(CStr(Point.Y)) & _
|
||||
vbTab & QPEncode(CStr(Comp.Orientation)) & vbTab & QPEncode(CStr(Comp.Scale)) & _
|
||||
vbTab & QPEncode(Connections) & vbCrLf
|
||||
AttributeText = ""
|
||||
For Each Attr In Comp.Attributes
|
||||
AttributeText = AttributeText & QPSnapshotAttribute(CStr(Comp.UID), Attr)
|
||||
Next
|
||||
QPUntouchedFullState = Result & QPSortSnapshotLines(AttributeText)
|
||||
End Function
|
||||
|
||||
Function QPEffectiveComponentAttribute(ByRef Comp, ByVal Name)
|
||||
@@ -1189,9 +1225,16 @@ Function QPEffectiveComponentAttribute(ByRef Comp, ByVal Name)
|
||||
End Function
|
||||
|
||||
Sub QPVerifyUntouched(ByRef Records)
|
||||
Dim Baseline, Components, Comp, Uid, Actual, Matched, Total, Seen
|
||||
If Not Records.Item("meta").Exists("target_scope") Then Exit Sub
|
||||
Dim Baseline, FullBaseline, Components, Comp, Uid, Actual, Expected, Matched, Total, Seen
|
||||
If Not Records.Exists("untouched_full_version") Then _
|
||||
Err.Raise vbObjectError + 874, "QuickPartReplace.Target", "legacy snapshot has no complete unselected-state proof; recovery requires manual verification"
|
||||
Set Baseline = Records.Item("untouched")
|
||||
Set FullBaseline = Records.Item("untouched_full")
|
||||
If Baseline.Count <> FullBaseline.Count Then _
|
||||
Err.Raise vbObjectError + 874, "QuickPartReplace.Target", "unselected full-state baseline is incomplete"
|
||||
' Read new component/pin proxies after each native mutation, restore or reopen.
|
||||
QPInvalidatePinIndex
|
||||
QPInvalidateComponentIndex
|
||||
Set Components = QP_App.ActiveView.Query(VDM_COMP, VD_ALL)
|
||||
Matched = 0
|
||||
Total = 0
|
||||
@@ -1203,10 +1246,16 @@ Sub QPVerifyUntouched(ByRef Records)
|
||||
"QuickPartReplace.Target", "duplicate component UID"
|
||||
Seen.Add Uid, True
|
||||
If Baseline.Exists(Uid) Then
|
||||
QPProgress "verify_untouched", Matched, Baseline.Count
|
||||
Matched = Matched + 1
|
||||
Actual = Replace(QPUntouchedComponent(Comp), vbCrLf, "")
|
||||
If Actual <> CStr(Baseline.Item(Uid)) Then _
|
||||
If Not FullBaseline.Exists(Uid) Then Err.Raise vbObjectError + 874, _
|
||||
"QuickPartReplace.Target", "unselected full-state baseline is missing"
|
||||
Actual = QPUntouchedComponent(Comp)
|
||||
Expected = CStr(Baseline.Item(Uid)) & vbCrLf & "G" & vbTab & QPEncode(Uid) & _
|
||||
vbTab & QPEncode(CStr(FullBaseline.Item(Uid))) & vbCrLf
|
||||
If Actual <> Expected Then _
|
||||
Err.Raise vbObjectError + 874, "QuickPartReplace.Target", "unselected component changed"
|
||||
QPProgress "verify_untouched", Matched, Baseline.Count
|
||||
End If
|
||||
Next
|
||||
If Total <> Baseline.Count + Records.Item("components").Count Then _
|
||||
@@ -1311,7 +1360,6 @@ End Function
|
||||
|
||||
Function QPSnapshotAttribute(ByVal ComponentUid, ByRef Attr)
|
||||
Dim Instance
|
||||
Dim InstanceWarning
|
||||
Dim LocationX
|
||||
Dim LocationY
|
||||
Dim Color
|
||||
@@ -1320,18 +1368,7 @@ Function QPSnapshotAttribute(ByVal ComponentUid, ByRef Attr)
|
||||
Dim Orientation
|
||||
Dim Visible
|
||||
|
||||
InstanceWarning = ""
|
||||
On Error Resume Next
|
||||
Instance = Attr.InstanceValue
|
||||
If Err.Number <> 0 Then
|
||||
Err.Clear
|
||||
Instance = Attr.Value
|
||||
InstanceWarning = "instance_value_fallback"
|
||||
End If
|
||||
On Error GoTo 0
|
||||
If Len(InstanceWarning) > 0 Then
|
||||
QPLog QP_Root, "WARN", InstanceWarning & " name=" & CStr(Attr.Name)
|
||||
End If
|
||||
LocationX = QPOptionalAttributeField(Attr, "location_x")
|
||||
LocationY = QPOptionalAttributeField(Attr, "location_y")
|
||||
Color = QPOptionalAttributeField(Attr, "color")
|
||||
@@ -1507,14 +1544,22 @@ Sub QPRestorePlans(ByRef Command, ByRef Records, ByRef Plans)
|
||||
QPProgress "restore_attributes", Index + 1, Plans.Count
|
||||
Next
|
||||
QPVerifyRestoredPlans Command, Records, Plans, ValueStates
|
||||
QPVerifyUntouched Records
|
||||
End Sub
|
||||
|
||||
Sub QPVerifyRestoredPlans(ByRef Command, ByRef Records, ByRef Plans, ByRef ValueStates)
|
||||
Dim Index, ComponentRecord, Candidate, AttributeIndex, Record, Attr
|
||||
Dim Index, ComponentRecord, Candidate, AttributeIndex, Record, Attr, Before
|
||||
QPProgress "verify_restoration", 0, Plans.Count
|
||||
For Index = 0 To Plans.Count - 1
|
||||
Set ComponentRecord = Records.Item("components").Item(CStr(Index))
|
||||
Set Candidate = Plans.Item(CStr(Index))
|
||||
' Captured only after native library identity validation (or recovery
|
||||
' command validation), before restoration/save; never derive this expected
|
||||
' identity from the reopened result or from its current Value.
|
||||
Set Before = ValueStates.Item(CStr(Index))
|
||||
If QPRequiredAttributeValue(Candidate, "Part Name") <> CStr(Before("part_name")) Or _
|
||||
QPEffectiveComponentAttribute(Candidate, "Part Label") <> CStr(Before("part_label")) Then _
|
||||
Err.Raise vbObjectError + 865, "QuickPartReplace", "target library identity changed during restoration or save"
|
||||
QPRestorePreflight Candidate, ComponentRecord, Records.Item("attributes"), _
|
||||
CStr(Command("new_part_number")), QPValueMode(Command)
|
||||
QPVerifyTransform Candidate, ComponentRecord
|
||||
@@ -1568,11 +1613,12 @@ Sub QPRecoverSavedJob(ByRef Command, ByVal SnapshotPath)
|
||||
ElseIf StrComp(PartNumber, CStr(Command("new_part_number")), vbTextCompare) = 0 Then
|
||||
NewCount = NewCount + 1
|
||||
If StrComp(QPRequiredAttributeValue(Candidate, "Part Name"), _
|
||||
CStr(Command("recovery_part_name")), vbTextCompare) <> 0 Then _
|
||||
CStr(Command("recovery_part_name")), vbBinaryCompare) <> 0 Then _
|
||||
Err.Raise vbObjectError + 865, "QuickPartReplace.Recovery", "saved target library identity differs"
|
||||
If QPValueMode(Command) <> "preserve" Then
|
||||
If StrComp(QPRequiredAttributeValue(Candidate, "Part Label"), _
|
||||
CStr(Command("recovery_part_label")), vbTextCompare) <> 0 Then _
|
||||
If Len(CStr(Command("recovery_part_label"))) > 0 Or _
|
||||
QPValueMode(Command) = "part_label" Or QPValueMode(Command) = "legacy_part_label" Then
|
||||
If StrComp(QPEffectiveComponentAttribute(Candidate, "Part Label"), _
|
||||
CStr(Command("recovery_part_label")), vbBinaryCompare) <> 0 Then _
|
||||
Err.Raise vbObjectError + 865, "QuickPartReplace.Recovery", "saved target library identity differs"
|
||||
End If
|
||||
QPRestorePreflight Candidate, Record, Records.Item("attributes"), _
|
||||
@@ -1662,6 +1708,9 @@ Sub QPRestorePreflight(ByRef Comp, ByRef ComponentRecord, _
|
||||
Dim CurrentConnections
|
||||
Dim SavedConnections
|
||||
|
||||
If CStr(Comp.UID) <> CStr(ComponentRecord("uid")) Or _
|
||||
CStr(Comp.Refdes) <> CStr(ComponentRecord("refdes")) Then _
|
||||
Err.Raise vbObjectError + 831, "QuickPartReplace", "replacement component UID or Refdes differs from snapshot; no restoration writes allowed"
|
||||
If StrComp(QPRequiredAttributeValue(Comp, "Part Number"), _
|
||||
CStr(NewPartNumber), vbTextCompare) <> 0 Then
|
||||
Err.Raise vbObjectError + 800, "QuickPartReplace", _
|
||||
@@ -2072,6 +2121,8 @@ Function QPCaptureValueState(ByRef Comp)
|
||||
State.Add "exists", Not (Attr Is Nothing)
|
||||
State.Add "value", ""
|
||||
State.Add "nc_required", False
|
||||
State.Add "part_name", QPRequiredAttributeValue(Comp, "Part Name")
|
||||
State.Add "part_label", QPEffectiveComponentAttribute(Comp, "Part Label")
|
||||
If Not Attr Is Nothing Then State("value") = QPEffectiveAttributeValue(Attr)
|
||||
Set QPCaptureValueState = State
|
||||
End Function
|
||||
@@ -2161,15 +2212,20 @@ Function QPConnectionsMatch(ByVal Current, ByVal Saved)
|
||||
Exit Function
|
||||
End If
|
||||
Next
|
||||
If QPAllSavedNumbersBlank(Expected) Then _
|
||||
QPConnectionsMatch = QPConnectionsMatchTopology(Actual, Expected)
|
||||
' Unknown source numbers permit only the same one-to-one physical/net map,
|
||||
' up to one common translation. Network counts alone cannot prove pin mapping.
|
||||
End Function
|
||||
|
||||
Function QPConnectionLineValid(ByVal Line, ByVal RequireNumber)
|
||||
Dim Fields, X, Y, ErrorNumber
|
||||
QPConnectionLineValid = False
|
||||
Fields = Split(CStr(Line), "|")
|
||||
If UBound(Fields) < 3 Then Exit Function
|
||||
If UBound(Fields) <> 3 And UBound(Fields) <> 4 Then Exit Function
|
||||
If UBound(Fields) = 3 Then
|
||||
If CStr(Fields(3)) <> "UNCONNECTED" Then Exit Function
|
||||
Else
|
||||
If Len(CStr(Fields(3))) = 0 Then Exit Function
|
||||
End If
|
||||
If RequireNumber And Len(Trim(CStr(Fields(0)))) = 0 Then Exit Function
|
||||
If Len(Trim(CStr(Fields(1)))) = 0 Or Len(Trim(CStr(Fields(2)))) = 0 Then Exit Function
|
||||
On Error Resume Next
|
||||
@@ -2197,7 +2253,11 @@ End Function
|
||||
Function QPConnectionNetIdentity(ByVal Line)
|
||||
Dim Fields
|
||||
Fields = Split(CStr(Line), "|")
|
||||
QPConnectionNetIdentity = Trim(CStr(Fields(UBound(Fields))))
|
||||
If UBound(Fields) = 3 Then
|
||||
QPConnectionNetIdentity = "UNCONNECTED"
|
||||
Else
|
||||
QPConnectionNetIdentity = CStr(Fields(3)) & "|" & CStr(Fields(4))
|
||||
End If
|
||||
End Function
|
||||
|
||||
Function QPConnectionsMatchOffset(ByRef Actual, ByRef Expected, ByVal OffsetX, ByVal OffsetY)
|
||||
@@ -2215,7 +2275,7 @@ Function QPConnectionsMatchOffset(ByRef Actual, ByRef Expected, ByVal OffsetX, B
|
||||
Abs(QPConnectionCoordinate(Candidate, 2) - _
|
||||
QPConnectionCoordinate(SavedLine, 2) - OffsetY) < 0.0001 And _
|
||||
StrComp(QPConnectionNetIdentity(Candidate), _
|
||||
QPConnectionNetIdentity(SavedLine), vbTextCompare) = 0)
|
||||
QPConnectionNetIdentity(SavedLine), vbBinaryCompare) = 0)
|
||||
Number = QPConnectionNumber(SavedLine)
|
||||
If Len(Trim(Number)) > 0 Then _
|
||||
Match = Match And StrComp(QPConnectionNumber(Candidate), Number, vbBinaryCompare) = 0
|
||||
@@ -2231,53 +2291,6 @@ Function QPConnectionsMatchOffset(ByRef Actual, ByRef Expected, ByVal OffsetX, B
|
||||
QPConnectionsMatchOffset = True
|
||||
End Function
|
||||
|
||||
Function QPAllSavedNumbersBlank(ByRef Expected)
|
||||
Dim Index
|
||||
QPAllSavedNumbersBlank = True
|
||||
For Index = 0 To Expected.Count - 1
|
||||
If Len(Trim(QPConnectionNumber(Expected.Item(CStr(Index))))) > 0 Then
|
||||
QPAllSavedNumbersBlank = False
|
||||
Exit Function
|
||||
End If
|
||||
Next
|
||||
End Function
|
||||
|
||||
Function QPConnectionsMatchTopology(ByRef Actual, ByRef Expected)
|
||||
Dim ActualNets, ExpectedNets, Index, Key, Value
|
||||
Set ActualNets = CreateObject("Scripting.Dictionary")
|
||||
Set ExpectedNets = CreateObject("Scripting.Dictionary")
|
||||
ActualNets.CompareMode = vbTextCompare
|
||||
ExpectedNets.CompareMode = vbTextCompare
|
||||
For Index = 0 To Actual.Count - 1
|
||||
Key = QPConnectionNetIdentity(Actual.Item(CStr(Index)))
|
||||
If ActualNets.Exists(Key) Then
|
||||
ActualNets(Key) = ActualNets(Key) + 1
|
||||
Else
|
||||
ActualNets.Add Key, 1
|
||||
End If
|
||||
Next
|
||||
For Index = 0 To Expected.Count - 1
|
||||
Key = QPConnectionNetIdentity(Expected.Item(CStr(Index)))
|
||||
If ExpectedNets.Exists(Key) Then
|
||||
ExpectedNets(Key) = ExpectedNets(Key) + 1
|
||||
Else
|
||||
ExpectedNets.Add Key, 1
|
||||
End If
|
||||
Next
|
||||
QPConnectionsMatchTopology = (ActualNets.Count = ExpectedNets.Count)
|
||||
If Not QPConnectionsMatchTopology Then Exit Function
|
||||
For Each Key In ExpectedNets.Keys
|
||||
If Not ActualNets.Exists(Key) Then
|
||||
QPConnectionsMatchTopology = False
|
||||
Exit Function
|
||||
End If
|
||||
If ActualNets(Key) <> ExpectedNets(Key) Then
|
||||
QPConnectionsMatchTopology = False
|
||||
Exit Function
|
||||
End If
|
||||
Next
|
||||
End Function
|
||||
|
||||
Sub QPRestoreDisplay(ByRef Attr, ByRef Record, ByVal Refdes)
|
||||
Dim Point, Field
|
||||
For Each Field In Array("x", "y", "color", "font", "size", "orientation", "visible")
|
||||
@@ -2333,16 +2346,7 @@ End Sub
|
||||
|
||||
Function QPFindCurrentAttribute(ByRef Comp, ByVal Name)
|
||||
Dim Attr
|
||||
On Error Resume Next
|
||||
Set Attr = Comp.FindAttribute(CStr(Name))
|
||||
If Err.Number <> 0 Then
|
||||
QPLog QP_Root, "WARN", "find_attribute name=" & CStr(Name) & _
|
||||
" number=" & Err.Number & " source=" & Err.Source & _
|
||||
" description=" & Err.Description
|
||||
Err.Clear
|
||||
Set Attr = Nothing
|
||||
End If
|
||||
On Error GoTo 0
|
||||
Set QPFindCurrentAttribute = Attr
|
||||
End Function
|
||||
|
||||
@@ -2375,9 +2379,7 @@ Function QPEffectiveAttributeValue(ByRef Attr)
|
||||
Exit Function
|
||||
End If
|
||||
If ErrorNumber <> 0 Then
|
||||
QPLog QP_Root, "WARN", "instance_value_fallback number=" & _
|
||||
ErrorNumber & " source=" & ErrorSource & " description=" & _
|
||||
ErrorDescription
|
||||
Err.Raise ErrorNumber, ErrorSource, ErrorDescription
|
||||
End If
|
||||
On Error Resume Next
|
||||
Value = CStr(Attr.Value)
|
||||
@@ -2689,7 +2691,7 @@ Function QPReadSnapshot(ByVal Path)
|
||||
Dim Result
|
||||
Dim Components
|
||||
Dim Attributes
|
||||
Dim Untouched
|
||||
Dim Untouched, UntouchedFull
|
||||
Dim Fields
|
||||
Dim Index
|
||||
Dim Record
|
||||
@@ -2699,6 +2701,7 @@ Function QPReadSnapshot(ByVal Path)
|
||||
Set Components = CreateObject("Scripting.Dictionary")
|
||||
Set Attributes = CreateObject("Scripting.Dictionary")
|
||||
Set Untouched = CreateObject("Scripting.Dictionary")
|
||||
Set UntouchedFull = CreateObject("Scripting.Dictionary")
|
||||
Lines = Split(QPReadUtf8(Path), vbLf)
|
||||
For Index = 0 To UBound(Lines)
|
||||
If Len(Replace(Lines(Index), vbCr, "")) > 0 Then
|
||||
@@ -2757,6 +2760,14 @@ Function QPReadSnapshot(ByVal Path)
|
||||
If Untouched.Exists(QPDecode(Fields(1))) Then Err.Raise vbObjectError + 874, _
|
||||
"QuickPartReplace.Target", "duplicate unselected component UID"
|
||||
Untouched.Add QPDecode(Fields(1)), Replace(Lines(Index), vbCr, "")
|
||||
Case "X"
|
||||
If UBound(Fields) <> 1 Or Fields(1) <> "untouched_full_v1" Then _
|
||||
Err.Raise vbObjectError + 874, "QuickPartReplace.Target", "invalid unselected-state protocol"
|
||||
Result.Add "untouched_full_version", CStr(Fields(1))
|
||||
Case "G"
|
||||
If UBound(Fields) <> 2 Or Len(QPDecode(Fields(1))) = 0 Or Len(QPDecode(Fields(2))) = 0 Then _
|
||||
Err.Raise vbObjectError + 874, "QuickPartReplace.Target", "invalid unselected full-state snapshot"
|
||||
UntouchedFull.Add QPDecode(Fields(1)), QPDecode(Fields(2))
|
||||
End Select
|
||||
End If
|
||||
Next
|
||||
@@ -2766,6 +2777,7 @@ Function QPReadSnapshot(ByVal Path)
|
||||
Result.Add "components", Components
|
||||
Result.Add "attributes", Attributes
|
||||
Result.Add "untouched", Untouched
|
||||
Result.Add "untouched_full", UntouchedFull
|
||||
Set QPReadSnapshot = Result
|
||||
End Function
|
||||
|
||||
|
||||
Reference in new issue
Block a user