You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
virt/web/tests/CloudSpecialTaskSingleDispa...

106 lines
4.6 KiB
PHTML

<?php
$root = dirname(__DIR__);
$read = static function (string $path) use ($root): string {
$value = file_get_contents($root . '/' . $path);
if (!is_string($value)) {
throw new RuntimeException('Unable to read ' . $path);
}
return $value;
};
$assert = static function (bool $condition, string $message): void {
if (!$condition) {
throw new RuntimeException($message);
}
};
$specialPaths = [
'app/Services/Cloud/CloudTemplateCatalogService.php',
'app/Services/Cloud/CloudRescueTemplateImportService.php',
'app/Services/Cloud/CloudRescueTemplateDeletionService.php',
'app/Services/Cloud/CloudUserIsoService.php',
'app/Services/Cloud/CloudHostStorageConfigurationService.php',
];
foreach ($specialPaths as $path) {
$source = $read($path);
$assert(!str_contains($source, '->request(')
&& !str_contains($source, '/v1/operations/')
&& !preg_match('/\breconcile(?:One|Job|Pending|Import|Delete)/i',
$source)
&& !str_contains($source, 'needs_attention')
&& !str_contains($source, 'not_dispatched'),
$path . ' retained a synchronous dispatch or replay path.');
}
$assert(!is_file($root
. '/app/Services/Cloud/CloudAgentOperationReconciler.php'),
'The retired Agent operation reconciler is still present.');
$jobs = $read('app/Services/Cloud/CloudJobService.php');
$worker = $read('app/Services/Cloud/CloudWorkerService.php');
$controller = $read('app/Controllers/CloudApiController.php');
$adminController = $read('app/Controllers/CloudAdminController.php');
$hostNetwork = $read(
'app/Services/Cloud/CloudAdminHostNetworkService.php'
);
$routes = $read('config/routes_cloud.php');
$schema = $read('sql/cloud.sql');
$assert(str_contains($jobs, 'reserveAggregate(')
&& str_contains($jobs, 'reserveStandaloneAgentMutation(')
&& str_contains($jobs, "'task_id' => (string) \$job->id")
&& str_contains($jobs, "'status_url' => '/api/v1/tasks/'")
&& str_contains($jobs, "whereNull('parent_job_id')")
&& !str_contains(substr($jobs,
strpos($jobs, 'public static function reserveStandaloneAgentMutation'),
2900), 'sealed_payload,')
&& str_contains($adminController, "'Idempotency-Key'"),
'Public task identity, idempotency, or parent visibility is incomplete.');
$assert(str_contains($worker,
"->whereIn('execution_mode', ['agent', 'local'])")
&& str_contains($worker, "->where('dispatch_attempts', 0)")
&& str_contains($jobs, "\$job->execution_mode = 'aggregate'")
&& str_contains($jobs, "\$job->execution_mode = 'agent'")
&& str_contains($read('app/Services/Cloud/CloudInvoicePaymentService.php'),
"\$job->execution_mode = 'local'")
&& str_contains($worker,
'CloudTemplateCatalogService::finishJobLocked(')
&& str_contains($worker, 'CloudUserIsoService::finishJobLocked(')
&& str_contains($worker,
'CloudRescueTemplateImportService::finishJobLocked(')
&& str_contains($worker,
'CloudRescueTemplateDeletionService::finishJobLocked(')
&& str_contains($worker,
'CloudHostStorageConfigurationService::finishJobLocked(')
&& !str_contains($worker, 'settleConfirmedInspection')
&& !str_contains($worker, 'reinstallCommitted')
&& !str_contains($worker, "'/v1/operations/'"),
'Worker claim/finalization lost explicit execution modes or retained an inspect/replay path.');
$assert(str_contains($controller,
"->whereNull('parent_job_id')")
&& !str_contains($controller, '/api/v1/user-isos/import-jobs/')
&& !str_contains($controller, '/api/v1/user-isos/delete-jobs/')
&& !str_contains($routes, '/import-jobs/')
&& !str_contains($routes, '/delete-jobs/')
&& !str_contains($routes, '/templates/cloud/import-jobs/')
&& !str_contains($routes, '/templates/rescue/import-jobs/'),
'A child task or retired special-job polling endpoint is public.');
$assert(str_contains($schema, 'parent_job_id BIGINT UNSIGNED DEFAULT NULL')
&& str_contains($schema, 'job_id BIGINT UNSIGNED DEFAULT NULL')
&& str_contains($schema,
'CONSTRAINT chk_cloud_job_dispatch_once CHECK (dispatch_attempts <= 1)')
&& str_contains($schema, 'active_job_id BIGINT UNSIGNED DEFAULT NULL'),
'Fresh schema lacks aggregate/child or single-dispatch links.');
$assert(!str_contains($hostNetwork, 'CloudAgentSettingsService')
&& !str_contains($hostNetwork, '->request(')
&& !str_contains($hostNetwork, 'markOutcome(')
&& str_contains($hostNetwork, '->transaction(')
&& str_contains($hostNetwork, "->sync_state = 'applied'"),
'Host-network configuration is not a single local transaction.');
echo "Special task single-dispatch contract passed.\n";