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/CloudAgentOperationStatusSe...

60 lines
2.9 KiB
PHP

<?php
// Dependency-free contract for the UUID Agent-operation polling bridge. The
// panel shell may not have PHP/Composer in the development environment, so
// keep this test at source level and leave the full HTTP/model test to panel
// CI.
$root = dirname(__DIR__);
$read = static function (string $path) use ($root): string {
$value = file_get_contents($root . '/' . $path);
if (!is_string($value)) {
throw new RuntimeException('Missing Cloud Agent status contract source: ' . $path);
}
return $value;
};
$assert = static function (bool $condition, string $message): void {
if (!$condition) {
throw new RuntimeException($message);
}
};
$service = $read('app/Services/Cloud/CloudAgentOperationStatusService.php');
$controller = $read('app/Controllers/CloudApiController.php');
$routes = $read('config/routes_cloud.php');
$middleware = $read('app/Middleware/CloudApi.php');
$uuid = '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}';
$jobRoute = "{id:{$uuid}}";
$jobPath = '(?:jobs|reinstall-jobs|rescue-jobs)/' . $uuid;
$assert(str_contains($routes, $jobRoute)
&& str_contains($routes, "'/' . $name . '/{id:[0-9]+}'"),
'Agent UUID job routes were added without retaining numeric legacy routes.');
$assert(str_contains($middleware, $jobPath)
&& str_contains($middleware, '(?:jobs|reinstall-jobs|rescue-jobs)/[0-9]+'),
'Cloud API middleware does not classify both Agent UUID and numeric jobs as database-only.');
$jobOffset = strpos($controller, 'public function job(');
$agentOffset = strpos($controller, 'CloudAgentOperationStatusService::forActor', $jobOffset === false ? 0 : $jobOffset);
$legacyOffset = strpos($controller, 'CloudJob::where', $jobOffset === false ? 0 : $jobOffset);
$assert($jobOffset !== false && $agentOffset !== false && $legacyOffset !== false
&& $agentOffset < $legacyOffset,
'The job controller must dispatch UUIDs to the Agent projection before the numeric CloudJob query.');
$assert(str_contains($service, 'CloudAgentOperationRepository')
&& str_contains($service, 'CloudInstance::where(\'uuid\', $row->instance_uuid)')
&& str_contains($service, 'CloudOperationErrorCatalog::result(')
&& str_contains($service, "'result' => $result"),
'Agent status projection lost repository validation, owner lookup, or result redaction.');
$assert(str_contains($service, "'job_id' => $operationId")
&& str_contains($service, "'operation_id' => $operationId")
&& str_contains($service, "'instance_id' => (string) $instance->id"),
'Agent status DTO no longer preserves the browser job identity fields.');
foreach (['CloudEngineClient', 'CloudJobService', 'CloudWorkerService', 'ssh', 'SSH', 'shell_exec', 'curl_exec'] as $forbidden) {
$assert(!str_contains($service, $forbidden),
'Agent status projection crossed a legacy transport boundary: ' . $forbidden);
}
fwrite(STDOUT, "Cloud Agent operation status contract passed.\n");