$entry) { if (str_contains($path, '..') || str_starts_with($path, '/') || str_contains($path, ':')) { throw new RuntimeException('Unsafe candidate path.'); } if (! is_dir(dirname($destination.'/'.$path))) { mkdir(dirname($destination.'/'.$path), 0700, true); } $check(hash_file('sha256', $host.'/'.$path) === $entry['before_sha256'], 'source unchanged '.$path); copy($host.'/'.$path, $destination.'/'.$path); } foreach (['packages/purchasing', 'bootstrap/cache', 'storage/framework'] as $dir) { if (! is_dir($destination.'/'.$dir)) { mkdir($destination.'/'.$dir, 0700, true); } } file_put_contents($destination.'/packages/purchasing/current.json', $pointer); file_put_contents($destination.'/storage/framework/down', '{}'); $deploy = new CodeDeployment($destination); $plan = $deploy->plan($bundle, $pin); $check($plan['writes'] === false, 'plan read only'); $applied = $deploy->apply($bundle, $pin, $plan['target_sha256'], 'Synthetic integration recovery', true); foreach ($manifest['host_overlays'] as $path => $entry) { $check(hash_file('sha256', $destination.'/'.$path) === $entry['after_sha256'], 'candidate applied '.$path); } $check($deploy->apply($bundle, $pin, $plan['target_sha256'], 'Synthetic integration recovery', true)['replayed'] === true, 'retry idempotent'); $rolled = $deploy->rollback($applied['deployment_id'], 'Synthetic integration recovery', true); $check($rolled['state'] === 'rolled-back', 'rollback completed'); foreach ($manifest['host_overlays'] as $path => $entry) { $check(hash_file('sha256', $destination.'/'.$path) === $entry['before_sha256'], 'previous code restored '.$path); $check(hash_file('sha256', $host.'/'.$path) === $entry['before_sha256'], 'actual host preserved '.$path); } $check(file_get_contents($host.'/packages/purchasing/current.json') === $pointer, 'actual host pointer preserved'); $proof = ['date' => gmdate('c'), 'candidate' => basename($bundle), 'manifest_sha256' => $pin, 'passed' => true, 'checks' => $checks, 'file_copy' => $destination, 'database_connected' => false, 'schema_changed' => false, 'destination_installed' => false, 'new_demo' => false, 'services_restarted' => false, 'business_flow_acceptance' => false]; file_put_contents($root.'/docs/proofs/sgf-total-integration-recovery-20261130.json', json_encode($proof, JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR)."\n"); echo json_encode(['passed' => true, 'checks' => count($checks), 'installed' => false, 'database_connected' => false]);