feat(01-05): complete offline Windows collection agenda and selftests
Prepare all session materials, explicit terminal outcomes and raw-media provenance while retaining open acceptance. Verify the package-free collector on synthetic fixtures without redistributing external tools.
This commit is contained in:
1 parent
c9b9f2eba9
commit
857466568d
4 files changed
+510
-22
No files matched your search
@@ -9,11 +9,13 @@ param(
|
||||
[string]$DxWndPath, [string]$ProfilePath, [string]$RecorderPath,
|
||||
[string]$BrowserPath, [string]$SettingsPath, [string]$AnnotationPath,
|
||||
[string]$ArtifactsDirectory, [string]$Reason,
|
||||
[ValidateSet('captured','failed','skipped','aborted')][string]$Outcome = 'captured',
|
||||
[ValidateRange(1,14400)][int]$TimeoutSeconds = 7200,
|
||||
[switch]$LibraryOnly
|
||||
)
|
||||
Set-StrictMode -Version 2
|
||||
$ErrorActionPreference = 'Stop'
|
||||
$script:CollectorSource = $PSCommandPath
|
||||
|
||||
function Test-FidelityId([string]$Value) {
|
||||
if ($Value -cnotmatch '^[A-Za-z0-9][A-Za-z0-9_.-]{0,95}$' -or
|
||||
@@ -65,7 +67,7 @@ function Read-FidelityJson([string]$Path) {
|
||||
}
|
||||
|
||||
function Write-FidelityJson([string]$Path, $Value) {
|
||||
$text = ($Value | ConvertTo-Json -Depth 40) + "`n"
|
||||
$text = (ConvertTo-Json -InputObject $Value -Depth 40) + "`n"
|
||||
$bytes = (New-Object Text.UTF8Encoding($false)).GetBytes($text)
|
||||
if ($bytes.Length -gt 4194304) { throw 'JSON exceeds 4 MiB' }
|
||||
$temporary = $Path + '.incomplete-' + [guid]::NewGuid().ToString('N')
|
||||
@@ -146,8 +148,10 @@ function Invoke-FidelityProcess([string]$Executable, [string[]]$Arguments,
|
||||
$out = [IO.File]::Open((Join-Path $OutputDirectory 'stdout.txt'),[IO.FileMode]::CreateNew)
|
||||
$err = [IO.File]::Open((Join-Path $OutputDirectory 'stderr.txt'),[IO.FileMode]::CreateNew)
|
||||
$timer = [Diagnostics.Stopwatch]::StartNew()
|
||||
$started = $false
|
||||
try {
|
||||
if (-not $process.Start()) { throw 'Process did not start' }
|
||||
$started = $process.Start()
|
||||
if (-not $started) { throw 'Process did not start' }
|
||||
$stdout = $process.StandardOutput.BaseStream.CopyToAsync($out)
|
||||
$stderr = $process.StandardError.BaseStream.CopyToAsync($err)
|
||||
while (-not $process.WaitForExit(200)) {
|
||||
@@ -155,15 +159,28 @@ function Invoke-FidelityProcess([string]$Executable, [string[]]$Arguments,
|
||||
$process.Kill(); $process.WaitForExit(); throw 'Process timed out or logs exceeded 64 MiB'
|
||||
}
|
||||
}
|
||||
$stdout.GetAwaiter().GetResult(); $stderr.GetAwaiter().GetResult()
|
||||
$remaining = [int][Math]::Max(1,($Seconds - $timer.Elapsed.TotalSeconds) * 1000)
|
||||
if (-not [Threading.Tasks.Task]::WaitAll([Threading.Tasks.Task[]]@($stdout,$stderr),$remaining)) {
|
||||
throw 'Process output did not close within the bounded wait'
|
||||
}
|
||||
$null = $stdout.GetAwaiter().GetResult(); $null = $stderr.GetAwaiter().GetResult()
|
||||
if ($out.Length -gt 67108864 -or $err.Length -gt 67108864) { throw 'Process logs exceeded 64 MiB' }
|
||||
return @{exit_code=$process.ExitCode; elapsed_seconds=$timer.Elapsed.TotalSeconds;
|
||||
executable=$Executable; argv=@($Executable)+$Arguments; cwd=$WorkingDirectory}
|
||||
} finally {
|
||||
if ($process.Id -and -not $process.HasExited) { $process.Kill(); $process.WaitForExit() }
|
||||
if ($started -and -not $process.HasExited) { $process.Kill(); $process.WaitForExit() }
|
||||
$out.Dispose(); $err.Dispose(); $process.Dispose(); $timer.Stop()
|
||||
}
|
||||
}
|
||||
|
||||
function Get-FidelityOutcome([string]$Prior, [string]$Requested, [string]$Why) {
|
||||
if ($Prior -notin @('incomplete','failed','skipped','aborted') -or
|
||||
$Requested -notin @('captured','failed','skipped','aborted')) { throw 'Invalid outcome' }
|
||||
if ($Prior -ne 'incomplete' -and $Requested -ne $Prior) { throw 'Failed/terminal run cannot be promoted; use a new session' }
|
||||
if ($Requested -ne 'captured' -and -not $Why) { throw 'Failure/skip/abort requires a reason' }
|
||||
return $Requested
|
||||
}
|
||||
|
||||
function Get-FidelityPlatform {
|
||||
$result = @{os='windows'; execution='native'; version=[Environment]::OSVersion.VersionString;
|
||||
powershell=$PSVersionTable.PSVersion.ToString(); gpu=''; driver=''; vulkan=''; sdl=''}
|
||||
@@ -222,24 +239,27 @@ function Start-FidelityRun {
|
||||
if ($manifest.tooling_only) { throw 'Synthetic checkpoint cannot launch native/original evidence' }
|
||||
$protocol = Read-FidelityJson (Join-Path $root 'protocol/scenarios.json')
|
||||
if ($CaseId -notin @($protocol.cells | ForEach-Object {$_.id})) { throw 'Unknown scenario cell' }
|
||||
if ($Action -in @('Skip','Abort')) {
|
||||
$receipt.status = Get-FidelityOutcome 'incomplete' $(if ($Action -eq 'Skip') {'skipped'} else {'aborted'}) $Reason
|
||||
$receipt.limitations = @($Reason)
|
||||
return 0
|
||||
}
|
||||
$platform = Get-FidelityPlatform
|
||||
$platform.execution = $(if ($Mode -eq 'original') {'dxwnd'} else {'native'})
|
||||
$receipt.platform = $platform
|
||||
$receipt.identity.checkpoint = Copy-FidelityEvidence (Join-Path $root 'manifest.json') $run 'identity/checkpoint.json'
|
||||
$receipt.identity.launcher = Copy-FidelityEvidence $PSCommandPath $run 'identity/collector.ps1'
|
||||
$receipt.identity.launcher = Copy-FidelityEvidence $script:CollectorSource $run 'identity/collector.ps1'
|
||||
$tools = @{}
|
||||
foreach ($entry in @(@('recorder',$RecorderPath),@('browser',$BrowserPath),@('settings',$SettingsPath))) {
|
||||
if (-not $entry[1]) { throw ('Select actual local ' + $entry[0] + ' file; no downloads are performed') }
|
||||
$id = Copy-FidelityEvidence $entry[1] $run ('identity/' + $entry[0] + [IO.Path]::GetExtension($entry[1]))
|
||||
# Identify external tools; do not redistribute their executables/installers.
|
||||
$id = Get-FidelityIdentity $entry[1]
|
||||
$tools[$entry[0]] = @{selected_path=$entry[1]; identity=$id;
|
||||
version=[Diagnostics.FileVersionInfo]::GetVersionInfo($entry[1]).FileVersion}
|
||||
}
|
||||
$receipt.identity.settings = Copy-FidelityEvidence $SettingsPath $run 'identity/settings.json'
|
||||
Write-FidelityJson (Join-Path $run 'tools.json') $tools
|
||||
if ($Action -in @('Skip','Abort')) {
|
||||
if (-not $Reason) { throw 'A skipped/aborted run requires a reason' }
|
||||
$receipt.status = $(if ($Action -eq 'Skip') {'skipped'} else {'aborted'})
|
||||
$receipt.limitations = @($Reason)
|
||||
} elseif ($Mode -eq 'port') {
|
||||
if ($Mode -eq 'port') {
|
||||
$package = Join-Path $root 'port/win-x64'
|
||||
$exe = Join-Path $package 'GamePort.exe'
|
||||
$receipt.identity.executable = Copy-FidelityEvidence $exe $run 'identity/GamePort.exe'
|
||||
@@ -263,7 +283,10 @@ function Start-FidelityRun {
|
||||
$receipt.limitations = @('Port process exited; media/event mapping and human review pending; observer overhead is diagnostic')
|
||||
} else {
|
||||
if (-not $DxWndPath -or -not $ProfilePath) { throw 'Select actual local DxWnd executable and exported profile' }
|
||||
$receipt.identity.dxwnd = Copy-FidelityEvidence $DxWndPath $run 'identity/dxwnd.exe'
|
||||
$dxwndId = Get-FidelityIdentity $DxWndPath
|
||||
Write-FidelityJson (Join-Path $run 'dxwnd-tool.json') @{selected_path=$DxWndPath;identity=$dxwndId;
|
||||
version=[Diagnostics.FileVersionInfo]::GetVersionInfo($DxWndPath).FileVersion}
|
||||
$receipt.identity.dxwnd = @{path='dxwnd-tool.json'} + (Get-FidelityIdentity (Join-Path $run 'dxwnd-tool.json'))
|
||||
$receipt.identity.dxwnd_config = Copy-FidelityEvidence $ProfilePath $run 'identity/original-profile.dxw'
|
||||
$copy = Get-FidelityPath $root ('original-runs/' + $SessionId)
|
||||
if (Test-Path -LiteralPath $copy) { throw 'Original run copy exists' }
|
||||
@@ -282,8 +305,6 @@ function Start-FidelityRun {
|
||||
$wrapper = [Diagnostics.Process]::Start($info)
|
||||
$receipt.invocation = @{argv=@($info.FileName);cwd=$copy;method='manual profile import and GUI launch; original child exit not inferred'}
|
||||
$null = Read-Host 'After the original has exited and recording stopped, press Enter (keep this collector alive during retained prerequisites)'
|
||||
Write-FidelityJson (Join-Path $run 'copy-post.json') @(Get-FidelityTree $copy)
|
||||
$receipt.identity.copy_post = @{path='copy-post.json'} + (Get-FidelityIdentity (Join-Path $run 'copy-post.json'))
|
||||
$receipt.wrapper_settings = 'Selected profile retained; relocated export/settings and wrapper limitations require annotation review'
|
||||
$receipt.limitations = @('DxWnd GUI launched; original child invocation/exit and visible/audible behavior require actual session annotations')
|
||||
$wrapper.Dispose()
|
||||
@@ -292,9 +313,16 @@ function Start-FidelityRun {
|
||||
$receipt.status = 'failed'; $receipt.limitations = @($_.Exception.Message)
|
||||
Write-Warning $_.Exception.Message
|
||||
} finally {
|
||||
if ($Mode -eq 'original' -and (Get-Variable copy -ErrorAction SilentlyContinue) -and
|
||||
(Test-Path -LiteralPath $copy) -and -not (Test-Path -LiteralPath (Join-Path $run 'copy-post.json'))) {
|
||||
try {
|
||||
Write-FidelityJson (Join-Path $run 'copy-post.json') @(Get-FidelityTree $copy)
|
||||
$receipt.identity.copy_post = @{path='copy-post.json'} + (Get-FidelityIdentity (Join-Path $run 'copy-post.json'))
|
||||
} catch { $receipt.status = 'failed'; $receipt.limitations += ('Postflight failed: ' + $_.Exception.Message) }
|
||||
}
|
||||
$clock.wall_end = [DateTime]::UtcNow.ToString('o'); $clock.monotonic_end = $watch.Elapsed.TotalSeconds
|
||||
Write-FidelityJson (Join-Path $run 'run.json') $receipt
|
||||
if ($receipt.status -in @('failed','skipped','aborted')) { Write-FidelityJson (Join-Path $run 'receipt.json') $receipt }
|
||||
if ($receipt.status -in @('failed','skipped','aborted')) { Write-FidelityJson (Join-Path $run 'failure.json') $receipt }
|
||||
$watch.Stop()
|
||||
}
|
||||
Write-Host "Result: $run ; status=$($receipt.status); acceptance OPEN"
|
||||
@@ -309,6 +337,34 @@ function Complete-FidelityRun {
|
||||
if (Test-Path -LiteralPath (Join-Path $run 'receipt.json')) { throw 'Result already finalized; preserve it and use a new result ID' }
|
||||
if (-not $AnnotationPath -or -not $ArtifactsDirectory) { throw 'Finish requires actual annotations and a local artifact directory' }
|
||||
$annotation = Read-FidelityJson $AnnotationPath
|
||||
$requested = Get-FidelityOutcome $receipt.status $Outcome $Reason
|
||||
if ($annotation.schema_version -ne 1) { throw 'Unsupported annotation schema' }
|
||||
if (@($annotation.artifacts).Count -gt 10000) { throw 'Too many artifacts' }
|
||||
$names = @{}
|
||||
foreach ($file in $annotation.artifacts) {
|
||||
$null = Get-FidelityPath $ArtifactsDirectory $file.path
|
||||
if ($names.ContainsKey($file.path)) { throw 'Duplicate/case-aliased artifact' }; $names[$file.path] = $file
|
||||
$null = Get-FidelityIdentity (Get-FidelityPath $ArtifactsDirectory $file.path)
|
||||
if ($file.PSObject.Properties.Name -contains 'synthetic' -and $file.synthetic) { throw 'Synthetic media cannot be relabeled as native/original' }
|
||||
}
|
||||
foreach ($event in $annotation.events) {
|
||||
if (-not $names.ContainsKey($event.artifact)) { throw 'Event references missing artifact' }
|
||||
}
|
||||
if ($requested -eq 'captured') {
|
||||
if (-not @($annotation.artifacts | Where-Object {$_.role -eq 'video' -and $_.path.EndsWith('.mkv',[StringComparison]::OrdinalIgnoreCase)}).Count) {
|
||||
throw 'Captured result requires retained raw MKV video'
|
||||
}
|
||||
if (-not @($annotation.artifacts | Where-Object {$_.role -eq 'audio'}).Count) { throw 'Captured result requires actual audio evidence' }
|
||||
}
|
||||
foreach ($derivative in $annotation.derivatives) {
|
||||
if (-not $names.ContainsKey($derivative.path) -or -not $names.ContainsKey($derivative.source) -or
|
||||
-not $derivative.tool -or -not $derivative.version -or -not $derivative.created_utc -or
|
||||
-not @($derivative.argv).Count -or -not $derivative.timestamp_mapping -or
|
||||
-not $derivative.crop_aspect -or $derivative.browser_playback_verified -isnot [bool] -or
|
||||
-not $derivative.browser_playback_verified) {
|
||||
throw 'Derivative requires source/output, actual tool/version/argv/time/crop and verified browser playback'
|
||||
}
|
||||
}
|
||||
$receipt.artifacts = @()
|
||||
foreach ($file in $annotation.artifacts) {
|
||||
$source = Get-FidelityPath $ArtifactsDirectory $file.path
|
||||
@@ -319,14 +375,30 @@ function Complete-FidelityRun {
|
||||
}
|
||||
$copied = Copy-FidelityEvidence $AnnotationPath $run 'annotations.json'
|
||||
$copied.role = 'input_events'; $receipt.artifacts += $copied
|
||||
$receipt.events = @($annotation.events)
|
||||
$receipt.derivatives = @($annotation.derivatives)
|
||||
$receipt.status = 'captured'
|
||||
$receipt.events = @($annotation.events | ForEach-Object {
|
||||
if (-not $names.ContainsKey($_.artifact)) { throw 'Event references missing artifact' }
|
||||
$_.artifact = 'media/' + $_.artifact; $_
|
||||
})
|
||||
$receipt.derivatives = @($annotation.derivatives | ForEach-Object {
|
||||
$_.path = 'media/' + $_.path; $_.source = 'media/' + $_.source; $_
|
||||
})
|
||||
$receipt.status = $requested
|
||||
if ($annotation.PSObject.Properties.Name -contains 'continuity') {
|
||||
$continuity = $annotation.continuity
|
||||
if ($continuity.PSObject.Properties.Name -contains 'prerequisite_artifact') {
|
||||
if (-not $names.ContainsKey($continuity.prerequisite_artifact)) { throw 'Continuity references missing artifact' }
|
||||
$continuity.prerequisite_artifact = 'media/' + $continuity.prerequisite_artifact
|
||||
}
|
||||
$receipt | Add-Member -Force -NotePropertyName continuity -NotePropertyValue $continuity
|
||||
}
|
||||
if ($annotation.PSObject.Properties.Name -contains 'diagnostic') { $receipt | Add-Member -Force -NotePropertyName diagnostic -NotePropertyValue ([bool]$annotation.diagnostic) }
|
||||
if ($Reason) { $receipt.limitations += $Reason }
|
||||
$receipt.limitations += @($annotation.limitations)
|
||||
# Human declarations remain source annotations; the shared importer and final
|
||||
# audit validate times, hashes, category, continuity and actual review later.
|
||||
$receipt.limitations += 'Imported annotations require shared validation; raw MKV and incomplete/failed cases are retained'
|
||||
Write-FidelityJson (Join-Path $run 'receipt.json') $receipt
|
||||
Write-Host 'Captured result saved; acceptance OPEN. Return full checkpoint locally for validation.'
|
||||
Write-Host "Result saved ($requested); acceptance OPEN. Return full checkpoint locally for validation."
|
||||
}
|
||||
|
||||
if ($LibraryOnly) { return }
|
||||
|
||||
Reference in new issue
Block a user