Files
Investidor-V2/outputs/investmoz-audit-current-20261012/option-B3-own-scan-QA.php
T
nala 287e991486
tests / ci (push) Waiting to run
oportunidades 7
2026-10-13 11:40:29 +02:00

36 lines
3.4 KiB
PHP

<?php
ini_set('zend.exception_ignore_args','1'); putenv('STABILITY_QA_MODE=consumers');
$b3Root=dirname(__DIR__,2); $b3QA=$b3Root.'/storage/app/private/investmoz-v2/portal-audit/portal-stability-source-20261011_083742';
$app=require $b3QA.'/tools/portal-stability-runtime.php'; $db=Illuminate\Support\Facades\DB::connection();
$t=(array)$db->selectOne('SELECT current_database() AS database, inet_server_port() AS port');
if($t!==['database'=>'stability_consumers_20261011_084534_test','port'=>55441]||config('portal.notifications_enabled')||config('suitecrm.enabled'))throw new RuntimeException('QA isolation/external integration guard');
$s=json_decode(file_get_contents(__DIR__.'/option-B3-project-progress.json'),true,512,JSON_THROW_ON_ERROR);
$f=json_decode(file_get_contents(__DIR__.'/option-B3-PDF-fixture.json'),true,512,JSON_THROW_ON_ERROR);
$r=$db->table('opportunity_documents')->where('id',$s['resource_id'])->where('opportunity_id',30)->first();
$d=$db->table('documents')->where('id',$s['document_id'])->first();
if(!$r||$r->document_id!==$s['document_id']||!$d||$d->uploaded_by!==21||$d->source_system!=='opportunity-resources'||trim($d->sha256)!==$f['sha256'])throw new RuntimeException('Own synthetic document binding required');
$dest=__DIR__.'/option-B3-own-scan-QA.json';if(is_file($dest))throw new RuntimeException('Preserve previous scan result');
$before=$db->table('jobs')->orderBy('id')->get()->keyBy('id');
$scanner=app(App\Services\Malware\MalwareScanner::class); $health=$scanner->health();
if(!$health['available'])throw new RuntimeException('Real scanner unavailable');
$job=new App\Jobs\ScanDocumentForMalware($s['document_id']); $job->handle($scanner);
$d=$db->table('documents')->where('id',$s['document_id'])->first();
if($d->malware_scan_status!=='clean'||trim($d->sha256)!==$d->malware_scanned_sha256||$d->status!=='active')throw new RuntimeException('Scan/hash mismatch');
$removed=[];
foreach($before as$jid=>$row){
$payload=json_decode($row->payload,true);
if(($payload['data']['commandName']??'')!==App\Jobs\ScanDocumentForMalware::class)continue;
$queued=unserialize($payload['data']['command'],['allowed_classes'=>[App\Jobs\ScanDocumentForMalware::class]]);
if($queued instanceof App\Jobs\ScanDocumentForMalware&&$queued->documentId===$s['document_id']){
if($db->table('jobs')->where('id',$jid)->where('payload',$row->payload)->delete()!==1)throw new RuntimeException('Own queue item changed');$removed[]=$jid;
}
}
(new Illuminate\Bus\UniqueLock(app(Illuminate\Contracts\Cache\Repository::class)))->release($job);
foreach($before as$jid=>$row)if(!in_array($jid,$removed,true)&&((array)$db->table('jobs')->where('id',$jid)->first()!==(array)$row))throw new RuntimeException('Unrelated queue work changed');
$p=['at'=>gmdate('c'),'target'=>$t,'own_resource_id'=>$s['resource_id'],'own_document_id'=>$s['document_id'],
'sha256'=>trim($d->sha256),'scan'=>'clean','scanned_sha256'=>$d->malware_scanned_sha256,
'engine_version'=>$d->malware_engine_version,'signatures_at'=>$d->malware_signatures_at,'attempts'=>$d->malware_scan_attempts,
'storage_encryption'=>$d->storage_encryption,'own_queue_jobs_removed'=>$removed,'unrelated_queue_work_unchanged'=>true,
'active_writes'=>0,'supervised_worker_test_claimed'=>false,'only_own_job_handler_executed'=>true,'result'=>'passed'];
file_put_contents($dest,json_encode($p,JSON_PRETTY_PRINT|JSON_THROW_ON_ERROR));echo json_encode($p).PHP_EOL;