## Spec 178 — Operations Lifecycle Alignment & Cross-Surface Truth Consistency Härtet die Run-Lifecycle-Wahrheit und Cross-Surface-Konsistenz über alle zentralen Operator-Flächen hinweg. ### Kern-Änderungen **Lifecycle Truth Alignment** - Einheitliche stale/stuck-Semantik zwischen Tenant-, Workspace-, Admin- und System-Surfaces - `OperationRunFreshnessState` wird konsistent über alle Widgets und Seiten propagiert - Gemeinsame Problem-Klassen-Trennung: `terminal_follow_up` vs. `active_stale_attention` **BulkOperationProgress Freshness** - Overlay zeigt nur noch `healthyActive()` Runs statt alle aktiven Runs - Likely-stale Runs halten das Polling nicht mehr künstlich aktiv - Terminal Runs verschwinden zeitnah aus dem Progress-Overlay **Decision Zone im Run Detail** - Stale/reconciled Attention in der primären Decision-Hierarchie - Klare Antworten: aktiv? stale? reconciled? nächster Schritt? - Artifact-reiche Runs behalten Lifecycle-Truth vor Deep-Diagnostics **Cross-Surface Link-Continuity** - Dashboard → Operations Hub → Run Detail erzählen dieselbe Geschichte - Notifications referenzieren korrekte Problem-Klasse - Workspace/Tenant-Attention verlinken problemklassengerecht **System-Plane Fixes** - `/system/ops/failures` 500-Error behoben (panel-sichere Artifact-URLs) - System-Stuck/Failures zeigen reconciled stale lineage ### Weitere Fixes - Inventory auth guard bereinigt (Gate statt ad-hoc Facades) - Browser-Smoke-Tests stabilisiert (DOM-Assertions statt fragile Klicks) - Test-Assertion-Drift für Verification/Lifecycle-Texte korrigiert ### Test-Ergebnis Full Suite: **3269 passed**, 8 skipped, 0 failed ### Spec-Artefakte - `specs/178-ops-truth-alignment/spec.md` - `specs/178-ops-truth-alignment/plan.md` - `specs/178-ops-truth-alignment/tasks.md` - `specs/178-ops-truth-alignment/research.md` - `specs/178-ops-truth-alignment/data-model.md` - `specs/178-ops-truth-alignment/quickstart.md` - `specs/178-ops-truth-alignment/contracts/operations-truth-alignment.openapi.yaml` Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de> Reviewed-on: #209
163 lines
5.6 KiB
PHP
163 lines
5.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Filament\Widgets\Dashboard;
|
|
|
|
use App\Filament\Resources\FindingResource;
|
|
use App\Models\Finding;
|
|
use App\Models\OperationRun;
|
|
use App\Models\Tenant;
|
|
use App\Models\User;
|
|
use App\Support\Auth\Capabilities;
|
|
use App\Support\OperationRunLinks;
|
|
use App\Support\OpsUx\ActiveRuns;
|
|
use App\Support\Rbac\UiTooltips;
|
|
use Filament\Facades\Filament;
|
|
use Filament\Widgets\StatsOverviewWidget;
|
|
use Filament\Widgets\StatsOverviewWidget\Stat;
|
|
|
|
class DashboardKpis extends StatsOverviewWidget
|
|
{
|
|
protected int|string|array $columnSpan = 'full';
|
|
|
|
protected function getPollingInterval(): ?string
|
|
{
|
|
return ActiveRuns::pollingIntervalForTenant(Filament::getTenant());
|
|
}
|
|
|
|
/**
|
|
* @return array<Stat>
|
|
*/
|
|
protected function getStats(): array
|
|
{
|
|
$tenant = Filament::getTenant();
|
|
|
|
if (! $tenant instanceof Tenant) {
|
|
return $this->emptyStats();
|
|
}
|
|
|
|
$tenantId = (int) $tenant->getKey();
|
|
|
|
$openDriftFindings = (int) Finding::query()
|
|
->where('tenant_id', $tenantId)
|
|
->openDrift()
|
|
->count();
|
|
|
|
$highSeverityActiveFindings = (int) Finding::query()
|
|
->where('tenant_id', $tenantId)
|
|
->highSeverityActive()
|
|
->count();
|
|
|
|
$activeRuns = (int) OperationRun::query()
|
|
->where('tenant_id', $tenantId)
|
|
->healthyActive()
|
|
->count();
|
|
|
|
$staleActiveRuns = (int) OperationRun::query()
|
|
->where('tenant_id', $tenantId)
|
|
->activeStaleAttention()
|
|
->count();
|
|
|
|
$terminalFollowUpRuns = (int) OperationRun::query()
|
|
->where('tenant_id', $tenantId)
|
|
->terminalFollowUp()
|
|
->count();
|
|
|
|
$openDriftUrl = $openDriftFindings > 0
|
|
? $this->findingsUrl($tenant, [
|
|
'tab' => 'needs_action',
|
|
'finding_type' => Finding::FINDING_TYPE_DRIFT,
|
|
])
|
|
: null;
|
|
$highSeverityUrl = $highSeverityActiveFindings > 0
|
|
? $this->findingsUrl($tenant, [
|
|
'tab' => 'needs_action',
|
|
'high_severity' => 1,
|
|
])
|
|
: null;
|
|
$findingsHelperText = $this->findingsHelperText($tenant);
|
|
|
|
return [
|
|
Stat::make('Open drift findings', $openDriftFindings)
|
|
->description($openDriftUrl === null && $openDriftFindings > 0
|
|
? $findingsHelperText
|
|
: 'active drift workflow items')
|
|
->color($openDriftFindings > 0 ? 'warning' : 'gray')
|
|
->url($openDriftUrl),
|
|
Stat::make('High severity active findings', $highSeverityActiveFindings)
|
|
->description($highSeverityUrl === null && $highSeverityActiveFindings > 0
|
|
? $findingsHelperText
|
|
: 'high or critical findings needing review')
|
|
->color($highSeverityActiveFindings > 0 ? 'danger' : 'gray')
|
|
->url($highSeverityUrl),
|
|
Stat::make('Active operations', $activeRuns)
|
|
->description('healthy queued or running tenant work')
|
|
->color($activeRuns > 0 ? 'info' : 'gray')
|
|
->url($activeRuns > 0 ? OperationRunLinks::index($tenant, activeTab: 'active') : null),
|
|
Stat::make('Likely stale operations', $staleActiveRuns)
|
|
->description('queued or running past the lifecycle window')
|
|
->color($staleActiveRuns > 0 ? 'warning' : 'gray')
|
|
->url($staleActiveRuns > 0
|
|
? OperationRunLinks::index(
|
|
$tenant,
|
|
activeTab: OperationRun::PROBLEM_CLASS_ACTIVE_STALE_ATTENTION,
|
|
problemClass: OperationRun::PROBLEM_CLASS_ACTIVE_STALE_ATTENTION,
|
|
)
|
|
: null),
|
|
Stat::make('Terminal follow-up operations', $terminalFollowUpRuns)
|
|
->description('blocked, partial, failed, or auto-reconciled runs')
|
|
->color($terminalFollowUpRuns > 0 ? 'danger' : 'gray')
|
|
->url($terminalFollowUpRuns > 0
|
|
? OperationRunLinks::index(
|
|
$tenant,
|
|
activeTab: OperationRun::PROBLEM_CLASS_TERMINAL_FOLLOW_UP,
|
|
problemClass: OperationRun::PROBLEM_CLASS_TERMINAL_FOLLOW_UP,
|
|
)
|
|
: null),
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return array<Stat>
|
|
*/
|
|
private function emptyStats(): array
|
|
{
|
|
return [
|
|
Stat::make('Open drift findings', 0),
|
|
Stat::make('High severity active findings', 0),
|
|
Stat::make('Active operations', 0),
|
|
Stat::make('Likely stale operations', 0),
|
|
Stat::make('Terminal follow-up operations', 0),
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @param array<string, mixed> $parameters
|
|
*/
|
|
private function findingsUrl(Tenant $tenant, array $parameters): ?string
|
|
{
|
|
if (! $this->canOpenFindings($tenant)) {
|
|
return null;
|
|
}
|
|
|
|
return FindingResource::getUrl('index', $parameters, panel: 'tenant', tenant: $tenant);
|
|
}
|
|
|
|
private function findingsHelperText(Tenant $tenant): string
|
|
{
|
|
return $this->canOpenFindings($tenant)
|
|
? 'Open findings'
|
|
: UiTooltips::INSUFFICIENT_PERMISSION;
|
|
}
|
|
|
|
private function canOpenFindings(Tenant $tenant): bool
|
|
{
|
|
$user = auth()->user();
|
|
|
|
return $user instanceof User
|
|
&& $user->canAccessTenant($tenant)
|
|
&& $user->can(Capabilities::TENANT_FINDINGS_VIEW, $tenant);
|
|
}
|
|
}
|