Files
compras/tests/Support/LandedQaReceipts.php
T
nala e709d900d1
tests / ci (push) Waiting to run
commit compras 2711
2026-11-27 13:49:31 +02:00

73 lines
4.6 KiB
PHP

<?php
/** PostgreSQL migration functions survive table refreshes across different Pest kernels.
* @param list<list<string>> $commands
*/
function landedQaCommandIsolationVerified(array $commands): bool
{
return count(array_filter($commands, fn ($command) => ($command[1] ?? '') === 'vendor/bin/pest')) <= 1;
}
/** Test-only protocol: a successful exit without verification receipts is not a passing proof.
* @param list<string> $command
*/
function landedQaReceiptsVerified(array $command, string $output): bool
{
$records = array_values(array_filter(array_map(fn ($line) => json_decode($line, true), explode("\n", $output)), 'is_array'));
$contains = static function (callable $test) use ($records): bool {
foreach ($records as $record) {
if ($test($record)) {
return true;
}
}
return false;
};
$mode = ($command[1] ?? '') === 'vendor/bin/pest' ? 'pest' : ($command[3] ?? '');
if ($mode === 'migrate') {
return $contains(fn ($row) => ($row['isolated_schema_prepared'] ?? false) === true);
}
if (in_array($mode, ['race', 'race-estimate', 'race-estimate-reconcile'], true)) {
foreach (['same_operation', 'conflicting_plan_version', 'same_source_different_plan'] 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]['commands'] ?? 0) !== ($mode === 'race-estimate-reconcile' ? 3 : 1) || ($matches[0]['audits'] ?? 0) !== 1
|| ($mode === 'race-estimate' && (($matches[0]['estimate'] ?? false) !== true || ($matches[0]['reserved_minor'] ?? null) !== 2000))
|| ($mode === 'race-estimate-reconcile' && (($matches[0]['reconciliation'] ?? false) !== true || ($matches[0]['reserved_minor'] ?? null) !== 3000))
|| ($matches[0]['statuses'] ?? null) !== ($scenario === 'same_operation' ? [200, 200] : [200, 409])) {
return false;
}
}
return $contains(fn ($row) => ($row['old_runtime_rejected_before_balance'] ?? false) === true && ($row['status'] ?? 0) === 503)
&& (! 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)) {
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]['statuses'] ?? null) !== ($scenario === 'same_operation' ? [200, 200] : [200, 409])) {
return false;
}
}
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))
&& $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
&& ($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);
}
return $mode === 'pest' && $contains(fn ($row) => ($row['tool'] ?? null) === 'pest' && ($row['result'] ?? null) === 'passed'
&& ($row['tests'] ?? 0) > 0 && ($row['passed'] ?? 0) === $row['tests']);
}