<?php
require __DIR__.'/db.php';$pre=json_decode(file_get_contents(__DIR__.'/private-preflight.json'),true);$check($pre['safe'],'Preflight first');
if($lane==='B'){$day='DATE(CREATE_TIME)';$sql='SELECT '.$day.' AS LOG_DAY,COUNT(*) AS CNT FROM '.$p.'agent_conversation_log WHERE BUSINESS=? GROUP BY '.$day.' HAVING COUNT(*) BETWEEN 4 AND 100 ORDER BY LOG_DAY ASC LIMIT 1';$groups=$q($sql,[$business]);$check(count($groups)===1,'No bounded historical source');$date=substr($groups[0]['log_day'],0,10);}else{$date=$argv[1]??'';$check((bool)preg_match('/^\d{4}-\d{2}-\d{2}$/D',$date),'Frozen B date required');}
$scope=['date'=>$date];$save('private-scope.json',$scope);require __DIR__.'/oracle.php';$rows=$source();$check($lane==='C'||count($rows)>=4,'B source>=4');$save('private-baseline.json',['source'=>$rows,'actor'=>$actor]);
$lock=[];foreach(['p/controller/AgentConversationLog.php','p/logic/AgentConversationLog.php','model/AgentConversationLog.php','model/BaseModel.php','base/AdminController.php','common.php']as $file)$lock[$file]=hash_file('sha256',__DIR__.'/source/application/'.$file);$save('private-source-lock.json',$lock);
$base=['date_start'=>$date,'date_end'=>$date,'page_size'=>2];$spec=[['label'=>'history_page1','method'=>'lists','params'=>$base+['page'=>1]],['label'=>'history_page2','method'=>'lists','params'=>$base+['page'=>2]]];
if($rows)$spec[]=['label'=>'source_detail','method'=>'detail','params'=>['id'=>$rows[0]['id']]];
$spec[]=['label'=>'missing_id','method'=>'detail','params'=>[]];$absent='CDXLOGABSENT'.bin2hex(random_bytes(8));foreach($rows as $r)$check(strpos((string)$r['question'],$absent)===false&&strpos((string)$r['answer'],$absent)===false,'No match source verified');$spec[]=['label'=>'no_match','method'=>'lists','params'=>$base+['page'=>1,'keyword'=>$absent]];$check(count($spec)<=5,'Request cap5');
require_once $root.'/application/base/Security.php';$a=$actor;$token=\app\base\Security::encrypt(implode("\t",[(string)$a['id'],(string)$a['uuid'],(string)$a['account'],'0','','',(string)$a['account']]));
$items=[];foreach($spec as $s){$negative=$s['label']==='missing_id';$wanted=$s['method']==='detail'?($negative?[]:$projection($rows[0])):['data'=>$s['label']==='no_match'?[]:array_map($projection,array_slice($rows,((int)$s['params']['page']-1)*2,2)),'total'=>$s['label']==='no_match'?0:count($rows),'page'=>(int)$s['params']['page'],'page_size'=>2];$expected=['code'=>$negative?1:0,'message'=>$negative?'缺少问答记录ID':'查询成功','data'=>$wanted];$expectedJson=json_encode($expected,JSON_UNESCAPED_UNICODE);$items[]=['id'=>$s['label'],'name'=>$s['label'],'type'=>'http','metaInfo'=>['type'=>'HTTP'],'request'=>['method'=>'POST','header'=>[['key'=>'X-CDX-Case','value'=>$s['label']],['key'=>'token','value'=>$token],['key'=>'Content-Type','value'=>'application/x-www-form-urlencoded']],'url'=>'http://127.0.0.1:'.($lane==='B'?18321:18322).'/p/agentConversationLog/'.$s['method'],'body'=>['mode'=>'urlencoded','urlencoded'=>array_map(static function($k,$v){return ['key'=>$k,'value'=>(string)$v,'type'=>'text'];},array_keys($s['params']),array_values($s['params']))]],'event'=>[['listen'=>'test','script'=>['type'=>'text/javascript','exec'=>["pm.test('HTTP200',()=>pm.response.to.have.status(200));","const b=pm.response.json();","pm.test('business status and message',()=>{pm.expect(b.code).to.eql(".($negative?'1':'0').");pm.expect(b.message).to.eql(".json_encode($expected['message'],JSON_UNESCAPED_UNICODE).");});","pm.test('all fields values types and pagination against independent source',()=>pm.expect(b).to.deep.eql(".$expectedJson."));"]]]]];}
$save('private-spec.json',$spec);$save('private-suite.json',['apifoxCli'=>'2.2.8','info'=>['name'=>'AgentConversationLog '.$lane],'item'=>[['name'=>'Frozen historical source','item'=>$items]]]);echo json_encode(['lane'=>$lane,'date'=>$date,'cases'=>count($spec),'scope_count'=>count($rows),'scope_sha256'=>$hash($rows),'source_lock'=>$lock]),"\n";
