Files
nt8-sdk/tools/preflight/tests/strategy-source-verification.tests.ps1

42 lines
3.3 KiB
PowerShell

$ErrorActionPreference = 'Stop'
. (Join-Path $PSScriptRoot '..\strategy-source-verification.ps1')
$tempRoot = Join-Path ([System.IO.Path]::GetTempPath()) ('strategy-source-verification-' + [guid]::NewGuid().ToString('N'))
$repoRoot = Join-Path $tempRoot 'repo'
$deployedDirectory = Join-Path $tempRoot 'deployed\Strategies'
$pipelineFiles = Get-ExpectedStrategySourceFiles -RepositoryRoot $repoRoot
if ($pipelineFiles.Count -ne 4 -or -not $pipelineFiles.ContainsKey('NT8StrategyBase.cs') -or -not $pipelineFiles.ContainsKey('SimpleORBNT8.cs') -or -not $pipelineFiles.ContainsKey('BaseNT8StrategyWrapper.cs') -or -not $pipelineFiles.ContainsKey('SimpleORBNT8Wrapper.cs')) {
throw 'Deploy-managed source allow-list does not match deployment contract.'
}
$null = New-Item -ItemType Directory -Path (Join-Path $repoRoot 'src\Fixtures') -Force
$null = New-Item -ItemType Directory -Path $deployedDirectory -Force
try {
$repoFiles = @{
'Match.cs' = 'src\Fixtures\Match.cs'
'Mismatch.cs' = 'src\Fixtures\Mismatch.cs'
'Missing.cs' = 'src\Fixtures\Missing.cs'
}
[System.IO.File]::WriteAllText((Join-Path $repoRoot $repoFiles['Match.cs']), 'same')
[System.IO.File]::WriteAllText((Join-Path $repoRoot $repoFiles['Mismatch.cs']), 'repository')
[System.IO.File]::WriteAllText((Join-Path $repoRoot $repoFiles['Missing.cs']), 'repository-only')
[System.IO.File]::WriteAllText((Join-Path $repoRoot 'src\Fixtures\Unexpected.cs'), "namespace Fixture {`r`n public class OrphanType {}`r`n}")
[System.IO.File]::WriteAllText((Join-Path $deployedDirectory 'Match.cs'), 'same')
[System.IO.File]::WriteAllText((Join-Path $deployedDirectory 'Mismatch.cs'), 'deployed')
[System.IO.File]::WriteAllText((Join-Path $deployedDirectory 'Unexpected.cs'), "namespace Fixture {`r`n public class OrphanType {}`r`n}")
[System.IO.File]::WriteAllText((Join-Path $deployedDirectory '@Sample.cs'), 'operator-owned')
$issues = @(Compare-DeployedStrategySources -RepositoryRoot $repoRoot -DeployedDirectory $deployedDirectory -ExpectedFiles $repoFiles)
if ($issues.Count -ne 3) { throw "Expected 3 discrepancies, got $($issues.Count)." }
if (@($issues | Where-Object Kind -eq 'hash-mismatch').Count -ne 1) { throw 'Expected one hash mismatch.' }
if (@($issues | Where-Object Kind -eq 'missing-deployed').Count -ne 1) { throw ('Expected one missing deployed file. Got: ' + [string]::Join(', ', @($issues | ForEach-Object { $_.Kind }))) }
$unexpected = @($issues | Where-Object Kind -eq 'unexpected')
if ($unexpected.Count -ne 1 -or $unexpected[0].File -ne 'Unexpected.cs') { throw 'Unexpected source file was not rejected.' }
if ($unexpected[0].SameNamedSource -ne 'src\Fixtures\Unexpected.cs') { throw 'Unexpected file did not report its matching src path.' }
if ($unexpected[0].RepoTimestamp -eq 'not found' -or $unexpected[0].DeployedTimestamp -eq 'missing') { throw 'Unexpected-file timestamps were not reported.' }
if (@(Get-DeclaredSourceTypeNames -FilePath (Join-Path $deployedDirectory 'Unexpected.cs')) -notcontains 'Fixture.OrphanType') { throw 'Source type-name detection did not identify the orphan type.' }
Write-Output 'PASS strategy-source verification fixture (match, mismatch, missing, allow-listed, unexpected)'
}
finally {
Remove-Item -LiteralPath $tempRoot -Recurse -Force -ErrorAction SilentlyContinue
}