Files
SGF/scripts/sgf-fiscal-expression-parity.php
2026-11-11 09:00:17 +02:00

8 lines
2.3 KiB
PHP

<?php
require __DIR__.'/sgf-single-bootstrap.php';$origin='C:/laragon/www/portal-investidor/app/Services/SimulationTaxRuleExpression.php';$pin=json_decode(file_get_contents($repo.'/docs/integration/sgf-fiscal-expression-port.json'),true);if(hash_file('sha256',$origin)!==$pin['source_sha256'])throw new LogicException('Original source changed; review parity source');require $origin;
$old=new App\Services\SimulationTaxRuleExpression;$new=new App\Modules\Services\FiscalRuleExpression;$definition=['language'=>'investmoz.tax.v1','nodes'=>['base'=>['op'=>'input','key'=>'base'],'rate'=>['op'=>'parameter','key'=>'rate'],'raw'=>['op'=>'multiply','args'=>['base','rate']],'tax'=>['op'=>'round','args'=>['raw'],'scale'=>2,'mode'=>'HALF_UP']],'result'=>'tax'];$checks=[];
foreach([['1234.56','0.16'],['1000.03','0.16'],['1000.00000001','0.17']]as[$base,$rate]){if($old->evaluate($definition,['base'=>$base],['rate'=>$rate])!==$new->evaluate($definition,['base'=>$base],['rate'=>$rate]))throw new LogicException('Parity difference');$checks[]='exact DAG parity '.$base;}
if($new->evaluate($definition,['base'=>'1234.56'],['rate'=>'0.16'])['result']!=='19753/100')throw new LogicException('Accepted reference result changed');$checks[]='accepted portal rounding197.53';if($old->evaluate($definition,[],[])!==$new->evaluate($definition,[],[]))throw new LogicException('Missing values parity');$checks[]='missing values no defaults';foreach([['language'=>'investmoz.tax.v1','nodes'=>['a'=>['op'=>'execute','code'=>'x']],'result'=>'a'],['language'=>'investmoz.tax.v1','nodes'=>['a'=>['op'=>'add','args'=>['b','b']],'b'=>['op'=>'add','args'=>['a','a']]],'result'=>'a']]as$bad){try{$new->validate($bad);throw new RuntimeException('Invalid expression accepted');}catch(InvalidArgumentException){$checks[]='unsafe expression/cycle rejected';}}
try{$new->evaluate($definition,['base'=>str_repeat('9',25)],['rate'=>'0.16']);throw new RuntimeException('Input bound absent');}catch(InvalidArgumentException){$checks[]='bounded consumer arithmetic';}
file_put_contents($work.'/fiscal-expression-parity.json',json_encode(['passed'=>true,'checks'=>$checks,'source_sha256'=>$pin['source_sha256'],'runtime_portal_dependency'=>false,'database_writes'=>0],JSON_PRETTY_PRINT));echo json_encode(['passed'=>true,'checks'=>count($checks),'proof'=>$work.'/fiscal-expression-parity.json']).PHP_EOL;