<?php
declare(strict_types=1);ob_start();require __DIR__.'/CompileGoodsRanking.php';$out=json_decode(ob_get_clean(),true);$count=0;$check=static function($ok,$why)use(&$count){$count++;if(!$ok)throw new RuntimeException($why);};$old=json_decode(file_get_contents(__DIR__.'/compiler-immutable-original-from-snapshot-'.$module.'.json'),true);$norm=static function($s){$s=str_replace('`','',$s);$s=preg_replace('/:ThinkBind_[A-Za-z0-9_]+/','?',$s);$s=preg_replace('/\border\b/i','ord',$s);return preg_replace('/\s+/',' ',trim($s));};
$check($old['service_sha256']===($module==='store'?'f117d9a632fb1b93f9cc68c337bd77fabacac87e7939684b721f362d194c61fa':'687484fd71c67adbc501618499cb55961af1adedb97050d17f05cd615dd63039'),'Original immutable source oracle, no self compare');
foreach(['dm','mysql'] as $dialect){$d=$out['dialects'][$dialect];$sql=$d['sql'][0];$plain=str_replace('`','',$sql);$bind=array_values($d['binds'][0]);$check($d['actual_connection_is_dm']===($dialect==='dm'),'Actual Dm gate '.$dialect);$check(!preg_match('/\border\./i',$sql),'Safe alias '.$dialect);$check(strpos($plain,'INNER JOIN yoshop_order ord ON ord.order_id')!==false,'Physical table prefix and join '.$dialect);$check($bind===[$tenant,20,20],'Tenant/paid/cancelled bindings exact '.$dialect);$check(strpos($plain,'o_goods.store_id')!==false,'Tenant alias qualification '.$dialect);$check(strpos($plain,'GROUP BY goods_id')!==false&&strpos($sql,'LIMIT 10')!==false,'Group and limit unchanged '.$dialect);$check(strpos($sql,'MAX(goods_name) AS goods_name')!==false,'Name aggregation unchanged '.$dialect);
 if($dialect==='dm'){$check(strpos($sql,"TO_CHAR(SUM(total_pay_price), 'FM99999999999999999999999999999999999990.00') AS sales_volume")!==false,'Server exact money text before PDO');$check(strpos($sql,'CAST(SUM(total_num) AS VARCHAR(40)) AS total_sales_num')!==false,'Server count text before PDO');$check(strpos($plain,'ORDER BY SUM(total_pay_price) DESC')!==false,'Numeric sum order, NOT lexicographic text alias');$check(strpos($plain,'ORDER BY sales_volume')===false,'No text alias order');}
 else{$check($norm($old['dialects']['mysql']['sql'][0])===$norm($sql),'MySQL whole SQL equivalent old fields/order');$check(strpos($sql,'TO_CHAR(')===false&&strpos($sql,'VARCHAR(40)')===false,'No DM projection in MySQL');}
}
echo json_encode(['module'=>$module,'assertions'=>$count,'PDO_opens'=>0,'SQL_executed'=>0,'actual_compiled'=>$out],JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES),"\n";
