test: bind Local G2 diagnostic evidence

This commit is contained in:
梁薄云
2026-08-02 19:43:20 +08:00
parent fdfd853df0
commit 570d132916
2 changed files with 81 additions and 26 deletions
@@ -34,23 +34,30 @@ Assert-Equal 'InsufficientClearance' $evidence.EvaluatorResult 'Diagnostic evide
Assert-Equal 'Clearance' $evidence.StopGate 'Diagnostic evidence must retain the observed stop gate.'
Assert-Equal 'Unchanged' $evidence.PublishedStatus 'Diagnostic evidence must retain the strict final status.'
$temporaryEvidencePath = Join-Path ([System.IO.Path]::GetTempPath()) ("local-g2-diagnostic-evidence-{0}.json" -f [System.Guid]::NewGuid())
try {
$tamperedContent = (Get-Content -LiteralPath $fixturePath -Raw).Replace('"StopGate": "Clearance"', '"StopGate": "Collision"')
[System.IO.File]::WriteAllText($temporaryEvidencePath, $tamperedContent, [System.Text.Encoding]::UTF8)
$rejected = $false
function Assert-Rejected([string]$tamperedContent, [string]$message) {
$temporaryEvidencePath = Join-Path ([System.IO.Path]::GetTempPath()) ("local-g2-diagnostic-evidence-{0}.json" -f [System.Guid]::NewGuid())
try {
$null = $loadAndVerify.Invoke($loader, @($temporaryEvidencePath))
}
catch {
$rejected = $true
}
[System.IO.File]::WriteAllText($temporaryEvidencePath, $tamperedContent, [System.Text.Encoding]::UTF8)
Assert-True $rejected 'Tampered diagnostic evidence must be rejected.'
}
finally {
if (Test-Path -LiteralPath $temporaryEvidencePath) {
Remove-Item -LiteralPath $temporaryEvidencePath -Force
$rejected = $false
try {
$null = $loadAndVerify.Invoke($loader, @($temporaryEvidencePath))
}
catch {
$rejected = $true
}
Assert-True $rejected $message
}
finally {
if (Test-Path -LiteralPath $temporaryEvidencePath) {
Remove-Item -LiteralPath $temporaryEvidencePath -Force
}
}
}
$fixtureContent = Get-Content -LiteralPath $fixturePath -Raw
Assert-Rejected ($fixtureContent.Replace('"StopGate": "Clearance"', '"StopGate": "Collision"')) 'Tampered stop gate must be rejected.'
Assert-Rejected ($fixtureContent.Replace('"HeadingRadians": 0.835253334801853', '"HeadingRadians": 0.935253334801853')) 'Tampered middle candidate heading must be rejected.'
Assert-Rejected ($fixtureContent.Replace('"WindowStartArcLengthMeters": 1.9199999999999982', '"WindowStartArcLengthMeters": 1.8199999999999982')) 'Tampered window must be rejected even when candidate endpoints are unchanged.'
Assert-Rejected ([regex]::Replace($fixtureContent, '(?m)^\s*"SegmentIndex": 0,\r?\n', '')) 'Evidence missing SegmentIndex must be rejected.'