56 lines
2.1 KiB
PowerShell
56 lines
2.1 KiB
PowerShell
$ErrorActionPreference = 'Stop'
|
|
|
|
$validator = Join-Path $PSScriptRoot 'validate-maintenance-report.ps1'
|
|
$fixture = Join-Path $PSScriptRoot 'maintenance-report.fixture.json'
|
|
$tempRoot = Join-Path ([IO.Path]::GetTempPath()) ("gitlink-maintenance-validator-" + [Guid]::NewGuid().ToString('N'))
|
|
New-Item -ItemType Directory -Path $tempRoot | Out-Null
|
|
|
|
function Write-Case {
|
|
param([string]$Name, [object]$Report)
|
|
$path = Join-Path $tempRoot "$Name.json"
|
|
[IO.File]::WriteAllText($path, ($Report | ConvertTo-Json -Depth 100), (New-Object Text.UTF8Encoding($false)))
|
|
return $path
|
|
}
|
|
|
|
function Read-Fixture {
|
|
return (Get-Content -Raw -Encoding utf8 $fixture | ConvertFrom-Json)
|
|
}
|
|
|
|
function Assert-Rejected {
|
|
param([string]$Name, [scriptblock]$Mutate)
|
|
$report = Read-Fixture
|
|
& $Mutate $report
|
|
$path = Write-Case $Name $report
|
|
$rejected = $false
|
|
try { & $validator -Path $path | Out-Null } catch { $rejected = $true }
|
|
if (-not $rejected) { throw "validator accepted invalid case: $Name" }
|
|
}
|
|
|
|
try {
|
|
& $validator -Path $fixture | Out-Null
|
|
|
|
Assert-Rejected 'invalid-decision' { param($r) $r.decision = 'ship_it' }
|
|
Assert-Rejected 'negative-count' { param($r) $r.counts.high = -1 }
|
|
Assert-Rejected 'count-mismatch' { param($r) $r.counts.low = 1 }
|
|
Assert-Rejected 'count-distribution-mismatch' { param($r) $r.findings[1].severity = 'high' }
|
|
Assert-Rejected 'severity-mismatch' { param($r) $r.severity = 'low' }
|
|
Assert-Rejected 'unsafe-merge' {
|
|
param($r)
|
|
$r.decision = 'merge'
|
|
$r.security_gate = 'failed'
|
|
}
|
|
Assert-Rejected 'duplicate-evidence' {
|
|
param($r)
|
|
$r.evidence = @($r.evidence[0], $r.evidence[0])
|
|
}
|
|
Assert-Rejected 'invalid-evidence-kind' { param($r) $r.evidence[0].kind = 'guess' }
|
|
Assert-Rejected 'unknown-evidence-reference' { param($r) $r.findings[0].evidence = @('E-MISSING') }
|
|
Assert-Rejected 'non-utc-run' { param($r) $r.run.as_of = '2026-07-20T20:01:10+08:00' }
|
|
|
|
Write-Output 'maintenance report validator tests passed: 1 valid, 10 invalid cases'
|
|
} finally {
|
|
if (Test-Path -LiteralPath $tempRoot) {
|
|
Remove-Item -LiteralPath $tempRoot -Recurse -Force
|
|
}
|
|
}
|