Files
SGF/scripts/summarize-sgc-dispatch.php
2026-11-11 09:00:17 +02:00

36 lines
7.7 KiB
PHP

<?php
require __DIR__.'/sgc-dispatch-pg-bootstrap.php';
use Illuminate\Support\Facades\DB;
$final=in_array('--final',$argv,true);$initial=$repo.'/docs/proofs/sgc-invoice-workspace-20261110.json';
$out=$repo.'/docs/proofs/sgc-invoice-workspace'.($final?'-final':'').'-20261110.json';if(is_file($out)||($final&&!is_file($initial)))throw new LogicException('Preserve completed workspace proof');
$pg=json_decode(file_get_contents($root.'/result.json'),true);if(!($pg['passed']??false)||count($pg['checks'])!==14)throw new LogicException('Incomplete PG proof');
$cases=[];$junit=[];foreach(['source-sqlite-junit.xml','source-screen-junit.xml','source-readiness-junit.xml',...($final?['source-context-audit-junit.xml']:[])]as$file){
$xml=simplexml_load_file($root.'/'.$file);if(count($xml->xpath('//failure|//error|//skipped')))throw new LogicException('Selected tests did not pass');
foreach($xml->xpath('//testcase')as$c){$name=(string)$c['name'];$assertions=(int)$c['assertions'];if(isset($cases[$name])&&$cases[$name]!==$assertions)throw new LogicException('Conflicting selected test');$cases[$name]=$assertions;}
$junit[]=['private_file'=>$file,'sha256'=>hash_file('sha256',$root.'/'.$file)];
}if(count($cases)!==($final?20:19)||array_sum($cases)!==($final?142:138))throw new LogicException('Exact unique coverage expected');
$snapshot=function($c){$out=[];foreach($c->select("SELECT tablename FROM pg_tables WHERE schemaname='public' ORDER BY tablename")as$r){$t=$r->tablename;if(!preg_match('/^[a-z_][a-z0-9_]*$/D',$t))throw new LogicException('Table');$out[$t]=(array)$c->selectOne('SELECT count(*) rows,md5(coalesce(string_agg(row_to_json(x)::text,chr(10) ORDER BY row_to_json(x)::text),\'\')) fingerprint FROM "'.$t.'" x');}$out['sequences']=$c->table('pg_sequences')->where('schemaname','public')->orderBy('sequencename')->get(['sequencename','last_value']);return hash('sha256',json_encode($out,JSON_THROW_ON_ERROR));};
$selected=json_decode(file_get_contents($run['root'].'/private/receipt-composition-cc50a276c10c/state.json'),true);
config(['database.connections.guard_host'=>array_replace(config('database.connections.pgsql'),['host'=>'127.0.0.1','port'=>55439,'database'=>$selected['env']['DB_DATABASE'],'username'=>$selected['env']['DB_USERNAME'],'password'=>$selected['env']['DB_PASSWORD'],'url'=>null]),'database.connections.guard_native'=>$selected['nativeConnection']]);
if([$snapshot(DB::connection('guard_host')),$snapshot(DB::connection('guard_native'))]!==$pg['protected_8085_fingerprints'])throw new RuntimeException('8085 changed');
$old=json_decode(file_get_contents($repo.'/docs/proofs/purchasing-completion-final-20261104-r2.json'),true);foreach($old['sources']as$source)if(hash_file('sha256',$selected['app'].'/'.$source['file'])!==$source['sha256'])throw new RuntimeException('8085 code changed');
$id=$final?'3bb99e866f52965dbb7d':'4a6df60a8e9f8ae95c1d';$stage=$run['root'].'/private/receipt-composition-cc50a276c10c/prepared-sgc-invoice/'.$id;$manifest=json_decode(file_get_contents($stage.'/manifest.json'),true);
if($manifest['sgc_configuration']['enabled']||$manifest['sgc_configuration']['workspace_enabled']||$manifest['modes']['install'])throw new RuntimeException('Preparation must stay inactive');
$defaults=require $sgc.'/config/sgf_invoice.php';if($defaults['enabled']||$defaults['workspace_enabled']||$defaults['connections']!==[]||$defaults['client_package']!==null)throw new RuntimeException('Operational source config changed');
$sources=[];foreach($manifest['client_files']as$file){$relative=$file['target'];$actual=str_starts_with($relative,'sgc/')?$sgc.'/'.substr($relative,4):$repo.'/packages/sgc-invoice-client/src/InvoiceClient.php';if(hash_file('sha256',$actual)!==$file['sha256'])throw new RuntimeException('Prepared source changed');$sources[]=['file'=>$actual,'sha256'=>$file['sha256']];}
foreach(['scripts/sgc-dispatch-receiver.php','scripts/sgc-dispatch-pg-bootstrap.php','scripts/sgc-dispatch-pg-proof.php','scripts/summarize-sgc-dispatch.php','scripts/prepare-sgc-8085.mjs']as$file)$sources[]=['file'=>$file,'sha256'=>hash_file('sha256',$repo.'/'.$file)];
$sources[]=['file'=>$sgc.'/tests/Integration/SgfInvoiceDispatchesTest.php','sha256'=>hash_file('sha256',$sgc.'/tests/Integration/SgfInvoiceDispatchesTest.php')];
$reused=[];foreach(['sgc-invoice-endpoint-20261110.json','sgc-8085-integration-preparation-20261110.json','purchasing-completion-final-20261104-r2.json']as$file)$reused[]=['file'=>'docs/proofs/'.$file,'sha256'=>hash_file('sha256',$repo.'/docs/proofs/'.$file),'repeated'=>false];
$proof=['date'=>'2026-11-10','passed'=>true,'scope'=>'SGC durable invoice source workspace for SGF intake; no operational activation',
'sqlite'=>['unique_cases'=>count($cases),'assertions'=>array_sum($cases),'cases'=>$cases,'junit'=>$junit,'database'=>':memory:','migration_scope'=>'only minimal synthetic fixtures and the new migration'],
'postgresql'=>['checks'=>$pg['checks'],'result_sha256'=>hash_file('sha256',$root.'/result.json'),'source_book'=>$pg['source_book'],'receiver_book'=>$pg['receiver_book'],
'new_receiver_pending_invoices'=>2,'source_concurrent_statuses'=>$pg['source_statuses'],'remote_commit_response_loss_recovered'=>true,'new_schema_only_in_regression'=>true,'original_source_rows_and_sequences_preserved'=>true],
'ui'=>['route'=>'/facturas/envio-sgf','blade_http_forms_tested'=>true,'history_and_list_page_size'=>25,'typescript_no_emit_exit'=>0,'private_tsx_sha256'=>hash_file('sha256',$root.'/invoices.private.js'),'typescript_diagnostics_sha256'=>hash_file('sha256',$root.'/typescript.log'),'rendered_inline_scripts_syntax_checked'=>3,'visual_browser_review'=>false,'full_product_build'=>false],
'preparation'=>['id'=>$id,'manifest_sha256'=>hash_file('sha256',$stage.'/manifest.json'),'endpoint_files'=>8,'client_source_files'=>15,'installed'=>false,'activated'=>false,'sql_privileges_approved'=>false],
'preservation'=>['8085_all_host_native_rows_and_sequences_sha256'=>$pg['protected_8085_fingerprints'],'8085_code_unchanged'=>true,'six_records_changed'=>false,'cache_cleared'=>false,'pilot_schema_changed'=>false,
'new_operational_credentials'=>false,'new_business_rights'=>false,'new_database'=>false,'new_role'=>false,'new_demo'=>false,'new_http_server'=>false,'publication'=>false,'checkpoint'=>false],
'sources'=>$sources,'reused_proofs'=>$reused,'report'=>'docs/SGC_INVOICE_WORKSPACE_DELIVERY.md',
'limits'=>['Two real application kernels in independent PHP processes, intercepted CLI bridge; no TCP8085 or pilot activation.','The initial receiver harness inherited SGC cache metadata; isolated environment corrected and same draft/key resumed without replaying an accepted confirmation.','19 unique selected cases, not20 executions or a sum with old endpoint/client suites.','Final schema-readiness guard covered by a directed SQLite check; successful integrated business commits were not repeated.','No full product bundle build, visual review, sustained load, disaster recovery or deployment capacity claim.','Exact source migration/SQL privileges, code installation, approved mappings/principal/secret and activation still require their authorised rollout.']];
if($final){$proof['initial_proof_preserved']=['file'=>'docs/proofs/sgc-invoice-workspace-20261110.json','sha256'=>hash_file('sha256',$initial)];$proof['limits'][2]='20 unique selected cases; earlier19-case summary preserved, duplicate executions not added.';$proof['limits'][3]='Final schema-readiness and frozen actor/context audit metadata covered by directed SQLite checks; integrated commits not repeated.';}
file_put_contents($out,json_encode($proof,JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES|JSON_THROW_ON_ERROR).PHP_EOL);echo json_encode(['passed'=>true,'unique_tests'=>count($cases),'assertions'=>array_sum($cases),'pg_checks'=>14,'preparation_id'=>$id]).PHP_EOL;