make(\Illuminate\Contracts\Console\Kernel::class)->bootstrap(); \App\Shared\Testing\TestingDatabaseGuard::assertSafe(); $f=json_decode(file_get_contents('C:/laragon/data/sgf-tempo/secrets/browser-fixture.json'),true,32,JSON_THROW_ON_ERROR); $input=['actor'=>$f['manager_id'],'tenant'=>$f['tenant'],'company'=>$f['company'],'unit'=>$f['unit'],'draft'=>$f['calculation_drafts'][1], 'command'=>['draft_version'=>1,'preparation_version'=>1,'profile_id'=>$f['calculation_profile'],'profile_version'=>1]]; $a=new Process([PHP_BINARY,'scripts/calculation-worker.php','--env=testing'],base_path(),null,json_encode($input+['pause'=>true])); $b=new Process([PHP_BINARY,'scripts/calculation-worker.php','--env=testing'],base_path(),null,json_encode($input)); $a->start(); if (!$a->waitUntil(fn ($type,$buffer)=>str_contains($buffer,'LOCK_HELD'))) { throw new RuntimeException('No concurrent lock established.'); } $b->start(); $a->wait(); $b->wait(); $results=[]; foreach ([$a,$b] as $worker) { if (!$worker->isSuccessful()) { throw new RuntimeException('Calculation worker failed.'); } $lines=array_values(array_filter(explode("\n",trim($worker->getOutput())),fn($s)=>str_starts_with($s,'{'))); $results[]=json_decode(end($lines),true,32,JSON_THROW_ON_ERROR); } if ($results[0]['id']!==$results[1]['id'] || $results[0]['replayed'] || !$results[1]['replayed'] || DB::table('service_calculation_results')->where('billing_draft_id',$input['draft'])->count()!==1) { throw new RuntimeException('Concurrent duplicate or unexpected replay.'); } file_put_contents(base_path('docs/proofs/calculation-concurrency.json'),json_encode(['database'=>'sgf_tempo_test','two_php_processes'=>true,'lock_overlap_observed'=>true,'same_result_id'=>true,'one_insert_one_replay'=>true,'result_count'=>1],JSON_PRETTY_PRINT|JSON_THROW_ON_ERROR)); echo "Concurrent calculation: one immutable result, one replay, two overlapping PHP processes.\n";