Files
SGF/scripts/stock-read-state.php
T
2026-11-02 20:29:34 +02:00

22 lines
2.0 KiB
PHP

<?php
// Postcheck confined to the existing regression host. No client data or credentials printed.
putenv('APP_ENV=testing');
$runtime='C:/laragon/data/sgf-tempo/run';
$state=json_decode(file_get_contents($runtime.'/modular-regression-current.json'),true,512,JSON_THROW_ON_ERROR);
if (!preg_match('/^[a-f0-9]{12}$/D',$state['id']) || realpath($state['root'])!==realpath($runtime.'/modular-regression-'.$state['id'])
|| realpath($state['app'])!==realpath($state['root'].'/app') || $state['port']!==55439) throw new RuntimeException('Unexpected regression host');
require $state['app'].'/vendor/autoload.php';
$app=require $state['app'].'/bootstrap/app.php'; $app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();
App\Shared\Testing\TestingDatabaseGuard::assertSafe();
$db=Illuminate\Support\Facades\DB::connection();$db->beginTransaction();
try {
$db->statement('SET TRANSACTION ISOLATION LEVEL REPEATABLE READ, READ ONLY');
$i=$db->selectOne("SELECT current_database() AS database,current_user AS role,inet_server_port() AS port,current_setting('cluster_name') AS cluster");
if($i->database!=='sgf_tempo_test'||$i->role!=='sgf_test_runner'||(int)$i->port!==55439||$i->cluster!=='sgf_modular_regression_'.$state['id'])throw new RuntimeException('Unexpected effective identity');
$definition=$db->selectOne("SELECT pg_get_constraintdef(oid) AS value FROM pg_constraint WHERE conrelid='permission_grants'::regclass AND conname='permission_grants_scope_check'")->value;
$grants=(int)$db->table('permission_grants')->where('permission','stock.view')->count();
if(str_contains($definition,'stock.view')||$grants!==0)throw new RuntimeException('QA stock rights were not restored');
echo json_encode(['identity'=>$i,'read_only'=>true,'temporary_stock_grants_remaining'=>$grants,'original_constraint_restored_without_stock_right'=>true,
'constraint_sha256'=>hash('sha256',$definition),'operational_source_bindings'=>count(config('stock_read.synthetic_sources',[]))],JSON_PRETTY_PRINT|JSON_THROW_ON_ERROR).PHP_EOL;
} finally {$db->rollBack();}