<?php
declare(strict_types=1);
date_default_timezone_set('Asia/Shanghai');require __DIR__.'/oracle.php';$db=smPdo();$sha=catSha();$runtime=getenv('SM7_RUNTIME');define('APP_PATH',getenv('SM7_ROOT').'/application/');require APP_PATH.'common/enum/EnumBasics.php';require APP_PATH.'common/enum/order/OrderSource.php';$spec=json_decode(file_get_contents($runtime.'/spec-private.json'),false,512,JSON_THROW_ON_ERROR);$boundary=smLoad('boundary-private.json');$events=[];foreach(file($runtime.'/queries.jsonl',FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES)?:[] as $line){$events[]=json_decode($line,true);}$end=[];$dml=0;foreach($events as $event){if($event['kind']==='request_end'){$end[$event['scenario']]=$event;}if($event['kind']==='query_observed'&&in_array($event['operation'],['insert','update','delete','replace','merge'],true)){$dml++;}}$cases=[];$afterProof=[];
foreach($spec as $entry){$name=$entry->name;try{$case=json_decode(json_encode($entry,JSON_UNESCAPED_UNICODE|JSON_THROW_ON_ERROR),true);unset($case['before']);$after=catSnapshot($db,$case,$boundary);$raw=file_get_contents($runtime.'/raw-'.$name.'-private.json');$body=json_decode($raw,false,512,JSON_THROW_ON_ERROR);$diff=[];catStrict($entry->before->body,$body,'$',$diff);$scope=$entry->before->source_digest===$after['source_digest'];$status=$end['PILOT_CAT_'.$name]['http_status']??0;$fatal=$end['PILOT_CAT_'.$name]['fatal']??true;$positive=false;if(in_array($case['kind'],['dishes','orders','recognize'],true)){$positive=!empty($body->data->data);}elseif($case['kind']==='face'){$positive=!empty($body->resultObject->data);}elseif($case['kind']==='card'){$positive=isset($body->code)&&$body->code===0&&!empty($body->data);}elseif($case['kind']==='rotation'){$positive=!empty($body->data->imgs);}$cases[]=['case'=>$name,'method'=>$case['method'],'path'=>$case['path'],'http_status'=>$status,'fatal'=>$fatal,'code'=>$body->code??$body->resultCode??null,'positive'=>$positive,'source_pass'=>$status===200&&!$fatal&&$diff===[]&&$scope,'source_window_unchanged'=>$scope,'differences'=>$diff,'wire_bytes'=>strlen($raw),'wire_sha256'=>hash('sha256',$raw)];$afterProof[$name]=$after;}catch(Throwable $e){$cases[]=['case'=>$name,'method'=>$entry->method,'path'=>$entry->path,'source_pass'=>false,'limited'=>true,'error_class'=>get_class($e),'error_sha256'=>hash('sha256',$e->getMessage())];smSave('post-error-'.$name.'-private.json',['message'=>$e->getMessage()]);}}
$result=['lane'=>getenv('SM7_LANE'),'source_sha256'=>$sha,'cases'=>$cases,'events'=>$events,'http_dml'=>$dml,'new_fixture_dml'=>0,'ddl'=>0,'actor_unchanged'=>(bool)catActor($db)];smSave('after-private.json',$afterProof);smSave('report-private.json',$result);echo json_encode(['lane'=>$result['lane'],'cases'=>$cases,'http_dml'=>$dml,'new_fixture_dml'=>0,'ddl'=>0]),PHP_EOL;
