true, 'old_estimate_runtime_rejected' => true, 'runtime_landed_version' => 'COMMON-BUDGET-LANDED-COST-QA-v2', 'status' => 503]]; foreach (['same_operation', 'conflicting_plan_version', 'same_source_different_plan'] as $scenario) { $rows[] = ['scenario' => $scenario, 'estimate' => true, 'statuses' => $scenario === 'same_operation' ? [200, 200] : [200, 409], 'blocked_writers_observed' => 2, 'commands' => 1, 'audits' => 1, 'reserved_minor' => 2000]; } $encode = fn ($records) => implode("\n", array_map(fn ($row) => json_encode($row, JSON_THROW_ON_ERROR), $records)); expect(landedQaReceiptsVerified($command, $encode($rows)))->toBeTrue(); $reconciliation = $rows; foreach ($reconciliation as &$row) { if (isset($row['scenario'])) { $row['reconciliation'] = true; $row['commands'] = 3; $row['reserved_minor'] = 3000; } } unset($row); $reconcileCommand = [...array_slice($command, 0, 3), 'race-estimate-reconcile']; expect(landedQaReceiptsVerified($reconcileCommand, $encode($reconciliation)))->toBeTrue(); $reconciliation[1]['reserved_minor'] = 2000; expect(landedQaReceiptsVerified($reconcileCommand, $encode($reconciliation)))->toBeFalse(); unset($rows[2]['estimate']); expect(landedQaReceiptsVerified($command, $encode($rows)))->toBeFalse(); }); test('separate Pest kernels cannot reuse one disposable database with persistent migration functions', function () { $pest = ['php', 'vendor/bin/pest', 'tests/Feature/ImportTariffCodesTest.php']; expect(landedQaCommandIsolationVerified([$pest]))->toBeTrue(); expect(landedQaCommandIsolationVerified([['php', 'worker.php', 'db', 'migrate'], $pest]))->toBeTrue(); expect(landedQaCommandIsolationVerified([$pest, $pest]))->toBeFalse(); }); test('the worker mode follows the database argument and a Laravel console exception is never a passing proof', function () { $command = ['php', 'tests/Concurrency/quotation-exchange-worker.php', 'compras_receipts_test_000000000001', 'migrate']; expect(landedQaReceiptsVerified($command, "{\"isolated_schema_prepared\":true}\n"))->toBeTrue(); expect(landedQaReceiptsVerified($command, 'In Connection.php line 864: synthetic missing table'))->toBeFalse(); expect(landedQaReceiptsVerified(['php', 'worker.php', 'compras_receipts_test_000000000001', 'landed-costs'], "{\"isolated_schema_prepared\":true}\n"))->toBeFalse(); }); test('a contention proof requires all three distinct blocked-writer scenarios and the incompatible-runtime refusal', function () { $command = ['php', 'worker.php', 'compras_receipts_test_000000000001', 'race']; $records = []; foreach (['same_operation', 'conflicting_plan_version', 'same_source_different_plan'] as $scenario) { $records[] = ['scenario' => $scenario, 'statuses' => $scenario === 'same_operation' ? [200, 200] : [200, 409], 'blocked_writers_observed' => 2, 'commands' => 1, 'audits' => 1]; } $encode = fn ($rows) => implode("\n", array_map(fn ($row) => json_encode($row, JSON_THROW_ON_ERROR), $rows)); expect(landedQaReceiptsVerified($command, $encode($records)))->toBeFalse(); $records[] = ['old_runtime_rejected_before_balance' => true, 'status' => 503]; expect(landedQaReceiptsVerified($command, $encode($records)))->toBeTrue(); $records[2] = $records[0]; expect(landedQaReceiptsVerified($command, $encode($records)))->toBeFalse(); }); test('restore completion requires the restored replay original snapshot and database cleanup', function () { $command = ['php', 'worker.php', 'compras_receipts_test_000000000001', 'landed-costs']; $proof = json_encode(['post_extension_restore_all_tables_equal' => true, 'recovered_operation_replay_no_effects' => true, 'pre_extension_schema_data_balance_restored' => true], JSON_THROW_ON_ERROR); expect(landedQaReceiptsVerified($command, $proof))->toBeFalse(); $databaseOnly = $proof."\n".json_encode(['isolated_restore_removed' => true], JSON_THROW_ON_ERROR); expect(landedQaReceiptsVerified($command, $databaseOnly))->toBeFalse(); $privateFiles = ['private_original_versions_restored' => 6, 'typed_dossier_versions_restored' => 4, 'selected_party_versions_restored' => 2, 'source_loss_detected' => true, 'separate_private_root_restored' => true, 'native_authorized_evidence_resolved' => true]; expect(landedQaReceiptsVerified($command, $databaseOnly."\n".json_encode($privateFiles, JSON_THROW_ON_ERROR)))->toBeTrue(); $estimateCommand = [...array_slice($command, 0, 3), 'import-estimates']; $existingRecovery = $databaseOnly."\n".json_encode($privateFiles, JSON_THROW_ON_ERROR); expect(landedQaReceiptsVerified($estimateCommand, $existingRecovery))->toBeFalse(); expect(landedQaReceiptsVerified($estimateCommand, $existingRecovery."\n".json_encode([ 'estimate_source_remainder_restored' => 1000, 'estimate_original_replay_without_effects' => true, ], JSON_THROW_ON_ERROR)))->toBeTrue(); $missingTyped = $privateFiles; unset($missingTyped['typed_dossier_versions_restored']); expect(landedQaReceiptsVerified($command, $databaseOnly."\n".json_encode($missingTyped, JSON_THROW_ON_ERROR)))->toBeFalse(); $missingParty = $privateFiles; unset($missingParty['selected_party_versions_restored']); expect(landedQaReceiptsVerified($command, $databaseOnly."\n".json_encode($missingParty, JSON_THROW_ON_ERROR)))->toBeFalse(); expect(landedQaReceiptsVerified(['php', 'vendor/bin/pest', '--compact'], '{"tool":"pest","result":"passed","tests":1,"passed":0,"skipped":1}'))->toBeFalse(); }); test('dossier contention requires both races one original and verified bytes', function () { $command = ['php', 'worker.php', 'compras_receipts_test_000000000001', 'race-dossier']; $rows = []; foreach (['same_operation', 'same_version'] as $scenario) { $rows[] = ['scenario' => $scenario, 'statuses' => $scenario === 'same_operation' ? [200, 200] : [200, 409], 'blocked_writers_observed' => 2, 'documents_created' => 1, 'audits' => 1, 'files_created' => 1, 'all_originals_verified' => true]; } $encode = fn ($records) => implode("\n", array_map(fn ($row) => json_encode($row, JSON_THROW_ON_ERROR), $records)); expect(landedQaReceiptsVerified($command, $encode($rows)))->toBeTrue(); expect(landedQaReceiptsVerified($command, $encode([$rows[0]])))->toBeFalse(); $rows[1]['files_created'] = 2; expect(landedQaReceiptsVerified($command, $encode($rows)))->toBeFalse(); $partyCommand = ['php', 'worker.php', 'compras_receipts_test_000000000001', 'race-party']; foreach ($rows as &$row) { $row['files_created'] = 0; } unset($row); expect(landedQaReceiptsVerified($partyCommand, $encode($rows)))->toBeTrue(); $rows[1]['files_created'] = 1; expect(landedQaReceiptsVerified($partyCommand, $encode($rows)))->toBeFalse(); });