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.
62 lines
2.8 KiB
PHP
62 lines
2.8 KiB
PHP
<?php
|
|
|
|
// This contract test is intentionally dependency-free. The development shell
|
|
// may not have PHP/Composer, so it checks the source-level boundary that must
|
|
// hold before the gateway is wired into controllers.
|
|
$root = dirname(__DIR__);
|
|
$gateway = file_get_contents($root . '/app/Services/Cloud/CloudAgentVmGateway.php');
|
|
$catalog = file_get_contents($root . '/app/Services/Cloud/CloudOperationCatalog.php');
|
|
if (!is_string($gateway) || !is_string($catalog)) {
|
|
throw new RuntimeException('Cloud Agent gateway contract sources are missing.');
|
|
}
|
|
|
|
$assert = static function (bool $condition, string $message): void {
|
|
if (!$condition) {
|
|
throw new RuntimeException($message);
|
|
}
|
|
};
|
|
|
|
foreach ([
|
|
'create', 'action', 'reinstall', 'rescue', 'delete', 'network_change',
|
|
'instance_settings', 'snapshot_create', 'snapshot_restore', 'snapshot_delete',
|
|
'firewall_apply', 'service_suspend', 'service_resume', 'network_suspend',
|
|
'network_resume', 'expiry_delete',
|
|
] as $kind) {
|
|
$assert(str_contains($gateway, "'{$kind}' =>"),
|
|
'Gateway map does not explicitly cover panel kind: ' . $kind);
|
|
$assert(str_contains($catalog, "'{$kind}' =>"),
|
|
'CloudOperationCatalog no longer contains panel kind: ' . $kind);
|
|
}
|
|
|
|
$assert(str_contains($gateway, "'action' => 'domain_power'"),
|
|
'The supported power-action mapping is missing.');
|
|
$assert(str_contains($gateway, "'poweroff' => 'destroy'"),
|
|
'Panel poweroff must map to the Agent destroy verb.');
|
|
$assert(!str_contains($gateway, "'reset' => '"),
|
|
'Panel reset must not be aliased to an unverified Agent action.');
|
|
$assert(str_contains($gateway, "该电源操作尚未由 Go Agent 实现"),
|
|
'Unsupported panel power actions must fail before dispatch.');
|
|
$assert(str_contains($gateway, "电源操作实例身份与目标不一致"),
|
|
'Power operations must bind the journal instance UUID to the Agent target.');
|
|
$assert(str_contains($gateway, "'create' => null")
|
|
&& str_contains($gateway, "'snapshot_create' => null")
|
|
&& str_contains($gateway, "'delete' => null"),
|
|
'Unsupported VM operations must fail closed instead of being aliased.');
|
|
foreach ([
|
|
'CloudEngineClient', 'CloudJobService', 'CloudWorkerService',
|
|
'ssh', 'SSH', 'shell_exec', 'exec(', 'curl_exec',
|
|
] as $forbidden) {
|
|
$assert(!str_contains($gateway, $forbidden),
|
|
'Gateway contains a forbidden legacy transport reference: ' . $forbidden);
|
|
}
|
|
foreach ([
|
|
'CloudAgentHostClientResolver', 'CloudAgentOperationRepository',
|
|
'CloudAgentOperationEnvelope', 'requestHash(', 'idempotency_key',
|
|
'operation_id', 'markUncertain', 'CloudError',
|
|
] as $required) {
|
|
$assert(str_contains($gateway, $required),
|
|
'Gateway is missing required typed operation boundary: ' . $required);
|
|
}
|
|
|
|
fwrite(STDOUT, "Cloud Agent VM gateway contract passed.\n");
|