make(Kernel::class)->bootstrap(); $installation = app(DemographicInstallation::class); throw_unless($installation->activeTarget(), RuntimeException::class, 'Confirmed operational target required.'); $directory = $root.'/outputs/demography-20261113'; $backup = json_decode(CheckedFile::read(storage_path('app/private/demography-deployment/backup.json')), true, 512, JSON_THROW_ON_ERROR); throw_unless($backup['restore_verified'] && $backup['files_verified'], RuntimeException::class, 'Backup/restore evidence required.'); foreach (['dump', 'files'] as $kind) { throw_unless(CheckedFile::matches($backup[$kind.'_path'], $backup[$kind.'_sha256']), RuntimeException::class, 'Backup integrity changed.'); } throw_unless(CheckedFile::matches(base_path('.env'), $backup['environment_sha256']), RuntimeException::class, 'Environment changed.'); throw_unless(CheckedFile::matches(public_path('build/manifest.json'), $backup['previous_manifest_sha256']), RuntimeException::class, 'Operational build changed; reconcile before replacing.'); $readResult = static function (string $path, int $expected): array { $bytes = CheckedFile::read($path); if (str_starts_with($bytes, "\xFF\xFE")) { $bytes = mb_convert_encoding($bytes, 'UTF-8', 'UTF-16'); } $result = json_decode(trim($bytes), true, 512, JSON_THROW_ON_ERROR); throw_unless(($result['result'] ?? '') === 'passed' && ($result['passed'] ?? 0) === $expected, RuntimeException::class, 'Release test did not pass.'); return $result; }; $releaseTests = $readResult($directory.'/installation-tests.log', 5); $regression = $readResult($directory.'/release-regression.log', 11); $mfa = json_decode(CheckedFile::read($directory.'/qa-http-homologation.json'), true, 512, JSON_THROW_ON_ERROR); throw_unless($mfa['mfa_authenticated'] && $mfa['administrative_preview_verified'], RuntimeException::class, 'Real QA MFA confirmation required.'); $sourceDirectory = 'C:/Mac/Home/Documents/TEMPO/Portal Tempo/Servicos Tempo/portal do investidor/demografia/Provincias'; foreach (DemographicInstallation::FILES as $name => $expected) { throw_unless(CheckedFile::matches($sourceDirectory.'/'.$name, $expected['sha256']), RuntimeException::class, 'Approved original changed.'); } $candidate = realpath($directory.'/release-build'); $destination = realpath(public_path('build')); throw_unless($candidate && $destination && str_replace('\\', '/', $destination) === str_replace('\\', '/', $root).'/public/build', RuntimeException::class, 'Build destination refused.'); $manifest = json_decode(CheckedFile::read($candidate.'/manifest.json'), true, 512, JSON_THROW_ON_ERROR); foreach (['resources/js/pages/management/demography-install.tsx', 'resources/js/pages/management/demography.tsx', 'resources/js/pages/investment/demography.tsx'] as $entry) { throw_unless(isset($manifest[$entry]) && is_file($candidate.'/'.$manifest[$entry]['file']), RuntimeException::class, 'Release page missing from build.'); } $releaseFiles = []; foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($candidate, FilesystemIterator::SKIP_DOTS)) as $file) { if (! $file->isFile()) { continue; } $relative = str_replace('\\', '/', substr($file->getPathname(), strlen($candidate) + 1)); throw_unless(! str_contains($relative, '..') && ! str_contains($relative, ':'), RuntimeException::class, 'Build member refused.'); $releaseFiles[$relative] = CheckedFile::sha256($file->getPathname()); if ($relative === 'manifest.json') { continue; } $target = $destination.'/'.$relative; if (! is_dir(dirname($target))) { mkdir(dirname($target), 0755, true); } throw_unless(copy($file->getPathname(), $target) && CheckedFile::matches($target, $releaseFiles[$relative]), RuntimeException::class, 'Release asset copy failed.'); } File::replace($destination.'/manifest.json', CheckedFile::read($candidate.'/manifest.json')); throw_unless(CheckedFile::matches($destination.'/manifest.json', $releaseFiles['manifest.json']), RuntimeException::class, 'Release manifest verification failed.'); $proof = [...$backup, 'code_sha256' => $installation->fingerprint(), 'verified_at' => gmdate(DATE_ATOM), 'qa_passed' => true, 'compatibility_verified' => true, 'release_manifest_sha256' => $releaseFiles['manifest.json'], 'release_files' => $releaseFiles, 'installation_tests' => $releaseTests, 'regression_tests' => $regression, 'qa_mfa_verified' => true, 'operational_data_applied' => false, 'next_action' => 'Existing authorised installation identity must execute with fresh session MFA at /management/demography/install.']; file_put_contents(storage_path('app/private/demography-deployment/readiness.json'), json_encode($proof, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_THROW_ON_ERROR)); $target = DB::selectOne('SELECT current_database() AS database,inet_server_port() AS port'); $publicProof = ['target' => $target, 'backup_tables' => count($backup['tables']), 'backup_files' => $backup['file_count'], 'restore_verified' => true, 'files_verified' => true, 'installation_tests' => $releaseTests, 'regression_tests' => $regression, 'release_manifest_sha256' => $releaseFiles['manifest.json'], 'code_sha256' => $proof['code_sha256'], 'operational_data_applied' => false, 'installation_url' => rtrim(config('app.url'), '/').'/management/demography/install', 'verified_at' => $proof['verified_at']]; file_put_contents($directory.'/release-readiness.json', json_encode($publicProof, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_THROW_ON_ERROR)); echo json_encode($publicProof, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE).PHP_EOL;