82 lines
4.7 KiB
PHP
82 lines
4.7 KiB
PHP
<?php
|
|
|
|
// Private review bundle only: no installed package, application configuration or database is changed.
|
|
$root = dirname(__DIR__);
|
|
$financial = realpath('C:/laragon/www/sgf-tempo/packages/budget-control');
|
|
if ($financial === false || str_replace('\\', '/', $financial) !== 'C:/laragon/www/sgf-tempo/packages/budget-control') {
|
|
throw new LogicException('Canonical financial source mismatch.');
|
|
}
|
|
$budgetFiles = ['bootstrap.php', 'README.md', 'src/BudgetContext.php', 'src/BudgetFailure.php', 'src/BudgetControl.php',
|
|
'src/BudgetDistributionPlan.php', 'src/BudgetDistributions.php', 'src/BudgetOrderParts.php', 'src/BudgetLandedCosts.php',
|
|
'src/BudgetLandedCostPlan.php', 'src/BudgetImportEstimate.php', 'src/BudgetRequisitionCycles.php'];
|
|
$purchasingFiles = ['bootstrap.php', 'README.md', 'module.json', 'src/ReplenishmentProjection.php', 'src/QuotationPricing.php',
|
|
'src/ProposalScoring.php', 'src/RequisitionPort.php', 'src/ExpiryRequisitionPort.php', 'src/RequisitionFailure.php', 'src/InternalRequisitions.php', 'src/Sourcing.php'];
|
|
$sources = [];
|
|
foreach (['budget-control' => [$financial, $budgetFiles], 'purchasing' => [$root.'/packages/purchasing', $purchasingFiles]] as $package => [$directory, $files]) {
|
|
foreach ($files as $file) {
|
|
$sources[$package.'/'.$file] = $directory.'/'.$file;
|
|
}
|
|
}
|
|
$schema = 'database/qa-migrations/2026_11_27_000001_add_requisition_cycles.php';
|
|
$sources[$schema] = $root.'/'.$schema;
|
|
$hashes = [];
|
|
foreach ($sources as $name => $source) {
|
|
if (! is_file($source) || is_link($source)) {
|
|
throw new RuntimeException('Missing canonical bundle file: '.$name);
|
|
}
|
|
$hashes[$name] = hash_file('sha256', $source);
|
|
}
|
|
$fingerprint = hash('sha256', json_encode($hashes, JSON_THROW_ON_ERROR));
|
|
$relative = 'storage/framework/testing/requisition-cycles-qa-'.substr($fingerprint, 0, 16);
|
|
$target = $root.'/'.$relative;
|
|
foreach ($sources as $name => $source) {
|
|
$destination = $target.'/'.$name;
|
|
if (! is_dir(dirname($destination)) && ! mkdir(dirname($destination), 0700, true)) {
|
|
throw new RuntimeException('Unable to create private cycle bundle.');
|
|
}
|
|
if (is_link($destination) || (is_file($destination) && hash_file('sha256', $destination) !== $hashes[$name])) {
|
|
throw new RuntimeException('Frozen cycle bundle differs; no file overwritten.');
|
|
}
|
|
if (! is_file($destination) && ! copy($source, $destination)) {
|
|
throw new RuntimeException('Cycle bundle copy failed.');
|
|
}
|
|
if (hash_file('sha256', $destination) !== $hashes[$name]) {
|
|
throw new RuntimeException('Cycle bundle verification failed.');
|
|
}
|
|
}
|
|
$manifest = ['contract' => 'COMMON-BUDGET-REQUISITION-CYCLES-QA-v1', 'status' => 'private_qa_not_installed', 'files' => $hashes];
|
|
$bytes = json_encode($manifest, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_THROW_ON_ERROR).PHP_EOL;
|
|
if (is_file($target.'/manifest.json') && file_get_contents($target.'/manifest.json') !== $bytes) {
|
|
throw new RuntimeException('Frozen cycle manifest differs.');
|
|
}
|
|
file_put_contents($target.'/manifest.json', $bytes);
|
|
$archive = $target.'.zip';
|
|
if (! is_file($archive)) {
|
|
$zip = new ZipArchive;
|
|
if ($zip->open($archive, ZipArchive::CREATE | ZipArchive::EXCL) !== true) {
|
|
throw new RuntimeException('Unable to create private cycle archive.');
|
|
}
|
|
foreach ($sources as $name => $source) {
|
|
$zip->addFile($target.'/'.$name, $name);
|
|
}
|
|
$zip->addFile($target.'/manifest.json', 'manifest.json');
|
|
$zip->close();
|
|
}
|
|
$zip = new ZipArchive;
|
|
if ($zip->open($archive) !== true || $zip->numFiles !== count($sources) + 1 || $zip->getFromName('manifest.json') !== $bytes) {
|
|
throw new RuntimeException('Cycle archive inventory mismatch.');
|
|
}
|
|
foreach ($hashes as $name => $hash) {
|
|
if (hash('sha256', $zip->getFromName($name)) !== $hash) {
|
|
throw new RuntimeException('Cycle archive byte mismatch.');
|
|
}
|
|
}
|
|
$zip->close();
|
|
$proof = ['date' => '2026-11-27', 'status' => 'private_qa_prepared_not_installed', 'path' => $relative,
|
|
'manifest_sha256' => hash('sha256', $bytes), 'archive' => $relative.'.zip', 'archive_sha256' => hash_file('sha256', $archive),
|
|
'canonical_fingerprint' => $fingerprint, 'files' => $hashes, 'independent_financial_load_test' => 'pending',
|
|
'installed_packages_changed' => false, 'pilot_or_sgf_activation' => false];
|
|
file_put_contents($root.'/docs/proofs/requisition-expiry-artifact.json', json_encode($proof, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_THROW_ON_ERROR).PHP_EOL);
|
|
echo json_encode(['private_cycle_bundle_prepared' => true, 'path' => $relative, 'files' => count($sources),
|
|
'manifest_sha256' => $proof['manifest_sha256'], 'archive_sha256' => $proof['archive_sha256']], JSON_THROW_ON_ERROR).PHP_EOL;
|