make(Kernel::class)->bootstrap(); if (! $app->environment('testing') || DB::getDriverName() !== 'pgsql' || DB::connection()->getDatabaseName() !== $database || ! preg_match('/^compras_receipts_test_[a-f0-9]{12}$/D', $database)) { throw new LogicException('Worker de relatório fora de QA.'); } require __DIR__.'/../Support/ReceiptFixture.php'; require __DIR__.'/../Support/SupplyFixture.php'; $f = receiptFixture(); supplyGrant($f['issuer'], ['supply_prepare']); supplyGrant($f['receiver'], ['supply_read', 'supply_review']); auth()->guard()->setUser($f['issuer']); $planning = app(SupplyPlanning::class); $draft = $planning->save($f['issuer'], 'agreement', supplyInput(['stock_item_id' => $f['stock']->id, 'warehouse_id' => $f['warehouse']->id, 'supplier_id' => $f['order']->supplier_id, 'habitual' => false, 'valid_from' => today()->toDateString(), 'valid_until' => today()->addDay()->toDateString(), 'origin' => 'local', 'currency' => 'MZN', 'price_minor' => 10000, 'lead_days' => 4, 'reference' => '=PG-FOLLOWUP-PROOF'])); auth()->guard()->setUser($f['receiver']); $planning->save($f['receiver'], 'agreement', supplyInput([], 'approve', $draft)); config(['agreement_order_limits.qa_enabled' => true]); auth()->guard()->setUser($f['issuer']); $header = $planning->save($f['issuer'], 'contract', supplyInput(['supplier_id' => $f['order']->supplier_id, 'reference' => '=PG-CONTRACT-PROOF', 'currency' => 'MZN', 'valid_from' => today()->toDateString(), 'valid_until' => today()->addDay()->toDateString(), 'order_limit_amount' => '0'])); auth()->guard()->setUser($f['receiver']); $planning->save($f['receiver'], 'contract', supplyInput([], 'approve', $header)); $before = DB::table('audit_logs')->count(); $checked = false; DB::listen(function (QueryExecuted $event) use (&$checked): void { if (! $checked && str_contains($event->sql, 'supply_records')) { $checked = true; $state = $event->connection->selectOne("select current_setting('transaction_isolation') as isolation,current_setting('transaction_read_only') as readonly"); if ($state->isolation !== 'repeatable read' || $state->readonly !== 'on') { throw new RuntimeException('CSV sem leitura consistente/somente leitura.'); } } }); $request = Request::create('/compras/acordos/vigencia.csv', 'GET'); $request->setUserResolver(fn () => $f['receiver']); $response = app(AgreementFollowupController::class)->csv($request, app(AgreementFollowup::class)); if (! $checked || ! str_contains($response->getContent(), "'=PG-FOLLOWUP-PROOF") || ! str_contains($response->getContent(), 'Vigente') || $before !== DB::table('audit_logs')->count() || DB::transactionLevel() !== 0) { throw new RuntimeException('CSV ou ausência de efeitos não demonstrados.'); } echo json_encode(['agreement_csv_read_only_snapshot' => true, 'formula_cell_protected' => true, 'no_audit_writes' => true, 'transaction_closed' => true], JSON_THROW_ON_ERROR).PHP_EOL; $checked = false; $request = Request::create('/compras/acordos/vigencia.csv?kind=contract', 'GET'); $request->setUserResolver(fn () => $f['receiver']); $response = app(AgreementFollowupController::class)->csv($request, app(AgreementFollowup::class)); if (! $checked || ! str_contains($response->getContent(), "'=PG-CONTRACT-PROOF") || ! str_contains($response->getContent(), 'Limite global por ordem') || $before !== DB::table('audit_logs')->count() || DB::transactionLevel() !== 0) { throw new RuntimeException('CSV global sem prova de leitura consistente ou sem efeitos.'); } echo json_encode(['contract_csv_read_only_snapshot' => true, 'formula_cell_protected' => true, 'no_audit_writes' => true, 'transaction_closed' => true], JSON_THROW_ON_ERROR).PHP_EOL;