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
149 lines
5.2 KiB
PHP
149 lines
5.2 KiB
PHP
<?php
|
|
|
|
use App\Jobs\AddPoliciesToBackupSetJob;
|
|
use App\Models\BackupItem;
|
|
use App\Models\BackupSet;
|
|
use App\Models\OperationRun;
|
|
use App\Models\Policy;
|
|
use App\Models\PolicyVersion;
|
|
use App\Services\Intune\FoundationSnapshotService;
|
|
use App\Services\Intune\PolicyCaptureOrchestrator;
|
|
use App\Services\Intune\SnapshotValidator;
|
|
use App\Services\OperationRunService;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Mockery\MockInterface;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
it('records stable failure reason codes and keeps run counts consistent', function () {
|
|
[$user, $tenant] = createUserWithTenant(role: 'owner');
|
|
$this->actingAs($user);
|
|
|
|
$backupSet = BackupSet::factory()->create([
|
|
'tenant_id' => $tenant->id,
|
|
'name' => 'Test backup',
|
|
'status' => 'completed',
|
|
'metadata' => ['failures' => []],
|
|
]);
|
|
|
|
$policyA = Policy::factory()->create([
|
|
'tenant_id' => $tenant->id,
|
|
'ignored_at' => null,
|
|
]);
|
|
|
|
$policyB = Policy::factory()->create([
|
|
'tenant_id' => $tenant->id,
|
|
'ignored_at' => null,
|
|
]);
|
|
|
|
$versionA = PolicyVersion::factory()->create([
|
|
'tenant_id' => $tenant->id,
|
|
'policy_id' => $policyA->id,
|
|
'policy_type' => $policyA->policy_type,
|
|
'platform' => $policyA->platform,
|
|
'snapshot' => ['id' => $policyA->external_id],
|
|
]);
|
|
|
|
$run = OperationRun::factory()->create([
|
|
'tenant_id' => $tenant->id,
|
|
'user_id' => $user->id,
|
|
'initiator_name' => $user->name,
|
|
'type' => 'backup_set.add_policies',
|
|
'status' => 'queued',
|
|
'outcome' => 'pending',
|
|
'context' => [
|
|
'backup_set_id' => (int) $backupSet->getKey(),
|
|
'policy_ids' => [(int) $policyA->getKey(), (int) $policyB->getKey()],
|
|
],
|
|
'summary_counts' => [],
|
|
'failure_summary' => [],
|
|
]);
|
|
|
|
$this->mock(PolicyCaptureOrchestrator::class, function (MockInterface $mock) use ($policyA, $policyB, $tenant, $versionA) {
|
|
$mock->shouldReceive('capture')
|
|
->twice()
|
|
->andReturnUsing(function (
|
|
Policy $policy,
|
|
\App\Models\Tenant $tenantArg,
|
|
bool $includeAssignments = false,
|
|
bool $includeScopeTags = false,
|
|
?string $createdBy = null,
|
|
array $metadata = []
|
|
) use ($policyA, $policyB, $tenant, $versionA) {
|
|
expect($tenantArg->id)->toBe($tenant->id);
|
|
expect($includeAssignments)->toBeTrue();
|
|
expect($includeScopeTags)->toBeTrue();
|
|
expect($metadata['backup_set_id'] ?? null)->not->toBeNull();
|
|
|
|
if ($policy->is($policyA)) {
|
|
return [
|
|
'version' => $versionA,
|
|
'captured' => [
|
|
'payload' => [
|
|
'id' => $policyA->external_id,
|
|
'@odata.type' => '#microsoft.graph.deviceManagementConfigurationPolicy',
|
|
],
|
|
'assignments' => [],
|
|
'scope_tags' => ['ids' => ['0'], 'names' => ['Default']],
|
|
'metadata' => [],
|
|
],
|
|
];
|
|
}
|
|
|
|
expect($policy->is($policyB))->toBeTrue();
|
|
|
|
return [
|
|
'failure' => [
|
|
'policy_id' => $policyB->id,
|
|
'reason' => 'Forbidden',
|
|
'status' => 403,
|
|
],
|
|
];
|
|
});
|
|
});
|
|
|
|
$job = new AddPoliciesToBackupSetJob(
|
|
tenantId: (int) $tenant->getKey(),
|
|
userId: (int) $user->getKey(),
|
|
backupSetId: (int) $backupSet->getKey(),
|
|
policyIds: [(int) $policyA->getKey(), (int) $policyB->getKey()],
|
|
options: [
|
|
'include_assignments' => true,
|
|
'include_scope_tags' => true,
|
|
'include_foundations' => false,
|
|
],
|
|
idempotencyKey: 'test-idempotency-key',
|
|
operationRun: $run,
|
|
);
|
|
|
|
$job->handle(
|
|
operationRunService: app(OperationRunService::class),
|
|
captureOrchestrator: app(PolicyCaptureOrchestrator::class),
|
|
foundationSnapshots: $this->mock(FoundationSnapshotService::class),
|
|
snapshotValidator: app(SnapshotValidator::class),
|
|
);
|
|
|
|
$run->refresh();
|
|
$backupSet->refresh();
|
|
|
|
expect($run->status)->toBe('completed');
|
|
expect($run->outcome)->toBe('partially_succeeded');
|
|
expect((int) ($run->summary_counts['total'] ?? 0))->toBe(2);
|
|
expect((int) ($run->summary_counts['processed'] ?? 0))->toBe(2);
|
|
expect((int) ($run->summary_counts['succeeded'] ?? 0))->toBe(1);
|
|
expect((int) ($run->summary_counts['failed'] ?? 0))->toBe(1);
|
|
expect((int) ($run->summary_counts['skipped'] ?? 0))->toBe(0);
|
|
|
|
expect(BackupItem::query()
|
|
->where('backup_set_id', $backupSet->id)
|
|
->where('policy_id', $policyA->id)
|
|
->exists())->toBeTrue();
|
|
|
|
$failureEntry = collect($run->failure_summary ?? [])
|
|
->first(fn ($entry): bool => is_array($entry) && (($entry['code'] ?? null) === 'graph.graph_forbidden'));
|
|
|
|
expect($failureEntry)->not->toBeNull();
|
|
|
|
expect($backupSet->status)->toBe('partial');
|
|
});
|