<?php
declare(strict_types=1);require __DIR__.'/bootstrap.php';require __DIR__.'/cases.php';$lock=fopen($runtime.'/run.lock','c');$check(flock($lock,LOCK_EX|LOCK_NB),'Serial same-lane run');$check(!is_file($runtime.'/run-started.json'),'No HTTP phase replay');$f=json_decode(file_get_contents($runtime.'/fixture-journal.json'),true);$check($f['committed']&&isset($f['after']),'Committed7 journal');$check($own()===$f['after'],'Batch-start all36 full original rows exact');$app=guardedApp($root,$runtime,'AUTH_PREPARATION');$cache=new \think\cache\driver\File($app,['path'=>$runtime.'/cache/','prefix'=>'','expire'=>0]);$tokens=[];$prior=json_decode(file_get_contents('/tmp/cdx-ai-admin-device-dishes-read5-20261011/private/evidence/final-original.json'),true)['original'];
foreach($tenants as $m=>$t){$old=array_values(array_filter($prior['store_user'],static function($r)use($t){return (int)$r['store_id']===$t;}));$check(count($old)===1,'Old marked operator');$class='app\\'.$m.'\\model\\store\\User';$model=$class::withoutGlobalScope()->where('store_user_id','=',(int)$old[0]['store_user_id'])->where('store_id','=',$t)->find();$check($model!==null,'Original normal Auth principal exists');$profile=$model->toArray();$check(!array_key_exists('password',$profile)&&(int)$profile['is_super']===1,'Original profile hides password');$tokens[$m]=bin2hex(random_bytes(24));$cache->set($tokens[$m],['user'=>$profile,'store_id'=>$t,'is_login'=>true],3600);}
$cases=ledgerCases($f,$prior);$persist('cases-NA.json',$cases);$persist('run-started.json',['lane'=>$lane,'case_count'=>count($cases),'no_replay'=>true]);$results=[];
try{foreach($cases as $scenario=>$c){$url=$base.$c['path'].'?'.$c['query'];$headers=['Host: '.$c['host'],'Platform: POC','X-Pilot-Scenario: '.$scenario];if($c['auth'])$headers[]='Access-Token: '.$tokens[$c['context']];$entry=['scenario'=>$scenario,'method'=>'GET','url'=>$url,'started'=>true,'response_received'=>false];file_put_contents($runtime.'/http-attempts.jsonl',json_encode($entry)."\n",FILE_APPEND|LOCK_EX);chmod($runtime.'/http-attempts.jsonl',0600);$ctx=stream_context_create(['http'=>['method'=>'GET','header'=>implode("\r\n",$headers),'timeout'=>30,'ignore_errors'=>true]]);$started=microtime(true);$raw=file_get_contents($url,false,$ctx);$responseHeaders=$http_response_header??[];$entry['response_received']=$raw!==false;$entry['response_headers']=$responseHeaders;$entry['elapsed_ms']=(microtime(true)-$started)*1000;$entry['raw']=$raw;$persist('response-'.$scenario.'.json',$entry);if($raw!==false){file_put_contents($runtime.'/response-'.$scenario.'.body',$raw);chmod($runtime.'/response-'.$scenario.'.body',0600);}$body=$raw!==false?json_decode($raw,true):null;$results[]=['scenario'=>$scenario,'received'=>$raw!==false,'json'=>is_array($body),'status'=>$body['status']??null,'harness_error'=>$body['harness_error']??null,'raw_sha256'=>$raw!==false?hash('sha256',$raw):null];}
 $end=$own();$check($end===$f['after'],'Batch-end all36 original scope exact');$persist('final-original.json',['lane'=>$lane,'original'=>$end,'marked7_retained'=>true,'old32_exact'=>true]);
}finally{foreach($tokens as $token)$cache->delete($token);$out=['lane'=>$lane,'true_http_attempts'=>count($results),'results'=>$results,'all_own_tokens_absent'=>count(array_filter($tokens,static function($t)use($cache){return $cache->has($t);}))===0];$persist('run-NA.json',$out);echo json_encode($out),"\n";}
