getLine().PHP_EOL);exit(1);}); require __DIR__.'/boot-QA.php'; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Crypt; use Illuminate\Support\Facades\Hash; $private=dirname($source);$file=$private.'/fixture-private.json';if(is_file($file))throw new RuntimeException('Preserve fixture'); $tables=['sectors','reference_catalog_versions','economic_activities','economic_clusters','value_chains','value_chain_links','portal_role_assignments','portal_superuser_pair','existing_businesses','existing_business_revisions','business_workflow_transitions','opportunities','audit_events']; $before=[]; foreach($tables as$t){$before[$t]=DB::table($t)->orderBy('id')->get()->toArray();} file_put_contents($private.'/database-before.json',json_encode($before,JSON_THROW_ON_ERROR)); $actors=[]; foreach([2=>'manager',21=>'owner',24=>'reviewer',25=>'publisher',23=>'outsider',31=>'auditor']as$id=>$role){ $password=bin2hex(random_bytes(20));$alphabet='ABCDEFGHIJKLMNOPQRSTUVWXYZ234567';$secret='';for($i=0;$i<32;$i++)$secret.=$alphabet[random_int(0,31)]; $email='qa-economic-'.$id.'@example.invalid'; DB::table('users')->where('id',$id)->update(['email'=>$email,'email_verified_at'=>now(),'password'=>Hash::make($password),'two_factor_secret'=>Crypt::encrypt($secret),'two_factor_recovery_codes'=>Crypt::encrypt('[]'),'two_factor_confirmed_at'=>now(),'remember_token'=>null]); $actors[$role]=['id'=>$id,'email'=>$email,'password'=>$password,'secret'=>$secret]; } $extra="PORTAL_MANAGER_EMAILS=qa-economic-2@example.invalid,qa-economic-31@example.invalid\nPORTAL_OPPORTUNITY_SPECIALIZED_DRAFTS_ENABLED=true\n"; file_put_contents($source.'/.env',$extra,FILE_APPEND); $document=DB::table('documents')->where('id','025cce5b-73c1-43a3-b969-dc6e592bc28d')->first(); if(!$document||$document->file_name!=='synthetic-qa-proof.txt'||$document->status!=='active'||$document->malware_scan_status!=='clean'||trim($document->sha256)!==trim($document->malware_scanned_sha256))throw new RuntimeException('Synthetic QA scanned support required'); $reference=dirname(__DIR__,2).'/storage/app/private/investmoz-v2/portal-audit/portal-stability-source-20261011_083742/storage/app/private'; $stored=file_get_contents($reference.'/'.$document->storage_key);$bytes=$document->storage_encryption==='laravel'?Crypt::decryptString($stored):$stored; if(hash('sha256',$bytes)!==trim($document->sha256))throw new RuntimeException('Synthetic bytes mismatch'); $dest=$source.'/storage/app/private/'.$document->storage_key;if(!is_dir(dirname($dest)))mkdir(dirname($dest),0700,true);file_put_contents($dest,$stored); $businessId='172aa874-98fc-4bf6-b78f-d2e9a386d345';$b=App\Models\ExistingBusiness::findOrFail($businessId);if($b->status!=='published'||$b->version_no!==12)throw new RuntimeException('Published QA v12 required'); $link=DB::table('existing_business_document_links')->where('existing_business_id',$businessId)->where('document_id',$document->id)->value('id'); if(!$link)DB::table('existing_business_document_links')->insert(['id'=>(string)Illuminate\Support\Str::uuid(),'existing_business_id'=>$businessId,'document_id'=>$document->id,'uploaded_by'=>21,'created_at'=>now(),'updated_at'=>now()]); $opportunities=DB::table('opportunities')->where('title','like','%QA%')->orderBy('id')->get(['id','title','status','owner_user_id','opportunity_category','workflow_context']); $selection=[]; foreach($opportunities as$o){$ctx=json_decode($o->workflow_context,true);$selection[]=['id'=>$o->id,'title'=>$o->title,'status'=>$o->status,'owner'=>$o->owner_user_id,'category'=>$o->opportunity_category,'context_keys'=>array_keys($ctx??[])];} file_put_contents(__DIR__.'/CANONICAL-CANDIDATES-QA.json',json_encode($selection,JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE)); $f=['url'=>'http://127.0.0.1:18531','database'=>'economic_references_20261016_test','actors'=>$actors,'business_id'=>$businessId,'business_slug'=>$b->public_slug,'document_id'=>$document->id]; file_put_contents($file,json_encode($f,JSON_THROW_ON_ERROR)); file_put_contents(__DIR__.'/FIXTURE-QA.json',json_encode(['database'=>$f['database'],'synthetic_accounts_in_clone'=>6,'grants_changed'=>0,'new_businesses'=>0,'document'=>$document->id,'existing_clean_bytes_verified'=>true,'active_changes'=>0],JSON_PRETTY_PRINT)); echo json_encode(['fixture'=>'private values retained locally','opportunity_candidates'=>count($selection),'business_version'=>$b->version_no,'role_assignments_unchanged'=>DB::table('portal_role_assignments')->orderBy('id')->get()->toArray()===$before['portal_role_assignments']]);