|
|
|
|
<?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, 'CloudAgent::where(\'agent_id\', $agentId)')
|
|
|
|
|
&& str_contains($service, '->where(\'host_id\', (int) $hostId)')
|
|
|
|
|
&& str_contains($service, "CloudInstance::where('host_id', $hostId)")
|
|
|
|
|
&& str_contains($service, "->where('id', (int) $instanceId)")
|
|
|
|
|
&& str_contains($service, "->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");
|