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

52 lines
2.8 KiB
PHTML

<?php
// Dependency-free contract for the read-only create-plan bridge. The local
// shell has no PHP/Composer runtime, so CI must execute the behavioral tests;
// this source check still prevents an accidental legacy fallback or a plan
// being presented as a successful VM create.
$root = dirname(__DIR__);
$service = file_get_contents($root . '/app/Services/Cloud/CloudAgentCreatePlanService.php');
$client = file_get_contents($root . '/app/Services/Cloud/CloudAgentClient.php');
$repository = file_get_contents($root . '/app/Services/Cloud/CloudAgentOperationRepository.php');
$assert = static function ($condition, string $message): void {
if (!$condition) {
throw new RuntimeException($message);
}
};
$assert(is_string($service) && is_string($client) && is_string($repository),
'Create-plan Agent contract sources are missing.');
$assert(str_contains($service, 'final class CloudAgentCreatePlanService')
&& str_contains($service, "private const KIND = 'domain_create_plan'")
&& str_contains($service, 'CloudAgentHostClientResolver')
&& str_contains($service, 'CloudAgentOperationRepository')
&& str_contains($service, 'public static function fromConfig(')
&& str_contains($service, 'CloudAgentOperationEnvelope::fromResponse(')
&& str_contains($service, '重试必须同时提供 operation_id 和幂等键')
&& !str_contains($service, 'idempotencyKeyForOperationId')
&& str_contains($service, 'CloudAgentDispatchUncertain')
&& str_contains($service, 'isDefinitiveReducedRejection')
&& str_contains($service, 'agent_create_plan_transport_uncertain')
&& str_contains($service, 'markUncertain')
&& str_contains($service, "'succeeded'")
&& str_contains($service, 'never a create acknowledgement'),
'Create-plan service must use the typed journal boundary and preserve read-only semantics.');
$assert(str_contains($service, "['domain', 'seed'], ['image']")
&& str_contains($service, "['artifact_id', 'instance_id', 'hostname']")
&& str_contains($service, "['network_config', 'startup_script']")
&& str_contains($service, "'secure_boot' => false")
&& str_contains($service, "'machine'] ?? null) !== 'q35'"),
'Create-plan request must have a strict schema and explicit no-Secure-Boot/q35 policy.');
$assert(str_contains($client, "'domain_create_plan'")
&& str_contains($repository, "'domain_create_plan'"),
'PHP Agent client and journal must allow the typed create-plan kind.');
foreach ([
'CloudEngineClient', 'CloudJobService', 'CloudWorkerService', 'CloudSecrets',
'shell_exec', 'exec(', 'curl_exec', 'ssh', 'SSH', 'domain_define', 'DefineDomain',
] as $forbidden) {
$assert(!str_contains($service, $forbidden),
'Create-plan service contains a forbidden legacy or mutating boundary: ' . $forbidden);
}
echo "Cloud Agent create-plan service contract passed.\n";