Skip to content
Open
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
34 changes: 29 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,20 +84,44 @@ jobs:
- name: Test isolation refusal and readiness guards
if: runner.os == 'Windows'
shell: pwsh
run: ./scripts/test-windows-disposable-profile-guards.ps1
- name: Prove disposable-profile isolation
run: |
./scripts/test-windows-disposable-profile-guards.ps1
./scripts/test-windows-recovery-guards.ps1
- name: Prove disposable-profile isolation, recovery row 1 (Local older, Roaming newer)
if: runner.os == 'Windows'
shell: pwsh
run: >-
./scripts/test-windows-disposable-profile.ps1
-ServerExe target/debug/aw-server.exe
-EvidencePath "${{ runner.temp }}/windows-disposable-profile-evidence.json"
- name: Retain Windows isolation evidence
-User awrow1
-EvidencePath "${{ runner.temp }}/windows-recovery-row1-evidence.json"
-ScenarioPath scripts/windows-recovery-scenarios/row1-local-older-roaming-newer.ps1
# Each row gets its own disposable user and profile, so rows cannot see
# one another's databases. A failed row does not hide the others.
- name: Windows recovery row 2 (stale Local testing history, newer Roaming)
if: ${{ !cancelled() && runner.os == 'Windows' }}
Comment thread
TimeToBuildBob marked this conversation as resolved.
Resolved
shell: pwsh
run: >-
./scripts/test-windows-disposable-profile.ps1
-ServerExe target/debug/aw-server.exe
-User awrow2
-EvidencePath "${{ runner.temp }}/windows-recovery-row2-evidence.json"
-ScenarioPath scripts/windows-recovery-scenarios/row2-stale-local-testing-newer-roaming.ps1
- name: Windows recovery row 3 (Roaming history, missed Python history)
if: ${{ !cancelled() && runner.os == 'Windows' }}
shell: pwsh
run: >-
./scripts/test-windows-disposable-profile.ps1
-ServerExe target/debug/aw-server.exe
-User awrow3
-EvidencePath "${{ runner.temp }}/windows-recovery-row3-evidence.json"
-ScenarioPath scripts/windows-recovery-scenarios/row3-roaming-with-missed-python-history.ps1
- name: Retain Windows recovery evidence
if: always() && runner.os == 'Windows'
uses: actions/upload-artifact@v7
with:
name: windows-disposable-profile-evidence
path: ${{ runner.temp }}/windows-disposable-profile-evidence.json
path: ${{ runner.temp }}/windows-recovery-row*-evidence.json
if-no-files-found: warn
- name: Run tests
run: cargo test --workspace --verbose
Expand Down
32 changes: 31 additions & 1 deletion scripts/test-windows-disposable-profile.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ param(

[int]$TimeoutSeconds = 120,

[string]$EvidencePath = (Join-Path $env:TEMP 'windows-disposable-profile-evidence.json')
[string]$EvidencePath = (Join-Path $env:TEMP 'windows-disposable-profile-evidence.json'),

# Optional recovery scenario, dot-sourced after the isolation proof passes
# and while the disposable user, profile and first server still exist.
[string]$ScenarioPath
)

Set-StrictMode -Version Latest
Expand Down Expand Up @@ -145,6 +149,20 @@ function Wait-ProfileInitTask {
throw "profile-init task timed out after $TimeoutSeconds seconds"
}

function Wait-ServerHttpReady {
param($Process, [int]$Port, [int]$TimeoutSeconds = 120)
$deadline = (Get-Date).AddSeconds($TimeoutSeconds)
while ((Get-Date) -lt $deadline) {
if ($Process.HasExited) { break }
try {
$null = Invoke-RestMethod -Uri "http://127.0.0.1:$Port/api/0/info" -TimeoutSec 3
return
}
catch { Start-Sleep -Milliseconds 500 }
}
throw "server HTTP API did not become ready on port $Port (exited: $($Process.HasExited))"
}

