$value) { putenv($key.'='.$value); $_ENV[$key] = $_SERVER[$key] = $value; } require $root.'/vendor/autoload.php'; $app = require $root.'/bootstrap/app.php'; $app->make(Kernel::class)->bootstrap(); if (DB::getDriverName() !== 'pgsql' || DB::connection()->getDatabaseName() !== $proof['database']) { throw new LogicException('Review verification database mismatch.'); } $request = DB::table('requisitions')->where('id', $proof['synthetic_fixture']['draft'])->first(); if (in_array('--saved-searches', $argv, true)) { $owner = DB::table('users')->where('email', $proof['synthetic_fixture']['users']['owner'])->sole(); $saved = DB::table('procurement_saved_searches')->sole(); if ($saved->tenant_id !== $owner->tenant_id || $saved->user_id !== $owner->id || (int) $saved->version !== 4 || $saved->name !== 'Meus pedidos revistos QA' || $saved->term !== 'REQ' || $saved->archived_at !== null || $request->status !== 'draft' || (int) $request->process_version !== 2 || DB::table('audit_logs')->where('requisition_id', $request->id)->where('action', 'requisition.updated')->exists() || DB::table('budget_entries')->where('requisition_id', $request->id)->exists() || DB::table('budget_distributions')->where('requisition_id', $request->id)->exists() || DB::table('invoices')->exists()) { throw new RuntimeException('Saved criteria must preserve owner, four native versions and absence of draft or financial operations.'); } echo json_encode(['native_private_search_cycle' => true, 'one_preference' => true, 'version' => 4, 'criterion_preserved' => true, 'active_after_restore' => true, 'no_draft_update_reservation_or_invoice' => true], JSON_THROW_ON_ERROR).PHP_EOL; exit; } if (in_array('--category', $argv, true)) { $line = DB::table('requisition_items')->where('requisition_id', $request->id)->sole(); $context = json_decode($line->category_context, true, 32, JSON_THROW_ON_ERROR); if ($request->status !== 'draft' || (int) $request->process_version !== 3 || $context !== ['version' => 1, 'category' => 'office_equipment', 'reason' => 'Artigo sintético de escritório ainda sem entrada no catálogo.'] || $line->category !== 'Material' || $line->purchase_type !== 'consumable' || (int) $request->total_minor !== 10000 || DB::table('budget_entries')->where('requisition_id', $request->id)->exists() || DB::table('budget_distributions')->where('requisition_id', $request->id)->exists() || DB::table('audit_logs')->where('requisition_id', $request->id)->where('action', 'requisition.updated')->count() !== 1 || DB::table('invoices')->exists()) { throw new RuntimeException('Native classification save must preserve the original category, type, totals and absence of business effects.'); } echo json_encode(['native_category_saved' => true, 'explicit_reason_preserved' => true, 'original_descriptors_and_totals_preserved' => true, 'draft_version' => 3, 'one_update_audit' => true, 'no_reservation_or_invoice' => true], JSON_THROW_ON_ERROR).PHP_EOL; exit; } $plan = json_decode($request->budget_distribution_preparation, true, 32, JSON_THROW_ON_ERROR); if ((int) $request->process_version !== 3 || $request->status !== 'draft' || count($plan['allocations']) !== 2 || array_column($plan['allocations'], 'subtotal_minor') !== [5000, 5000] || array_column($plan['allocations'], 'total_minor') !== [5000, 5000] || DB::table('budget_distributions')->where('requisition_id', $request->id)->exists() || DB::table('audit_logs')->where('requisition_id', $request->id)->where('action', 'requisition.allocations_prepared')->count() !== 2) { throw new RuntimeException('Browser correction did not preserve the draft, exact values and absence of financial effects.'); } echo json_encode(['native_browser_draft_saved' => true, 'version' => 3, 'failed_attempt_no_effects' => true, 'two_explicit_allocations' => true, 'no_reservation_on_prepare' => true], JSON_THROW_ON_ERROR).PHP_EOL; if (in_array('--amended', $argv, true)) { $order = DB::table('purchase_orders')->where('id', $proof['synthetic_fixture']['foreign_order'])->first(); $source = DB::table('budget_distributions')->where('requisition_id', $order->requisition_id)->first(); $current = json_decode($source->snapshot, true, 32, JSON_THROW_ON_ERROR); $original = json_decode(DB::table('budget_distribution_events')->where('distribution_id', $source->id)->where('kind', 'commit')->value('snapshot'), true, 32, JSON_THROW_ON_ERROR); $document = json_decode($order->snapshot, true, 32, JSON_THROW_ON_ERROR); $values = array_column($current['allocations'], 'total_minor'); sort($values); if ($current['amendment_version'] !== 1 || $values !== [4999, 5001] || array_column($original['allocations'], 'total_minor') !== [5000, 5000] || array_sum(array_column($current['allocations'], 'subtotal_minor')) !== 10000 || $document['budget_control']['plan_hash'] !== $original['plan_hash'] || $document['exchange_basis']['rate'] !== '1.0000000000' || $order->currency !== 'USD' || (int) $order->total_minor !== 10000 || DB::table('budget_distribution_events')->where('distribution_id', $source->id)->count() !== 4 || DB::table('audit_logs')->where('requisition_id', $order->requisition_id)->where('action', 'budget.distribution_amended')->count() !== 1) { throw new RuntimeException('Native browser amendment did not preserve the original document, exact total, version and history.'); } if (DB::table('invoices')->count() !== 0 || DB::table('purchase_awards')->where('requisition_id', $proof['synthetic_fixture']['award'])->exists()) { throw new RuntimeException('Read-only invoice/adjudication review unexpectedly registered a business document.'); } echo json_encode(['native_browser_finance_amendment' => true, 'version' => 1, 'original_commitment_and_rate_preserved' => true, 'one_amendment_and_audit' => true], JSON_THROW_ON_ERROR).PHP_EOL; }