<?php
declare(strict_types=1);require __DIR__.'/oracle.php';$runtime=$argv[1]??'';$lane=$argv[2]??'';if(!preg_match('#^/tmp/cdx-catalog7-[BC]-[A-Za-z0-9]+/private-runtime$#D',$runtime)||!in_array($lane,['B','C'],true)||is_link($runtime)){throw new RuntimeException('Private restaurant expected-body repair boundary');}putenv('SM7_RUNTIME='.$runtime);putenv('SM7_LANE='.$lane);
$file=$runtime.'/restaurant-spec-private.json';$backup=$runtime.'/restaurant-spec-before-canonical-private.json';if(is_file($backup)){throw new RuntimeException('One-time canonical contract repair');}copy($file,$backup);chmod($backup,0600);$spec=json_decode(file_get_contents($file),false,512,JSON_THROW_ON_ERROR);
foreach($spec as $case){if($case->kind==='restaurant_list'){foreach($case->before->body->data->rows as &$row){$row=(object)n7CanonicalRestaurantRow((array)$row);}unset($row);}else{$case->before->body->data=(object)n7CanonicalRestaurantRow((array)$case->before->body->data);}}
smSave('restaurant-spec-private.json',$spec);copy($runtime.'/restaurant-report-private.json',$runtime.'/restaurant-report-before-canonical-private.json');chmod($runtime.'/restaurant-report-before-canonical-private.json',0600);
smSave('restaurant-oracle-tool-repair-private.json',['reason'=>'Actual B wire plus exact source schema canonical case; root-approved TIMESTAMP(0) seconds display from independent stored value','original_spec_sha256'=>hash_file('sha256',$backup),'corrected_spec_sha256'=>hash_file('sha256',$file),'raw_wire_changed'=>false,'source_sets_or_digest_changed'=>false,'database_http_operations'=>0]);echo json_encode(['lane'=>$lane,'raw_wire_changed'=>false,'source_sets_changed'=>false,'database_http_operations'=>0]),PHP_EOL;
