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.
266 lines
12 KiB
PHP
266 lines
12 KiB
PHP
<?php
|
|
|
|
// The operation error catalog is a trust-boundary contract. Keep this test
|
|
// independent from the database and Agent so it can run in a minimal CI job.
|
|
require dirname(__DIR__) . '/vendor/autoload.php';
|
|
|
|
use App\Services\Cloud\CloudOperationErrorCatalog;
|
|
use App\Services\Cloud\CloudInstanceMetadata;
|
|
|
|
$assert = static function ($condition, string $message): void {
|
|
if (!$condition) {
|
|
throw new RuntimeException($message);
|
|
}
|
|
};
|
|
|
|
foreach (['errorMessage', 'stderrText', 'debugInfo', 'error-code', 'agent.error.detail'] as $key) {
|
|
$assert(CloudOperationErrorCatalog::isDiagnosticKey($key),
|
|
'Diagnostic spelling bypassed the normalized key catalog: ' . $key);
|
|
}
|
|
|
|
$raw = [
|
|
'status' => 'succeeded',
|
|
'cause_code' => 'storage_clone_failed',
|
|
'phase' => 'Traceback: /var/lib/libvirt/private.xml',
|
|
'errorMessage' => 'libvirtError: source=/srv/secret-volume',
|
|
'safe_to_refund' => true,
|
|
'unknown_agent_field' => 'host-internal-value',
|
|
'vm' => [
|
|
'uuid' => '11111111-1111-4111-8111-111111111111',
|
|
'status' => 'succeeded',
|
|
'disks' => [['source' => '/srv/secret-volume', 'capacity_gib' => 40]],
|
|
'rescue_volume_name' => 'rescue-secret',
|
|
'console_port' => 5901,
|
|
],
|
|
];
|
|
|
|
$user = CloudOperationErrorCatalog::result($raw, false, 'action', 'failed');
|
|
$assert(!isset($user['errorMessage'], $user['diagnostic'], $user['safe_to_refund'],
|
|
$user['unknown_agent_field'], $user['cause_code'])
|
|
&& !isset($user['vm']['disks'], $user['vm']['rescue_volume_name'], $user['vm']['console_port'])
|
|
&& !str_contains(json_encode($user, JSON_UNESCAPED_UNICODE), '/var/lib'),
|
|
'User operation result retained raw Agent diagnostics or storage metadata.');
|
|
|
|
$admin = CloudOperationErrorCatalog::result($raw, true, 'action', 'failed');
|
|
$adminJson = json_encode($admin, JSON_UNESCAPED_UNICODE);
|
|
$assert(isset($admin['diagnostic'])
|
|
&& !isset($admin['cause_code'])
|
|
&& !str_contains($adminJson, '/var/lib') && !str_contains($adminJson, '/srv/secret'),
|
|
'Administrator operation result did not retain a redacted diagnostic summary.');
|
|
|
|
$durable = CloudOperationErrorCatalog::workerResult($raw);
|
|
$assert(!isset($durable['errorMessage'], $durable['diagnostic'], $durable['safe_to_refund'])
|
|
&& ($durable['cause_code'] ?? null) === 'storage_clone_failed'
|
|
&& !isset($durable['vm']['disks'], $durable['vm']['rescue_volume_name'], $durable['vm']['console_port'])
|
|
&& !str_contains(json_encode($durable, JSON_UNESCAPED_UNICODE), 'host-internal-value'),
|
|
'Durable operation result retained a non-allowlisted Agent field.');
|
|
|
|
$rescueResult = CloudOperationErrorCatalog::workerResult([
|
|
'active' => true,
|
|
'staged' => false,
|
|
'pending_manual_restart' => true,
|
|
'template_id' => '0123456789abcdef0123456789abcdef',
|
|
'network_suspended' => false,
|
|
'warning' => 'host path /srv/private/rescue.iso',
|
|
]);
|
|
$assert($rescueResult === [
|
|
'active' => true,
|
|
'staged' => false,
|
|
'pending_manual_restart' => true,
|
|
'network_suspended' => false,
|
|
],
|
|
'Rescue task result lost its bounded public state or retained a warning.');
|
|
$resultBooleanKeys = [
|
|
'active', 'staged', 'pending_manual_restart', 'network_suspended',
|
|
'network_enabled',
|
|
];
|
|
foreach ($resultBooleanKeys as $key) {
|
|
foreach (['true', 1, null] as $invalidValue) {
|
|
$assert(CloudOperationErrorCatalog::workerResult([
|
|
$key => $invalidValue,
|
|
]) === [],
|
|
'Invalid task result boolean crossed the public result boundary: '
|
|
. $key);
|
|
}
|
|
}
|
|
$assert(CloudOperationErrorCatalog::workerResult([
|
|
'network_enabled' => false,
|
|
]) === ['network_enabled' => false]
|
|
&& CloudOperationErrorCatalog::workerResult([
|
|
'network_enabled' => true,
|
|
]) === ['network_enabled' => true],
|
|
'Network suspend/resume result was removed from the public task result.');
|
|
|
|
foreach (['StorageCloneFailed', 'storage__clone_failed', 'storage_clone_failed_',
|
|
'storage-clone-failed', 'storage/clone', "storage_clone_failed\n",
|
|
str_repeat('a', 65)] as $invalidCauseCode) {
|
|
$assert(CloudOperationErrorCatalog::agentCauseCode($invalidCauseCode) === null
|
|
&& !isset(CloudOperationErrorCatalog::workerResult([
|
|
'cause_code' => $invalidCauseCode,
|
|
])['cause_code']),
|
|
'Invalid Agent cause code entered durable result_json.');
|
|
}
|
|
$assert(CloudOperationErrorCatalog::agentCauseCode('domain_define_failed')
|
|
=== 'domain_define_failed'
|
|
&& !isset(CloudOperationErrorCatalog::workerResult([
|
|
'vm' => ['cause_code' => 'nested_cause_must_not_persist'],
|
|
])['vm']['cause_code']),
|
|
'Stable Agent cause-code validation or top-level boundary failed.');
|
|
$assert(str_contains((string) CloudOperationErrorCatalog::agentCauseLabel(
|
|
'external_snapshot_cleanup_required'), '外部快照')
|
|
&& str_contains((string) CloudOperationErrorCatalog::agentCauseLabel(
|
|
'native_snapshot_delete_in_progress'), '删除尚未完成')
|
|
&& str_contains((string) CloudOperationErrorCatalog::agentCauseLabel(
|
|
'managed_disk_shared'), '另一台虚拟机')
|
|
&& str_contains((string) CloudOperationErrorCatalog::agentCauseLabel(
|
|
'managed_filter_shared'), '过滤器引用')
|
|
&& str_contains((string) CloudOperationErrorCatalog::agentCauseLabel(
|
|
'backup_disk_transition_active'), '旧系统盘')
|
|
&& CloudOperationErrorCatalog::agentCauseLabel('storage_clone_failed') === null
|
|
&& CloudOperationErrorCatalog::agentCauseLabel('bad/path') === null,
|
|
'Reviewed Agent cause labels exposed raw or unknown diagnostic codes.');
|
|
$storageCauseLabels = [
|
|
'resource_operation_blocked' => '旧任务',
|
|
'storage_path_root_unavailable' => 'storage_path_roots',
|
|
'storage_directory_invalid' => '符号链接',
|
|
'storage_path_not_allowed' => '允许范围',
|
|
'storage_pool_path_conflict' => '不会改绑',
|
|
'storage_pool_definition_invalid' => '存储池定义',
|
|
'storage_pool_configuration_failed' => '自动启动状态',
|
|
'storage_configuration_busy' => '立即失败',
|
|
'storage_configuration_lock_unavailable' => '进程锁',
|
|
'libvirt_unavailable' => 'libvirt',
|
|
];
|
|
foreach ($storageCauseLabels as $causeCode => $expectedLabelText) {
|
|
$label = CloudOperationErrorCatalog::agentCauseLabel($causeCode);
|
|
$assert(is_string($label) && str_contains($label, $expectedLabelText),
|
|
'Storage Agent cause did not receive a reviewed administrator label: '
|
|
. $causeCode);
|
|
}
|
|
|
|
$assert(CloudOperationErrorCatalog::workerSummary('create', 'failed', [
|
|
'cause_code' => 'storage_clone_failed',
|
|
'safe_to_refund' => true,
|
|
], true) === 'operation_failed_effect_unknown'
|
|
&& CloudOperationErrorCatalog::workerSummary('create', 'failed', [
|
|
'cause_code' => 'storage_clone_failed',
|
|
'effect_may_have_applied' => false,
|
|
'safe_to_resubmit' => true,
|
|
], true) === 'provision_failed_refunded',
|
|
'Create failure messaging trusted Agent refund hints or ignored PHP-normalized absence proof.');
|
|
|
|
$assert(CloudOperationErrorCatalog::userStatus('SUCCEEDED') === 'succeeded'
|
|
&& CloudOperationErrorCatalog::userStatus('ACTIVE') === 'active'
|
|
&& CloudOperationErrorCatalog::userStatus('FAILED') === 'failed'
|
|
&& CloudOperationErrorCatalog::userStatus('CANCELLED') === null
|
|
&& CloudOperationErrorCatalog::userStatus('NEEDS_ATTENTION') === null
|
|
&& CloudOperationErrorCatalog::userStatus('UNCERTAIN') === null
|
|
&& CloudOperationErrorCatalog::userStatus('host-internal-state') === null,
|
|
'Unknown operation status bypassed the user status allow-list.');
|
|
$phase = CloudOperationErrorCatalog::userPhase('宿主机 /var/lib/libvirt', 'running');
|
|
$assert($phase === null, 'A retired running status produced a public phase.');
|
|
$assert(CloudOperationErrorCatalog::userPhase('宿主机 /var/lib/libvirt', 'active')
|
|
=== '正在处理'
|
|
&& CloudOperationErrorCatalog::userPhase('宿主机 /var/lib/libvirt', 'failed')
|
|
=== '处理失败',
|
|
'Unknown operation phase bypassed the active/terminal status fallback.');
|
|
$reinstall = CloudOperationErrorCatalog::workerResult([
|
|
'status' => 'failed', 'phase' => '重装完成',
|
|
'reinstall_committed' => true, 'cleanup_pending' => true,
|
|
'warning' => '旧存储卷 /srv/private.qcow2 删除失败',
|
|
]);
|
|
$assert(($reinstall['reinstall_committed'] ?? false) === true
|
|
&& ($reinstall['cleanup_pending'] ?? false) === true
|
|
&& !isset($reinstall['warning']),
|
|
'Reinstall cleanup marker was lost or raw warning was persisted.');
|
|
$assert(CloudOperationErrorCatalog::workerSummary('reinstall', 'failed', [
|
|
'error_code' => 'reinstall_cleanup_pending',
|
|
]) === 'reinstall_cleanup_pending'
|
|
&& str_contains((string) CloudOperationErrorCatalog::userMessage(
|
|
'reinstall', 'failed', 'reinstall_cleanup_pending'), '旧系统盘清理'),
|
|
'Terminal reinstall cleanup failure did not retain its reviewed error code.');
|
|
$assert(CloudOperationErrorCatalog::workerSummary('delete', 'failed', [
|
|
'error_code' => 'force_required',
|
|
]) === 'force_required'
|
|
&& str_contains((string) CloudOperationErrorCatalog::userMessage(
|
|
'delete', 'failed', 'force_required'), '强制删除')
|
|
&& CloudOperationErrorCatalog::workerResult([
|
|
'forced' => true, 'managed_artifacts_absent' => true,
|
|
]) === ['forced' => true, 'managed_artifacts_absent' => true],
|
|
'Force-delete boundary or bounded cleanup evidence was not preserved safely.');
|
|
$assert(CloudOperationErrorCatalog::workerSummary('delete', 'failed', [
|
|
'error_code' => 'graceful_shutdown_unconfirmed',
|
|
]) === 'graceful_shutdown_unconfirmed'
|
|
&& CloudOperationErrorCatalog::workerSummary('service_suspend', 'failed', [
|
|
'error_code' => 'graceful_shutdown_request_failed',
|
|
]) === 'graceful_shutdown_request_failed',
|
|
'A safe graceful retry outcome lost its reviewed operation code.');
|
|
$assert(CloudOperationErrorCatalog::workerSummary('delete_force', 'failed', [
|
|
'error_code' => 'force_delete_unconfirmed_active',
|
|
]) === 'force_delete_unconfirmed_active'
|
|
&& str_contains((string) CloudOperationErrorCatalog::userMessage(
|
|
'delete_force', 'failed', 'force_delete_unconfirmed_active'),
|
|
'资源保持安全锁定'),
|
|
'A failed independent force-delete task lost its reviewed terminal code.');
|
|
|
|
$vpcBatchResult = CloudOperationErrorCatalog::result([
|
|
'batch_key' => 'private-batch-identity',
|
|
'action' => 'attach',
|
|
'total' => 6,
|
|
'succeeded' => 5,
|
|
'failed' => 1,
|
|
'message' => 'host-internal diagnostic',
|
|
], false, 'vpc_membership_batch', 'failed');
|
|
$assert($vpcBatchResult === [
|
|
'action' => 'attach',
|
|
'total' => 6,
|
|
'succeeded' => 5,
|
|
'failed' => 1,
|
|
]
|
|
&& CloudOperationErrorCatalog::result([
|
|
'action' => 'attach',
|
|
'total' => 6,
|
|
'succeeded' => 6,
|
|
'failed' => 1,
|
|
], false, 'vpc_membership_batch', 'failed') === []
|
|
&& CloudOperationErrorCatalog::result([
|
|
'action' => 'attach',
|
|
'total' => 6,
|
|
'succeeded' => 5,
|
|
'failed' => 1,
|
|
], false, 'action', 'failed') === [],
|
|
'VPC membership batch result was hidden, inconsistent, or leaked into other task kinds.');
|
|
|
|
$publicSpec = CloudInstanceMetadata::publicSpec([
|
|
'plan_name' => 'Basic',
|
|
'public_network' => [
|
|
'contract' => 1,
|
|
'network_selector' => 'bridge:br0',
|
|
'ipv4' => [
|
|
'pool_key' => str_repeat('1', 32), 'pool_cidr' => '8.8.8.0/24',
|
|
'address_cidr' => '8.8.8.10/24', 'gateway' => '8.8.8.1',
|
|
'gateway_on_link' => false,
|
|
],
|
|
'ipv6' => [
|
|
'pool_key' => str_repeat('2', 32),
|
|
'pool_cidr' => '2404:c140:156:3a::/64',
|
|
'address_cidr' => '2404:c140:156:3a::10/64',
|
|
'gateway' => '2404:c140:156::1', 'gateway_on_link' => true,
|
|
],
|
|
'dns_servers' => ['1.1.1.1', '2606:4700:4700::1111'],
|
|
],
|
|
'region' => str_repeat('x', 500), 'memory_mib' => 'not-a-number',
|
|
'host_private_path' => '/srv/libvirt/secret.qcow2',
|
|
'agent_debug' => 'libvirt traceback',
|
|
]);
|
|
$publicJson = json_encode($publicSpec, JSON_UNESCAPED_UNICODE);
|
|
$assert(isset($publicSpec['plan_name'], $publicSpec['public_network'])
|
|
&& ($publicSpec['public_ipv4'] ?? null) === '8.8.8.10'
|
|
&& ($publicSpec['public_ipv6'] ?? null) === '2404:c140:156:3a::10'
|
|
&& !isset($publicSpec['region'], $publicSpec['memory_mib'])
|
|
&& !isset($publicSpec['host_private_path'], $publicSpec['agent_debug'])
|
|
&& !str_contains($publicJson, '/srv/libvirt'),
|
|
'Public instance spec copied an unallowlisted historical field.');
|
|
|
|
echo "Cloud operation error catalog checks passed.\n";
|