<?php
declare(strict_types=1);require __DIR__.'/common.php';$check(!file_exists($runtime.'/preflight.json'),'Preflight once');$orig=json_decode(file_get_contents(dirname(__DIR__).'/source-frozen-sha.json'),true)['files'];foreach($orig as $name=>$sha)$check(hash_file('sha256',$root.'/'.$name)===$sha,'Initial original whole source pin '.$name);$before=$small();$last=$lane==='B'?'PROBLEM_CREATE_RETRY':'FOOD_DETAIL1';$old=json_decode(file_get_contents($prior.'/wire-original-'.$last.'.json'),true);$check($before===$old['after'],'Live exact first-phase after state');$guard=$protected();$batch=json_decode(file_get_contents($prior.'/batch-before.json'),true);foreach($batch['protected'] as $key=>$rows)$check($guard[$key]===$rows,'Old protected snapshot '.$key);$check($guard['dictionary']===$batch['dictionary'],'Dictionary179 original snapshot');$check(count($guard['users'])===2,'Two marked retained API users');$app=invApp($root,$runtime,'AUTH_REFRESH');InvGate::$case=['kind'=>'read'];$profiles=json_decode(file_get_contents($prior.'/auth-profiles.json'),true);$tokens=[];foreach($operators as $i=>$id){$model=\app\store\model\store\User::withoutGlobalScope()->where('store_user_id','=',$id)->where('store_id','=',$tenants[$i])->find();$check($model!==null,'Exact existing profile');$profile=$model->toArray();$name=$i===0?'one':'two';$check(!array_key_exists('password',$profile)&&$profile['is_super']===1&&$profile['is_delete']===0&&strpos($profile['user_name'],'cdxop11f64c_')===0,'Exact marked auth profile');$actual=['store_user_id'=>$id,'store_id'=>$tenants[$i],'create_by'=>$profile['real_name']?:$profile['user_name']?:$id];$check($actual===$profiles[$name],'Prior actual profile unchanged');$tokens[$name]=bin2hex(random_bytes(24));$app->cache->set($tokens[$name],['user'=>$profile,'store_id'=>$tenants[$i],'is_login'=>true],3600);}$persist('tokens.json',$tokens);$cases=json_decode(file_get_contents($prior.'/cases-original.json'),true);foreach(['PROBLEM','MEALS'] as $group){$cases[$group.'_CREATE_RETRY']=$cases[$group.'_CREATE'];}foreach(['PROBLEM','MEALS','FOOD'] as $group)$cases[$group.'_FINAL_CONTROL']=$cases[$group.'_DETAIL2'];$fresh=$cases['FOOD_CREATE'];$fresh['body']['set_date']='2097-11-12';foreach(['other_text','food_allergy','food_Intolerance','food_disable'] as $k)$fresh['body'][$k]='CDXIW11C8F2_FRESH_'.$k;$fresh['body_raw']=json_encode($fresh['body'],JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES);$cases['FOOD_FRESH_CREATE']=$fresh;$fresh=$cases['FOOD_DETAIL1'];$fresh['body']['set_date']='2097-11-12';$fresh['body_raw']=json_encode($fresh['body'],JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES);$cases['FOOD_FRESH_DETAIL']=$fresh;$persist('cases.json',$cases);$persist('preflight.json',['lane'=>$lane,'prior_last'=>$last,'own'=>$before,'protected'=>$guard,'source_files'=>count($orig),'HTTP'=>0,'DML'=>0,'DDL'=>0]);echo json_encode(['lane'=>$lane,'own_masters'=>count($before['nutrition_meals']),'own_answers'=>count($before['nutrition_lack']),'source_files'=>count($orig),'dictionary_rows'=>count($guard['dictionary']),'old_protected_exact'=>true,'HTTP'=>0,'DML'=>0,'DDL'=>0]),"\n";
