Files
compras/tests/Support/RequisitionLedgerQaRuntime.php
T
nalaandClaude Opus 5.5 8e1e8799a5 Tornar a suite de testes portável e alinhada com o código
- sgfTempoPath(): substitui caminhos C:/laragon fixos (SGF_TEMPO_ROOT, por
  omissão a pasta irmã sgf-tempo, igual ao Laragon).
- skipUnlessIsolatedPostgres(): testes que exigem a base QA PostgreSQL isolada
  passam a ser ignorados com motivo em SQLite em vez de rebentar.
- Artefacto de distribuição orçamental gerado localmente: ignorado se ausente.
- Páginas públicas /consulta e /proposta: testes alinhados com os
  redireccionamentos para os módulos reais (decisão de 29/11).
- Impressão da ordem: texto do aviso orçamental actualizado.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-30 23:01:36 +02:00

49 lines
2.5 KiB
PHP

<?php
use Illuminate\Support\Facades\DB;
use Tempo\Finance\Budget\BudgetControl;
use Tempo\Finance\Composition\Bundle;
use Tempo\Finance\GeneralLedger\LedgerSchema;
use Tempo\Finance\Payables\PayablesSchema;
/** Only the canonical QA source or the exact verified private runtime is accepted. */
function requisitionLedgerQaSource(): ?string
{
$source = getenv('RQ01_LEDGER_QA_SOURCE');
if (! is_string($source) || $source === '') {
return null;
}
if ($source === sgfTempoPath('packages/general-ledger')) {
if (config('common-finance-bundle.manifest_sha256') === '182e10ceec556e120ecb14b57d17f0132ce0b555041cb054cdf9d17bcc1d51df') {
throw new LogicException('A pinned private composition cannot fall back to the canonical development source.');
}
return $source;
}
$root = base_path('storage/framework/testing/requisition-ledger-runtime-qa-182e10ceec556e12');
$pin = '182e10ceec556e120ecb14b57d17f0132ce0b555041cb054cdf9d17bcc1d51df';
$normal = static fn ($value) => is_string($value) && realpath($value) !== false ? str_replace('\\', '/', realpath($value)) : null;
if (! app()->environment('testing') || DB::connection()->getConfig('host') !== '127.0.0.1'
|| DB::connection()->getConfig('port') !== '55439'
|| ! preg_match('/^compras_receipts_test_[a-f0-9]{12}$/D', DB::connection()->getDatabaseName())
|| $normal($source) !== $normal($root.'/general-ledger')
|| $normal(config('common-finance-bundle.root')) !== $normal($root)
|| config('common-finance-bundle.manifest_sha256') !== $pin
|| $normal(config('general-ledger.path')) !== $normal($source)) {
throw new LogicException('Only the pinned independently verified private ledger runtime is allowed.');
}
// AppServiceProvider already verified the pinned loader before loading Bundle or Payables.
Bundle::verify($root, $pin);
require_once $source.'/bootstrap.php';
foreach ([LedgerSchema::class => $root.'/general-ledger',
BudgetControl::class => base_path('storage/framework/testing/requisition-cycles-qa-35701ec1614f871e/budget-control'),
PayablesSchema::class => $root.'/payables'] as $class => $boundary) {
$file = (new ReflectionClass($class))->getFileName();
if (! is_string($file) || ! str_starts_with($normal($file) ?? '', ($normal($boundary) ?? 'unavailable').'/')) {
throw new LogicException('A financial class escaped the pinned private composition.');
}
}
return $source;
}