make(Kernel::class)->bootstrap(); $root = dirname(__DIR__); $host = realpath($root.'/../sgf-tempo'); $config = DB::connection('pgsql')->getConfig(); if ($config['host'] !== '127.0.0.1') { throw new RuntimeException('Prova apenas local.'); } config(['database.connections.access_admin' => [...$config, 'url' => null, 'database' => 'postgres']]); $db = DB::connection('access_admin'); $suffix = bin2hex(random_bytes(6)); $role = 'ir_composition_'.$suffix; $database = 'sgc_composition_'.$suffix; $password = bin2hex(random_bytes(32)); $roleCreated = false; $databaseCreated = false; $code = 1; $before = file_get_contents($host.'/packages/purchasing/current.json'); try { $prepare = new Process([PHP_BINARY, $root.'/scripts/prepare-sgf-operational.php', $host], $root); $prepare->mustRun(); $overlay = json_decode($prepare->getOutput(), true, 16, JSON_THROW_ON_ERROR)['directory']; require $root.'/tests/Support/sgf-composition-clone.php'; $clone = compositionClone($host, $overlay, $suffix); $db->statement('CREATE ROLE "'.$role.'" LOGIN NOSUPERUSER NOCREATEDB NOCREATEROLE PASSWORD '.$db->getPdo()->quote($password)); $roleCreated = true; $db->statement('CREATE DATABASE "'.$database.'" OWNER "'.$role.'"'); $databaseCreated = true; $env = ['APP_ENV' => 'production', 'APP_DEBUG' => 'false', 'APP_KEY' => 'base64:'.base64_encode(random_bytes(32)), 'DB_CONNECTION' => 'pgsql', 'DB_URL' => '', 'DB_HOST' => '127.0.0.1', 'DB_PORT' => (string) $config['port'], 'DB_DATABASE' => $database, 'DB_USERNAME' => $role, 'DB_PASSWORD' => $password, 'CACHE_STORE' => 'array', 'SESSION_DRIVER' => 'array', 'IR_SGF_HOST' => $host, 'IR_CANDIDATE_ROOT' => $root, 'IR_ACCESS_OVERLAY' => $overlay]; $env += ['IR_CLONE' => $clone, 'SESSION_DRIVER' => 'file']; $env['SESSION_DRIVER'] = 'file'; $env['SESSION_FILES'] = $clone.'/storage/framework/sessions'; $env['SESSION_COOKIE'] = 'composition_'.$suffix; $env['APP_BASE_PATH'] = $clone; $process = new Process(['powershell.exe', '-NoProfile', '-ExecutionPolicy', 'Bypass', '-File', $host.'/scripts/sgf.ps1', 'php', $root.'/tests/Support/sgf-composition-proof.php'], $host, $env, null, 120); $process->mustRun(); try { $proof = json_decode($process->getOutput(), true, 32, JSON_THROW_ON_ERROR); } catch (JsonException $error) { file_put_contents($clone.'/diagnostic.txt', $process->getOutput().$process->getErrorOutput()); throw new RuntimeException('Diagnóstico privado: '.$clone.'/diagnostic.txt'); } if (! $proof['passed'] || file_get_contents($host.'/packages/purchasing/current.json') !== $before || json_decode($before, true)['version'] !== '0.1.1') { throw new RuntimeException('Prova ou preservação do destino falhou.'); } $proof += ['overlay' => $overlay, 'checked_at' => gmdate('c'), 'destination_version' => '0.1.1', 'prior_tests_repeated' => false]; $code = 0; } catch (Throwable $error) { fwrite(STDERR, $error->getMessage()."\n"); } finally { if ($databaseCreated) { $db->select('select pg_terminate_backend(pid) from pg_stat_activity where datname=? and pid<>pg_backend_pid()', [$database]); $db->statement('DROP DATABASE "'.$database.'"'); } if ($roleCreated) { $db->statement('DROP ROLE "'.$role.'"'); } } if ($code === 0) { $proof['isolated_database_removed'] = true; file_put_contents($root.'/docs/proofs/sgf-composition-delivery.json', json_encode($proof, JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR)); echo json_encode($proof, JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR)."\n"; } exit($code);