'testing', 'DB_CONNECTION' => 'pgsql', 'DB_HOST' => '127.0.0.1', 'DB_PORT' => '55441', 'DB_DATABASE' => 'anchor_restore_20261007_test', 'DB_USERNAME' => 'postgres', 'DB_PASSWORD' => '', 'DB_URL' => ''] as $key => $value) { putenv($key.'='.$value); $_ENV[$key] = $_SERVER[$key] = $value; } require dirname(__DIR__).'/vendor/autoload.php'; $app = require dirname(__DIR__).'/bootstrap/app.php'; $app->make(Kernel::class)->bootstrap(); $identity = DB::selectOne('select current_database() as database, inet_server_port() as port'); if ($identity->database !== 'anchor_restore_20261007_test' || (int) $identity->port !== 55441) { throw new RuntimeException('Isolated QA required'); } $root = storage_path('app/private/anchor-project-reconciliation'); $fixture = json_decode(file_get_contents($root.'/qa-browser-fixture.json'), true, 512, JSON_THROW_ON_ERROR); $dossier = DB::table('investment_dossiers')->where('id', $fixture['project_dossier'])->first(); $project = DB::table('projects')->where('id', $dossier->project_id)->first(); if (! str_starts_with($project->code, 'QA-')) { throw new RuntimeException('Synthetic project required'); } $site = DB::table('project_locations')->where('project_id', $project->id)->where('role', 'primary')->first(); $nodes = []; $id = $site->geo_location_id; while ($id) { $node = DB::table('geo_locations')->where('id', $id)->first(); $nodes[$node->location_type] = $node; $id = $node->parent_id; } $base = ['project_id' => $project->id, 'code' => $project->code, 'dossier_id' => $dossier->id, 'dossier_version' => $dossier->version_no, 'source_reference' => $dossier->source, 'source_quote' => json_decode($dossier->content, true)['location'], 'reason' => 'Synthetic QA individual territorial validation', 'expected_project_version' => $project->version_no, 'data_classification' => 'public']; $rows = []; foreach ([['province', 'secondary'], ['district', 'impact'], ['admin_post', 'secondary'], ['locality', 'impact']] as [$type, $role]) { $rows[] = [...$base, 'geo_location_id' => $nodes[$type]->id, 'name' => $nodes[$type]->name, 'role' => $role, 'existing' => false]; } $rows[2]['source_quote'] = ''; $rows[3]['province_id'] = (string) Str::uuid(); $directory = $root.'/qa-territorial-preview'; if (! is_dir($directory)) { mkdir($directory, 0700, true); } file_put_contents($directory.'/preview.json', json_encode(['target' => ['database' => $identity->database, 'port' => (int) $identity->port], 'locations' => $rows, 'memberships' => [], 'prepared_opportunities' => [], 'pending' => []], JSON_THROW_ON_ERROR)); copy($root.'/qa-preview/backup-proof.json', $directory.'/backup-proof.json'); echo "Synthetic isolated QA territorial preview prepared.\n";