<?php
declare(strict_types=1);require __DIR__.'/app.php';require __DIR__.'/data.php';require __DIR__.'/scope.php';require __DIR__.'/fast-scope.php';$app=coreApp('FINAL_RETEST_CAPTURE');$s=json_decode(file_get_contents($runtime.'/resolved-scope.json'),true);$snapshot=fastSnapshot();$before=json_decode(file_get_contents($runtime.'/source-snapshot.json'),true);$protection=fastProtection();$old=json_decode(file_get_contents($runtime.'/preflight-state.json'),true)['protection'];
$rows=readNative('ZHCT','SELECT r.record_id,r.ai_user_id,r.metric_code,r.value,r.start_time,r.session_id FROM ydy_health_record r INNER JOIN ydy_measurement_session s ON r.session_id=s.session_id WHERE s.vendor=? AND s.is_valid=1 AND s.device_type=? AND r.metric_code=? AND r.start_time>=? AND r.start_time<=? ORDER BY r.record_id',['yingjiduo','treadmill','activity_duration','2026-01-01 00:00:00','2026-12-31 23:59:59']);
$wanted=[];$ids=array_column($before['global_sessions'],'session_id');foreach($before['health'] as $r){if($r['metric_code']!=='activity_duration'||!in_array($r['session_id'],$ids,true)||substr($r['start_time'],0,19)<'2026-01-01 00:00:00'||substr($r['start_time'],0,19)>'2026-12-31 23:59:59')continue;$w=[];foreach(['record_id','ai_user_id','metric_code','value','start_time','session_id'] as $n)$w[$n]=$r[$n];ksort($w);$wanted[]=$w;}
saveOnce('final-retest-capture.json',['snapshot'=>$snapshot,'snapshot_unchanged'=>$snapshot===$before,'protection'=>$protection,'protection_unchanged'=>$protection===$old,'source_rank_predicate_full_record_membership'=>$rows===$wanted,'source_rank_records'=>$rows,'source'=>sourceProof(),'SQL'=>count(file($runtime.'/sql-budget.jsonl')),'HTTP'=>count(glob($runtime.'/client-attempt-*.json')),'business_DMLDDL'=>0,'Prepay_raw_not_guarded'=>true,'global_StoreStaff_not_claimed'=>true]);echo json_encode(['lane'=>$lane,'snapshot_unchanged'=>$snapshot===$before,'protection_unchanged'=>$protection===$old,'exact_rank_record_membership'=>$rows===$wanted,'SQL'=>count(file($runtime.'/sql-budget.jsonl'))]),"\n";
