| 1 | #requires -Version 5.1 |
| 2 | # Test frame rejection and output handling without accessing any desktop. |
| 3 | $ErrorActionPreference = 'Stop' |
| 4 | . (Join-Path $PSScriptRoot 'claude-window-windows.ps1') |
| 5 | |
| 6 | if ($PSVersionTable.PSEdition -eq 'Desktop') { |
| 7 | Add-Type -TypeDefinition $cageWindowSource -ReferencedAssemblies System.Drawing |
| 8 | } else { |
| 9 | $references = @((Get-ChildItem "$PSHOME/ref/*.dll").FullName) + @([Drawing.Bitmap].Assembly.Location) |
| 10 | $references += @((Get-ChildItem "$PSHOME/System.Private.Windows.*.dll").FullName) |
| 11 | Add-Type -TypeDefinition $cageWindowSource -ReferencedAssemblies $references |
| 12 | } |
| 13 | |
| 14 | if ([CageClaudeWindow]::FrameProblem([int[]]@()) -ne 'empty_frame' -or |
| 15 | [CageClaudeWindow]::FrameProblem([int[]]@(0, 0x010204)) -ne 'black_frame' -or |
| 16 | [CageClaudeWindow]::FrameProblem([int[]]@(0xFAFAFA, 0xFBFBFB)) -ne 'uniform_frame' -or |
| 17 | [CageClaudeWindow]::FrameProblem([int[]]@(0xFAFAFA, 0x111111))) { |
| 18 | throw 'Blank or nonuniform frame classification failed.' |
| 19 | } |
| 20 | |
| 21 | $output = Join-Path ([IO.Path]::GetTempPath()) ("cage-window-" + [guid]::NewGuid() + ".png") |
| 22 | if ((Get-ClaudeCapturePath $output) -ne [IO.Path]::GetFullPath($output)) { throw 'Failed to accept a temporary PNG.' } |
| 23 | try { |
| 24 | [IO.File]::WriteAllText($output, 'preserve') |
| 25 | foreach ($bad in @($output, "$output.txt", [IO.Path]::Combine([IO.Path]::GetDirectoryName($output), '..', 'outside.png'))) { |
| 26 | $rejected = $false |
| 27 | try { $null = Get-ClaudeCapturePath $bad } catch { $rejected = $true } |
| 28 | if (!$rejected) { throw "Accepted invalid output: $bad" } |
| 29 | } |
| 30 | if ([IO.File]::ReadAllText($output) -cne 'preserve') { throw 'Existing output was changed.' } |
| 31 | } finally { [IO.File]::Delete($output) } |
| 32 | Write-Output 'Passed simulated Claude window frame and output-path checks.' |