commit melhorias compras1
tests / ci (push) Waiting to run

This commit is contained in:
2026-11-21 21:04:40 +02:00
parent 976271f948
commit 12dd6df28a
108 changed files with 4391 additions and 408 deletions
+43 -11
View File
@@ -5,24 +5,56 @@ namespace App\Services;
use App\Enums\PurchasingRole;
use App\Models\User;
use Illuminate\Support\Facades\DB;
use Tempo\Inventory\ReceiptMovementWriter;
/** Called only within ReceiptWorkflow's company-locked transaction. */
final class ReceiptStockMovement
{
public function for(User $actor): \Tempo\Inventory\ReceiptMovementWriter
public function load(): void
{
$root=base_path('packages/inventory-write/releases/0.1.0');
if(!is_file($root.'/manifest.json')||!hash_equals('f0b99e591f9a4df135e685f64ceffad77bed259222debe0f34c20f95e3cad800',hash_file('sha256',$root.'/manifest.json')))
$root = base_path('packages/inventory-write/releases/0.1.0');
$pin = 'f0b99e591f9a4df135e685f64ceffad77bed259222debe0f34c20f95e3cad800';
$files = ['bootstrap.php', 'src/ReceiptMovementWriter.php'];
if (config('inventory_conversion.qa_enabled') === true) {
abort_unless(app()->environment('testing'), 503, 'Extensão de conversão limitada a QA.');
$connection = DB::connection();
abort_unless(($connection->getDriverName() === 'sqlite' && $connection->getDatabaseName() === ':memory:')
|| ($connection->getDriverName() === 'pgsql' && preg_match('/^compras_receipts_test_[a-f0-9]{12}$/D', $connection->getDatabaseName())), 503, 'Base QA isolada obrigatória.');
$root = base_path('packages/inventory-write/development');
$pin = '90cf565537e7fd48eb54a87bcfd6d585cf53239f075764910047838b3b8b4c38';
$files[] = 'src/QuantityConversion.php';
}
$bytes = is_file($root.'/manifest.json') ? file_get_contents($root.'/manifest.json') : false;
if (! is_string($bytes) || ! hash_equals($pin, hash('sha256', $bytes))) {
throw new \LogicException('Pacote de recepção incompatível; não executar outro escritor.');
$manifest=json_decode(file_get_contents($root.'/manifest.json'),true,512,JSON_THROW_ON_ERROR);
foreach(['bootstrap.php','src/ReceiptMovementWriter.php'] as $file)
if(!is_file($root.'/'.$file)||!hash_equals($manifest['files'][$file]??'',hash_file('sha256',$root.'/'.$file)))throw new \LogicException('Pacote de recepção alterado.');
}
$manifest = json_decode($bytes, true, 512, JSON_THROW_ON_ERROR);
foreach ($files as $file) {
$actual = is_file($root.'/'.$file) ? hash_file('sha256', $root.'/'.$file) : false;
if (! is_string($actual) || ! hash_equals($manifest['files'][$file] ?? '', $actual)) {
throw new \LogicException('Pacote de recepção alterado.');
}
}
if (class_exists(ReceiptMovementWriter::class, false)) {
$loaded = (new \ReflectionClass(ReceiptMovementWriter::class))->getFileName();
if (! is_string($loaded) || realpath($loaded) !== realpath($root.'/src/ReceiptMovementWriter.php')) {
throw new \LogicException('Escritor já carregado de outra versão; use um kernel QA separado.');
}
}
require_once $root.'/bootstrap.php';
$schema=match(DB::connection()->getDriverName()){
'pgsql'=>'public','sqlite'=>'main','mysql','mariadb'=>DB::connection()->getDatabaseName(),
default=>throw new \LogicException('Driver de inventário não suportado.'),
}
public function for(User $actor): ReceiptMovementWriter
{
$this->load();
$schema = match (DB::connection()->getDriverName()) {
'pgsql' => 'public','sqlite' => 'main','mysql','mariadb' => DB::connection()->getDatabaseName(),
default => throw new \LogicException('Driver de inventário não suportado.'),
};
return new \Tempo\Inventory\ReceiptMovementWriter(DB::connection(),$schema,(int)$actor->tenant_id,(int)$actor->id,
function () use ($actor) {app(CurrentActor::class)->lock($actor,[PurchasingRole::Warehouse]);});
return new ReceiptMovementWriter(DB::connection(), $schema, (int) $actor->tenant_id, (int) $actor->id,
function () use ($actor) {
app(CurrentActor::class)->lock($actor, [PurchasingRole::Warehouse]);
});
}
}