@ -33,6 +33,7 @@ $schema->create('cloud_instances', static function (Blueprint $table): void {
$table->string('name');
$table->string('status');
$table->string('service_status');
$table->integer('expires_at')->nullable();
});
$schema->create('cloud_backup_subscriptions',
static function (Blueprint $table): void {
@ -79,6 +80,7 @@ $instance->user_id = 9;
$instance->name = 'migrated-vm';
$instance->status = 'active';
$instance->service_status = 'active';
$instance->expires_at = $now + 86400;
$instance->save();
$subscription = new CloudBackupSubscription();
@ -135,6 +137,50 @@ $check(($presented['can_restore_original'] ?? false) === true
& & ($presented['restore_original_block_reason'] ?? '') === '',
'The user catalog disagreed with the authoritative restore policy.');
$instance->expires_at = $now - 1;
$instance->save();
$expiredDecision = CloudOriginalBackupRestorePolicy::evaluate(
$instance, $backup, $now
);
$expiredPresented = $display->invoke(null, $backup, $instance);
$expiredRejected = false;
try {
CloudOriginalBackupRestorePolicy::assertEligible(
$instance, $backup, $now
);
} catch (CloudError $error) {
$expiredRejected = $error->httpStatus === 409;
}
$check(($expiredDecision['eligible'] ?? true) === false
& & ($expiredDecision['reason'] ?? '') === 'instance_service_expired'
& & ($expiredPresented['can_restore_original'] ?? true) === false
& & ($expiredPresented['restore_original_block_reason'] ?? '') !== ''
& & $expiredRejected,
'An expired instance remained restorable during backup retention grace.');
$instance->service_status = 'expired_grace';
$instance->expires_at = $now + 86400;
$instance->save();
$graceDecision = CloudOriginalBackupRestorePolicy::evaluate(
$instance, $backup, $now
);
$gracePresented = $display->invoke(null, $backup, $instance);
$check(($graceDecision['eligible'] ?? true) === false
& & ($graceDecision['reason'] ?? '') === 'instance_service_expired'
& & ($gracePresented['can_restore_original'] ?? true) === false,
'A grace-period service state remained restorable before renewal.');
$instance->service_status = 'active';
$instance->expires_at = $now + 86400;
$instance->save();
$renewedDecision = CloudOriginalBackupRestorePolicy::evaluate(
$instance, $backup, $now
);
$renewedPresented = $display->invoke(null, $backup, $instance);
$check(($renewedDecision['eligible'] ?? false) === true
& & ($renewedPresented['can_restore_original'] ?? false) === true,
'Renewal did not restore automatic-backup recovery eligibility.');
$backup->refresh();
$check((string) $backup->source_uuid === $sourceUuid,
'Restore eligibility rewrote the immutable source UUID audit field.');
@ -146,6 +192,7 @@ $other->user_id = (int) $instance->user_id;
$other->name = 'different-logical-vm';
$other->status = 'active';
$other->service_status = 'active';
$other->expires_at = $now + 86400;
$other->save();
$rejected = CloudOriginalBackupRestorePolicy::evaluate($other, $backup, $now);
$check(($rejected['eligible'] ?? true) === false
@ -168,8 +215,15 @@ $automaticSource = (string) file_get_contents(
$backupSource = (string) file_get_contents(
dirname(__DIR__) . '/app/Services/Cloud/CloudBackupService.php'
);
$policySource = (string) file_get_contents(
dirname(__DIR__) . '/app/Services/Cloud/CloudOriginalBackupRestorePolicy.php'
);
$check(str_contains($automaticSource,
'CloudOriginalBackupRestorePolicy::evaluate(')
& & str_contains($automaticSource,
"'service_status', 'expires_at'")
& & str_contains($policySource,
'CloudAutomaticBackupService::shouldPauseForInstanceExpiry(')
& & substr_count($backupSource,
'CloudOriginalBackupRestorePolicy::assertEligible(') >= 2
& & !str_contains($backupSource,