function Get-ProfileTail {
param([string]$Dir)
if (-not (Test-Path -LiteralPath $Dir)) {
Expand Down Expand Up @@ -453,6 +471,18 @@ try {
Write-Host 'Disposable-profile isolation proven:'
Write-Host " datastore: $expectedDb ($($evidence['datastore_bytes']) bytes, owner $owner)"
Write-Host " runner profile untouched: $runnerActivityWatch absent"

if ($ScenarioPath) {
# A SQLite header precedes Rocket startup. Never write fixtures until
# the server accepts HTTP, even when native-root isolation is proven.
Wait-ServerHttpReady -Process $serverProcess -Port $port -TimeoutSeconds $TimeoutSeconds
$evidence['scenario_http_ready'] = $true
# Scenario context: $exe $User $credential $disposableProfile $serverProcess
# $port $runId $evidence. The scenario owns every process it starts.
Write-Host "Running recovery scenario: $ScenarioPath"
. (Resolve-Path -LiteralPath $ScenarioPath).Path
Comment thread
TimeToBuildBob marked this conversation as resolved.
Resolved
$evidence['conclusion'] = 'disposable Known Folder roots proven; recovery scenario passed'
}
}
catch {
$failure = $_.Exception.Message
Expand Down
177 changes: 177 additions & 0 deletions scripts/test-windows-recovery-guards.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
#Requires -Version 5.1
# Hermetic regressions for the recovery harness; no Windows account or server.
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
$mainPath = Join-Path $PSScriptRoot 'test-windows-disposable-profile.ps1'
$commonPath = Join-Path $PSScriptRoot 'windows-recovery-scenarios/common.ps1'
$tokens = $null
$errors = $null
$ast = [System.Management.Automation.Language.Parser]::ParseFile($mainPath, [ref]$tokens, [ref]$errors)
if ($errors.Count) { throw ($errors | Out-String) }
$waiter = $ast.Find({ param($node)
$node -is [System.Management.Automation.Language.FunctionDefinitionAst] -and
$node.Name -eq 'Wait-ServerHttpReady'
}, $true)
if ($null -eq $waiter) { throw 'missing HTTP readiness waiter' }
. ([scriptblock]::Create($waiter.Extent.Text))
. $commonPath
function Assert-True {
param([bool]$Condition, [string]$Message)
if (-not $Condition) { throw $Message }
}
$root = Join-Path ([IO.Path]::GetTempPath()) ([guid]::NewGuid().ToString('N'))
New-Item -ItemType Directory -Path $root | Out-Null
$savedPublic = $env:Public
$savedSystemRoot = $env:SystemRoot
try {
& {
$script:clock = [datetime]'2026-01-01'
$script:polls = 0
function Get-Date { return $script:clock }
function Start-Sleep { param($Milliseconds) $script:clock = $script:clock.AddMilliseconds($Milliseconds) }
function Invoke-RestMethod {
param($Uri, $TimeoutSec)
$script:polls++
if ($script:polls -lt 3) { throw 'HTTP not ready' }
return @{ version = 'test' }
}
Wait-ServerHttpReady -Process ([pscustomobject]@{ HasExited = $false }) -Port 1234 -TimeoutSeconds 2
Assert-True ($script:polls -eq 3) 'HTTP readiness did not retry transient startup failures'
function Invoke-RestMethod { param($Uri, $TimeoutSec) throw 'never ready' }
$caught = $null
try { Wait-ServerHttpReady -Process ([pscustomobject]@{ HasExited = $false }) -Port 1234 -TimeoutSeconds 1 }
catch { $caught = $_.Exception.Message }
Assert-True ($null -ne $caught -and $caught -like '*HTTP*') 'HTTP timeout accepted'

# Execute the actual scenario hook: even with a valid SQLite file,
# a failed HTTP wait must stop it before the scenario writes fixtures.
$hook = $ast.Find({ param($node)
$node -is [System.Management.Automation.Language.IfStatementAst] -and
$node.Extent.Text -like 'if ($ScenarioPath)*'
}, $true)
$ScenarioPath = Join-Path $root 'scenario.ps1'
Set-Content -LiteralPath $ScenarioPath -Value '$script:scenarioRan = $true'
$script:scenarioRan = $false
# Pin the URL the hook polls: the mock used to ignore $Uri, so a
# harness polling the wrong port would have passed this guard.
$script:polledUris = @()
function Invoke-RestMethod { param($Uri, $TimeoutSec) $script:polledUris += $Uri; throw 'never ready' }
$serverProcess = [pscustomobject]@{ HasExited = $false }
$port = 1234
$TimeoutSeconds = 1
$evidence = @{}
$caught = $null
try { . ([scriptblock]::Create($hook.Extent.Text)) }
Comment thread
TimeToBuildBob marked this conversation as resolved.
Resolved
catch { $caught = $_.Exception.Message }
Assert-True ($null -ne $caught -and -not $script:scenarioRan) 'scenario ran before HTTP was ready'
Assert-True (($script:polledUris.Count -gt 0) -and -not ($script:polledUris | Where-Object { $_ -ne 'http://127.0.0.1:1234/api/0/info' })) `
"scenario hook polled the wrong URL: $($script:polledUris -join ', ')"
}

& {
$env:Public = $root
$env:SystemRoot = $root
$exe = 'fake-server.exe'
$credential = $null
$runId = 'guard'
$scenario = @{}
$script:killed = $false
$script:waited = $false
$script:clock = [datetime]'2026-01-01'
function Get-Date { $script:clock = $script:clock.AddSeconds(121); return $script:clock }
Comment thread
TimeToBuildBob marked this conversation as resolved.
Resolved
function Start-Process {
param($FilePath, $ArgumentList, $Credential, [switch]$LoadUserProfile, [switch]$UseNewEnvironment, $WorkingDirectory, [switch]$PassThru)
Set-Content -LiteralPath (Join-Path $root 'aw-timeout-guard.log') -Value 'startup diagnostic'
$proc = [pscustomobject]@{ Id = 42; HasExited = $false }
$proc | Add-Member ScriptMethod WaitForExit { param($Timeout) $script:waited = $true; return $true }
return $proc
}
function taskkill.exe {
Assert-True (($args -join ' ') -eq '/PID 42 /T /F') 'wrong process tree killed'
$script:killed = $true
}
$caught = $null
try { Start-ScenarioServer -Name 'timeout' -Port 1234 -ExtraArgs '' }
Comment thread
TimeToBuildBob marked this conversation as resolved.
Resolved
catch { $caught = $_.Exception.Message }
Assert-True ($caught -like '*startup diagnostic*') 'startup diagnostic lost'
Assert-True ($script:killed -and $script:waited) 'timed-out process was leaked'
Assert-True (-not (Test-Path (Join-Path $root 'aw-timeout-guard.cmd'))) 'wrapper leaked'
Assert-True (-not (Test-Path (Join-Path $root 'aw-timeout-guard.log'))) 'log leaked'
Assert-True ($scenario['log_1234'] -contains 'startup diagnostic') 'cleanup discarded evidence'
}

& {
$scenario = @{}
$script:clock = [datetime]'2026-01-01'
$script:reads = 0
function Get-Date { return $script:clock }
function Start-Sleep { param($Seconds) $script:clock = $script:clock.AddSeconds($Seconds) }
function Invoke-RestMethod {
param($Uri, $TimeoutSec)
if ($Uri -notlike '*/events*') { return [pscustomobject]@{ 'aw-guard' = 1 } }
$script:reads++
if ($script:reads -lt 3) { throw 'bucket not found' }
return @([pscustomobject]@{ data = [pscustomobject]@{ sentinel = 'A-1' } })
}
$got = Wait-ScenarioSentinels -Port 1234 -Expected @('A-1') -Bucket 'aw-guard'
Assert-True ((($got -join ',') -eq 'A-1') -and $script:reads -eq 3) 'sentinel polling aborted on a transient read failure'
function Invoke-RestMethod { param($Uri, $TimeoutSec) throw 'bucket never appeared' }
$caught = $null
try { $null = Wait-ScenarioSentinels -Port 1234 -Expected @('A-1') -Bucket 'aw-guard' -TimeoutSeconds 5 }
catch { $caught = $_.Exception.Message }
Assert-True ($caught -like '*never appeared*') 'persistent sentinel read failure was reported as empty'
}

& {
$scenario = @{}
foreach ($case in @('zero', 'inserted', 'skipped', 'missing')) {
$inserted = if ($case -eq 'inserted') { 1 } else { 0 }
$skipped = if ($case -eq 'skipped') { 3 } else { 0 }
$scenario['log_1234'] = if ($case -eq 'missing') { @('unrelated log') } else {
@("INFO History recovery from source: 0 buckets created, $inserted events inserted, $skipped duplicates skipped")
}
$caught = $null
try { Assert-NoRecoveryWork -Port 1234 }
catch { $caught = $_.Exception.Message }
Assert-True (($null -eq $caught) -eq ($case -eq 'zero')) "incorrect zero-work verdict for $case"
}
$scenario['log_1234'] = @('INFO History recovery from source: 0 buckets created, 0 events inserted, 3 duplicates skipped')
Assert-NoRecoveryWork -Port 1234 -AllowSkipped
}
& {
$rowPath = Join-Path $PSScriptRoot 'windows-recovery-scenarios/row1-local-older-roaming-newer.ps1'
$rowAst = [System.Management.Automation.Language.Parser]::ParseFile($rowPath, [ref]$tokens, [ref]$errors)
if ($errors.Count) { throw ($errors | Out-String) }
$preservation = $rowAst.Find({ param($node)
Comment thread
TimeToBuildBob marked this conversation as resolved.
Resolved
$node -is [System.Management.Automation.Language.ForEachStatementAst] -and
$node.Extent.Text -like '*pre-migration-*'
}, $true)
if ($null -eq $preservation) { throw 'missing original-tree assertions' }
$disposableProfile = $root
$localApp = Join-Path $root 'Local/aw-server-rust'
$roamApp = Join-Path $root 'Roaming/aw-server-rust'
$localBackup = "$localApp.pre-migration-test"
$roamBackup = "$roamApp.migrated-test"
foreach ($dir in @($localApp, $roamApp, $localBackup, $roamBackup)) {
New-Item -ItemType Directory -Path $dir -Force | Out-Null
Set-Content -LiteralPath (Join-Path $dir 'sqlite.db') -Value 'fixture'
}
$scenario = @{}
. ([scriptblock]::Create($preservation.Extent.Text))
foreach ($backup in @($localBackup, $roamBackup)) {
$db = Join-Path $backup 'sqlite.db'
Remove-Item -LiteralPath $db
$caught = $null
try { . ([scriptblock]::Create($preservation.Extent.Text)) }
catch { $caught = $_.Exception.Message }
Assert-True ($null -ne $caught -and $caught -like '*not retained*') 'active database masked a missing original'
Set-Content -LiteralPath $db -Value 'fixture'
}
}
Write-Host 'PASS: HTTP readiness gates fixtures, startup timeout cleans its process tree and evidence, sentinel polling retries transient reads, restart counts fail closed, both originals required'
}
finally {
$env:Public = $savedPublic
$env:SystemRoot = $savedSystemRoot
Remove-Item -LiteralPath $root -Recurse -Force
}
Loading
Loading