make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();$queries=0;$checks=[];DB::listen(function()use(&$queries){$queries++;});$probe=function($fn,$status,$name)use(&$checks,&$queries){$before=$queries;try{$fn();throw new RuntimeException('Guard unexpectedly accepted');}catch(Symfony\Component\HttpKernel\Exception\HttpException $e){if($e->getStatusCode()!==$status||$queries!==$before)throw new RuntimeException($name);$checks[]=$name;}};config(['receipt_qa.invoices_enabled'=>false]);$rt=new App\Modules\Purchasing\ReceiptRuntime;$probe(fn()=>$rt->run('purchasing_invoices.prepare',fn()=>true),404,'disabled invoice runtime refuses before SQL');$probe(fn()=>(new App\Modules\Purchasing\InvoiceController)->preview(1,new Illuminate\Http\Request,$rt),404,'disabled invoice preview refuses before validation and SQL');config(['receipt_qa.invoices_enabled'=>true]);$app->instance('env','production');$probe(fn()=>$rt->run('purchasing_invoices.prepare',fn()=>true),403,'production refuses synthetic invoice workflow');foreach(['purchasing/invoices','api/purchasing-invoices','api/purchasing-invoices/orders/1/confirm']as$path){if(App\Shared\Context\ModuleNavigation::owner($path)!=='purchasing')throw new RuntimeException('Wrong module owner');$checks[]='invoice route remains in purchasing: '.$path;}file_put_contents($out,json_encode(['passed'=>true,'checks'=>$checks,'database_queries'=>0],JSON_PRETTY_PRINT|JSON_THROW_ON_ERROR));echo count($checks)." invoice guard checks passed.\n";