make(\Illuminate\Contracts\Console\Kernel::class)->bootstrap(); \App\Shared\Testing\TestingDatabaseGuard::assertSafe(); $fixture = json_decode(file_get_contents('C:/laragon/data/sgf-tempo/secrets/browser-fixture.json'), true, 32, JSON_THROW_ON_ERROR); app(\App\Shared\Context\CompanyContext::class)->selectFor($fixture['manager_id'], $fixture['tenant'], $fixture['company'], $fixture['unit']); $preparation = app(\App\Modules\Services\DocumentPreparation::class); $issuer = $preparation->show('issuer', $fixture['company'], $fixture['manager_id']); $client = $preparation->show('client', $fixture['document_client_id'], $fixture['manager_id']); $input = ['actor' => $fixture['manager_id'], 'tenant' => $fixture['tenant'], 'company' => $fixture['company'], 'unit' => $fixture['unit'], 'draft' => $fixture['document_draft_id'], 'issuer' => $issuer['data']['nuit'], 'client' => $client['data']['nuit']]; $worker = new Process([PHP_BINARY, 'scripts/preview-coherence-worker.php', '--env=testing'], base_path(), null, json_encode($input)); $worker->start(); if (! $worker->waitUntil(fn ($type, $buffer) => str_contains($buffer, 'SNAPSHOT_STARTED'))) { throw new RuntimeException('Could not establish concurrent snapshot.'); } DB::transaction(function () use ($preparation, $fixture, $issuer, $client): void { $preparation->save('issuer', $fixture['company'], $fixture['manager_id'], ['version' => (int) $issuer['version']] + array_replace($issuer['data'], ['nuit' => 'EMITENTE-SINTETICO-REVISTO'])); $preparation->save('client', $fixture['document_client_id'], $fixture['manager_id'], ['version' => (int) $client['version']] + array_replace($client['data'], ['nuit' => 'CLIENTE-SINTETICO-REVISTO'])); }); $worker->wait(); if (! $worker->isSuccessful()) { throw new RuntimeException('Synthetic snapshot process failed.'); } $lines = array_values(array_filter(explode("\n", trim($worker->getOutput())), fn ($line) => str_starts_with($line, '{'))); $result = json_decode(end($lines), true, 32, JSON_THROW_ON_ERROR); if (in_array(false, $result, true)) { throw new RuntimeException('Mixed snapshot detected.'); } $next = app(\App\Modules\Services\DocumentPreview::class)->read($fixture['document_draft_id'], $fixture['manager_id']); if ($next['issuer']['data']['nuit'] !== 'EMITENTE-SINTETICO-REVISTO' || $next['client']['data']['nuit'] !== 'CLIENTE-SINTETICO-REVISTO') { throw new RuntimeException('Explicit refresh did not observe committed changes.'); } file_put_contents(base_path('docs/proofs/preview-coherence.json'), json_encode(['database' => 'sgf_tempo_test', 'parallel_php_processes' => true, 'repeatable_read_verified' => true, 'old_consultation' => 'both original versions', 'explicit_new_consultation' => 'both committed new versions', 'mixed_versions' => false, 'instruction_values' => 'omitted'], JSON_PRETTY_PRINT|JSON_THROW_ON_ERROR)); echo "Concurrent preview coherence passed: old snapshot remained coherent; new consultation saw both committed versions.\n";