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

178 lines
9.1 KiB
PHP

<?php
$root = dirname(__DIR__);
$controller = file_get_contents($root . '/app/Controllers/CloudAdminInstanceController.php');
$options = file_get_contents($root . '/app/Services/Cloud/CloudNetworkChangeOptionsService.php');
$jobs = file_get_contents($root . '/app/Services/Cloud/CloudJobService.php');
$workflow = file_get_contents(
$root . '/app/Services/Cloud/CloudPublicNetworkTransitionWorkflow.php'
);
$command = file_get_contents(
$root . '/app/Services/Cloud/CloudPublicNetworkTransitionCommand.php'
);
$placement = file_get_contents($root . '/app/Services/Cloud/CloudPlacementService.php');
$placementNetwork = file_get_contents(
$root . '/app/Services/Cloud/CloudPlacementNetworkService.php'
);
$allocation = file_get_contents(
$root . '/app/Services/Cloud/CloudPublicNetworkAllocationService.php'
);
$adminInstanceService = file_get_contents(
$root . '/app/Services/Cloud/CloudAdminInstanceService.php'
);
$admission = file_get_contents(
$root . '/app/Services/Cloud/CloudPublicNetworkMutationAdmission.php'
);
$replacementBatch = file_get_contents(
$root . '/app/Services/Cloud/CloudPublicIpPoolReplacementBatchService.php'
);
$worker = file_get_contents($root . '/app/Services/Cloud/CloudWorkerService.php');
$input = file_get_contents($root . '/app/Services/Cloud/CloudInput.php');
$adminInstances = file_get_contents($root . '/public/cloud/admin-instances.js')
. "\n" . file_get_contents(
$root . '/public/cloud/admin-instance-configuration.js'
);
$pendingStart = is_string($placement)
? strpos($placement, 'private static function pendingUsageByHost') : false;
$pendingEnd = is_string($placement)
? strpos($placement, 'private static function availableIpHosts') : false;
$pendingMethod = $pendingStart !== false && $pendingEnd !== false
? substr($placement, $pendingStart, $pendingEnd - $pendingStart) : '';
$assert = static function ($condition, string $message): void {
if (!$condition) {
throw new RuntimeException($message);
}
};
$assert(is_string($controller) && is_string($options)
&& str_contains($controller,
'CloudNetworkChangeOptionsService::adminOptions($instance)')
&& str_contains($controller,
'CloudPublicNetworkTransitionCommand::adminExact(')
&& str_contains($controller,
'CloudPublicNetworkTransitionWorkflow::begin($command)')
&& str_contains($controller, '$this->actor($request, true)')
&& str_contains($options, 'public static function tenantQuote(')
&& str_contains($options, 'public static function adminOptions(')
&& str_contains($options,
'CloudPublicNetworkAllocationService::currentClaimSet(')
&& str_contains($options, "->where('state', 'available')")
&& str_contains($options, 'CloudPublicIp::where(')
&& str_contains($options, "->where('sync_state', 'applied')")
&& str_contains($options, 'observed_revision')
&& !str_contains($controller, 'CloudEngineClient')
&& !str_contains($controller, 'host/network-options')
&& str_contains($options, "'available_options'")
&& str_contains($options, "'current_public_network'")
&& str_contains($options, "'allocation_start'")
&& str_contains($options, "'allocation_end'")
&& str_contains($options, "'excluded_addresses'")
&& str_contains($options,
'CloudPublicNetworkMutationAdmission::inspect($instance)')
&& str_contains($controller,
"CloudInput::only(\$body, ['targets', 'confirm_restart'])"),
'Dual-stack network options or administrator transition command drifted.');
$assert(is_string($adminInstanceService)
&& str_contains(
$adminInstanceService,
"'network_change_supported' => \$networkMutation->allowed()"
)
&& str_contains($adminInstanceService, '$managedCloudTemplate')
&& str_contains($adminInstanceService, '$networkValid')
&& str_contains($adminInstanceService,
'$instance->serviceAvailable($now)'),
'Administrator network admission is not tied to active canonical managed instances.');
$assert(is_string($admission)
&& str_contains($admission, 'public static function inspect(')
&& str_contains($admission, 'public static function inspectMany(')
&& str_contains($admission, 'public static function assertCanBegin(')
&& str_contains($admission, 'public static function assertCanBeginMany(')
&& str_contains($admission,
'CloudJobService::blockingQueryForInstances(')
&& str_contains($admission, 'CloudInstanceMigration::whereIn(')
&& str_contains($admission, 'CloudBackupRecovery::whereIn(')
&& str_contains($admission, 'CloudPublicNetworkTransition::whereIn(')
&& !str_contains($admission, 'lockForUpdate(')
&& !str_contains($admission, 'transaction(')
&& !str_contains($admission, 'hasTable(')
&& !str_contains($admission, 'CloudPublicIp'),
'Shared public-network admission became shallow or took catalog ownership.');
$assert(is_string($replacementBatch)
&& str_contains($replacementBatch,
'CloudPublicNetworkMutationAdmission::inspectMany($instances)')
&& str_contains($replacementBatch,
'CloudPublicNetworkMutationAdmission::assertCanBeginMany(')
&& str_contains($replacementBatch,
"->whereColumn('observed_revision', '=', 'desired_revision')")
&& substr_count(
$replacementBatch,
'CloudAgentSettingsService::publicNetworkReady('
) >= 3,
'Pool replacement bypassed bulk admission or strict network evidence.');
$assert(is_string($adminInstances)
&& str_contains($adminInstances, 'buildAdminNetworkTargets(')
&& str_contains($adminInstances, 'targets: target.targets')
&& str_contains($adminInstances, 'ipv4_target')
&& str_contains($adminInstances, 'ipv6_address_cidr')
&& str_contains($adminInstances,
'await enqueue(`/api/v1/admin/instances/'),
'Admin UI no longer submits one idempotent attachment-bound target map.');
$assert(is_string($input)
&& str_contains($input, 'function publicPoolKey')
&& str_contains($input, '/^[a-f0-9]{32}$/D'),
'Public pool keys no longer have a fixed lowercase-hex input boundary.');
$assert(is_string($jobs) && is_string($workflow) && is_string($command)
&& str_contains($jobs, "if (\$kind === 'network_change')")
&& str_contains($jobs, '旧公网网络写入口已停用')
&& !str_contains($jobs, 'paidNetworkChangeExpectedAmount')
&& str_contains($workflow,
"(int) (\$claim->active_claim ?? 0) === 1")
&& str_contains($workflow,
"CloudPublicIp::where('host_id', (int) \$instance->host_id)")
&& str_contains($workflow,
'CloudActivePublicNetworkClaimSet::fromLedger(')
&& str_contains($workflow, 'source_network_attachment_id')
&& str_contains($workflow, 'target_network_attachment_id')
&& str_contains($workflow, 'source_claim_set_sha256')
&& str_contains($workflow, 'target_claim_set_sha256')
&& str_contains($workflow,
"\$job->public_network_transition_id = (int) \$transition->id")
&& str_contains($command, 'private static function normalizeTargets('),
'Canonical workflow no longer owns and freezes the dual-stack ledger identity.');
$assert(is_string($worker)
&& str_contains($worker,
"throw new CloudError('旧公网网络写任务已停用', 409)")
&& str_contains($worker,
'CloudPublicNetworkTransitionWorkflow::finishJobLocked(')
&& !str_contains($worker, 'CloudPlacementService::finishNetworkChange')
&& str_contains($worker, "\$job->phase = 'terminal'")
&& str_contains($worker, '$job->outcome = $status')
&& str_contains($worker, '$effectMayHaveApplied'),
'Worker retained the scalar writer or bypassed canonical transition settlement.');
$assert(is_string($placement)
&& is_string($placementNetwork)
&& is_string($allocation)
&& str_contains($placement, 'cloud_host_resource_pool_memberships as pool_membership')
&& !str_contains($placement, 'eligible_host.host')
&& !str_contains($placement, "->where('cloud_hosts.resource_pool_id', \$poolId)")
&& str_contains($placement,
'CloudPublicNetworkAllocationService::reserveBundle(')
&& str_contains($placement,
"\$payload['body']['public_network'] = \$publicNetwork->toArray()")
&& str_contains($placement,
'CloudPublicNetworkAllocationService::releaseBundle(')
&& str_contains($allocation, "->where('active_claim', 1)")
&& str_contains($allocation, 'reservation_ip_claim_id')
&& !str_contains($placement, 'finishNetworkChange(')
&& !str_contains($placement, 'availablePublicIpQuery(')
&& !str_contains($placement, 'publicIpBelongsToPool('),
'Placement retained a retired scalar network writer.');
$assert(str_contains($allocation, 'lockReservableAddressCandidate(')
&& str_contains($allocation, 'rawAddressAllowedByPool(')
&& str_contains($placementNetwork, 'addressAllowedByPool('),
'Canonical allocation lost address-level pool validation.');
$assert(str_contains($pendingMethod, 'CloudPanelUsageService::forHosts($candidateIds)')
&& !str_contains($pendingMethod, 'resource_pool_id'),
'Advisory pending usage is no longer deducted once per physical host across memberships.');
echo "Cloud network IP ledger contract tests passed\n";