Files
Investidor-V2/outputs/investmoz-negocios-classificacao-QA-20261016/prove-scopes.php
T
nala 6a76aac80f
tests / ci (push) Canceled after 0s
versao compilada 1
2026-10-16 09:17:28 +02:00

45 lines
3.5 KiB
PHP

<?php
ini_set('zend.exception_ignore_args','1');require __DIR__.'/boot-QA.php';
use App\Models\ExistingBusiness;
use App\Models\User;
use App\Services\ExistingBusinessClassification;
use App\Policies\ExistingBusinessPolicy;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Gate;
$business=ExistingBusiness::findOrFail('172aa874-98fc-4bf6-b78f-d2e9a386d345');$service=app(ExistingBusinessClassification::class);$actor=User::findOrFail(24);$checks=[];
$check=function($name,$value)use(&$checks){if(!$value)throw new RuntimeException($name);$checks[$name]=true;};
session()->put(['portal.mfa_actor'=>24,'portal.mfa_at'=>time()]);
$before=$service->privateView($actor,$business);
if($before['rows'][3]['state']!=='confirmed'){
$business=$service->act($actor,$business->id,['action'=>'review','version_no'=>$business->version_no,'hash'=>$before['rows'][3]['hash'],'state'=>'confirmed','reason'=>'Ensaio sintético: confirmar relação privada com fundamento, independente da evidência do outro vínculo.']);
$before=$service->privateView($actor,$business);
}
$roles=DB::table('portal_role_assignments')->orderBy('id')->get()->toJson();
DB::beginTransaction();
try {
DB::table('portal_role_assignments')->where('user_id',24)->where('role','validator')->update(['revoked_at'=>now()]);
$check('revoked_validator_cannot_decide',!Gate::forUser($actor)->allows('reviewClassification',$business));
$rows=$service->privateView(User::findOrFail(21),$business)['rows'];
$check('confirmation_rechecks_current_grants',collect($rows)->every(fn($r)=>$r['state']==='in_validation'));
}finally{DB::rollBack();}
$check('roles_restored_exactly',$roles===DB::table('portal_role_assignments')->orderBy('id')->get()->toJson());
DB::beginTransaction();
try {
DB::table('documents')->where('id','025cce5b-73c1-43a3-b969-dc6e592bc28d')->increment('version_no');
$rows=$service->privateView($actor,$business)['rows'];
$check('changed_evidence_version_requires_review',collect(array_slice($rows,0,3))->every(fn($r)=>$r['state']==='in_validation'));
$check('unaffected_relation_confirmation_preserved',$rows[3]['state']==='confirmed');
}finally{DB::rollBack();}
$check('document_transaction_rolled_back',$service->privateView($actor,$business)['rows']===$before['rows']);
session()->put('portal.mfa_at',time()-901);
$check('expired_MFA_cannot_review',!Gate::forUser($actor)->allows('reviewClassification',$business));
session()->put(['portal.mfa_actor'=>24,'portal.mfa_at'=>time()]);
$auditor=User::findOrFail(31);$owned=clone $business;$owned->owner_user_id=31;
$check('Auditor_cannot_prepare_even_as_owner',!app(ExistingBusinessPolicy::class)->prepareClassification($auditor,$owned));
$check('published_general_editor_remains_denied',!Gate::forUser(User::findOrFail(21))->allows('update',$business));
$check('workflow_review_not_reopened',!Gate::forUser($actor)->allows('review',$business));
$proof=['target'=>$target,'checks'=>$checks,'count'=>count($checks),'testing_context'=>'Direct service/policy checks with synthetic framework session; independent normal HTTP/Fortify/MFA proof in HTTP-QA.json','negative_mutations'=>'Isolated transactions rolled back','grants_persisted'=>0,'business_transitions'=>0,'active_changes'=>0];
file_put_contents(__DIR__.'/SCOPES-QA.json',json_encode($proof,JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE).PHP_EOL);
$drafts=ExistingBusiness::where('owner_user_id',21)->whereIn('status',['draft','needs_information'])->get(['id','status','version_no']);
echo json_encode(['passed'=>count($checks),'existing_drafts_for_old_code_edit'=>$drafts]).PHP_EOL;