fix(01): WR-02 recover interrupted Windows runs without invented clocks
This commit is contained in:
1 parent
548c97aa58
commit
2608517c37
5 files changed
+86
-2
No files matched your search
@@ -150,6 +150,12 @@ powershell.exe -NoProfile -File .\scripts\collect-fidelity-windows.ps1 -Action S
|
||||
selection. An interrupted active run retains its initial `incomplete.json`;
|
||||
when safe, collect its artifacts with `Finish -Outcome aborted -Reason '...'`
|
||||
instead of pretending a separate aborted launch describes its lifetime.
|
||||
When only `incomplete.json` survived, this command preserves its exact bytes as
|
||||
a diagnostic artifact and permits only `aborted`. End clocks remain absent;
|
||||
initial placeholder end values are discarded. Keep recovered media and source
|
||||
notes, with an empty `events` array because no complete launch interval was
|
||||
observed. The receipt remains open and importable; recovery does not establish
|
||||
missing executable identity, process completion, or a captured/reviewed run.
|
||||
Failed starts preserve `run.json`, `failure.json` and available logs. To collect
|
||||
failed/skipped/aborted media use `Finish -Outcome failed|skipped|aborted` matching
|
||||
the prior status, a reason and annotation/artifact directories (empty arrays are
|
||||
|
||||
@@ -333,12 +333,28 @@ function Complete-FidelityRun {
|
||||
$null = Test-FidelityId $SessionId
|
||||
$run = Get-FidelityPath $Bundle ('results/' + $SessionId)
|
||||
$null = Test-FidelityBundle $Bundle
|
||||
$receipt = Read-FidelityJson (Join-Path $run 'run.json')
|
||||
$runPath = Join-Path $run 'run.json'
|
||||
$recovering = -not (Test-Path -LiteralPath $runPath)
|
||||
if ($recovering) {
|
||||
if ($Outcome -ne 'aborted') { throw 'Interrupted initial record can only be finalized as aborted' }
|
||||
$runPath = Join-Path $run 'incomplete.json'
|
||||
}
|
||||
$receipt = Read-FidelityJson $runPath
|
||||
if ($recovering) {
|
||||
if ($receipt.status -ne 'incomplete' -or $receipt.session_id -cne $SessionId) { throw 'Interrupted initial record does not match the incomplete session' }
|
||||
# Initial records from older collectors contain placeholder end values.
|
||||
# Neither those placeholders nor recovery time observed the process end.
|
||||
$receipt.clocks.PSObject.Properties.Remove('wall_end')
|
||||
$receipt.clocks.PSObject.Properties.Remove('monotonic_end')
|
||||
$receipt.missing_evidence += 'Interrupted collector: end clocks and launch-aligned observations unavailable'
|
||||
$receipt | Add-Member -Force -NotePropertyName diagnostic -NotePropertyValue $true
|
||||
}
|
||||
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 ($recovering -and @($annotation.events).Count) { throw 'Interrupted run has no observed end interval; retain annotations without launch-aligned events' }
|
||||
if (@($annotation.artifacts).Count -gt 10000) { throw 'Too many artifacts' }
|
||||
$names = @{}
|
||||
foreach ($file in $annotation.artifacts) {
|
||||
@@ -366,6 +382,11 @@ function Complete-FidelityRun {
|
||||
}
|
||||
}
|
||||
$receipt.artifacts = @()
|
||||
if ($recovering) {
|
||||
$initial = Copy-FidelityEvidence $runPath $run 'recovery-initial.json'
|
||||
$initial.role = 'diagnostic'
|
||||
$receipt.artifacts += $initial
|
||||
}
|
||||
foreach ($file in $annotation.artifacts) {
|
||||
$source = Get-FidelityPath $ArtifactsDirectory $file.path
|
||||
$id = Copy-FidelityEvidence $source $run ('media/' + $file.path)
|
||||
|
||||
@@ -177,6 +177,37 @@ try {
|
||||
Assert-True ($saved.status -eq $state -and $saved.artifacts.Count -eq 1 -and $saved.events -is [array] -and $saved.events.Count -eq 0 -and $saved.acceptance.state -eq 'open') 'Terminal fixture changed'
|
||||
}
|
||||
}
|
||||
Check 'incomplete-only interrupted recovery preserves launch bytes and absent end clocks' {
|
||||
$script:SessionId = 'fixture-interrupted'
|
||||
$interruptedRun = Join-Path $bundleRoot ('results/' + $SessionId)
|
||||
$null = [IO.Directory]::CreateDirectory($interruptedRun)
|
||||
$initial = New-FidelityReceipt $SessionId 'fresh-natural-ordinary' 'continuous' 'synthetic' 'incomplete' @{os='test';execution='synthetic'} $clock 'Interrupted synthetic collector'
|
||||
Write-FidelityJson (Join-Path $interruptedRun 'incomplete.json') $initial
|
||||
$before = Get-FidelityIdentity (Join-Path $interruptedRun 'incomplete.json')
|
||||
$script:AnnotationPath = Join-Path $temporary 'interrupted-notes.json'
|
||||
Write-FidelityJson $AnnotationPath @{schema_version=1;artifacts=@(@{path='raw.mkv';role='video';duration_seconds=2});events=@();derivatives=@();limitations=@('Recovered synthetic media only')}
|
||||
$script:Reason = 'Interrupted before final collector state'
|
||||
$script:Outcome = 'captured'
|
||||
Assert-Throws { Complete-FidelityRun }
|
||||
Assert-True (-not (Test-Path -LiteralPath (Join-Path $interruptedRun 'receipt.json'))) 'Interrupted record promoted'
|
||||
$script:Outcome = 'aborted'
|
||||
[IO.File]::Delete($AnnotationPath)
|
||||
Write-FidelityJson $AnnotationPath @{schema_version=1;artifacts=@();events=@(@{name='invented';artifact='raw.mkv';elapsed_seconds=1});derivatives=@();limitations=@()}
|
||||
Assert-Throws { Complete-FidelityRun }
|
||||
Assert-True (-not (Test-Path -LiteralPath (Join-Path $interruptedRun 'recovery-initial.json'))) 'Invalid recovery wrote evidence'
|
||||
[IO.File]::Delete($AnnotationPath)
|
||||
Write-FidelityJson $AnnotationPath @{schema_version=1;artifacts=@(@{path='raw.mkv';role='video';duration_seconds=2});events=@();derivatives=@();limitations=@('Recovered synthetic media only')}
|
||||
Complete-FidelityRun
|
||||
$saved = Read-FidelityJson (Join-Path $interruptedRun 'receipt.json')
|
||||
Assert-True ($saved.status -eq 'aborted' -and $saved.acceptance.state -eq 'open' -and $saved.session_id -ceq $SessionId) 'Recovery changed launch/status'
|
||||
Assert-True ($saved.clocks.PSObject.Properties.Name -notcontains 'wall_end' -and $saved.clocks.PSObject.Properties.Name -notcontains 'monotonic_end') 'Recovery invented end clocks'
|
||||
$rawInitial = Read-FidelityJson (Join-Path $interruptedRun 'incomplete.json')
|
||||
Assert-True ($saved.clocks.wall_start -eq $rawInitial.clocks.wall_start -and $saved.clocks.monotonic_start -eq $rawInitial.clocks.monotonic_start) 'Recovery changed initial clocks'
|
||||
Assert-True ((Get-FidelityIdentity (Join-Path $interruptedRun 'incomplete.json')).sha256 -eq $before.sha256) 'Recovery changed raw initial bytes'
|
||||
Assert-True ($saved.artifacts[0].path -eq 'recovery-initial.json' -and $saved.artifacts[0].sha256 -eq $before.sha256) 'Missing raw initial identity'
|
||||
Assert-True (Test-Path -LiteralPath (Join-Path $interruptedRun 'media/raw.mkv')) 'Missing recovered media'
|
||||
Assert-Throws { Complete-FidelityRun }
|
||||
}
|
||||
if ($FixtureOutput) {
|
||||
if (Test-Path -LiteralPath $FixtureOutput) { throw 'Fixture output must be new' }
|
||||
$null = [IO.Directory]::CreateDirectory($FixtureOutput)
|
||||
|
||||
@@ -193,6 +193,24 @@ class FidelityScenarios(unittest.TestCase):
|
||||
value['acceptance'] = {'state': 'open', 'remaining': [status]}
|
||||
self.assertEqual(api.audit_scenarios(self.protocol(), [(value, root)])['accepted'], 0)
|
||||
|
||||
def test_aborted_missing_end_clocks_imports_without_invented_observations(self):
|
||||
value, root = self.receipt()
|
||||
value['status'] = 'aborted'
|
||||
value['acceptance'] = {'state': 'open', 'remaining': ['interrupted']}
|
||||
value['events'] = []
|
||||
for field in ('wall_end', 'monotonic_end'):
|
||||
del value['clocks'][field]
|
||||
(root / 'receipt.json').write_bytes(api.canonical_bytes(value))
|
||||
imported = api.import_receipt(root / 'receipt.json', root, self.base / 'imports')
|
||||
path = Path(imported['path'])
|
||||
saved = api.read_receipt(path)
|
||||
result = api.validate_receipt(saved, path.parent)
|
||||
self.assertFalse(result['accepted'])
|
||||
self.assertNotIn('wall_end', saved['clocks'])
|
||||
self.assertNotIn('monotonic_end', saved['clocks'])
|
||||
value['status'] = 'reviewed'
|
||||
with self.assertRaises(ValueError): api.validate_receipt(value, root)
|
||||
|
||||
def test_missing_event_and_media_out_of_range_rejected(self):
|
||||
value, root = self.receipt()
|
||||
value['events'].pop()
|
||||
|
||||
@@ -331,9 +331,15 @@ def validate_receipt(receipt, root):
|
||||
if not isinstance(clocks, dict):
|
||||
raise ValueError('Clocks must be an object')
|
||||
start, end = clocks.get('monotonic_start'), clocks.get('monotonic_end')
|
||||
if not _finite(start) or not _finite(end) or start < 0 or end < start:
|
||||
missing_end = (status == 'aborted' and receipt.get('acceptance', {}).get('state') == 'open'
|
||||
and end is None and clocks.get('wall_end') is None)
|
||||
if not _finite(start) or start < 0 or (not missing_end and (not _finite(end) or end < start)):
|
||||
raise ValueError('Invalid/reset monotonic clocks')
|
||||
if missing_end and receipt['events']:
|
||||
raise ValueError('Missing end clocks cannot bound launch-aligned event observations')
|
||||
for key in ('wall_start', 'wall_end'):
|
||||
if key == 'wall_end' and missing_end:
|
||||
continue
|
||||
try:
|
||||
dt = datetime.fromisoformat(clocks[key].replace('Z', '+00:00'))
|
||||
if dt.tzinfo is None:
|
||||
@@ -395,6 +401,8 @@ def validate_receipt(receipt, root):
|
||||
if synthetic and kind != 'synthetic':
|
||||
raise ValueError('Synthetic artifacts cannot be relabeled as runtime evidence')
|
||||
missing = list(receipt['missing_evidence']) + list(acceptance['remaining'])
|
||||
if missing_end:
|
||||
missing.append('Interrupted collector end clocks unavailable')
|
||||
if kind not in ('native_port', 'original_dxwnd'):
|
||||
missing.append(kind + ' is not original/native gameplay acceptance')
|
||||
if receipt['historical']:
|
||||
|
||||
Reference in new issue
Block a user