TenantAtlas/apps/platform/tests/Feature/Operations/Spec362UnsupportedSyncBackupFamiliesTest.php
ahmido 548a37c888 feat: implement sync capture backup operation semantics (#433)
Implemented sync capture backup operation semantics as requested.

Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de>
Reviewed-on: #433
2026-06-07 01:19:08 +00:00

126 lines
4.5 KiB
PHP

<?php
declare(strict_types=1);
use App\Models\BackupSet;
use App\Models\OperationRun;
use App\Services\AdapterRunReconciler;
use App\Support\Inventory\InventoryCoverage;
use App\Support\OperationRunLinks;
use App\Support\OperationRunOutcome;
use App\Support\OperationRunStatus;
use App\Support\Workspaces\WorkspaceContext;
use Filament\Facades\Filament;
use Illuminate\Foundation\Testing\RefreshDatabase;
uses(RefreshDatabase::class);
it('keeps scheduled reconciliation scoped to the selected Spec362 families only', function (): void {
[, $tenant] = createUserWithTenant(role: 'owner');
BackupSet::factory()->for($tenant)->create();
$policyRun = OperationRun::factory()->forTenant($tenant)->create([
'type' => 'policy.sync',
'status' => OperationRunStatus::Queued->value,
'outcome' => OperationRunOutcome::Pending->value,
'created_at' => now()->subMinutes(20),
'context' => [
'inventory' => [
'coverage' => InventoryCoverage::buildPayload([
'deviceConfiguration' => 'succeeded',
], []),
],
],
]);
$backupSetUpdateRun = OperationRun::factory()->forTenant($tenant)->create([
'type' => 'backup_set.update',
'status' => OperationRunStatus::Queued->value,
'outcome' => OperationRunOutcome::Pending->value,
'created_at' => now()->subMinutes(20),
'context' => [
'backup_set_id' => 1,
],
]);
$result = app(AdapterRunReconciler::class)->reconcile([
'managed_environment_id' => (int) $tenant->getKey(),
'older_than_minutes' => 10,
'limit' => 10,
'dry_run' => false,
]);
expect($result['candidates'] ?? null)->toBe(0)
->and($result['reconciled'] ?? null)->toBe(0)
->and($result['changes'] ?? null)->toBe([]);
$policyRun->refresh();
$backupSetUpdateRun->refresh();
expect($policyRun->status)->toBe(OperationRunStatus::Queued->value)
->and($backupSetUpdateRun->status)->toBe(OperationRunStatus::Queued->value);
});
it('does not auto-reconcile unsupported sync and backup families from adjacent selected-family proof in Spec362', function (): void {
[, $tenant] = createUserWithTenant(role: 'owner');
$backupSet = BackupSet::factory()->for($tenant)->create();
$policyRun = OperationRun::factory()->forTenant($tenant)->create([
'type' => 'policy.sync',
'status' => OperationRunStatus::Queued->value,
'outcome' => OperationRunOutcome::Pending->value,
'created_at' => now()->subMinutes(20),
'context' => [
'inventory' => [
'coverage' => InventoryCoverage::buildPayload([
'deviceConfiguration' => 'succeeded',
], []),
],
],
]);
$backupSetUpdateRun = OperationRun::factory()->forTenant($tenant)->create([
'type' => 'backup_set.update',
'status' => OperationRunStatus::Queued->value,
'outcome' => OperationRunOutcome::Pending->value,
'created_at' => now()->subMinutes(20),
'context' => [
'backup_set_id' => (int) $backupSet->getKey(),
],
]);
expect(app(AdapterRunReconciler::class)->reconcileOperationRun($policyRun, true))->toBeNull()
->and(app(AdapterRunReconciler::class)->reconcileOperationRun($backupSetUpdateRun, true))->toBeNull();
});
it('keeps unsupported sync and backup detail surfaces diagnostic-first in Spec362', function (): void {
[$user, $tenant] = createUserWithTenant(role: 'owner');
$policyRun = OperationRun::factory()->forTenant($tenant)->create([
'type' => 'policy.sync',
'status' => OperationRunStatus::Queued->value,
'outcome' => OperationRunOutcome::Pending->value,
'created_at' => now()->subMinutes(20),
]);
$backupSetUpdateRun = OperationRun::factory()->forTenant($tenant)->create([
'type' => 'backup_set.update',
'status' => OperationRunStatus::Queued->value,
'outcome' => OperationRunOutcome::Pending->value,
'created_at' => now()->subMinutes(20),
]);
Filament::setTenant(null, true);
foreach ([$policyRun, $backupSetUpdateRun] as $run) {
$this->actingAs($user)
->withSession([WorkspaceContext::SESSION_KEY => (int) $tenant->workspace_id])
->get(OperationRunLinks::tenantlessView($run))
->assertSuccessful()
->assertSee('Monitoring detail')
->assertDontSee('Automatically reconciled');
}
});