Files
SGF/scripts/stock-ledger-entry.php
T
2026-11-04 09:37:20 +02:00

29 lines
4.7 KiB
PHP

<?php
$file=realpath($argv[1]??'');$run=json_decode(file_get_contents('C:/laragon/data/sgf-tempo/run/modular-regression-current.json'),true,32,JSON_THROW_ON_ERROR);$private=realpath($run['root'].'/private');
if(!$file||!str_starts_with($file,$private.DIRECTORY_SEPARATOR))throw new LogicException('Private QA settings required');$s=json_decode(file_get_contents($file),true,64,JSON_THROW_ON_ERROR);$phase=$argv[2]??'';
if(!preg_match('/^[a-f0-9]{12}$/D',$s['tag'])||$s['database']!=='compras_receipts_test_'.$s['tag']||$s['role']!=='payable_history_native_'.$s['tag']||$s['run']!==$run['id'])throw new LogicException('QA identity refused');
$env=['APP_ENV'=>'testing','APP_DEBUG'=>'false','APP_KEY'=>$s['app_key'],'DB_CONNECTION'=>'pgsql','DB_HOST'=>'127.0.0.1','DB_PORT'=>'55439','DB_DATABASE'=>$s['database'],'DB_USERNAME'=>$s['role'],'DB_PASSWORD'=>$s['password'],'DB_URL'=>'','SESSION_DRIVER'=>'file','SESSION_COOKIE'=>'stock_ledger_'.$s['tag'],'CACHE_STORE'=>'array','QUEUE_CONNECTION'=>'sync','MAIL_MAILER'=>'array','BCRYPT_ROUNDS'=>'4','LARAVEL_STORAGE_PATH'=>$s['storage'],'APP_CONFIG_CACHE'=>$s['storage'].'/cache/config.php','APP_ROUTES_CACHE'=>$s['storage'].'/cache/routes.php','APP_SERVICES_CACHE'=>$s['storage'].'/cache/services.php','APP_PACKAGES_CACHE'=>$s['storage'].'/cache/packages.php','VIEW_COMPILED_PATH'=>$s['storage'].'/framework/views','SGF_ISOLATED_REGRESSION_RUN'=>$s['run'],'COMMON_PAYABLES_PATH'=>dirname(__DIR__).'/packages/payables','COMMON_PAYABLES_ENABLED'=>'true','PAYABLE_SOURCE_INSTANCE'=>'qa-stock-ledger-'.$s['tag']];
if(isset($s['payables']))$env['COMMON_PAYABLES_PATH']=$s['payables'];
if(isset($s['bundle_manifest_sha256'])){$manifest=$s['root'].'/bundle/manifest.json';if(hash_file('sha256',$manifest)!==$s['bundle_manifest_sha256'])throw new LogicException('Pinned stock bundle manifest changed');$bundle=json_decode(file_get_contents($manifest),true,64,JSON_THROW_ON_ERROR);foreach($bundle['files']as$relative=>$pin){if(!preg_match('~^(general-ledger|payables|integrations)/[a-zA-Z0-9_./-]+$~D',$relative)||str_contains($relative,'..')||hash_file('sha256',$s['root'].'/bundle/'.$relative)!==$pin)throw new LogicException('Pinned stock bundle file changed');}}
foreach($env as$k=>$v){putenv($k.'='.$v);$_ENV[$k]=$_SERVER[$k]=$v;}
require $s['native'].'/vendor/autoload.php';$app=require $s['native'].'/bootstrap/app.php';$app->useStoragePath($s['storage']);$app->addAbsoluteCachePathPrefix('C:');$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();
require_once $s['ledger'].'/bootstrap.php';
Tempo\Finance\GeneralLedger\LedgerSchema::assertSynthetic(Illuminate\Support\Facades\DB::connection());
try{
if($phase==='invoice-native-negative'){require __DIR__.'/invoice-native-negative.php';exit;}
if($phase==='order-native-setup'){require __DIR__.'/order-native-setup.php';exit;}
if($phase==='receipt-native-setup'){require __DIR__.'/receipt-native-setup.php';exit;}
if($phase==='receipt-native-extra'){require __DIR__.'/receipt-native-extra.php';exit;}
if($phase==='period-batches'){require __DIR__.'/stock-period-proof.php';exit;}
if($phase==='period-concurrency'){require __DIR__.'/stock-period-concurrency.php';exit;}
if(in_array($phase,['prefix-context','prefix-context-current'],true)){require __DIR__.'/stock-prefix-context.php';exit;}
if($phase==='prefix-plan'){require __DIR__.'/stock-prefix-plan.php';exit;}
if(in_array($phase,['prefix-review','prefix-review-final','prefix-review-join','prefix-review-cursor','prefix-review-selected','prefix-review-measured','prefix-review-types','prefix-review-safe'],true)){require __DIR__.'/stock-prefix-proof.php';exit;}
if($phase==='access'){
require $s['native'].'/tests/Support/SupplyFixture.php';$f=json_decode(file_get_contents($s['root'].'/fixture.json'),true,32,JSON_THROW_ON_ERROR);
foreach($f['actors']as$id){if(Illuminate\Support\Facades\DB::table('organization_memberships')->where('user_id',$id)->exists())throw new LogicException('Existing fixture function profile preserved');supplyGrant(App\Models\User::findOrFail($id),['finance']);}
file_put_contents($s['root'].'/access.json',json_encode(['passed'=>true,'qa_finance_function_memberships'=>3,'existing_native_function'=>'finance','real_grants'=>0],JSON_PRETTY_PRINT|JSON_THROW_ON_ERROR));exit;
}
if($phase==='setup')require __DIR__.'/stock-ledger-setup.php';else require __DIR__.'/stock-ledger-proof.php';
}catch(Throwable $e){file_put_contents($s['root'].'/failure-'.time().'.json',json_encode(['class'=>get_class($e),'message'=>$e->getMessage(),'file'=>$e->getFile(),'line'=>$e->getLine(),'frames'=>array_map(fn($f)=>array_intersect_key($f,array_flip(['file','line','function'])),$e->getTrace())],JSON_PRETTY_PRINT|JSON_THROW_ON_ERROR));fwrite(STDERR,get_class($e).': '.$e->getMessage()."\n");exit(1);}