Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
*.swift text eol=lf
*.sh text eol=lf
*.ps1 text eol=lf
*.psm1 text eol=lf
*.cs text eol=lf
*.zig text eol=lf
investigation/macos-parity-evidence/evidence/*.png filter=lfs diff=lfs merge=lfs -text
investigation/visual-baseline/rendered-macos/*.png filter=lfs diff=lfs merge=lfs -text
investigation/visual-baseline/rendered-windows/*.png filter=lfs diff=lfs merge=lfs -text
219 changes: 219 additions & 0 deletions Tools/windows/CandidateAdmission.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
. (Join-Path $PSScriptRoot "SourceReader.ps1")

function Invoke-CandidateAdmissionGit([string] $Repository, [string[]] $Arguments) {
$output = @(& git -C $Repository @Arguments 2>&1)
if ($LASTEXITCODE -ne 0) {
throw "Candidate admission git -C '$Repository' $($Arguments -join ' ') failed: $($output -join '; ')"
}
return $output
}

function Get-CandidateAdmissionFileRecord([string] $Kind, [string] $Path, [string] $RelativeRoot) {
$fullPath = [IO.Path]::GetFullPath($Path)
if (-not (Test-Path -LiteralPath $fullPath -PathType Leaf)) {
throw "Candidate admission $Kind file is missing: $fullPath"
}
$relative = [IO.Path]::GetRelativePath($RelativeRoot, $fullPath).Replace('\', '/')
return [ordered]@{
kind = $Kind
path = $fullPath
relativePath = $relative
length = [IO.FileInfo]::new($fullPath).Length
sha256 = (Get-FileHash -LiteralPath $fullPath -Algorithm SHA256).Hash
}
}

function Get-CandidateAdmissionRepositoryRecord([string] $Name, [string] $Path, [switch] $RequireClean) {
$fullPath = [IO.Path]::GetFullPath($Path)
if (-not (Test-Path -LiteralPath (Join-Path $fullPath ".git"))) {
throw "Candidate admission $Name is not a Git worktree: $fullPath"
}
$head = [string](Invoke-CandidateAdmissionGit $fullPath @("rev-parse", "HEAD") |
Select-Object -Last 1)
$tree = [string](Invoke-CandidateAdmissionGit $fullPath @("rev-parse", "HEAD^{tree}") |
Select-Object -Last 1)
$status = @(Invoke-CandidateAdmissionGit $fullPath @(
"status", "--porcelain=v1", "--untracked-files=all"
))
if ($RequireClean -and $status.Count -ne 0) {
throw "Candidate admission $Name worktree is dirty: $($status -join '; ')"
}
[ordered]@{
name = $Name
path = $fullPath
head = $head
tree = $tree
status = $status
}
}

function Assert-WindowsShellCandidateEnvironment {
$environment = [Environment]::GetEnvironmentVariables('Process')
foreach ($name in @(
'GRAPHCODE_UIA_GATE',
'GRAPHCODE_UIA_SUPERVISED_FOREGROUND',
'GRAPHCODE_UIA_EDGE_ACTION_TRACE'
)) {
if ($environment.Contains($name)) {
throw "Candidate admission requires $name to be absent before Windows shell validation."
}
}
if ($environment.Contains('GRAPHCODE_VALIDATION_ASSEMBLY')) {
$assembly = [Environment]::GetEnvironmentVariable('GRAPHCODE_VALIDATION_ASSEMBLY', 'Process')
if ([string]::IsNullOrEmpty($assembly) -or
-not [IO.Path]::IsPathFullyQualified($assembly) -or
-not (Test-Path -LiteralPath $assembly -PathType Leaf)) {
throw "GRAPHCODE_VALIDATION_ASSEMBLY has an explicitly empty or invalid candidate binding."
}
}
}

function Assert-WindowsShellValidationRootsFresh([string] $Parent) {
$fullParent = [IO.Path]::GetFullPath($Parent)
if (-not (Test-Path -LiteralPath $fullParent -PathType Container)) { return }
$stale = @(Get-ChildItem -LiteralPath $fullParent -Force |
Where-Object { $_.Name -cmatch '^[0-9a-f]{32}$' } |
Sort-Object Name)
if ($stale.Count -ne 0) {
throw "Candidate admission found stale Windows shell validation root(s): " +
(($stale | ForEach-Object FullName) -join ', ')
}
}

function Get-WindowsShellCandidateManifestPaths([string] $WorkspaceRoot) {
$workspace = [IO.Path]::GetFullPath($WorkspaceRoot)
$paths = [Collections.Generic.List[string]]::new()
foreach ($relative in @(
'graphcode-windows\provider-pins.json',
'graphcode-windows\build.zig.zon',
'graphcode-windows\build.zig',
'Tools\windows\ValidationRunner\ValidationRunner.csproj'
)) {
$paths.Add([IO.Path]::GetFullPath((Join-Path $workspace $relative)))
}
$manifestRoot = Join-Path $workspace 'Tools\windows\ValidationRunner\Manifests'
foreach ($manifest in Get-ChildItem -LiteralPath $manifestRoot -Filter '*.json' -File |
Sort-Object FullName) {
$paths.Add($manifest.FullName)
}
return @($paths | Sort-Object -Unique)
}

function Get-CandidateAdmissionPaths([object[]] $Paths) {
$normalized = [Collections.Generic.List[string]]::new()
$pending = [Collections.Generic.Queue[object]]::new()
foreach ($path in @($Paths)) { $pending.Enqueue($path) }
while ($pending.Count -ne 0) {
$candidate = $pending.Dequeue()
if ($candidate -is [string]) {
if ([string]::IsNullOrEmpty($candidate) -or $candidate -match "[`r`n]") {
throw 'Candidate admission paths must be nonempty scalar strings without embedded line endings.'
}
$normalized.Add($candidate)
continue
}
if ($candidate -is [Collections.IEnumerable]) {
foreach ($entry in $candidate) { $pending.Enqueue($entry) }
continue
}
throw "Candidate admission path collection contains an unsupported value of type '$($candidate.GetType().FullName)'."
}
return @($normalized | Sort-Object -Unique)
}

function Get-CandidateAdmissionFileRecords(
[Parameter(Mandatory)][string] $Kind,
[Parameter(Mandatory)][object[]] $Paths,
[Parameter(Mandatory)][string] $RelativeRoot
) {
$records = [Collections.Generic.List[object]]::new()
foreach ($path in @(Get-CandidateAdmissionPaths -Paths $Paths)) {
$records.Add((Get-CandidateAdmissionFileRecord `
-Kind $Kind `
-Path ([string]$path) `
-RelativeRoot $RelativeRoot))
}
return $records.ToArray()
}

function Write-WindowsShellCandidateAdmission(
[Parameter(Mandatory)][string] $WorkspaceRoot,
[Parameter(Mandatory)][string] $ValidationRoot,
[Parameter(Mandatory)][object[]] $BindingPaths,
[Parameter(Mandatory)][string] $WinghosttyRoot,
[Parameter(Mandatory)][string] $ZmxRoot,
[Parameter(Mandatory)][string] $Zig0152,
[Parameter(Mandatory)][string] $Zig0160,
[object[]] $ManifestPaths = @(),
[object[]] $SourcePaths = @()
) {
Assert-WindowsShellCandidateEnvironment
$workspace = [IO.Path]::GetFullPath($WorkspaceRoot)
$validation = [IO.Path]::GetFullPath($ValidationRoot)
$processEnvironment = [Environment]::GetEnvironmentVariables('Process')
$environment = [ordered]@{}
foreach ($name in @(
'GRAPHCODE_UIA_GATE',
'GRAPHCODE_UIA_SUPERVISED_FOREGROUND',
'GRAPHCODE_UIA_EDGE_ACTION_TRACE',
'GRAPHCODE_VALIDATION_ASSEMBLY'
)) {
$environment[$name] = [ordered]@{
present = $processEnvironment.Contains($name)
value = if ($processEnvironment.Contains($name)) {
[Environment]::GetEnvironmentVariable($name, 'Process')
} else { $null }
}
}
$pinsPath = Join-Path $workspace 'graphcode-windows\provider-pins.json'
if (-not (Test-Path -LiteralPath $pinsPath -PathType Leaf)) {
throw "Candidate admission provider pin manifest is missing: $pinsPath"
}
$pins = Read-SemanticSource $pinsPath | ConvertFrom-Json -Depth 20 -ErrorAction Stop
$repository = Get-CandidateAdmissionRepositoryRecord 'workspace' $workspace
$winghostty = Get-CandidateAdmissionRepositoryRecord 'winghostty' $WinghosttyRoot -RequireClean
$zmx = Get-CandidateAdmissionRepositoryRecord 'zmx' $ZmxRoot -RequireClean
if ($winghostty.head -cne [string]$pins.winghostty.sha -or
$zmx.head -cne [string]$pins.zmx.sha) {
throw 'Candidate admission provider worktrees do not match graphcode-windows\provider-pins.json.'
}

$allManifestPaths = @(Get-CandidateAdmissionPaths -Paths @($ManifestPaths, $pinsPath))
$allSourcePaths = @(Get-CandidateAdmissionPaths -Paths $SourcePaths)
$allBindingPaths = @(Get-CandidateAdmissionPaths -Paths $BindingPaths)
$tools = @(
(Get-CandidateAdmissionFileRecord 'zig-0.15.2' $Zig0152 $workspace),
(Get-CandidateAdmissionFileRecord 'zig-0.16.0' $Zig0160 $workspace)
)
$bindings = @(Get-CandidateAdmissionFileRecords `
-Kind 'validation-binding' -Paths $allBindingPaths -RelativeRoot $workspace)
$manifests = @(Get-CandidateAdmissionFileRecords `
-Kind 'manifest' -Paths $allManifestPaths -RelativeRoot $workspace)
$sources = @(Get-CandidateAdmissionFileRecords `
-Kind 'source' -Paths $allSourcePaths -RelativeRoot $workspace)
if ($bindings.Count -eq 0 -or $manifests.Count -eq 0 -or $sources.Count -eq 0) {
throw 'Candidate admission requires binding, manifest and source hashes.'
}
$record = [ordered]@{
schemaVersion = 1
environment = $environment
validationRoot = $validation
repository = $repository
providers = [ordered]@{
winghostty = $winghostty
zmx = $zmx
}
tools = $tools
bindings = $bindings
manifests = $manifests
sources = $sources
}
$path = Join-Path $validation 'candidate-admission.json'
$json = $record | ConvertTo-Json -Depth 30 -Compress
[IO.File]::WriteAllText($path, $json + "`n", [Text.UTF8Encoding]::new($false))
[pscustomobject]@{
Path = $path
Sha256 = (Get-FileHash -LiteralPath $path -Algorithm SHA256).Hash
Json = $json
}
}
14 changes: 14 additions & 0 deletions Tools/windows/SourceReader.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
function ConvertTo-SemanticSourceText([string] $Source) {
return $Source.Replace("`r`n", "`n")
}

function Read-SemanticSource([string] $Path) {
$fullPath = [IO.Path]::GetFullPath($Path)
$bytes = [IO.File]::ReadAllBytes($fullPath)
if ($bytes.Length -ge 3 -and $bytes[0] -eq 0xEF -and $bytes[1] -eq 0xBB -and
$bytes[2] -eq 0xBF) {
throw [IO.InvalidDataException]::new("Semantic source must be UTF-8 without BOM: $fullPath")
}
$text = [Text.UTF8Encoding]::new($false, $true).GetString($bytes)
return ConvertTo-SemanticSourceText $text
}
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,8 @@ exit $result
$start.CreateNoWindow = $true
$start.RedirectStandardOutput = $true
$start.RedirectStandardError = $true
[Text.Encoding]::RegisterProvider([Text.CodePagesEncodingProvider]::Instance)
$wrapperEncoding = [Text.Encoding]::GetEncoding([ShellOwnedLaunch]::OemCodePage(),
[Text.EncoderFallback]::ExceptionFallback, [Text.DecoderFallback]::ExceptionFallback)
$start.StandardOutputEncoding = $wrapperEncoding
$start.StandardErrorEncoding = $wrapperEncoding
$start.StandardOutputEncoding = [Text.UTF8Encoding]::new($false, $true)
$start.StandardErrorEncoding = [Text.UTF8Encoding]::new($false, $true)
foreach ($argument in @(
"-NoProfile", "-File", $wrapper, "-NativeScript",
$NativeScriptUnderTest, "-VcVars", $vcvars,
Expand Down Expand Up @@ -221,10 +218,10 @@ exit $result
-not $proof.cleanup.StdoutEof -or -not $proof.cleanup.StderrEof -or -not $proof.cleanup.ResourcesClosed) {
throw "Native mock failure did not retain exact exit and successful held cleanup proof"
}
if ($proof.stdoutCodePage -ne [ShellOwnedLaunch]::OemCodePage() -or
if ($proof.stdoutCodePage -ne 65001 -or
$proof.stderrCodePage -ne $proof.stdoutCodePage) { throw "cmd producer encodings were not bound explicitly" }
if ($Stage -ceq "compile" -and -not $output.Contains((Join-Path $fixture "cl.cmd"))) {
throw "Controlled non-ASCII compiler path did not roundtrip through cmd's actual OEM codec"
throw "Controlled non-ASCII compiler path did not roundtrip through cmd's UTF-8 codec"
}
if ($output -notmatch '\[native-harness\] original PATH restored') {
throw "RED: native harness did not restore the exact original PATH after $Stage failure"
Expand Down
8 changes: 3 additions & 5 deletions Tools/windows/Tests/AccessibilityProvider.Native.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ try {
# Keep batch source ASCII; pass Unicode paths through cmd arguments.
$command = @'
@echo off
chcp 65001 >nul
cd /d "%~dp0"
if errorlevel 1 exit /b %errorlevel%
echo [native-uia] stage=vcvars start
Expand Down Expand Up @@ -204,11 +205,8 @@ exit /b %test_exit%
$native.WorkingDirectory = $scratch
$native.RedirectStandardOutput = $true
$native.RedirectStandardError = $true
[Text.Encoding]::RegisterProvider([Text.CodePagesEncodingProvider]::Instance)
$oemEncoding = [Text.Encoding]::GetEncoding([ShellOwnedLaunch]::OemCodePage(),
[Text.EncoderFallback]::ExceptionFallback, [Text.DecoderFallback]::ExceptionFallback)
$native.StandardOutputEncoding = $oemEncoding
$native.StandardErrorEncoding = $oemEncoding
$native.StandardOutputEncoding = [Text.UTF8Encoding]::new($false, $true)
$native.StandardErrorEncoding = [Text.UTF8Encoding]::new($false, $true)
foreach ($argument in @("/d", "/s", "/c", "run-native.cmd")) { $native.ArgumentList.Add($argument) }
$native.Environment["GRAPHCODE_NATIVE_VCVARS"] = [IO.Path]::GetFullPath($VcVars)
$native.Environment["GRAPHCODE_NATIVE_TEST"] = $test
Expand Down
Loading
Loading