<?php
declare(strict_types=1);
require __DIR__.'/bootstrap.php';require __DIR__.'/StrictWire.php';
$original=$lane==='B'?'/private/var/folders/21/wq30qp_s6m5f1fnbzq3vq5b80000gn/T/cdx-client-settings-B-j39Ae4':'/tmp/cdx-client-settings-C-dyEGZo';$p=json_decode(file_get_contents($original.'/private-retention.json'),true);$check($p['marker']===$marker&&$p['tenants']===$tenants,'Known exact retained chain');$owned=$p['owned_unique_tuples'];$before=$snapshot();$check($before===$p['before'],'Exact original natural SHA before CLI');
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.'/cli-fixture-runtime/');$app->initialize();$cache=new \think\cache\driver\File($app,['path'=>$runtime.'/cache/','prefix'=>'','expire'=>0]);$tokens=[];$items=[];$all=[];
foreach($tenants as $module=>$tenant){$tokens[$module]=bin2hex(random_bytes(24));$cache->set($tokens[$module],['user'=>['store_user_id'=>$tenant,'store_id'=>$tenant,'real_name'=>$marker,'user_name'=>$marker,'is_super'=>1],'store_id'=>$tenant,'is_login'=>true],1800);foreach([['h5','basic'],['wxapp','basic'],['wxapp','examine']] as [$family,$key]){$table=$family==='h5'?'h5_setting':'wxapp_setting';$rows=$query('SELECT * FROM yoshop_'.$table.' WHERE '.$qkey.'=? AND store_id=?',[$key,$tenant]);$check(count($rows)===1&&isset($owned[$table][(string)$tenant][$key]),'CLI exact tuple independently owned');$r=$rows[0];$want=$p['expected_values'][$module][$family][$key];$check($r['describe']===($key==='basic'?'基础设置':'审核开关')&&strictWireEqual(json_decode($r['values']),json_decode(json_encode($want,JSON_UNESCAPED_UNICODE))),'CLI before full original JSON and describe');$all[$module][$family][$key]=$r;$data=['detail'=>$want];if($family==='wxapp')$data['domain']=$module.'.client-settings.invalid';$jsWant=json_encode($data,JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES);$scenario='PILOT_CS_CLI_'.strtoupper($module.'_'.$family.'_'.$key);$script=[
 "pm.test('HTTP传输200',function(){pm.response.to.have.status(200);});",
 "pm.test('JSON响应可解析',function(){pm.response.to.be.json;});var b=pm.response.json();",
 "pm.test('业务码数字200',function(){pm.expect(b.status).to.eql(200);});",
 "pm.test('动态trace为13位十六进制',function(){pm.expect(b.trace_id).to.match(/^[0-9a-f]{13}$/);});",
 "function eq(a,b){if(a===null||b===null)return a===b;if(typeof a!==typeof b||Array.isArray(a)!==Array.isArray(b))return false;if(typeof a!=='object')return a===b;var ak=Object.keys(a),bk=Object.keys(b);if(ak.length!==bk.length)return false;if(Array.isArray(a))return ak.every(function(k){return eq(a[k],b[k]);});return ak.every(function(k){return Object.prototype.hasOwnProperty.call(b,k)&&eq(a[k],b[k]);});}",
 "pm.test('完整原表投影值类型容器及数组次序',function(){pm.expect(eq(b.data,".$jsWant.")).to.eql(true);});",
 $key==='basic'?"pm.test('留存配置明确关闭且布尔类型',function(){pm.expect(b.data.detail.enabled).to.eql(false);});":"pm.test('审核开关保持数字0且版本数组',function(){pm.expect(b.data.detail.switch).to.eql(0);pm.expect(Array.isArray(b.data.detail.versions)).to.eql(true);});"
 ];$items[]=['id'=>$scenario,'name'=>$module.' '.$family.' '.$key.' 真实留存配置只读回归','type'=>'http','metaInfo'=>['type'=>'HTTP'],'request'=>['method'=>'GET','url'=>$base.'/'.$module.'/client.'.$family.'.setting/detail?key='.$key,'header'=>[['key'=>'Host','value'=>$module.'.client-settings.invalid'],['key'=>'Access-Token','value'=>$tokens[$module]],['key'=>'Platform','value'=>'POC'],['key'=>'X-Pilot-Scenario','value'=>$scenario]]],'event'=>[['listen'=>'test','script'=>['type'=>'text/javascript','exec'=>$script]]]];}}
$collection=['apifoxCli'=>'2.2.8','info'=>['name'=>'智慧餐厅AI客户端配置-自有留存数据只读回归'],'item'=>[['name'=>'Store与terminal配置完整契约','item'=>$items]]];foreach(['private-cli-collection.json'=>$collection,'private-cli-before.json'=>['original_runtime'=>$original,'rows'=>$all,'natural'=>$before,'tokens'=>$tokens,'loaded_boundary'=>$boundary]] as $name=>$value){file_put_contents($runtime.'/'.$name,json_encode($value,JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES));chmod($runtime.'/'.$name,0600);}if(!is_dir($runtime.'/private-cli-report'))mkdir($runtime.'/private-cli-report',0700);echo json_encode(['lane'=>$lane,'native_Apifox_read_requests'=>count($items),'named_assertions'=>36,'all_exact_original_tuples_verified'=>true,'collection'=>$runtime.'/private-cli-collection.json']),"\n";
