39 lines
3.9 KiB
PHP
39 lines
3.9 KiB
PHP
<?php
|
|
// Test harness only. Reuses an existing regression book; never8085 or a new demo.
|
|
$repo = dirname(__DIR__);
|
|
$run = json_decode(file_get_contents('C:/laragon/data/sgf-tempo/run/modular-regression-current.json'), true, 64, JSON_THROW_ON_ERROR);
|
|
$stateFile = $run['root'].'/private/receipt-composition-da77bb730751/state.json';
|
|
$s = json_decode(file_get_contents($stateFile), true, 64, JSON_THROW_ON_ERROR);
|
|
if ($run['id'] !== '2576427d1939' || $s['tag'] !== 'da77bb730751' || !is_file($s['root'].'/invoice-result.json') || is_file($s['root'].'/demo-server.json')) throw new LogicException('Existing regression only');
|
|
$proofRoot = getenv('SGC_INVOICE_PROOF_ROOT');
|
|
if (!$proofRoot || dirname(str_replace('\\','/',$proofRoot)) !== str_replace('\\','/',$run['root'].'/private') || !preg_match('/^sgc-invoice-proof-[a-f0-9]{12}$/D', basename($proofRoot))) throw new LogicException('Private proof path required');
|
|
foreach ($s['env'] as $key=>$value) if (preg_match('/^(APP_|DB_|SGF_|SESSION_|CACHE_|QUEUE_|BCRYPT_)/', $key)) { putenv($key.'='.$value); $_ENV[$key] = $value; }
|
|
$isolated = ['APP_BASE_PATH'=>$repo, 'APP_CONFIG_CACHE'=>$proofRoot.'/config.php', 'APP_ROUTES_CACHE'=>$proofRoot.'/routes.php',
|
|
'APP_SERVICES_CACHE'=>$proofRoot.'/services.php', 'APP_PACKAGES_CACHE'=>$proofRoot.'/packages.php', 'SESSION_DRIVER'=>'array','CACHE_STORE'=>'array'];
|
|
foreach ($isolated as $key=>$value) { putenv($key.'='.$value); $_ENV[$key]=$value; }
|
|
foreach (['storage/logs','storage/framework/views','storage/framework/sessions','storage/framework/cache/data'] as $dir) if (!is_dir($proofRoot.'/'.$dir)) mkdir($proofRoot.'/'.$dir, 0700, true);
|
|
require $repo.'/vendor/autoload.php';
|
|
$app = require $repo.'/bootstrap/app.php'; $app->addAbsoluteCachePathPrefix('C:'); $app->useStoragePath($proofRoot.'/storage');
|
|
$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();
|
|
App\Modules\Purchasing\BudgetAdapter::guard();
|
|
$f = json_decode(file_get_contents($s['root'].'/fixture.json'), true);
|
|
$nativeFixture = json_decode(file_get_contents($s['root'].'/native-fixture.json'), true);
|
|
$secret = json_decode(file_get_contents($proofRoot.'/client.json'), true);
|
|
$principal = ['enabled'=>true,'token_sha256'=>hash('sha256',$secret['token']), 'user_id'=>$f['issuer'], 'auth_version'=>1,
|
|
'tenant_id'=>$f['tenant'],'company_id'=>$f['company'],'unit_id'=>$f['unit'],'context_version'=>$secret['context']];
|
|
config(['sgc_invoice.enabled'=>true, 'sgc_invoice.principals'=>['synthetic'=>$principal], 'database.connections.sgc_verify'=>$s['nativeConnection'],
|
|
'receipt_qa.requests_enabled'=>true]); // Test-only audited-origin reader; no request command is dispatched.
|
|
$native = Illuminate\Support\Facades\DB::connection('sgc_verify');
|
|
$host = Illuminate\Support\Facades\DB::connection();
|
|
$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
|
|
$send = function (array $body, ?string $key=null, array $headers=[], string $path='/api/v1/integration/sgc/invoices', ?string $raw=null, string $method='POST') use ($secret,$kernel,$proofRoot) {
|
|
$server = ['REMOTE_ADDR'=>'127.0.0.1','HTTP_ACCEPT'=>'application/json','CONTENT_TYPE'=>'application/json',
|
|
'HTTP_AUTHORIZATION'=>'Bearer '.$secret['token'],'HTTP_X_SGC_CLIENT'=>'synthetic','HTTP_X_SGC_CONTEXT'=>$secret['context'],
|
|
'HTTP_X_IDEMPOTENCY_KEY'=>$key??(string)Illuminate\Support\Str::uuid()];
|
|
foreach ($headers as $name=>$value) { if ($value === null) unset($server[$name]); else $server[$name]=$value; }
|
|
$request = Illuminate\Http\Request::create($path, $method, [], [], [], $server, $method==='GET'?$raw:($raw??json_encode($body, JSON_THROW_ON_ERROR)));
|
|
$response = $kernel->handle($request); $kernel->terminate($request,$response);
|
|
if ($response->getStatusCode()>=500) file_put_contents($proofRoot.'/last-error.json',$response->getContent());
|
|
return ['status'=>$response->getStatusCode(),'data'=>json_decode($response->getContent(),true),'no_store'=>str_contains((string)$response->headers->get('Cache-Control'),'no-store')];
|
|
};
|