commit compras1 3011
tests / ci (push) Canceled after 0s

This commit is contained in:
2026-11-30 09:33:36 +02:00
parent 96b30368bc
commit 47649bd46c
163 changed files with 9419 additions and 145 deletions
@@ -0,0 +1,64 @@
<?php
declare(strict_types=1);
require dirname(__DIR__).'/integrations/sgf/operational/CodeDeployment.php';
use Tempo\Purchasing\Delivery\CodeDeployment;
$root = dirname(__DIR__);
$host = realpath($root.'/../sgf-tempo');
$bundle = realpath($argv[1] ?? '');
if (! $host || ! $bundle || ! str_starts_with($bundle, realpath($root.'/storage/app/private/candidates').DIRECTORY_SEPARATOR)) {
throw new RuntimeException('Only an existing private candidate can be rehearsed.');
}
$manifest = json_decode(file_get_contents($bundle.'/manifest.json'), true, 64, JSON_THROW_ON_ERROR);
$pin = hash_file('sha256', $bundle.'/manifest.json');
$pointer = file_get_contents($host.'/packages/purchasing/current.json');
$checks = [];
$check = function (bool $condition, string $label) use (&$checks): void {
if (! $condition) {
throw new RuntimeException($label);
}
$checks[] = $label;
};
$destination = $root.'/storage/framework/testing/sgf-integration-recovery-'.bin2hex(random_bytes(6));
mkdir($destination, 0700, true);
foreach ($manifest['host_overlays'] as $path => $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]);