|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
require dirname(__DIR__) . '/vendor/autoload.php';
|
|
|
|
|
|
|
|
|
|
use App\Services\Cloud\CloudAutomaticBackupService;
|
|
|
|
|
|
|
|
|
|
$assert = static function (bool $condition, string $message): void {
|
|
|
|
|
if (!$condition) {
|
|
|
|
|
throw new RuntimeException($message);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// UTC midnight never moves with daylight-saving transitions.
|
|
|
|
|
$beforeDst = strtotime('2026-03-08T23:30:00Z');
|
|
|
|
|
$first = CloudAutomaticBackupService::nextRunAt($beforeDst, 'daily', 0);
|
|
|
|
|
$second = CloudAutomaticBackupService::nextRunAt($first, 'daily', 0);
|
|
|
|
|
$assert(CloudAutomaticBackupService::TIMEZONE === 'UTC'
|
|
|
|
|
&& gmdate('Y-m-d H:i:s', $first) === '2026-03-09 00:00:00'
|
|
|
|
|
&& gmdate('Y-m-d H:i:s', $second) === '2026-03-10 00:00:00'
|
|
|
|
|
&& $second - $first === 24 * 3600,
|
|
|
|
|
'Automatic backup schedule did not remain fixed at UTC midnight.');
|
|
|
|
|
|
|
|
|
|
$weekly = CloudAutomaticBackupService::nextRunAt(
|
|
|
|
|
strtotime('2026-10-24T19:00:00Z'), 'weekly', 1
|
|
|
|
|
);
|
|
|
|
|
$utc = (new DateTimeImmutable('@' . $weekly))->setTimezone(
|
|
|
|
|
new DateTimeZone(CloudAutomaticBackupService::TIMEZONE)
|
|
|
|
|
);
|
|
|
|
|
$assert($utc->format('w H:i') === '1 00:00'
|
|
|
|
|
&& $utc->format('Ymd-His') === '20261026-000000',
|
|
|
|
|
'Weekly schedule or its deterministic UTC-midnight name timestamp drifted.');
|
|
|
|
|
|
|
|
|
|
$routes = file_get_contents(dirname(__DIR__) . '/config/routes_cloud.php');
|
|
|
|
|
$controller = file_get_contents(
|
|
|
|
|
dirname(__DIR__) . '/app/Controllers/CloudApiController.php'
|
|
|
|
|
);
|
|
|
|
|
$middleware = file_get_contents(dirname(__DIR__) . '/app/Middleware/CloudApi.php');
|
|
|
|
|
$automaticService = file_get_contents(
|
|
|
|
|
dirname(__DIR__) . '/app/Services/Cloud/CloudAutomaticBackupService.php'
|
|
|
|
|
);
|
|
|
|
|
$backupService = file_get_contents(
|
|
|
|
|
dirname(__DIR__) . '/app/Services/Cloud/CloudBackupService.php'
|
|
|
|
|
);
|
|
|
|
|
$assert(str_contains($routes, "'/backups'")
|
|
|
|
|
&& str_contains($routes, "'/vms/{id:[0-9]+}/automatic-backup'")
|
|
|
|
|
&& str_contains($routes,
|
|
|
|
|
"'/vms/{id:[0-9]+}/automatic-backup/enable'")
|
|
|
|
|
&& str_contains($routes,
|
|
|
|
|
"'/vms/{id:[0-9]+}/automatic-backup/disable'")
|
|
|
|
|
&& str_contains($routes,
|
|
|
|
|
"'/vms/{id:[0-9]+}/automatic-backup/{backup_id:[0-9]+}/restore'"),
|
|
|
|
|
'Owner backup routes are incomplete.');
|
|
|
|
|
$assert(str_contains($controller, 'CloudAutomaticBackupBillingService::enable(')
|
|
|
|
|
&& str_contains($controller, 'CloudAutomaticBackupBillingService::disable(')
|
|
|
|
|
&& str_contains($controller, '$value[\'billing\'] =')
|
|
|
|
|
&& str_contains($controller, "'entitlement_paid_until' =>")
|
|
|
|
|
&& str_contains($controller, "'state_revision' =>"),
|
|
|
|
|
'Owner backup API does not expose the paid toggle and billing state.');
|
|
|
|
|
$assert(str_contains($middleware,
|
|
|
|
|
"#^/api/v1/vms/[0-9]+/automatic-backup(?:/(?:enable|disable))?$#D")
|
|
|
|
|
&& !str_contains($middleware,
|
|
|
|
|
'automatic-backup(?:/|$)'),
|
|
|
|
|
'Database-only backup routes are missing or incorrectly include restore.');
|
|
|
|
|
$assert(str_contains($automaticService,
|
|
|
|
|
'CloudBackupPeriodEntitlement::where(')
|
|
|
|
|
&& str_contains($automaticService,
|
|
|
|
|
'->where(\'starts_at\', \'<=\', $scheduledFor)')
|
|
|
|
|
&& str_contains($backupService,
|
|
|
|
|
'CloudBackupPeriodEntitlement::where(')
|
|
|
|
|
&& str_contains($backupService,
|
|
|
|
|
'->where(\'ends_at\', \'>\', $scheduledFor)')
|
|
|
|
|
&& str_contains($automaticService,
|
|
|
|
|
"->where('next_run_at', '>', 0)")
|
|
|
|
|
&& str_contains($backupService,
|
|
|
|
|
'shouldPauseForInstanceExpiry($locked, time())')
|
|
|
|
|
&& !str_contains($backupService,
|
|
|
|
|
'($spec[\'automatic_backup\'] ?? null) !== true'),
|
|
|
|
|
'Automatic backup scheduling is not guarded by paid-period entitlement on both sides of the transaction.');
|
|
|
|
|
$assert(str_contains($backupService, '$name = \'autobackup-\'')
|
|
|
|
|
&& !str_contains($backupService, '$name = \'automatic-\''),
|
|
|
|
|
'Scheduled backup names must use the autobackup prefix.');
|
|
|
|
|
|
|
|
|
|
echo "Automatic backup UTC schedule and route contract passed.\n";
|