<?php
declare(strict_types=1);
require __DIR__.'/bootstrap.php';$check($lane==='B','B source-identity reprobe only');
$p=json_decode((string)file_get_contents($runtime.'/private-retention.json'),true);$report=json_decode((string)file_get_contents($runtime.'/report.json'),true);$ownedIds=$p['owned_primary_keys'];$sid=$p['staff_id'];$uid=$p['user_id'];$check($p['tenant']===$tenant&&$p['marker']===$marker,'Existing retained chain');
$root=(string)getenv('CATEGORY_ROOT');$check(hash_file('sha256',$root.'/app/store/model/nutrition/Nutrition.php')==='a68cdfa33dfe1cac94823b546e43e0e4550185db6a1349fd699b2574989db9a9','Exact final model source');
define('TP_ENV','poc');define('BUSINESS','aizhct');define('ENTERPRISE_NO','10001');require $root.'/vendor/autoload.php';$app=new \think\App($root);$app->setEnvName('poc');$app->setRuntimePath($runtime.'/fixture-runtime/');$app->initialize();
$cache=new \think\cache\driver\File($app,['path'=>$runtime.'/cache/','prefix'=>'','expire'=>0]);$token=bin2hex(random_bytes(24));$cache->set($token,['user'=>['store_user_id'=>$tenant,'store_id'=>$tenant,'real_name'=>$marker,'user_name'=>$marker,'is_super'=>1],'store_id'=>$tenant,'is_login'=>true],1800);
$shape=static function($v)use(&$shape){if(is_object($v)){$o=[];foreach(get_object_vars($v) as $k=>$x)$o[$k]=$shape($x);ksort($o);return ['object'=>$o];}if(is_array($v))return ['array'=>array_map($shape,$v)];return gettype($v);};$new=[];
$request=static function(string $name,string $action,array $data)use($base,$token,$check,$shape,&$new,&$p):array{
    $scenario='PILOT_NT_GREEN_PLAN_'.$name;$raw=file_get_contents($base.'/store/nutrition.Nutrition/'.$action,false,stream_context_create(['http'=>['method'=>'POST','header'=>"Host: store.nutrition-target.invalid\r\nAccess-Token: ".$token."\r\nPlatform: POC\r\nX-Pilot-Scenario: ".$scenario."\r\nContent-Type: application/json\r\n",'content'=>json_encode($data,JSON_UNESCAPED_UNICODE),'timeout'=>30,'ignore_errors'=>true]]));$body=json_decode($raw,true);preg_match('#^HTTP/\S+\s+(\d+)#',$http_response_header[0]??'',$m);$check(($m[1]??'')==='200'&&($body['status']??0)===200,'Reprobe actual HTTP '.$name);$case=['scenario'=>$scenario,'method'=>'POST','path'=>'/store/nutrition.Nutrition/'.$action,'http_status'=>200,'body'=>$body,'raw_json_shape'=>$shape(json_decode($raw))];$new[$scenario]=$case;$p['responses'][$scenario]=$raw;return $case;
};
$plan=['staff_id'=>$sid,'set_date'=>'2030-04-02','data'=>[['name'=>$marker."_补充'甲",'use_time'=>"饭后'30分钟",'use_number'=>'1.50','unit_id'=>1,'method'=>"中文\\服用"]]];
$request('ADD_ORIGINAL_PC','add',$plan);$all=$query('SELECT * FROM yoshop_nurtrition WHERE staff_id=? AND store_id=? ORDER BY id',[$sid,$tenant]);$active=[];
foreach($all as $row){$check((int)$row['user_id']===$tenant&&strpos($row['name'],$marker)===0,'Reprobe exact plan owner');$id=(int)$row['id'];if(!in_array($id,$ownedIds['nurtrition'],true))$ownedIds['nurtrition'][]=$id;if((int)$row['is_delete']===0)$active[]=$row;}
$check(count($active)===1,'Reprobe source one active');$map=json_decode((string)file_get_contents($runtime.'/private-owned-map.json'),true);$map['plan_ids']=$ownedIds['nurtrition'];file_put_contents($runtime.'/private-owned-map.json',json_encode($map));
$c=$request('LIST_NONEMPTY','lists',['staff_id'=>$sid,'start_date'=>'2030-04-02','end_date'=>'2030-04-02','page'=>1,'page_size'=>10]);$want=$active[0];foreach(['id','user_id','staff_id','unit_id','store_id','is_delete'] as $k)$want[$k]=(int)$want[$k];foreach(['create_time','update_time'] as $k)$want[$k]=date('Y-m-d H:i:s',strtotime($want[$k]));$check($c['body']['data']===['list'=>['total'=>1,'per_page'=>10,'current_page'=>1,'last_page'=>1,'data'=>[$want]]],'Reprobe full original table/wire strict types/order');
$id=(int)$active[0]['id'];$request('DELETE_OWN','delete',['id'=>$id]);$r=$query('SELECT * FROM yoshop_nurtrition WHERE id=? AND staff_id=? AND store_id=?',[$id,$sid,$tenant]);$check(count($r)===1&&(int)$r[0]['is_delete']===1,'Reprobe real soft delete');$c=$request('LIST_EMPTY','lists',['staff_id'=>$sid,'start_date'=>'2030-04-02','end_date'=>'2030-04-02','page'=>1,'page_size'=>10]);$check($c['body']['data']===['list'=>['total'=>0,'per_page'=>10,'current_page'=>1,'last_page'=>0,'data'=>[]]],'Reprobe empty exact pagination');
$cache->delete($token);$cache->clear();$check($cache->get($token)===null,'Reprobe token removed');
foreach($p['cases'] as &$c)if(isset($new[$c['scenario']]))$c=$new[$c['scenario']];unset($c);$p['owned_primary_keys']=$ownedIds;foreach($p['proofs'] as &$proof)if($proof['kind']==='plan')$proof['source_owned_rows']=count($all);unset($proof);
$newEvents=[];foreach(file($runtime.'/queries.jsonl',FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES)?:[] as $line)$newEvents[]=json_decode($line,true);$oldEvents=array_values(array_filter($report['events'],static function($e){return strpos($e['scenario'],'PILOT_NT_GREEN_PLAN_')!==0;}));$report['events']=array_merge($oldEvents,$newEvents);
$newAudit=[];foreach(file($runtime.'/write-audit.jsonl',FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES)?:[] as $line)$newAudit[]=json_decode($line,true);$otherAudit=array_values(array_filter($report['write_audit'],static function($e){return $e['table']!=='yoshop_nurtrition';}));$report['write_audit']=array_merge($newAudit,$otherAudit);$report['retention']['counts']['nurtrition']=count($all);$report['resources']=['token_absent'=>true,'cache_files'=>0];
$report['source_identity_reprobe']=['candidate_original_preserved'=>true,'comments_only_model_sha_difference_not_hidden'=>true,'same_owned_chain'=>true,'new_http_cases'=>4,'new_jobs'=>0,'new_soft_deleted_plan_rows'=>1,'complete_wire_original_readback'=>true,'actual_recorder_model_sha'=>'a68cdfa33dfe1cac94823b546e43e0e4550185db6a1349fd699b2574989db9a9'];
file_put_contents($runtime.'/report.json',json_encode($report,JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE));file_put_contents($runtime.'/private-retention.json',json_encode($p,JSON_PRETTY_PRINT|JSON_PRESERVE_ZERO_FRACTION|JSON_UNESCAPED_UNICODE));echo '{"reprobe_http_cases":4,"jobs_executed":0,"complete_wire_original_readback":true}',"\n";
