Kurzbeschreibung Versteckt die Rerun-Row-Action für archivierte (soft-deleted) RestoreRuns und verhindert damit fehlerhafte Neu-Starts aus dem Archiv; ergänzt einen Regressionstest. Änderungen Code: RestoreRunResource.php — Sichtbarkeit der rerun-Action geprüft auf ! $record->trashed() und defensive Abbruchprüfung im Action-Handler. Tests: RestoreRunRerunTest.php — neuer Test rerun action is hidden for archived restore runs. Warum Archivierte RestoreRuns durften nicht neu gestartet werden; UI zeigte trotzdem die Option. Das führte zu verwirrendem Verhalten und möglichen Fehlern beim Enqueueing. Verifikation / QA Unit/Feature: ./vendor/bin/sail artisan test tests/Feature/RestoreRunRerunTest.php Stil/format: ./vendor/bin/pint --dirty Manuell (UI): Als Tenant-Admin Filament → Restore Runs öffnen. Filter Archived aktivieren (oder Trashed filter auswählen). Sicherstellen, dass für archivierte Einträge die Rerun-Action nicht sichtbar ist. Auf einem aktiven (nicht-archivierten) Run prüfen, dass Rerun sichtbar bleibt und wie erwartet eine neue RestoreRun erzeugt. Wichtige Hinweise Kein DB-Migration required. Diese PR enthält nur den UI-/Filament-Fix; die zuvor gemachten operative Fixes für Queue/adapter-Reconciliation bleiben ebenfalls auf dem Branch (z. B. frühere commits während der Debugging-Session). T055 (Schema squash) wurde bewusst zurückgestellt und ist nicht Teil dieses PRs. Merge-Checklist Tests lokal laufen (RestoreRunRerunTest grünt) Pint läuft ohne ungepatchte Fehler Branch gepusht: 056-remove-legacy-bulkops (PR-URL: https://git.cloudarix.de/ahmido/TenantAtlas/compare/dev...056-remove-legacy-bulkops) Co-authored-by: Ahmed Darrazi <ahmeddarrazi@adsmac.local> Reviewed-on: #65
185 lines
5.8 KiB
PHP
185 lines
5.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Models\BackupSet;
|
|
use App\Models\OperationRun;
|
|
use App\Models\RestoreRun;
|
|
use App\Services\AdapterRunReconciler;
|
|
use Carbon\CarbonImmutable;
|
|
|
|
it('reconciles a queued restore.execute operation run when restore run is terminal (even with malformed payload)', function (): void {
|
|
[$user, $tenant] = createUserWithTenant(role: 'owner');
|
|
|
|
$backupSet = BackupSet::factory()->create([
|
|
'tenant_id' => $tenant->getKey(),
|
|
]);
|
|
|
|
$restoreRun = RestoreRun::factory()->create([
|
|
'tenant_id' => $tenant->getKey(),
|
|
'backup_set_id' => $backupSet->getKey(),
|
|
'status' => 'completed',
|
|
'is_dry_run' => false,
|
|
'started_at' => CarbonImmutable::now()->subMinutes(20),
|
|
'completed_at' => CarbonImmutable::now()->subMinutes(10),
|
|
'metadata' => [
|
|
'total' => 10,
|
|
'succeeded' => 8,
|
|
'failed' => 1,
|
|
'skipped' => 1,
|
|
],
|
|
// Intentionally malformed outcomes to ensure reconciler never explodes.
|
|
'results' => [
|
|
'items' => [
|
|
'123' => [
|
|
'assignment_outcomes' => ['not-an-array'],
|
|
],
|
|
],
|
|
],
|
|
]);
|
|
|
|
$opRun = OperationRun::factory()->create([
|
|
'tenant_id' => $tenant->getKey(),
|
|
'user_id' => $user->getKey(),
|
|
'initiator_name' => $user->name,
|
|
'type' => 'restore.execute',
|
|
'status' => 'queued',
|
|
'outcome' => 'pending',
|
|
'started_at' => null,
|
|
'completed_at' => null,
|
|
'created_at' => CarbonImmutable::now()->subMinutes(120),
|
|
'context' => [
|
|
'restore_run_id' => $restoreRun->getKey(),
|
|
],
|
|
'summary_counts' => [],
|
|
]);
|
|
|
|
$result = app(AdapterRunReconciler::class)->reconcile([
|
|
'type' => 'restore.execute',
|
|
'tenant_id' => (int) $tenant->getKey(),
|
|
'older_than_minutes' => 10,
|
|
'limit' => 10,
|
|
'dry_run' => false,
|
|
]);
|
|
|
|
expect($result['reconciled'] ?? null)->toBe(1);
|
|
|
|
$opRun->refresh();
|
|
|
|
expect($opRun->status)->toBe('completed');
|
|
expect($opRun->outcome)->toBe('succeeded');
|
|
|
|
expect($opRun->summary_counts['total'] ?? null)->toBe(10);
|
|
expect($opRun->summary_counts['succeeded'] ?? null)->toBe(8);
|
|
expect($opRun->summary_counts['failed'] ?? null)->toBe(1);
|
|
expect($opRun->summary_counts['skipped'] ?? null)->toBe(1);
|
|
|
|
$context = is_array($opRun->context) ? $opRun->context : [];
|
|
expect($context['reconciliation']['reason'] ?? null)->toBe('adapter_out_of_sync');
|
|
expect($context['reconciliation']['reconciled_at'] ?? null)->toBeString();
|
|
|
|
expect($opRun->started_at)->not->toBeNull();
|
|
expect($opRun->completed_at)->not->toBeNull();
|
|
})->group('ops-ux');
|
|
|
|
it('is idempotent (second run performs no work)', function (): void {
|
|
[$user, $tenant] = createUserWithTenant(role: 'owner');
|
|
|
|
$backupSet = BackupSet::factory()->create([
|
|
'tenant_id' => $tenant->getKey(),
|
|
]);
|
|
|
|
$restoreRun = RestoreRun::factory()->create([
|
|
'tenant_id' => $tenant->getKey(),
|
|
'backup_set_id' => $backupSet->getKey(),
|
|
'status' => 'completed',
|
|
'is_dry_run' => false,
|
|
'metadata' => [
|
|
'total' => 1,
|
|
'succeeded' => 1,
|
|
],
|
|
]);
|
|
|
|
OperationRun::factory()->create([
|
|
'tenant_id' => $tenant->getKey(),
|
|
'user_id' => $user->getKey(),
|
|
'initiator_name' => $user->name,
|
|
'type' => 'restore.execute',
|
|
'status' => 'queued',
|
|
'outcome' => 'pending',
|
|
'created_at' => CarbonImmutable::now()->subMinutes(120),
|
|
'context' => [
|
|
'restore_run_id' => $restoreRun->getKey(),
|
|
],
|
|
]);
|
|
|
|
$reconciler = app(AdapterRunReconciler::class);
|
|
|
|
$first = $reconciler->reconcile([
|
|
'tenant_id' => (int) $tenant->getKey(),
|
|
'older_than_minutes' => 10,
|
|
'limit' => 10,
|
|
'dry_run' => false,
|
|
]);
|
|
|
|
expect($first['reconciled'] ?? null)->toBe(1);
|
|
|
|
$second = $reconciler->reconcile([
|
|
'tenant_id' => (int) $tenant->getKey(),
|
|
'older_than_minutes' => 10,
|
|
'limit' => 10,
|
|
'dry_run' => false,
|
|
]);
|
|
|
|
expect($second['candidates'] ?? null)->toBe(0);
|
|
expect($second['reconciled'] ?? null)->toBe(0);
|
|
})->group('ops-ux');
|
|
|
|
it('does not persist non-whitelisted summary_counts keys during reconciliation', function (): void {
|
|
[$user, $tenant] = createUserWithTenant(role: 'owner');
|
|
|
|
$backupSet = BackupSet::factory()->create([
|
|
'tenant_id' => $tenant->getKey(),
|
|
]);
|
|
|
|
$restoreRun = RestoreRun::factory()->create([
|
|
'tenant_id' => $tenant->getKey(),
|
|
'backup_set_id' => $backupSet->getKey(),
|
|
'status' => 'completed',
|
|
'is_dry_run' => false,
|
|
'metadata' => [
|
|
'total' => 2,
|
|
'succeeded' => 2,
|
|
'secrets' => 999,
|
|
'assignments_success' => 123,
|
|
],
|
|
]);
|
|
|
|
$opRun = OperationRun::factory()->create([
|
|
'tenant_id' => $tenant->getKey(),
|
|
'user_id' => $user->getKey(),
|
|
'initiator_name' => $user->name,
|
|
'type' => 'restore.execute',
|
|
'status' => 'queued',
|
|
'outcome' => 'pending',
|
|
'created_at' => CarbonImmutable::now()->subMinutes(120),
|
|
'context' => [
|
|
'restore_run_id' => $restoreRun->getKey(),
|
|
],
|
|
]);
|
|
|
|
app(AdapterRunReconciler::class)->reconcile([
|
|
'tenant_id' => (int) $tenant->getKey(),
|
|
'older_than_minutes' => 10,
|
|
'limit' => 10,
|
|
'dry_run' => false,
|
|
]);
|
|
|
|
$opRun->refresh();
|
|
|
|
expect($opRun->summary_counts['total'] ?? null)->toBe(2);
|
|
expect($opRun->summary_counts['succeeded'] ?? null)->toBe(2);
|
|
expect($opRun->summary_counts)->not->toHaveKey('secrets');
|
|
expect($opRun->summary_counts)->not->toHaveKey('assignments_success');
|
|
})->group('ops-ux');
|