## Summary - implement Spec 209 heavy-governance cost recovery end to end - add the heavy-governance contract, hotspot inventory, decomposition, snapshots, budget outcome, and author-guidance surfaces in the shared lane support seams - slim the baseline and findings hotspot families, harden wrapper behavior, and refresh the spec, quickstart, and contract artifacts ## Validation - `cd apps/platform && ./vendor/bin/sail bin pint --dirty --format agent` - `cd apps/platform && ./vendor/bin/sail artisan test --compact tests/Feature/Guards/TestLaneCommandContractTest.php tests/Feature/Guards/ActionSurfaceContractTest.php tests/Feature/Guards/OperationLifecycleOpsUxGuardTest.php` - `cd apps/platform && ./vendor/bin/sail artisan test --compact tests/Feature/Filament/BaselineProfileCaptureStartSurfaceTest.php tests/Feature/Filament/BaselineProfileCompareStartSurfaceTest.php tests/Feature/Filament/BaselineActionAuthorizationTest.php tests/Feature/Findings/FindingsListFiltersTest.php tests/Feature/Findings/FindingExceptionRenewalTest.php tests/Feature/Findings/FindingWorkflowRowActionsTest.php tests/Feature/Findings/FindingWorkflowViewActionsTest.php tests/Feature/Guards/ActionSurfaceContractTest.php tests/Feature/Guards/OperationLifecycleOpsUxGuardTest.php` - `./scripts/platform-sail artisan test --compact` ## Outcome - heavy-governance latest artifacts now agree on an authoritative `330s` threshold with `recalibrated` outcome after the honest rerun - full suite result: `3760 passed`, `8 skipped`, `23535 assertions` Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de> Reviewed-on: #242
133 lines
4.3 KiB
PHP
133 lines
4.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Filament\Resources\FindingResource\Pages\ListFindings;
|
|
use App\Models\AuditLog;
|
|
use App\Models\Finding;
|
|
use App\Models\User;
|
|
use Filament\Facades\Filament;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Livewire\Livewire;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
function findingBulkAuditResourceIds(int $tenantId, string $action): array
|
|
{
|
|
return AuditLog::query()
|
|
->where('tenant_id', $tenantId)
|
|
->where('action', $action)
|
|
->pluck('resource_id')
|
|
->map(static fn (string $resourceId): int => (int) $resourceId)
|
|
->sort()
|
|
->values()
|
|
->all();
|
|
}
|
|
|
|
it('supports bulk workflow actions and audits each record', function (): void {
|
|
[$manager, $tenant] = createUserWithTenant(role: 'manager');
|
|
$this->actingAs($manager);
|
|
Filament::setTenant($tenant, true);
|
|
|
|
$findings = Finding::factory()
|
|
->count(6)
|
|
->for($tenant)
|
|
->create([
|
|
'status' => Finding::STATUS_NEW,
|
|
'triaged_at' => null,
|
|
]);
|
|
|
|
$component = Livewire::test(ListFindings::class);
|
|
|
|
$component
|
|
->callTableBulkAction('triage_selected', $findings)
|
|
->assertHasNoTableBulkActionErrors();
|
|
|
|
$findings->each(fn (Finding $finding) => expect($finding->refresh()->status)->toBe(Finding::STATUS_TRIAGED));
|
|
|
|
expect(findingBulkAuditResourceIds((int) $tenant->getKey(), 'finding.triaged'))
|
|
->toEqual($findings->pluck('id')->sort()->values()->all());
|
|
|
|
$assignee = User::factory()->create();
|
|
createUserWithTenant(tenant: $tenant, user: $assignee, role: 'operator');
|
|
|
|
$assignFindings = Finding::factory()
|
|
->count(3)
|
|
->for($tenant)
|
|
->create([
|
|
'status' => Finding::STATUS_TRIAGED,
|
|
'assignee_user_id' => null,
|
|
'owner_user_id' => null,
|
|
]);
|
|
|
|
$component
|
|
->callTableBulkAction('assign_selected', $assignFindings, data: [
|
|
'assignee_user_id' => (int) $assignee->getKey(),
|
|
'owner_user_id' => (int) $manager->getKey(),
|
|
])
|
|
->assertHasNoTableBulkActionErrors();
|
|
|
|
$assignFindings->each(function (Finding $finding) use ($assignee, $manager): void {
|
|
$finding->refresh();
|
|
|
|
expect((int) $finding->assignee_user_id)->toBe((int) $assignee->getKey())
|
|
->and((int) $finding->owner_user_id)->toBe((int) $manager->getKey());
|
|
});
|
|
|
|
expect(findingBulkAuditResourceIds((int) $tenant->getKey(), 'finding.assigned'))
|
|
->toEqual($assignFindings->pluck('id')->sort()->values()->all());
|
|
|
|
$resolveFindings = Finding::factory()
|
|
->count(2)
|
|
->for($tenant)
|
|
->create([
|
|
'status' => Finding::STATUS_IN_PROGRESS,
|
|
'resolved_at' => null,
|
|
'resolved_reason' => null,
|
|
]);
|
|
|
|
$component
|
|
->callTableBulkAction('resolve_selected', $resolveFindings, data: [
|
|
'resolved_reason' => 'fixed',
|
|
])
|
|
->assertHasNoTableBulkActionErrors();
|
|
|
|
$resolveFindings->each(function (Finding $finding): void {
|
|
$finding->refresh();
|
|
|
|
expect($finding->status)->toBe(Finding::STATUS_RESOLVED)
|
|
->and($finding->resolved_reason)->toBe('fixed')
|
|
->and($finding->resolved_at)->not->toBeNull();
|
|
});
|
|
|
|
expect(findingBulkAuditResourceIds((int) $tenant->getKey(), 'finding.resolved'))
|
|
->toEqual($resolveFindings->pluck('id')->sort()->values()->all());
|
|
|
|
$closeFindings = Finding::factory()
|
|
->count(2)
|
|
->for($tenant)
|
|
->create([
|
|
'status' => Finding::STATUS_TRIAGED,
|
|
'closed_at' => null,
|
|
'closed_reason' => null,
|
|
]);
|
|
|
|
$component
|
|
->callTableBulkAction('close_selected', $closeFindings, data: [
|
|
'closed_reason' => 'not applicable',
|
|
])
|
|
->assertHasNoTableBulkActionErrors();
|
|
|
|
$closeFindings->each(function (Finding $finding): void {
|
|
$finding->refresh();
|
|
|
|
expect($finding->status)->toBe(Finding::STATUS_CLOSED)
|
|
->and($finding->closed_reason)->toBe('not applicable')
|
|
->and($finding->closed_at)->not->toBeNull()
|
|
->and($finding->closed_by_user_id)->not->toBeNull();
|
|
});
|
|
|
|
expect(findingBulkAuditResourceIds((int) $tenant->getKey(), 'finding.closed'))
|
|
->toEqual($closeFindings->pluck('id')->sort()->values()->all());
|
|
});
|