# E07-S01 integration checks for scripts/prepare-disk.ps1. [CmdletBinding()] param() $ErrorActionPreference = "Stop" $project = Split-Path (Split-Path $PSScriptRoot -Parent) -Parent $repository = Split-Path $project -Parent $prepare = Join-Path $project "scripts\prepare-disk.ps1" $buildMinimal = Join-Path $project "scripts\build-minimal.ps1" $source = Join-Path $repository "vim\work.d81" $c1541 = "C:\Program Files\GTK3VICE-3.10-win64\bin\c1541.exe" $testRoot = Join-Path $project "build\disk-test" $output = Join-Path $testRoot "newlang-test.d81" $examples = Join-Path $testRoot "examples" $testCompiler = Join-Path $testRoot "n128c-test.prg" $missing = Join-Path $testRoot "missing" if (-not (Test-Path -LiteralPath $prepare -PathType Leaf)) { throw "prepare-disk.ps1 not found" } if (-not (Test-Path -LiteralPath $source -PathType Leaf)) { throw "test source D81 not found: $source" } if (-not (Test-Path -LiteralPath $c1541 -PathType Leaf)) { throw "test c1541 not found: $c1541" } New-Item -ItemType Directory -Force -Path $examples | Out-Null [IO.File]::WriteAllText((Join-Path $examples "demo.n8"), "program Main`n print `"Nova128`"`nend program`n", [Text.UTF8Encoding]::new($false)) # E01-S01 is this story's completed dependency and provides a known-good PRG. & $buildMinimal | Out-Host $minimal = Join-Path $project "build\minimal.prg" Copy-Item -LiteralPath $minimal -Destination $testCompiler -Force $sourceHashBefore = (Get-FileHash -LiteralPath $source -Algorithm SHA256).Hash $first = & $prepare -SourceImage $source -OutputImage $output -C1541Path $c1541 ` -CompilerPrg $testCompiler -ProbePrg $minimal -ExamplesDirectory $examples ` -RequireCompiler if (-not (Test-Path -LiteralPath $output -PathType Leaf)) { throw "prepare-disk did not create the disposable image" } $firstHash = (Get-FileHash -LiteralPath $output -Algorithm SHA256).Hash $listing = (& $c1541 $output -list 2>&1) -join "`n" foreach ($expected in @( '(?im)"n128c"\s+prg\s*$', '(?im)"n128probe"\s+prg\s*$', '(?im)"demo\.n8"\s+seq\s*$')) { if ($listing -notmatch $expected) { throw "prepared directory lacks expected entry $expected`n$listing" } } # Damage only the generated output, then prove a rebuild returns to the exact # same bytes from the clean source image. [IO.File]::WriteAllBytes($output, [byte[]](1, 2, 3, 4)) $second = & $prepare -SourceImage $source -OutputImage $output -C1541Path $c1541 ` -CompilerPrg $testCompiler -ProbePrg $minimal -ExamplesDirectory $examples ` -RequireCompiler $secondHash = (Get-FileHash -LiteralPath $output -Algorithm SHA256).Hash if ($firstHash -ne $secondHash) { throw "two clean prepares produced different D81 hashes" } $sourceHashAfter = (Get-FileHash -LiteralPath $source -Algorithm SHA256).Hash if ($sourceHashAfter -ne $sourceHashBefore) { throw "source D81 hash changed during prepare test" } # Optional, not-yet-built artifacts must be skipped without preventing a clean # copy. This deliberately uses absent compiler, probe, and examples paths. $optionalOutput = Join-Path $testRoot "optional-only.d81" $optional = & $prepare -SourceImage $source -OutputImage $optionalOutput ` -C1541Path $c1541 -CompilerPrg (Join-Path $missing "n128c.prg") ` -ProbePrg (Join-Path $missing "probe.prg") ` -ExamplesDirectory (Join-Path $missing "examples") 3>&1 if (-not (Test-Path -LiteralPath $optionalOutput -PathType Leaf)) { throw "missing optional artifacts prevented creation of the copied D81" } function Assert-FailsWith { param( [Parameter(Mandatory = $true)][scriptblock]$Action, [Parameter(Mandatory = $true)][string]$Pattern ) $caught = $null try { & $Action } catch { $caught = $_.Exception.Message } if ($null -eq $caught) { throw "expected failure matching '$Pattern', but the command succeeded" } if ($caught -notmatch $Pattern) { throw "failure '$caught' did not match '$Pattern'" } } Assert-FailsWith -Pattern 'source D81 not found' -Action { & $prepare -SourceImage (Join-Path $missing "work.d81") ` -OutputImage (Join-Path $testRoot "never-source.d81") ` -C1541Path $c1541 } Assert-FailsWith -Pattern 'c1541 tool not found' -Action { & $prepare -SourceImage $source ` -OutputImage (Join-Path $testRoot "never-tool.d81") ` -C1541Path (Join-Path $missing "c1541.exe") } Assert-FailsWith -Pattern 'must not be the source' -Action { & $prepare -SourceImage $source -OutputImage $source -C1541Path $c1541 } Write-Host "prepare-disk tests passed" Write-Host "source SHA-256 unchanged: $sourceHashAfter" Write-Host "deterministic output SHA-256: $secondHash" Write-Host "directory entries verified: n128c, n128probe, demo.n8"