commit compras2 2711
tests / ci (push) Waiting to run

This commit is contained in:
2026-11-27 18:11:02 +02:00
parent e709d900d1
commit 930064269e
74 changed files with 7506 additions and 40 deletions
+35
View File
@@ -0,0 +1,35 @@
<?php
use App\Models\SupplyRecord;
use App\Models\User;
use App\Services\ImportDossier;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
/** Synthetic originals only; caller supplies an authorised native import-preparation actor.
* @return array{documents:array<string,SupplyRecord>,input:array<string,mixed>}
*/
function importBankQaFixture(User $actor, SupplyRecord $import): array
{
$db = DB::connection();
if (! app()->environment('testing') || ! (($db->getDriverName() === 'sqlite' && $db->getDatabaseName() === ':memory:')
|| ($db->getDriverName() === 'pgsql' && $db->getConfig('host') === '127.0.0.1' && preg_match('/^compras_receipts_test_[a-f0-9]{12}$/D', $db->getDatabaseName())))) {
throw new LogicException('Bank evidence fixtures require isolated QA.');
}
$documents = [];
foreach (['term' => 'bank_commitment', 'declaration' => 'customs_declaration', 'invoice' => 'commercial_invoice', 'delivery' => 'bank_support'] as $key => $type) {
$reference = 'BANK-QA-'.$key.'-'.Str::random(8);
$documents[$key] = app(ImportDossier::class)->record($actor, $import, ['operation_key' => (string) Str::uuid(), 'type' => $type,
'reference' => $reference, 'issuer_reference' => 'Synthetic bank evidence issuer', 'issued_on' => today()->toDateString(),
'reason' => 'Original estritamente sintético de suporte documental bancário'],
UploadedFile::fake()->createWithContent('bank-'.$key.'.pdf', "%PDF-1.4\nSynthetic evidence ".$reference."\n%%EOF"));
}
return ['documents' => $documents, 'input' => ['operation_key' => (string) Str::uuid(), 'record_key' => null, 'version' => 0,
'commitment_document_id' => $documents['term']->id, 'declaration_document_id' => $documents['declaration']->id,
'support_document_ids' => [$documents['invoice']->id], 'requirements_known' => true, 'required_support_types' => ['commercial_invoice'],
'required_support_counts' => ['commercial_invoice' => 1], 'requirements_basis' => 'Explicit synthetic bank letter requests one invoice',
'submission_document_id' => null, 'submission_basis' => null, 'submitted_on' => null,
'due_on' => today()->toDateString(), 'deadline_basis' => 'Explicit synthetic bank letter deadline', 'reason' => 'Acompanhamento bancário exclusivamente sintético']];
}
+42
View File
@@ -0,0 +1,42 @@
<?php
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
/** Synthetic rules only. Never seed official rates or a customer's configuration. */
function importLegalQaInput(array $overrides = []): array
{
$db = DB::connection();
if (! app()->environment('testing') || ! (($db->getDriverName() === 'sqlite' && $db->getDatabaseName() === ':memory:')
|| ($db->getDriverName() === 'pgsql' && $db->getConfig('host') === '127.0.0.1' && preg_match('/^compras_receipts_test_[a-f0-9]{12}$/D', $db->getDatabaseName())))) {
throw new LogicException('Legal fixtures require isolated QA.');
}
return [...['operation_key' => (string) Str::uuid(), 'record_key' => null, 'version' => 0, 'action' => 'save',
'title' => 'Synthetic tariff rule', 'official_reference' => 'Synthetic official edition QA only',
'official_url' => 'https://example.test/official-qa.pdf', 'citation' => 'Synthetic article 1, page 2',
'valid_from' => '2026-01-01', 'valid_until' => '2026-12-31', 'match_code' => '1234', 'suggested_code' => '1234.56',
'origin_country' => 'Synthetic A', 'sector' => 'Synthetic sector', 'obligations' => 'Synthetic conditions only; no real tax activated',
'document_types' => ['licence'], 'reason' => 'Synthetic legal configuration; not an approved real legal rule'], ...$overrides];
}
function importLegalQaFile(): UploadedFile
{
return UploadedFile::fake()->createWithContent('source.pdf', "%PDF-1.4\nSynthetic official source for QA only\n%%EOF");
}
function importLegalQaCharge(): array
{
return ['key' => 'synthetic-duty', 'kind' => 'duty', 'label' => 'Synthetic duty', 'method' => 'ad_valorem',
'rate_percent' => '7.5', 'specific_minor' => null, 'quantity_unit' => null,
'basis_reference' => 'Synthetic explicit customs valuation; no real rate configured'];
}
function importLegalQaAmountInput(int $itemId, int $ruleId): array
{
return ['operation_key' => (string) Str::uuid(), 'version' => 0, 'requisition_item_id' => $itemId, 'rule_id' => $ruleId,
'match_code' => '1234', 'origin' => 'Synthetic A', 'sector' => 'Synthetic sector', 'date' => '2026-11-27',
'bases' => ['synthetic-duty' => ['value_minor' => 10001, 'quantity' => null, 'quantity_unit' => null, 'source' => 'Synthetic exact declared valuation']],
'reason' => 'Synthetic legal charge estimate without financial or stock effects'];
}
+29 -5
View File
@@ -43,12 +43,12 @@ function landedQaReceiptsVerified(array $command, string $output): bool
&& (! in_array($mode, ['race-estimate', 'race-estimate-reconcile'], true) || $contains(fn ($row) => ($row['old_estimate_runtime_rejected'] ?? false) === true
&& ($row['runtime_landed_version'] ?? null) === 'COMMON-BUDGET-LANDED-COST-QA-v2' && ($row['status'] ?? null) === 503));
}
if (in_array($mode, ['race-dossier', 'race-party'], true)) {
if (in_array($mode, ['race-dossier', 'race-party', 'race-bank', 'race-legal', 'race-legal-amount', 'race-capital'], true)) {
foreach (['same_operation', 'same_version'] as $scenario) {
$matches = array_values(array_filter($records, fn ($row) => ($row['scenario'] ?? null) === $scenario));
if (count($matches) !== 1 || ($matches[0]['blocked_writers_observed'] ?? 0) < 2
|| ($matches[0]['documents_created'] ?? 0) !== 1 || ($matches[0]['audits'] ?? 0) !== 1
|| ($matches[0]['files_created'] ?? -1) !== ($mode === 'race-party' ? 0 : 1) || ($matches[0]['all_originals_verified'] ?? false) !== true
|| ($matches[0]['files_created'] ?? -1) !== (in_array($mode, ['race-party', 'race-bank', 'race-legal-amount', 'race-capital'], true) ? 0 : 1) || ($matches[0]['all_originals_verified'] ?? false) !== true
|| ($matches[0]['statuses'] ?? null) !== ($scenario === 'same_operation' ? [200, 200] : [200, 409])) {
return false;
}
@@ -56,17 +56,41 @@ function landedQaReceiptsVerified(array $command, string $output): bool
return true;
}
if (in_array($mode, ['landed-costs', 'import-estimates'], true)) {
return ($mode !== 'import-estimates' || $contains(fn ($row) => ($row['estimate_source_remainder_restored'] ?? null) === 1000 && ($row['estimate_original_replay_without_effects'] ?? false) === true))
if (in_array($mode, ['landed-costs', 'import-estimates', 'import-bank-support', 'import-legal', 'import-legal-amount'], true)) {
return ($mode === 'landed-costs' || $contains(fn ($row) => ($row['estimate_source_remainder_restored'] ?? null) === 1000 && ($row['estimate_original_replay_without_effects'] ?? false) === true))
&& ($mode !== 'import-legal-amount' || $contains(fn ($row) => ($row['legal_amount_minor_restored'] ?? null) === 750 && ($row['legal_amount_replay_without_effects'] ?? false) === true
&& ($row['native_legal_plan_total_minor'] ?? null) === 10750 && ($row['native_legal_plan_source_restored'] ?? false) === true && ($row['native_legal_plan_replay_without_effects'] ?? false) === true))
&& (! in_array($mode, ['import-legal', 'import-legal-amount'], true) || $contains(fn ($row) => ($row['legal_source_restored'] ?? false) === true && ($row['legal_published_version_restored'] ?? false) === true
&& ($row['legal_buyer_context_restored'] ?? false) === true && ($row['legal_replay_without_effects'] ?? false) === true))
&& (! in_array($mode, ['import-bank-support', 'import-legal', 'import-legal-amount'], true) || $contains(fn ($row) => ($row['bank_support_versions_restored'] ?? null) === 2
&& ($row['bank_support_relationships_restored'] ?? false) === true && ($row['bank_support_replay_without_effects'] ?? false) === true))
&& $contains(fn ($row) => ($row['post_extension_restore_all_tables_equal'] ?? false) === true
&& ($row['recovered_operation_replay_no_effects'] ?? false) === true && ($row['pre_extension_schema_data_balance_restored'] ?? false) === true)
&& $contains(fn ($row) => ($row['private_original_versions_restored'] ?? 0) === 6 && ($row['typed_dossier_versions_restored'] ?? 0) === 4
&& $contains(fn ($row) => ($row['private_original_versions_restored'] ?? 0) === (in_array($mode, ['import-legal', 'import-legal-amount'], true) ? 11 : ($mode === 'import-bank-support' ? 10 : 6)) && ($row['typed_dossier_versions_restored'] ?? 0) === (in_array($mode, ['import-bank-support', 'import-legal', 'import-legal-amount'], true) ? 8 : 4)
&& ($row['selected_party_versions_restored'] ?? 0) === 2
&& ($row['source_loss_detected'] ?? false) === true
&& ($row['separate_private_root_restored'] ?? false) === true && ($row['native_authorized_evidence_resolved'] ?? false) === true)
&& $contains(fn ($row) => ($row['isolated_restore_removed'] ?? false) === true);
}
if (in_array($mode, ['legal-http', 'legal-review'], true)) {
return $contains(fn ($row) => ($row['native_legal_http_login'] ?? false) === true && ($row['csrf_required'] ?? false) === true
&& ($row['large_multipart_upload_bytes'] ?? 0) > 2097152 && ($row['original_unchanged'] ?? false) === true
&& ($row['exact_native_download'] ?? false) === true && ($row['one_source_one_audit_after_replay'] ?? false) === true
&& ($row['guest_status'] ?? null) === 401 && ($row['revoked_status'] ?? null) === 403 && ($row['rules_published'] ?? null) === 0
&& ($row['financial_stock_unchanged'] ?? false) === true && ($row['global_php_config_unchanged'] ?? false) === true
&& ($row['private_http_server_stopped'] ?? false) === true && ($row['private_http_root_removed'] ?? false) === true);
}
if ($mode === 'corpus') {
return $contains(fn ($row) => ($row['shared_corpus_files_inventoried'] ?? 0) > 0 && count($row['real_official_sources_prepared'] ?? []) === 4
&& is_string($row['inventory_metadata_sha256'] ?? null) && preg_match('/^[a-f0-9]{64}$/D', $row['inventory_metadata_sha256']) === 1
&& count(array_filter($row['real_official_sources_prepared'], fn ($source) => is_string($source['sha256'] ?? null)
&& preg_match('/^[a-f0-9]{64}$/D', $source['sha256']) === 1 && ($source['bytes'] ?? 0) > 0
&& ($source['native_authorized_download_verified'] ?? false) === true)) === 4
&& ($row['rules_published'] ?? null) === 0 && ($row['originals_unchanged'] ?? false) === true
&& ($row['financial_and_stock_unchanged'] ?? false) === true && ($row['synthetic_qa_organization_only'] ?? false) === true);
}
return $mode === 'pest' && $contains(fn ($row) => ($row['tool'] ?? null) === 'pest' && ($row['result'] ?? null) === 'passed'
&& ($row['tests'] ?? 0) > 0 && ($row['passed'] ?? 0) === $row['tests']);
}
@@ -0,0 +1,38 @@
<?php
use Illuminate\Http\Request;
// Private HTTP composition only. Real Fortify login and CSRF middleware remain in the native routes.
$root = realpath(getenv('SGC_LEGAL_HTTP_QA_ROOT') ?: '');
$database = getenv('DB_DATABASE') ?: '';
$boundary = realpath(__DIR__.'/../../storage/framework/testing');
if (getenv('APP_ENV') !== 'testing' || getenv('DB_HOST') !== '127.0.0.1' || ! preg_match('/^compras_receipts_test_[a-f0-9]{12}$/D', $database)
|| ($_SERVER['REMOTE_ADDR'] ?? '') !== '127.0.0.1' || ($_SERVER['SERVER_PORT'] ?? '') != getenv('SGC_LEGAL_HTTP_QA_PORT')
|| $root === false || $boundary === false || str_replace('\\', '/', $root) !== str_replace('\\', '/', $boundary).'/legal-http-'.$database) {
http_response_code(503);
exit;
}
require __DIR__.'/../../vendor/autoload.php';
$public = $root.'/public';
$requestPath = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
$asset = realpath($public.'/'.ltrim(rawurldecode($requestPath), '/'));
$types = ['js' => 'text/javascript', 'css' => 'text/css', 'svg' => 'image/svg+xml', 'png' => 'image/png', 'ico' => 'image/x-icon', 'woff' => 'font/woff', 'woff2' => 'font/woff2'];
if ($asset !== false && is_file($asset) && str_starts_with(str_replace('\\', '/', $asset), str_replace('\\', '/', $public).'/')
&& isset($types[pathinfo($asset, PATHINFO_EXTENSION)])) {
header('Content-Type: '.$types[pathinfo($asset, PATHINFO_EXTENSION)]);
readfile($asset);
exit;
}
$app = require __DIR__.'/../../bootstrap/app.php';
$app->useStoragePath($root.'/storage');
$app->usePublicPath($root.'/public');
$app->booted(function () use ($root, $database) {
if (config('database.default') !== 'pgsql' || config('database.connections.pgsql.database') !== $database) {
abort(503);
}
config(['capital-register.qa_enabled' => true, 'import-legal.qa_enabled' => true, 'import-tariffs.qa_enabled' => true,
'import-dossier.qa_enabled' => true, 'import-bank-support.qa_enabled' => true, 'import-readiness.qa_enabled' => true, 'import-estimates.qa_enabled' => true,
'session.driver' => 'file', 'session.files' => $root.'/storage/framework/sessions', 'session.domain' => null,
'session.secure' => false, 'cache.default' => 'array']);
});
$app->handleRequest(Request::capture());