<?php
declare(strict_types=1);date_default_timezone_set('Asia/Shanghai');require __DIR__.'/oracle.php';
$db=smPdo();$sha=catSha();$runtime=getenv('SM7_RUNTIME');$spec=json_decode(file_get_contents($runtime.'/spec-private.json'),false,512,JSON_THROW_ON_ERROR);$events=[];$end=[];$dml=0;
foreach(file($runtime.'/queries.jsonl',FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES)?:[] as $line){$event=json_decode($line,true);$events[]=$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=[];$after=[];
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']);$proof=n7Snapshot($db,$case);$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);$window=$entry->before->source_digest===$proof['source_digest'];$status=$end['PILOT_CAT7_'.$name]['http_status']??0;$fatal=$end['PILOT_CAT7_'.$name]['fatal']??true;$positive=false;
 if($case['kind']==='search'){$positive=!empty($body->data->list);}elseif(in_array($case['kind'],['card','log'],true)){$positive=!empty($body->data->data);}elseif($case['kind']==='bill'){foreach($body->data??[] as $list){if(!empty($list)){$positive=true;}}}
 $cases[]=['case'=>$name,'method'=>'POST','path'=>$case['path'],'http_status'=>$status,'fatal'=>$fatal,'code'=>$body->code??null,'positive'=>$positive,'source_pass'=>$status===200&&!$fatal&&$diff===[]&&$window,'source_window_unchanged'=>$window,'differences'=>$diff,'wire_bytes'=>strlen($raw),'wire_sha256'=>hash('sha256',$raw)];$after[$name]=$proof;
 }catch(Throwable $error){$cases[]=['case'=>$name,'method'=>'POST','path'=>$entry->path,'source_pass'=>false,'limited'=>true,'error_class'=>get_class($error),'error_sha256'=>hash('sha256',$error->getMessage())];smSave('post-error-'.$name.'-private.json',['message'=>$error->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',$after);smSave('report-private.json',$result);echo json_encode(['lane'=>$result['lane'],'cases'=>$cases,'http_dml'=>$dml,'new_fixture_dml'=>0,'ddl'=>0]),PHP_EOL;
