# E07-S02 integration checks for scripts/launch-editor.ps1 and # scripts/launch-compiler.ps1. [CmdletBinding()] param() $ErrorActionPreference = "Stop" $project = Split-Path (Split-Path $PSScriptRoot -Parent) -Parent $repository = Split-Path $project -Parent $launchEditor = Join-Path $project "scripts\launch-editor.ps1" $launchCompiler = Join-Path $project "scripts\launch-compiler.ps1" $modulePath = Join-Path $project "scripts\lib\Nova128Launcher.psm1" $source = Join-Path $repository "vim\vim-improved.d81" $minimal = Join-Path $project "build\minimal.prg" $testRoot = Join-Path $project "build\launcher-test" $diskA = Join-Path $testRoot "editor.d81" $diskB = Join-Path $testRoot "compiler.d81" $editorShot = Join-Path $testRoot "editor.png" $compilerShot = Join-Path $testRoot "compiler.png" foreach ($path in @($launchEditor, $launchCompiler, $modulePath)) { if (-not (Test-Path -LiteralPath $path -PathType Leaf)) { throw "missing $path" } } if (-not (Test-Path -LiteralPath $source -PathType Leaf)) { throw "source image missing: $source" } New-Item -ItemType Directory -Force -Path $testRoot | Out-Null & (Join-Path $project "scripts\build-minimal.ps1") | Out-Host if (-not (Test-Path -LiteralPath $minimal -PathType Leaf)) { throw "minimal PRG missing" } Import-Module $modulePath -Force 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 it succeeded" } if ($caught -notmatch $Pattern) { throw "failure '$caught' did not match '$Pattern'" } } $sourceHashBefore = (Get-FileHash -LiteralPath $source -Algorithm SHA256).Hash # 1: missing inputs are reported before any emulator starts. Assert-FailsWith -Pattern 'editor program not found' -Action { & $launchEditor -EditorPrg (Join-Path $testRoot "missing.prg") ` -SourceImage $source -DiskImage $diskA } Assert-FailsWith -Pattern 'compiler program not found' -Action { & $launchCompiler -CompilerPrg (Join-Path $testRoot "missing.prg") ` -DiskImage $diskB -SkipPrepare } # 2: an editor session owns the image for the duration; a live lock blocks the # compiler launcher on the same folder. Copy-Item -LiteralPath $source -Destination $diskA -Force $held = Enter-Nova128ImageSession -Image $diskA -Kind "editor" try { Assert-FailsWith -Pattern 'still owns|already holds' -Action { & $launchCompiler -CompilerPrg $minimal -DiskImage $diskA -SkipPrepare } } finally { Exit-Nova128ImageSession -Session $held } if (Test-Path -LiteralPath (Join-Path $testRoot ".newlang-session.lock")) { throw "the session lock was not released" } # 3: flush waiting refuses a locked image and accepts a released one. $partner = [IO.File]::Open($diskA, [IO.FileMode]::Open, [IO.FileAccess]::Read, [IO.FileShare]::None) try { Assert-FailsWith -Pattern 'still locked' -Action { Wait-Nova128ImageFlush -Image $diskA -TimeoutSeconds 1 } } finally { $partner.Dispose() } Wait-Nova128ImageFlush -Image $diskA -TimeoutSeconds 2 # 4: the editor launcher autostarts its program in x64sc on a fresh copy and # returns only after the process exits and the image flushes. & $launchEditor -EditorPrg $minimal -SourceImage $source -DiskImage $diskA ` -LimitCycles 2000000 -Screenshot $editorShot -Warp if (-not (Test-Path -LiteralPath $editorShot)) { throw "editor launcher produced no screenshot" } $editorListing = (& "C:\Program Files\GTK3VICE-3.10-win64\bin\c1541.exe" $diskA -list 2>&1) -join "`n" if ($editorListing -notmatch '(?im)"vim128"\s+prg') { throw "the editor launcher did not put vim128 on the session disk" } # 5: the compiler launcher autostarts its program in x128 and leaves the # disposable image flushed and unlocked. Copy-Item -LiteralPath $source -Destination $diskB -Force & $launchCompiler -CompilerPrg $minimal -DiskImage $diskB -LimitCycles 2000000 ` -Screenshot $compilerShot -Warp -SkipPrepare if (-not (Test-Path -LiteralPath $compilerShot)) { throw "compiler launcher produced no screenshot" } Wait-Nova128ImageFlush -Image $diskB -TimeoutSeconds 2 $sourceHashAfter = (Get-FileHash -LiteralPath $source -Algorithm SHA256).Hash if ($sourceHashAfter -ne $sourceHashBefore) { throw "the Vim source image changed during the session tests" } Write-Host "launcher tests passed" Write-Host "editor disk copy (vim128 injected), lock refusal, flush wait, x128 editor and compiler autostart" Write-Host "source disk unchanged: $sourceHashAfter"