commit compras5 2911
tests / ci (push) Canceled after 0s

This commit is contained in:
2026-11-29 19:49:19 +02:00
parent a935499d64
commit 96b30368bc
96 changed files with 3397 additions and 111 deletions
@@ -0,0 +1,45 @@
<?php
use App\Services\InventoryConversionRuntime;
require __DIR__.'/../vendor/autoload.php';
$root = dirname(__DIR__).'/packages/inventory-write/releases/0.2.0-rc.1';
InventoryConversionRuntime::verifyArtifact($root);
$manifest = json_decode(file_get_contents($root.'/manifest.json'), true, 512, JSON_THROW_ON_ERROR);
$parent = dirname(__DIR__).'/storage/framework/testing';
if (! is_dir($parent) && ! mkdir($parent, 0700, true)) {
throw new LogicException('Private artifact directory unavailable.');
}
$target = $parent.'/compras-inventory-'.InventoryConversionRuntime::MANIFEST_SHA256.'.zip';
$temporary = $target.'.'.bin2hex(random_bytes(8)).'.tmp';
try {
$zip = new ZipArchive;
if ($zip->open($temporary, ZipArchive::CREATE | ZipArchive::EXCL) !== true) {
throw new LogicException('Private archive creation failed.');
}
foreach (['manifest.json', ...array_keys($manifest['files'])] as $file) {
if (! $zip->addFile($root.'/'.$file, $file) || ! $zip->setMtimeName($file, 1795910400)
|| ! $zip->setExternalAttributesName($file, ZipArchive::OPSYS_UNIX, 0100644 << 16)) {
throw new LogicException('Private archive entry failed.');
}
}
if (! $zip->close()) {
throw new LogicException('Private archive close failed.');
}
$hash = hash_file('sha256', $temporary);
if (is_file($target)) {
if (is_link($target) || ! hash_equals($hash, hash_file('sha256', $target))) {
throw new LogicException('Existing archive differs; replacement refused.');
}
} elseif (! rename($temporary, $target)) {
throw new LogicException('Private archive publication failed.');
}
echo json_encode(['state' => 'private_candidate_only', 'archive' => $target, 'entries' => 4,
'manifest_sha256' => InventoryConversionRuntime::MANIFEST_SHA256, 'archive_sha256' => $hash,
'pilot_or_production_changes' => false], JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT).PHP_EOL;
} finally {
if (is_file($temporary)) {
unlink($temporary);
}
}