$hash) { if (! hash_equals($hash, hash_file('sha256', $root.'/'.$file))) { throw new LogicException('Reviewed replenishment task source changed.'); } } if (! $check) { $approval = json_decode(file_get_contents($root.'/docs/proofs/replenishment-task-authorization.json'), true, 32, JSON_THROW_ON_ERROR); if (($approval['state'] ?? null) !== 'approved' || ($approval['scope'] ?? null) !== 'existing_pilot_replenishment_task' || ! hash_equals($approval['proposal_sha256'], hash_file('sha256', $planPath))) { throw new LogicException('Replenishment passage not authorized.'); } } foreach ([...$settings, 'DB_CONNECTION' => 'pgsql', 'DB_URL' => '', 'PGOPTIONS' => $check ? '-c default_transaction_read_only=on' : '', 'CACHE_STORE' => $check ? 'array' : ($settings['CACHE_STORE'] ?? 'file'), 'LOG_CHANNEL' => 'stderr'] as $key => $value) { putenv($key.'='.$value); $_ENV[$key] = $_SERVER[$key] = $value; } $app = require $root.'/bootstrap/app.php'; $app->make(Kernel::class)->bootstrap(); app(StandaloneRuntime::class)->assertLoadedPackages(); if (! app(ReplenishmentQueue::class)->ready()) { throw new LogicException('Native replenishment capability unavailable.'); } if ($check) { if (DB::selectOne('SHOW default_transaction_read_only')->default_transaction_read_only !== 'on') { throw new LogicException('Read-only task preflight required.'); } echo json_encode(['state' => 'ready', 'database_enforced_read_only' => true, 'health' => app(ReplenishmentQueue::class)->health(), 'task_started' => false], JSON_THROW_ON_ERROR).PHP_EOL; exit; } // The native command owns process exclusion, durable recovery and bound heartbeat. exit(Artisan::call('sgc:replenishment-tick'));