<?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';
$entry=json_decode(file_get_contents($runtime.'/card-spec-private.json'),false,512,JSON_THROW_ON_ERROR);
$case=json_decode(json_encode($entry,JSON_UNESCAPED_UNICODE|JSON_THROW_ON_ERROR),true);unset($case['before']);
$after=catSnapshot($db,$case,smLoad('boundary-private.json'));$raw=file_get_contents($runtime.'/raw-CARD_SOURCE-private.json');$body=json_decode($raw,false,512,JSON_THROW_ON_ERROR);$diff=[];catStrict($entry->before->body,$body,'$',$diff);
$end=null;$dml=0;foreach(file($runtime.'/queries.jsonl',FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES)?:[] as $line){$event=json_decode($line,true);if(($event['scenario']??'')!=='PILOT_CAT_CARD_SOURCE'){continue;}if($event['kind']==='request_end'){$end=$event;}if($event['kind']==='query_observed'&&in_array($event['operation'],['insert','update','delete','replace','merge'],true)){$dml++;}}
$scope=$entry->before->source_digest===$after['source_digest'];
$caseResult=['case'=>'CARD_SOURCE','method'=>'POST','path'=>$case['path'],'http_status'=>$end['http_status']??0,'fatal'=>$end['fatal']??true,'code'=>$body->code??null,'positive'=>isset($body->code)&&$body->code===0&&!empty($body->data),'source_pass'=>($end['http_status']??0)===200&&!($end['fatal']??true)&&$diff===[]&&$scope,'source_window_unchanged'=>$scope,'differences'=>$diff,'wire_bytes'=>strlen($raw),'wire_sha256'=>hash('sha256',$raw)];
smSave('card-after-private.json',$after);smSave('card-report-private.json',['lane'=>getenv('SM7_LANE'),'source_sha256'=>$sha,'cases'=>[$caseResult],'http_dml'=>$dml,'new_fixture_dml'=>0,'ddl'=>0,'actor_unchanged'=>(bool)catActor($db)]);
echo json_encode(['lane'=>getenv('SM7_LANE'),'cases'=>[$caseResult],'http_dml'=>$dml,'new_fixture_dml'=>0,'ddl'=>0]),PHP_EOL;
