Files
SGF/scripts/obligation-boundary-body.php
2026-11-04 09:37:20 +02:00

12 lines
2.5 KiB
PHP

<?php
if(!is_file($s['root'].'/obligation-result.json'))throw new LogicException('Valid integrated proof required');
$invoice=(int)$db->table('invoices')->where('tenant_id',$n['tenant'])->value('id');$url='/api/purchasing-obligations/'.$invoice;
$before=hash('sha256',json_encode([$db->table('pa_commands')->orderBy('id')->get(),$db->table('pa_events')->orderBy('id')->get(),$db->table('pa_obligations')->orderBy('id')->get(),$db->table('audit_logs')->orderBy('id')->get()]));
$enter('issuer',1,['module'=>'commercial']);$ok($call('issuer',$url,null,1)['status']===403,'commercial module cannot inspect purchasing obligation route');$enter('issuer',1);
$r=$call('issuer','/purchasing/invoices');$ok($r['status']===200&&str_contains($r['body'],'href="/purchasing/obligations"'),'invoice screen exposes explicit authorised next step');
$state=$call('issuer',$url);$p=$call('issuer',$url.'/preview',['operation_key'=>(string)Str::uuid(),'revision'=>$state['data']['revision'],'action'=>'prepare','proposal_id'=>0,'reason'=>'Sonda de contexto sem novo reconhecimento.']);$ok($p['status']===200&&$p['data']['impact']['result']['state']==='recognised','existing responsibility preview remains rollback-only');
$file=$s['root'].'/binding.json';$bytes=file_get_contents($file);$profile=json_decode($bytes,true);$key=implode(':',array_values($f['scope'])).':'.$f['issuer'];$profile['bindings'][$key]['warehouse_ids'][]=999999;file_put_contents($file,json_encode($profile));try{$ok($call('issuer',$url.'/confirm',['preview'=>$p['data']['preview']])['status']===409,'changed authorised binding requires fresh conference');}finally{file_put_contents($file,$bytes);}
$profile=json_decode($bytes,true);$profile['bindings'][$key]['payable_instance']='another-responsibility';file_put_contents($file,json_encode($profile));try{$ok($call('issuer',$url)['status']===403,'source authority identity cannot silently change to a second debt book');}finally{file_put_contents($file,$bytes);}
$after=hash('sha256',json_encode([$db->table('pa_commands')->orderBy('id')->get(),$db->table('pa_events')->orderBy('id')->get(),$db->table('pa_obligations')->orderBy('id')->get(),$db->table('audit_logs')->orderBy('id')->get()]));$ok($before===$after,'new module and binding boundary probes preserve prior valid financial proof');
file_put_contents($out,json_encode(['passed'=>true,'checks'=>$checks,'before'=>$before,'after'=>$after,'valid35_checks_not_repeated'=>true],JSON_PRETTY_PRINT|JSON_THROW_ON_ERROR));echo count($checks)." obligation boundary checks passed.\n";