Files
SGF/scripts/sgf-material-isolation-proof.php
2026-11-11 09:00:17 +02:00

15 lines
2.3 KiB
PHP

<?php
require __DIR__.'/sgf-ledger-proof-bootstrap.php';
$isolation=app(App\Modules\Accounting\ComposedMaterialIsolation::class);$scope=['tenant_id'=>1,'company_id'=>2,'unit_id'=>2];$path=$s['root'].'/single-material-perimeter.json';$original=file_get_contents($path);$pin=hash('sha256',$original);
$refused=function(Closure $fn){try{$fn();return false;}catch(DomainException){return true;}};
$isolation->check($host,$native,$scope);$ok(true,'explicit artificial cost and stock perimeters are disjoint');
try{
config(['sgf_single_installation.material_perimeter_sha256'=>str_repeat('0',64)]);$ok($refused(fn()=>$isolation->check($host,$native,$scope)),'changed private material perimeter fails its installed pin');config(['sgf_single_installation.material_perimeter_sha256'=>$pin]);
$p=json_decode($original,true);$first=array_key_first($p['direct_costs']);$p['direct_costs'][$first]['resource']=$native->table('stock_items')->where('id',$p['valued_stock'][0]['stock_item_id'])->value('code');file_put_contents($path,json_encode($p));config(['sgf_single_installation.material_perimeter_sha256'=>hash_file('sha256',$path)]);$ok($refused(fn()=>$isolation->check($host,$native,$scope)),'cost material declared as valued stock is refused even with a matching policy pin');
}finally{file_put_contents($path,$original);config(['sgf_single_installation.material_perimeter_sha256'=>$pin]);}
$native->beginTransaction();try{
$map=(array)$native->table('gl_cost_sources')->where($scope)->first();unset($map['id']);$map['order_id']=99999999;$map['material_origin']='QA-UNKNOWN-ORIGIN';$native->table('gl_cost_sources')->insert($map);$ok($refused(fn()=>$isolation->check($host,$native,$scope)),'unreviewed additional cost mapping blocks valuation instead of guessing an association');
}finally{$native->rollBack();}
$isolation->check($host,$native,$scope);$ok(hash_file('sha256',$path)===$pin,'negative checks restore exact original policy and preserve known mappings');
file_put_contents($work.'/material-isolation-result.json',json_encode(['passed'=>true,'checks'=>$checks,'native_changes_rolled_back'=>true,'private_policy_restored'=>true,'synthetic_material_claims_only'=>true],JSON_PRETTY_PRINT));echo json_encode(['passed'=>true,'checks'=>count($checks),'proof'=>$work.'/material-isolation-result.json']).PHP_EOL;