basePath();$id=json_decode(file_get_contents(__DIR__.'/FUNCTIONAL-STATE.json'),true)['case_id'];$actor=App\Models\User::findOrFail(21);$desk=app(App\Services\VirtualDesk::class);$before=$desk->case($actor,$id);$ctx=app(App\Services\InvestorContext::class)->view($actor,$id); $requests=DB::table('desk_requests')->where('case_id',$id)->orderBy('id')->get()->toJson();$public=DB::table('existing_businesses')->where('id','172aa874-98fc-4bf6-b78f-d2e9a386d345')->first();$publicHash=hash('sha256',json_encode($public,JSON_THROW_ON_ERROR)); function methodTokens($file,$method){$tokens=token_get_all(file_get_contents($file));$record=false;$seen=false;$depth=0;$out='';foreach($tokens as$i=>$t){if(is_array($t)&&$t[0]===T_FUNCTION){$j=$i+1;while(isset($tokens[$j])&&is_array($tokens[$j])&&$tokens[$j][0]===T_WHITESPACE)$j++;if(is_array($tokens[$j]??null)&&$tokens[$j][1]===$method)$record=true;}if(!$record)continue;$v=is_array($t)?$t[1]:$t;if(is_array($t)&&in_array($t[0],[T_WHITESPACE,T_COMMENT,T_DOC_COMMENT],true))continue;$out.=$v;if($v==='{'){$depth++;$seen=true;}if($v==='}'&&--$depth===0&&$seen)break;}return hash('sha256',$out);} if(methodTokens($root.'/app/Services/VirtualDesk.php','stage')!==methodTokens($source.'/app/Services/VirtualDesk.php','stage'))throw new RuntimeException('Previous editor method changed'); if(hash_file('sha256',$root.'/resources/js/pages/desk/case.tsx')!==hash_file('sha256',$source.'/resources/js/pages/desk/case.tsx'))throw new RuntimeException('Previous editor changed'); $after=$desk->stage($actor,$id,['version'=>$before->version,'stage'=>'E0','status'=>'preparing','reason'=>'Ensaio sintético QA de edição pelo editor anterior na reversão compatível.']); $view=app(App\Services\InvestorContext::class)->view($actor,$id); if($before->payload!==$after->payload||$ctx['context']!==$view['context']||$ctx['results']!==$view['results']||$requests!==DB::table('desk_requests')->where('case_id',$id)->orderBy('id')->get()->toJson())throw new RuntimeException('After-use data lost by previous editor'); if($publicHash!==hash('sha256',json_encode(DB::table('existing_businesses')->where('id',$public->id)->first(),JSON_THROW_ON_ERROR)))throw new RuntimeException('Published reference modified'); $routes=collect(app('router')->getRoutes()->getRoutes())->map(fn($r)=>$r->uri())->all();if(in_array('investimentos/{id}/contexto/confirmar',$routes,true))throw new RuntimeException('Context writes still exposed'); $proof=['target'=>$target,'previous_editor_sha256'=>hash_file('sha256',$root.'/resources/js/pages/desk/case.tsx'),'previous_stage_method_tokens_sha256'=>methodTokens($root.'/app/Services/VirtualDesk.php','stage'),'save_executed'=>true,'case_version_before'=>$before->version,'case_version_after'=>$after->version,'encrypted_payload_byte_identical'=>true,'context_preserved'=>true,'financial_evidence_and_stale_markers_preserved'=>true,'submitted_request_rows_byte_identical'=>true,'published_reference_untouched'=>true,'published_reference_baseline_version'=>(int)$public->version_no,'context_write_routes_removed'=>true,'retained_sources'=>json_decode(file_get_contents(__DIR__.'/COMPATIBILITY-FILES.json'),true)['retained_sources'],'scope'=>'Editor anterior e método de gravação anteriores, com componentes de compatibilidade explicitamente mantidos. Não é reposição literal de todo o código antigo.'];file_put_contents(__DIR__.'/COMPATIBILITY-QA.json',json_encode($proof,JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE));echo json_encode(['previous_editor_save'=>true,'payload_preserved'=>true,'submitted_requests_preserved'=>true,'compatible_sources'=>count($proof['retained_sources'])]);