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

This commit is contained in:
2026-11-29 05:28:30 +02:00
parent 1ddabbbdcc
commit 448948a487
137 changed files with 9481 additions and 1926 deletions
@@ -1,11 +1,20 @@
<?php
use App\Models\ConflictDeclaration;
use App\Models\ConflictRelease;
use App\Models\OrderCancellation;
use App\Models\PurchaseOrder;
use App\Models\Requisition;
use App\Models\User;
use App\Services\ConflictGuard;
use App\Services\OrderCancellationWorkflow;
use App\Services\ProposalComparison;
use App\Services\RequisitionAccountAssignments;
use App\Services\UrgentQuotationBasis;
use Carbon\Carbon;
use Carbon\CarbonImmutable;
use Illuminate\Contracts\Console\Kernel;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
@@ -14,7 +23,7 @@ use Tempo\Finance\GeneralLedger\LedgerSchema;
require __DIR__.'/../../vendor/autoload.php';
$app = require __DIR__.'/../../bootstrap/app.php';
if (in_array($argv[2] ?? '', ['prepare-native-review', 'read-office-purchase', 'describe-private-audit-schema'], true)) {
if (in_array($argv[2] ?? '', ['prepare-native-review', 'read-office-purchase', 'describe-private-audit-schema', 'read-native-conflict-release', 'read-native-urgent-stock', 'read-native-cancellation'], true)) {
$privateRoot = realpath(getenv('SGC_REQUISITION_QA_ROOT') ?: '');
$boundary = realpath(__DIR__.'/../../storage/framework/testing');
$databaseName = getenv('DB_DATABASE') ?: '';
@@ -78,6 +87,116 @@ if ($mode === 'read-office-purchase') {
}
exit;
}
if ($mode === 'read-native-conflict-release') {
if (getenv('RQ01_QA_CONFLICT_RELEASE') !== '1') {
throw new LogicException('Conflict assertions require their own synthetic preview.');
}
$fixture = json_decode(file_get_contents($privateRoot.'/native-review.json'), true, 64, JSON_THROW_ON_ERROR);
$context = $fixture['conflict_review'];
config(['conflict-releases.qa_enabled' => true]);
auth()->guard()->setUser(User::query()->findOrFail($context['author_id']));
$state = DB::transaction(function () use ($context) {
DB::statement('SET TRANSACTION ISOLATION LEVEL REPEATABLE READ READ ONLY');
$originals = ConflictDeclaration::query()->where('user_id', $context['author_id'])->orderBy('id')->get();
if (hash('sha256', $originals->toJson()) !== $context['originals_sha256']) {
throw new LogicException('Native release must preserve both original declarations.');
}
foreach ($context['protected_frames'] as $table => $expected) {
$rows = DB::table($table)->when($table === 'users', fn ($query) => $query->select(['id', 'tenant_id', 'department_id', 'purchasing_role']))->orderBy('id')->get();
if (hash('sha256', $rows->toJson()) !== $expected) {
throw new LogicException('Native release changed protected financial, stock or authority frame: '.$table);
}
}
$release = ConflictRelease::query()->sole();
$guard = app(ConflictGuard::class);
$supplierBlocked = $guard->hasConflict($context['author_id'], $context['supplier_id'], null);
$otherProcessBlocked = $guard->hasConflict($context['author_id'], $context['supplier_id'], $context['requisition_id']);
if ($release->declaration_id !== $context['declaration_id'] || $release->authorised_by !== $context['direction_id']
|| Arr::sortRecursive($release->snapshot) !== Arr::sortRecursive($originals->first()->toArray()) || $supplierBlocked || ! $otherProcessBlocked
|| DB::table('audit_logs')->where('action', 'conflict.release_authorised')->count() !== 1) {
throw new LogicException('Native direction decision must release only the selected chain once.');
}
return ['release_id' => $release->id, 'declaration_id' => $release->declaration_id,
'direction_id' => $release->authorised_by, 'originals_preserved' => true,
'financial_stock_and_authority_frames_preserved' => count($context['protected_frames']),
'selected_supplier_impediment_released' => ! $supplierBlocked, 'other_process_impediment_still_blocks' => $otherProcessBlocked,
'release_audit_count' => 1, 'readonly_transaction' => DB::selectOne('SHOW transaction_read_only')->transaction_read_only === 'on',
'synthetic_only' => true, 'operational_changes' => false];
});
echo json_encode($state, JSON_THROW_ON_ERROR);
exit;
}
if ($mode === 'read-native-urgent-stock') {
if (getenv('RQ01_QA_URGENT_STOCK') !== '1') {
throw new LogicException('Urgent stock assertions require their own synthetic preview.');
}
$fixture = json_decode(file_get_contents($privateRoot.'/native-review.json'), true, 64, JSON_THROW_ON_ERROR);
$context = $fixture['urgent_stock_review'];
config(['urgent-quotations.qa_enabled' => true]);
auth()->guard()->setUser(User::query()->findOrFail($context['actor_id']));
$state = DB::transaction(function () use ($context) {
DB::statement('SET TRANSACTION ISOLATION LEVEL REPEATABLE READ READ ONLY');
foreach ($context['protected_frames'] as $table => $expected) {
$rows = DB::table($table)->when($table === 'users', fn ($query) => $query->select(['id', 'tenant_id', 'department_id', 'purchasing_role']))->orderBy('id')->get();
if (hash('sha256', $rows->toJson()) !== $expected) {
throw new LogicException('Urgent evidence changed a protected frame: '.$table);
}
}
$request = Requisition::query()->findOrFail($context['request_id']);
$eligible = app(UrgentQuotationBasis::class)->eligible($request);
$policy = app(ProposalComparison::class)->inspect($request)['policy'];
if (count($eligible) !== 1 || $policy['minimum_proposals'] !== 1 || $policy['normal_minimum_proposals'] !== 3 || $policy['minimum_evaluators'] !== 2
|| DB::table('audit_logs')->where('action', 'urgent.stock_minimum_recorded')->where('requisition_id', $request->id)->count() !== 1) {
throw new LogicException('Native urgent conference must preserve one valid evidence and independent evaluations.');
}
return ['eligible_evidence' => 1, 'minimum_proposals' => 1, 'normal_minimum_proposals' => 3, 'minimum_evaluators' => 2,
'protected_frames_preserved' => count($context['protected_frames']), 'single_audit' => true, 'readonly_transaction' => true, 'synthetic_only' => true];
});
echo json_encode($state, JSON_THROW_ON_ERROR);
exit;
}
if ($mode === 'read-native-cancellation') {
if (getenv('RQ01_QA_ORDER_CANCELLATION') !== '1') {
throw new LogicException('Cancellation assertions require their own synthetic preview.');
}
$fixture = json_decode(file_get_contents($privateRoot.'/native-review.json'), true, 64, JSON_THROW_ON_ERROR);
$context = $fixture['cancellation_review'];
config(['order_cancellation.enabled' => true]);
auth()->guard()->setUser(User::query()->findOrFail($context['finance_id']));
$state = DB::transaction(function () use ($context) {
DB::statement('SET TRANSACTION ISOLATION LEVEL REPEATABLE READ READ ONLY');
foreach ($context['protected_frames'] as $table => $expected) {
$rows = DB::table($table)->when($table === 'users', fn ($query) => $query->select(['id', 'tenant_id', 'department_id', 'purchasing_role']))->orderBy('id')->get();
if (hash('sha256', $rows->toJson()) !== $expected) {
throw new LogicException('Legacy cancellation changed a protected frame: '.$table);
}
}
$order = PurchaseOrder::query()->findOrFail($context['order_id']);
$request = Requisition::query()->findOrFail($context['request_id']);
$record = OrderCancellation::query()->where('purchase_order_id', $order->id)->sole();
$currentSource = Arr::except($request->getAttributes(), ['status', 'updated_at']);
$originalSource = Arr::except($context['original_request'], ['status', 'updated_at']);
if ($record->status !== 'approved' || $record->created_by !== $context['author_id'] || $record->reviewed_by !== $context['finance_id']
|| $request->status !== 'cancelled' || $currentSource !== $originalSource || $order->status !== 'issued'
|| hash('sha256', json_encode($order->getAttributes(), JSON_THROW_ON_ERROR)) !== $context['original_order_sha256']
|| app(OrderCancellationWorkflow::class)->state($order) !== 'cancelled') {
throw new LogicException('Native cancellation must preserve the issued original and independent decision.');
}
foreach (['requested', 'approved'] as $action) {
if (DB::table('audit_logs')->where('action', 'order_cancellation.'.$action)->where('requisition_id', $request->id)->count() !== 1) {
throw new LogicException('Native cancellation must create one request and one decision audit.');
}
}
return ['original_order_preserved' => true, 'original_status' => 'issued', 'operational_status' => 'cancelled',
'source_request_cancelled_only' => true, 'independent_finance_decision' => true, 'protected_frames_preserved' => count($context['protected_frames']),
'no_fabricated_legacy_reversal' => true, 'one_request_one_decision' => true, 'readonly_transaction' => true, 'synthetic_only' => true];
});
echo json_encode($state, JSON_THROW_ON_ERROR);
exit;
}
$financial = static function (): string {
$rows = [];
foreach (['gl_accounts', 'gl_journals', 'gl_lines', 'requisitions', 'requisition_items', 'invoices', 'invoice_items', 'external_payments', 'budget_entries', 'stock_movements'] as $table) {