@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
use App\Services\OrderCancellationRuntime;
|
||||
use Illuminate\Contracts\Console\Kernel;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
require dirname(__DIR__).'/vendor/autoload.php';
|
||||
if (count($argv) !== 2 || ! in_array($argv[1], ['--read-only', '--installed-read-only'], true)) {
|
||||
throw new LogicException('Explicit cancellation read-only check required.');
|
||||
}
|
||||
$root = dirname(__DIR__);
|
||||
$installed = $argv[1] === '--installed-read-only';
|
||||
$sourcePath = 'C:/laragon/data/sgf-tempo/secrets/payables-demo-compras.json';
|
||||
$before = file_get_contents($sourcePath);
|
||||
$source = json_decode($before, true, 32, JSON_THROW_ON_ERROR);
|
||||
$plan = json_decode(file_get_contents($root.'/docs/proofs/order-cancellation-pilot-proposal.json'), true, 32, JSON_THROW_ON_ERROR);
|
||||
if ($source['APP_ENV'] !== 'payable-testing' || $source['DB_HOST'] !== '127.0.0.1' || (string) $source['DB_PORT'] !== '5432'
|
||||
|| realpath($source['HOST_ROOT']) !== realpath($root)
|
||||
|| ! preg_match('/^compras_receipts_test_([a-f0-9]{12})$/D', $source['DB_DATABASE'], $match)
|
||||
|| $source['DB_USERNAME'] !== 'payable_qa_'.$match[1]
|
||||
|| $source['COMPRAS_RUNTIME_INSTALLATION_ID'] !== '0602a856-0413-480f-9ef3-1a1f3238bb90'
|
||||
|| ($installed ? array_intersect_key($source, $plan['proposed_settings_only']) !== $plan['proposed_settings_only']
|
||||
: ! hash_equals($plan['settings_before_sha256'], hash('sha256', $before)))) {
|
||||
throw new LogicException('Cancellation pilot identity or settings differ.');
|
||||
}
|
||||
$environment = [...$source, 'APP_ENV' => 'pilot-readonly', 'APP_DEBUG' => 'false', 'DB_CONNECTION' => 'pgsql', 'DB_URL' => '',
|
||||
'PGOPTIONS' => '-c default_transaction_read_only=on', 'CACHE_STORE' => 'array', 'SESSION_DRIVER' => 'array',
|
||||
'QUEUE_CONNECTION' => 'null', 'MAIL_MAILER' => 'array', 'LOG_CHANNEL' => 'stderr',
|
||||
'COMPRAS_ORDER_CANCELLATION_ENABLED' => 'true',
|
||||
'COMPRAS_ORDER_CANCELLATION_ROOT' => $installed ? $plan['target_root'] : $root.'/'.$plan['candidate_root'],
|
||||
'APP_CONFIG_CACHE' => $root.'/storage/framework/absent-cancellation-readonly-config.php'];
|
||||
foreach ($environment as $key => $value) {
|
||||
putenv($key.'='.$value);
|
||||
$_ENV[$key] = $_SERVER[$key] = $value;
|
||||
}
|
||||
$app = require $root.'/bootstrap/app.php';
|
||||
$app->make(Kernel::class)->bootstrap();
|
||||
if (DB::selectOne('SHOW default_transaction_read_only')->default_transaction_read_only !== 'on') {
|
||||
throw new LogicException('Enforced read-only database required.');
|
||||
}
|
||||
app(OrderCancellationRuntime::class)->assertReady();
|
||||
app(OrderCancellationRuntime::class)->load(0); // Byte-checked class loading only, no reversal command.
|
||||
if (! hash_equals(hash('sha256', $before), hash_file('sha256', $sourcePath))) {
|
||||
throw new LogicException('Concurrent cancellation configuration edit.');
|
||||
}
|
||||
$result = ['date' => gmdate('c'), 'state' => 'passed', 'installed' => $installed, 'database_enforced_read_only' => true,
|
||||
'manifest_sha256' => OrderCancellationRuntime::MANIFEST_SHA256,
|
||||
'existing_cancellation_records' => DB::table('order_cancellations')->count(),
|
||||
'existing_approved_policies' => DB::table('order_cancellation_policies')->where('status', 'approved')->count(),
|
||||
'new_policies_grants_business_commands_or_settings_changes' => false];
|
||||
file_put_contents($root.'/docs/proofs/order-cancellation-pilot-'.($installed ? 'postcheck' : 'preflight').'.json', json_encode($result, JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR).PHP_EOL);
|
||||
echo json_encode($result, JSON_THROW_ON_ERROR).PHP_EOL;
|
||||
Reference in New Issue
Block a user