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
@@ -10,6 +10,7 @@ use App\Models\StockMovement;
use App\Models\User;
use App\Services\AgreementOrderLimits;
use App\Services\ConflictGuard;
use App\Services\InventoryConversionRuntime;
use App\Services\InventoryDispositions;
use App\Services\InventoryLots;
use App\Services\InventoryReversals;
@@ -17,17 +18,27 @@ use App\Services\InvoiceWorkflow;
use App\Services\ReceiptStockMovement;
use App\Services\ReceiptWorkflow;
use App\Services\RequisitionWorkflow;
use App\Services\StandaloneArtifact;
use App\Services\StandaloneRuntime;
use App\Services\StockWorkflow;
use App\Services\SupplyCoordination;
use App\Services\SupplyPlanning;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
use Illuminate\Validation\ValidationException;
use Inertia\Testing\AssertableInertia as Assert;
require_once __DIR__.'/../Support/ReceiptFixture.php';
require_once __DIR__.'/../Support/SupplyFixture.php';
require_once __DIR__.'/../Support/StandaloneCompositionFixture.php';
beforeEach(function () {
config(['inventory_conversion.qa_enabled' => true]);
$this->operationalConversion = getenv('COMPRAS_STANDALONE_CONVERSION_QA') === '1';
if ($this->operationalConversion) {
prepareSyntheticStandaloneRuntime();
}
config(['inventory_conversion.qa_enabled' => ! $this->operationalConversion,
'inventory_conversion.enabled' => $this->operationalConversion]);
$this->f = receiptFixture();
// New consistent synthetic process: 2 boxes x 100 MZN = 200 MZN. Original fixture is untouched.
$request = $this->f['r']->replicate();
@@ -55,6 +66,7 @@ beforeEach(function () {
});
test('two boxes retain two documentary units and 200 MZN while crediting exactly 24 physical units once', function () {
$this->get($this->url)->assertOk()->assertInertia(fn (Assert $page) => $page->component('receipts/order')->where('conversionQaEnabled', true));
$id = $this->postJson($this->url, $this->body)->assertCreated()->json('id');
$this->postJson($this->url, $this->body)->assertOk()->assertJsonPath('id', $id);
$line = GoodsReceipt::query()->findOrFail($id)->items()->sole();
@@ -112,11 +124,53 @@ test('missing source factor and nonrepresentable physical quantities never creat
});
test('conversion is not enabled by its presence in a request and cannot escape the QA guard', function () {
config(['inventory_conversion.qa_enabled' => false]);
config(['inventory_conversion.qa_enabled' => false, 'inventory_conversion.enabled' => false]);
$this->postJson($this->url, $this->body)->assertUnprocessable();
expect(StockMovement::query()->count())->toBe(0);
});
test('a frozen conversion refuses fallback to the legacy inventory writer when the component is disabled', function () {
$this->postJson($this->url, $this->body)->assertCreated();
config(['inventory_conversion.qa_enabled' => false, 'inventory_conversion.enabled' => false]);
expect(fn () => app(ReceiptStockMovement::class)->load())->toThrow(LogicException::class, 'COMPRAS_INVENTORY_DOWNGRADE_REFUSED');
expect(StockMovement::query()->sole()->quantity_milli)->toBe(24000);
});
test('an interrupted outer transaction rolls back the converted receipt and retries once with the same physical quantity', function () {
expect(fn () => DB::transaction(function () {
app(ReceiptWorkflow::class)->confirm($this->f['receiver'], $this->f['order'], $this->body);
throw new RuntimeException('synthetic interruption after movement');
}))->toThrow(RuntimeException::class, 'synthetic interruption after movement');
expect(GoodsReceipt::query()->count())->toBe(0)->and(StockMovement::query()->count())->toBe(0);
$this->postJson($this->url, $this->body)->assertCreated();
$this->postJson($this->url, $this->body)->assertOk();
expect(StockMovement::query()->sole()->quantity_milli)->toBe(24000);
});
test('operational conversion refuses an unbound installation and mixed QA configuration before stock effects', function () {
if (! $this->operationalConversion) {
$this->markTestSkipped('Operational installation checks run with the owned PostgreSQL standalone runner.');
}
$runtime = app(InventoryConversionRuntime::class);
config(['inventory_conversion.qa_enabled' => true]);
expect(fn () => $runtime->root())->toThrow(LogicException::class, 'COMPRAS_INVENTORY_CONFIGURATION');
config(['inventory_conversion.qa_enabled' => false]);
$settings = config('standalone-runtime');
$settings['installation_id'] = (string) Str::uuid();
app()->instance(StandaloneRuntime::class, new StandaloneRuntime($settings, new StandaloneArtifact));
expect(fn () => $runtime->root())->toThrow(LogicException::class, 'COMPRAS_RUNTIME_INSTALLATION_MISMATCH');
expect(StockMovement::query()->count())->toBe(0)->and(GoodsReceipt::query()->count())->toBe(0);
});
test('operational conversion refuses an incomplete inventory schema before loading a writer', function () {
if (! $this->operationalConversion) {
$this->markTestSkipped('Operational schema checks run with the owned PostgreSQL standalone runner.');
}
DB::statement('ALTER TABLE goods_receipt_items DROP COLUMN notes');
expect(fn () => app(InventoryConversionRuntime::class)->root())->toThrow(LogicException::class, 'COMPRAS_INVENTORY_SCHEMA');
expect(StockMovement::query()->count())->toBe(0);
});
test('legacy receipt facts retain the exact v1 hash and compatible replay without a conversion basis', function () {
$this->f['stock']->update(['unit' => 'cx']);
$body = $this->body;