124 lines
9.5 KiB
PHP
124 lines
9.5 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 === 'recover-cycles') {
|
|
return $contains(fn ($row) => ($row['cycle_post_extension_all_tables_equal'] ?? false) === true
|
|
&& ($row['cycle_native_replays_without_effects'] ?? false) === true && ($row['cycle_history_and_reserve_restored'] ?? false) === true
|
|
&& ($row['cycle_reserved_minor'] ?? null) === 12000 && ($row['cycle_pre_extension_all_tables_equal'] ?? false) === true)
|
|
&& $contains(fn ($row) => ($row['isolated_restore_removed'] ?? false) === true);
|
|
}
|
|
if ($mode === 'race-cycles') {
|
|
foreach (['same_operation', 'different_operations', 'late_decision'] 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]['returns'] ?? null) !== 1 || ($matches[0]['reserve_minor'] ?? null) !== 0
|
|
|| ($matches[0]['late_approvals'] ?? null) !== 0
|
|
|| ($matches[0]['statuses'] ?? null) !== ($scenario === 'same_operation' ? [200, 200] : [200, 409])) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return $contains(fn ($row) => ($row['old_cycle_runtime_rejected_before_balance'] ?? false) === true && ($row['status'] ?? null) === 503);
|
|
}
|
|
if ($mode === 'capital') {
|
|
if (! $contains(fn ($row) => ($row['capital_register_versions_restored'] ?? null) === 2
|
|
&& ($row['capital_assignment_source_version_restored'] ?? null) === 1 && ($row['capital_archived_head_preserved'] ?? false) === true
|
|
&& ($row['capital_replay_without_effects'] ?? false) === true)) {
|
|
return false;
|
|
}
|
|
$mode = 'import-legal-amount';
|
|
}
|
|
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', '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) !== (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;
|
|
}
|
|
}
|
|
|
|
return 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) === (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']);
|
|
}
|