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

543 lines
34 KiB
PHP

<?php
// Source contract remains useful on developer checkouts that do not have a
// PHP CLI or a configured database. The runtime integration suite can bind
// these same models to MariaDB/SQLite separately.
$root = dirname(__DIR__);
$read = static fn (string $path): string => (string) file_get_contents($root . '/' . $path);
$assert = static function ($condition, string $message): void {
if (!$condition) {
throw new RuntimeException($message);
}
};
$schema = $read('sql/cloud.sql');
$service = $read('app/Services/Cloud/CloudVpcService.php');
$allocator = $read('app/Services/Cloud/CloudPrivateCidrAllocator.php');
$regionFabricModel = $read('app/Models/CloudRegionFabric.php');
$adminResource = $read('app/Services/Cloud/CloudAdminResourceService.php');
$adminResourceController = $read('app/Controllers/CloudAdminResourceController.php');
$adminFabric = $read('app/Services/Cloud/CloudAdminFabricService.php');
$adminFabricController = $read('app/Controllers/CloudAdminFabricController.php');
$controller = $read('app/Controllers/CloudVpcController.php');
$routes = $read('config/routes_cloud.php');
$middleware = $read('app/Middleware/CloudApi.php');
$engineClient = $read('app/Services/Cloud/CloudEngineClient.php');
$cloudError = $read('app/Services/Cloud/CloudError.php');
$accountDeletion = $read('app/Services/UserDataDeletionService.php');
$jobService = $read('app/Services/Cloud/CloudJobService.php');
$orderService = $read('app/Services/Cloud/CloudOrderService.php');
$workerService = $read('app/Services/Cloud/CloudWorkerService.php');
$vpcWorkerService = $read('app/Services/Cloud/CloudVpcWorkerService.php');
$runtimeService = $read('app/Services/Cloud/CloudInstanceRuntimeService.php');
$operationErrorCatalog = $read('app/Services/Cloud/CloudOperationErrorCatalog.php');
$engineVpcService = (string) file_get_contents(
dirname($root) . '/engine/virsh_panel/vpc.py'
);
foreach ([
'cloud_region_fabrics',
'cloud_vpcs', 'cloud_vpc_subnets', 'cloud_vpc_private_ips', 'cloud_vpc_members',
'cloud_vpc_routes', 'cloud_vpc_acl_rules',
'cloud_vpc_host_deployments', 'cloud_vpc_operations',
] as $table) {
$assert(str_contains($schema,
'CREATE TABLE IF NOT EXISTS ' . $table . ' ('),
'VPC schema lost ' . $table . '.');
}
$assert(str_contains($schema, 'UNIQUE KEY cloud_vpc_member_instance_global (instance_id)')
&& str_contains($schema, 'UNIQUE KEY cloud_vpc_private_ip_address (vpc_id, private_ip)')
&& str_contains($schema, 'UNIQUE KEY cloud_vpc_member_private_ip (private_ip_id)')
&& str_contains($schema, 'UNIQUE KEY cloud_vpc_operation_idempotency (vpc_id, idempotency_key)')
&& str_contains($schema, 'KEY cloud_vpc_operation_power_instance (power_instance_id)')
&& str_contains($schema, 'source_int BIGINT UNSIGNED NOT NULL')
&& str_contains($schema, 'destination_broadcast_int BIGINT UNSIGNED NOT NULL')
&& str_contains($schema, 'desired_digest CHAR(64)')
&& str_contains($schema, 'observed_digest CHAR(64)')
&& str_contains($schema, 'evidence_version SMALLINT UNSIGNED NOT NULL DEFAULT 0'),
'VPC schema lost the single-NIC, idempotency or revision digest guards.');
$assert(str_contains($service, 'lockForUpdate()')
&& str_contains($service, 'desired_revision')
&& str_contains($service, 'observed_revision')
&& str_contains($service, 'CloudVpcOperation')
&& str_contains($service, 'CloudVpcPrivateIp')
&& str_contains($service, 'lockedPrivateIpForMember')
&& str_contains($service, 'CloudVpcHostDeployment')
&& str_contains($service, 'new CloudEngineClient(')
&& str_contains($service, '))->vpc(')
&& str_contains($service, 'canonicalJson')
&& str_contains($service, 'next_stage_allowed'),
'VPC service lost independent locking, desired/observed revisions or Fabric gate.');
$assert(str_contains($service, 'public const ENGINE_TIMEOUT_SECONDS = 60.0;')
&& str_contains($service, 'public const OPERATION_LEASE_SECONDS = 120;')
&& str_contains($engineVpcService, 'VPC_REQUEST_DEADLINE_SECONDS = 40.0')
&& str_contains($service, 'self::ENGINE_TIMEOUT_SECONDS')
&& str_contains($service, 'self::OPERATION_LEASE_SECONDS'),
'VPC PHP timeout/lease no longer contain the engine request-wide probe budget.');
preg_match('/VPC_REQUEST_DEADLINE_SECONDS\s*=\s*([0-9.]+)/',
$engineVpcService, $engineBudgetMatch);
$engineBudget = isset($engineBudgetMatch[1]) ? (float) $engineBudgetMatch[1] : 0.0;
preg_match('/ENGINE_TIMEOUT_SECONDS\s*=\s*([0-9.]+)/',
$service, $phpTimeoutMatch);
preg_match('/OPERATION_LEASE_SECONDS\s*=\s*([0-9]+)/',
$service, $phpLeaseMatch);
$phpTimeout = isset($phpTimeoutMatch[1]) ? (float) $phpTimeoutMatch[1] : 0.0;
$phpLease = isset($phpLeaseMatch[1]) ? (int) $phpLeaseMatch[1] : 0;
$assert($engineBudget > 0.0 && $phpTimeout > $engineBudget
&& $phpLease >= $phpTimeout + 30.0,
'VPC PHP timeout/lease numeric ordering no longer bounds the engine probe.');
$regionFabricControllerStart = strpos(
$adminResourceController, 'public function regionFabric('
);
$regionFabricControllerEnd = strpos(
$adminResourceController, 'public function networkLines(',
$regionFabricControllerStart ?: 0
);
$regionFabricControllerBlock = $regionFabricControllerStart !== false
&& $regionFabricControllerEnd !== false
? substr($adminResourceController, $regionFabricControllerStart,
$regionFabricControllerEnd - $regionFabricControllerStart)
: '';
$assert(str_contains($service, 'CloudRegionFabric')
&& str_contains($service, 'fabric_region')
&& str_contains($adminResource, 'saveRegionFabric')
&& str_contains($adminResource, 'fabricStatus')
&& str_contains($adminResource, 'next_stage_allowed')
&& str_contains($adminResource, '$exactActivation')
&& str_contains($adminResource, "(string) \$current->state === 'disabled'")
&& str_contains($adminResource, "\$state === 'active'")
&& str_contains($adminResource, '$liveVpcPinsMatch')
&& str_contains($adminResource,
"->get(['fabric_id', 'fabric_region', 'fabric_revision'])")
&& str_contains($adminResource, '$lockedRegion')
&& str_contains($adminResource,
"(string) \$lockedRegion->status !== 'active'")
&& str_contains($adminResourceController, 'regionFabric')
&& str_contains($routes,
"\$this->get('/admin/regions/{id:[0-9]+}/fabric'")
&& !str_contains($routes,
"\$this->map(['GET', 'PUT', 'PATCH'], '/admin/regions/{id:[0-9]+}/fabric'")
&& $regionFabricControllerBlock !== ''
&& !str_contains($regionFabricControllerBlock, 'getMethod(')
&& !str_contains($regionFabricControllerBlock, 'CloudInput::')
&& !str_contains($regionFabricControllerBlock, 'saveRegionFabric(')
&& str_contains($adminFabric,
'CloudAdminResourceService::saveRegionFabric')
&& str_contains($adminFabric, 'assertLiveVpcFabricPinsCompatible(')
&& str_contains($adminFabric, "'vpc_fabric_pin_mismatch'")
&& str_contains($adminFabric, "'vpc_fabric_mapping_missing'")
&& str_contains($regionFabricModel, 'cloud_region_fabrics'),
'VPC creation must pin a platform-owned mapping whose public resource API is read-only.');
$assert(!str_contains($routes, "'/admin/fabric/apply'")
&& !preg_match(
"#/admin/fabric/\\{fabric_id:[^\\n]+/reconcile#",
$routes
)
&& !str_contains($adminFabricController, 'public function apply(')
&& !str_contains($adminFabricController, 'public function reconcile(')
&& !str_contains($adminFabric, 'public static function apply(')
&& !str_contains($adminFabric, 'public static function reconcile(')
&& str_contains($adminFabric, 'public static function applyRegion(')
&& str_contains($adminFabric, 'public static function reconcileRegion('),
'Raw Fabric plan/reconcile actions must not bypass the region workflow.');
$createStart = strpos($service, 'public static function create(');
$createEnd = strpos($service, 'public static function delete(', $createStart ?: 0);
$createBlock = $createStart !== false && $createEnd !== false
? substr($service, $createStart, $createEnd - $createStart) : '';
$replayPosition = strpos($createBlock, 'replayCreateLocked(');
$quotaPosition = strpos($createBlock, 'accountVpcLimit()');
$fabricPosition = strpos($createBlock, "CloudRegionFabric::where('region_id', \$regionId)");
$assert($createBlock !== ''
&& str_contains($createBlock,
"CloudInput::only(\$input, ['name', 'region_id', 'request_key'])")
&& str_contains($createBlock, '$maxMembers = self::DEFAULT_MAX_MEMBERS')
&& str_contains($createBlock, '$prefix = self::DEFAULT_PREFIX_LENGTH')
&& str_contains($createBlock, "'name' => \$name")
&& str_contains($createBlock, "'region_id' => \$regionId")
&& !str_contains($createBlock, "'cidr' => \$requestedCidr")
&& $replayPosition !== false && $quotaPosition !== false
&& $fabricPosition !== false
&& $replayPosition < $quotaPosition && $quotaPosition < $fabricPosition
&& str_contains($service, 'public const DEFAULT_MAX_MEMBERS = 200;')
&& str_contains($service, 'public const DEFAULT_MAX_VPCS_PER_ACCOUNT = 5;')
&& str_contains($service, "where('state', '<>', 'deleted')->count()")
&& str_contains($service, 'VPC 创建操作账本不完整')
&& str_contains($service, 'VPC 创建资源账本不完整')
&& str_contains($service, 'CloudPrivateCidrAllocator::assertAllocationLedger')
&& str_contains($allocator, 'public static function assertAllocationLedger')
&& !str_contains($createBlock, 'CloudPrivateCidrAllocator::release')
&& str_contains($service, "(string) \$row->state !== 'deleted'")
&& str_contains($schema, 'max_members INT UNSIGNED NOT NULL DEFAULT 200')
&& str_contains($schema, 'ALTER COLUMN max_members SET DEFAULT 200'),
'Tenant VPC creation lost its strict intent contract, bounded policy, quota lock or stable replay ordering.');
$assert(str_contains($service, "'status' => 'superseded'")
&& str_contains($service, 'where(\'lease_token\', $leaseToken)')
&& str_contains($service, "where('status', 'running')"),
'VPC operation lease/supersede guards are incomplete.');
$assert(str_contains($service, 'waiting_observed')
&& str_contains($service, 'allowDeferredRetry')
&& str_contains($service, 'vpc_no_members')
&& str_contains($service, "(\$fabricGate['active'] ?? null) === false")
&& str_contains($service, "(\$observed['next_stage_allowed'] ?? null) === false")
&& str_contains($service,
"(\$observed['private_dataplane_verified'] ?? null) === false")
&& str_contains($service, '$emptyControlPlaneComplete = $noDataPlaneTerminalProof')
&& str_contains($service, "(string) \$operation->kind === 'vpc_create'")
&& str_contains($service, '$desiredContractValid')
&& str_contains($service, '$emptyCreateLedgerValid')
&& str_contains($service, '!$pendingChildTombstone')
&& str_contains($service, '|| $emptyControlPlaneComplete')
&& str_contains($service, '&& !$emptyControlPlaneComplete')
&& str_contains($service, "terminalFailure ? 'failed'")
&& str_contains($service, "result['operation_id']")
&& str_contains($service, "result['desired_digest']")
&& str_contains($service, "existing->subnet_id")
&& str_contains($service, 'hasBlockingMembership'),
'VPC deferred observation, response identity or membership gates are incomplete.');
$assert(str_contains($service, 'public static function delete(')
&& str_contains($service, "'confirmation_name', 'request_key'")
&& str_contains($service, "'vpc_delete'")
&& str_contains($service, 'deletionDocument')
&& str_contains($service, 'recordDeleted')
&& str_contains($service, "'/internal/v1/vpcs/' . \$vpcKey . '/delete'")
&& str_contains($service, 'removed_host_ids')
&& str_contains($service, "\$document['retiring_members'] = \$retiringMembers")
&& str_contains($service, 'sort($hostIds, SORT_STRING)')
&& str_contains($service, 'canonicalJson($payloadDocument)')
&& str_contains($service, 'array_diff($payloadHostIds, $canonicalRemovedHostIds)')
&& str_contains($service, 'array_diff($canonicalRemovedHostIds, $historicalHostIds)')
&& str_contains($service, "if ((string) \$vpc->state === 'deleting')")
&& str_contains($service, 'cannot shrink that manifest')
&& str_contains($service, 'CloudPrivateCidrAllocator::release')
&& str_contains($service, '$childModel::where(\'vpc_id\', $vpc->id)->delete()')
&& str_contains($service, "\$vpc->state = 'deleted'")
&& str_contains($service, "\$root->state = (string) \$row->kind === 'vpc_delete'")
&& str_contains($service, "\$error->errorCode ?? ''")
&& str_contains($engineClient, 'safeVpcServerErrorCode')
&& str_contains($engineClient, "strtoupper(\$method) !== 'POST'")
&& str_contains($engineClient,
'#^/internal/v1/vpcs/[0-9a-f]{32}/delete$#D')
&& str_contains($cloudError, 'public readonly ?string $errorCode = null'),
'VPC root deletion lost confirmation, durable operation, exact receipt or CIDR CAS finalization.');
$assert(!str_contains($routes, "/subnets'")
&& !str_contains($routes, '/subnets/{')
&& !str_contains($controller, 'public function addSubnet(')
&& !str_contains($controller, 'public function removeSubnet(')
&& !str_contains($service, 'public static function addSubnet(')
&& !str_contains($service, 'public static function removeSubnet('),
'Tenant VPC API must not expose subnet creation or deletion mutators.');
$attachStart = strpos($service, 'public static function attachMember(');
$attachEnd = strpos($service, 'public static function detachMember(', $attachStart ?: 0);
$attachBlock = $attachStart !== false && $attachEnd !== false
? substr($service, $attachStart, $attachEnd - $attachStart) : '';
$automaticSubnetStart = strpos($service, 'private static function lockedAutomaticSubnet(');
$automaticSubnetEnd = strpos(
$service, 'private static function hasMemberAttachOperation(',
$automaticSubnetStart ?: 0
);
$automaticSubnetBlock = $automaticSubnetStart !== false && $automaticSubnetEnd !== false
? substr($service, $automaticSubnetStart,
$automaticSubnetEnd - $automaticSubnetStart) : '';
$assert($attachBlock !== ''
&& str_contains($attachBlock, "'instance_id', 'request_key', 'subnet_key', 'private_ip'")
&& str_contains($attachBlock, 'if ($legacyRequestHash !== null)')
&& str_contains($attachBlock, '子网和私网 IP 由平台自动分配')
&& str_contains($attachBlock, 'self::lockedAutomaticSubnet(')
&& str_contains($attachBlock,
'self::firstFreeIp($subnet, $privateIps, $reservedRouteIps)')
&& $automaticSubnetBlock !== ''
&& str_contains($automaticSubnetBlock, "CloudVpcSubnet::where('vpc_id', \$vpc->id)")
&& str_contains($automaticSubnetBlock, "if (\$state === 'deleting')")
&& str_contains($automaticSubnetBlock, 'if (count($live) !== 1)')
&& str_contains($automaticSubnetBlock,
'preg_match(self::KEY_PATTERN, (string) $subnet->subnet_key)'),
'Tenant member attach must select exactly one live subnet and allocate its private IP server-side.');
$missingRemovalHost = strpos(
$service, '$item = $hosts[(string) $hostId] ?? null;'
);
$missingRemovalEnd = $missingRemovalHost === false ? false
: strpos($service, '// A deleting host remains a tombstone', $missingRemovalHost);
$missingRemovalBlock = ($missingRemovalHost !== false && $missingRemovalEnd !== false)
? substr($service, $missingRemovalHost,
$missingRemovalEnd - $missingRemovalHost) : '';
$assert($missingRemovalBlock !== ''
&& str_contains($missingRemovalBlock, '$hasRemovalTarget = true')
&& str_contains($missingRemovalBlock, '$allRemovalProof = false'),
'A missing deleting host must make multi-host removal proof incomplete.');
$assert(str_contains($service, 'canViewInfrastructure')
&& str_contains($service, 'publicRoot($vpc, $includeHostDetails)')
&& str_contains($service, 'digestMatches($desiredDigest, $observedDigest)')
&& str_contains($service, "'configured' => \$configurationReady")
&& !str_contains($service, "'configuration_ready' =>")
&& str_contains($service, "'member_count' => \$runtimeMembers->count()")
&& str_contains($service, "'setup_state' => \$awaitingMembers ? 'awaiting_members' : null")
&& str_contains($service, "['deleting', 'deleted']")
&& str_contains($service, '$hostRows->count() === 0')
&& str_contains($service, '$runtimeMembers->count() === 0')
&& str_contains($service, '!$pendingTombstone')
&& str_contains($service, '$successfulEmptyRevision')
&& str_contains($service,
"\$legacyEmptyFailure = (string) \$currentOperation->kind === 'vpc_create'")
&& str_contains($service, 'if ($awaitingMembers && $legacyEmptyFailure)')
&& str_contains($service, 'self::desiredDocument($vpc)')
&& str_contains($service, "hash('sha256', self::canonicalJson(\$emptyDesired))")
&& str_contains($service, "CloudVpcPrivateIp::where('vpc_id', \$vpc->id)")
&& str_contains($service, "CloudVpcRoute::where('vpc_id', \$vpc->id)")
&& str_contains($service, "CloudVpcAclRule::where('vpc_id', \$vpc->id)"),
'VPC public projection or usable digest gate leaks infrastructure or is incomplete.');
$assert(str_contains($service, "CloudVpcMember::where('instance_id', \$instanceId)")
&& str_contains($service, "['deleted', 'deleting'], true")
&& str_contains($service, 'releasePersistedDeletedMembershipsBeforeAttach')
&& str_contains($service, 'persistedDeletedPairProofValid')
&& str_contains($service, 'historicalOperationProofSummaries')
&& str_contains($service, 'historicalOperationProofSummary')
&& str_contains($service, 'rootObservedProof')
&& str_contains($service, 'deploymentRemovalMatchesProof')
&& str_contains($service, "CloudVpcPrivateIp::where('instance_id', \$instanceId)")
&& !str_contains($service, "->where('vpc_id', '<>', \$vpc->id)\n ->where('state', '<>', 'deleted')"),
'Proven historical member/IP identities must be physically released while unproven or orphan ledgers remain fail-closed.');
$assert(str_contains($service, "'observed_revision' => " . '$revision')
&& str_contains($service, 'CloudVpcAclRule::class')
&& str_contains($service, 'whereNotIn(\'state\', [\'deleted\'])'),
'VPC child observed revisions are not advanced with the all-host gate.');
$assert(str_contains($service, 'deletedByDestination')
&& str_contains($service, 'deletedByPriority')
&& str_contains($service, 'CloudVpcRoute::class, CloudVpcAclRule::class')
&& str_contains($service, '$allRequiredHostsExact')
&& str_contains($service, 'releaseMemberTombstones')
&& str_contains($service, 'releaseSubnetTombstones')
&& str_contains($service, "where('desired_revision', \$revision)")
&& str_contains($service, 'individually matched above'),
'VPC child tombstones must close only after exact readback and release unique identities safely.');
$terminalProofStart = strpos($service, '$noDataPlaneTerminalProof');
$terminalProofEnd = $terminalProofStart === false ? false
: strpos($service, '// Routes and ACLs are part of the exact host dataplane digest.',
$terminalProofStart);
$terminalProofBlock = ($terminalProofStart !== false && $terminalProofEnd !== false)
? substr($service, $terminalProofStart, $terminalProofEnd - $terminalProofStart) : '';
$assert($terminalProofBlock !== ''
&& str_contains($terminalProofBlock, '$terminalGate')
&& str_contains($terminalProofBlock, '$required->count() === 0')
&& str_contains($terminalProofBlock, '$liveRequired->count() === 0')
&& str_contains($terminalProofBlock, '$hosts === []')
&& str_contains($terminalProofBlock, '!$pendingHostTombstone')
&& str_contains($terminalProofBlock, 'no_data_plane_terminal_proof')
&& str_contains($terminalProofBlock, 'CloudVpcRoute::class, CloudVpcAclRule::class')
&& str_contains($terminalProofBlock, 'releaseSubnetTombstones')
&& !str_contains($terminalProofBlock, 'CloudVpcMember::class')
&& !str_contains($terminalProofBlock, 'CloudVpcPrivateIp::class'),
'Empty-VPC terminal proof may close an unreferenced subnet but must not release private member resources.');
$emptyCompletionStart = strpos($service, '} elseif ($emptyControlPlaneComplete) {');
$emptyCompletionEnd = $emptyCompletionStart === false ? false
: strpos($service, '} elseif ($terminalSubnetComplete) {', $emptyCompletionStart);
$emptyCompletionBlock = ($emptyCompletionStart !== false && $emptyCompletionEnd !== false)
? substr($service, $emptyCompletionStart,
$emptyCompletionEnd - $emptyCompletionStart) : '';
$assert($emptyCompletionBlock !== ''
&& str_contains($emptyCompletionBlock, 'CloudVpcSubnet::where')
&& str_contains($emptyCompletionBlock, "->whereNotIn('state', ['deleting', 'deleted'])")
&& str_contains($emptyCompletionBlock, "'state' => 'active'")
&& !str_contains($emptyCompletionBlock, 'CloudVpcRoute::class')
&& !str_contains($emptyCompletionBlock, 'CloudVpcAclRule::class')
&& !str_contains($emptyCompletionBlock, 'CloudVpcMember::class')
&& !str_contains($emptyCompletionBlock, 'CloudVpcPrivateIp::class')
&& !str_contains($emptyCompletionBlock, 'persistMemberGuestEvidence'),
'Empty VPC creation must advance only the control-plane subnet reservation.');
$assert(str_contains($service, '$emptyCreateLedgerValid')
&& str_contains($service, '$emptyAutomaticSubnetValid')
&& str_contains($service, 'self::lockedAutomaticSubnet($vpc)')
&& str_contains($service, "(\$desired['routes'] ?? null) === []")
&& str_contains($service, "is_array(\$desired['acls'] ?? null)")
&& str_contains($service, 'CloudVpcDefaultAcl::matchesEmptyReservation($vpc)')
&& str_contains($service, 'count($desired[\'subnets\']) === 1')
&& str_contains($service, "hash('sha256', self::canonicalJson(\$desired))")
&& str_contains($service, "CloudVpcPrivateIp::where('vpc_id', \$vpc->id)")
&& str_contains($service, "CloudVpcRoute::where('vpc_id', \$vpc->id)")
&& str_contains($service, "CloudVpcAclRule::where('vpc_id', \$vpc->id)"),
'Empty create completion must reject malformed, leased, or non-default policy ledgers.');
$assert(!str_contains($service, 'new CloudJob')
&& !str_contains($service, 'CloudJob::create')
&& !str_contains($service, 'CloudJobService::')
&& !str_contains($service, 'network_change')
&& !str_contains($service, 'publicIpCidr'),
'VPC admission may inspect instance tasks but must not enqueue VM jobs or reuse public network payloads.');
$assert(str_contains($service, '$orphanLease')
&& str_contains($service, '$stateMatches')
&& str_contains($service, "where('instance_id', \$instanceId)")
&& str_contains($service, "where('vpc_id', (int) \$vpc->id)")
&& str_contains($service, 'hash_equals($rootOperationId')
&& str_contains($service, "where('status', 'succeeded')")
&& str_contains($service, '$operationFresh')
&& str_contains($service, '$vpc->last_success_at')
&& str_contains($service, '$privateIp->observed_revision')
&& str_contains($service, '$privateIp->observed_digest')
&& str_contains($service, "(string) \$privateIp->state === 'active'")
&& str_contains($service, '$private->state = $privateState'),
'VPC private projections must fail closed on orphan/mismatched leases and require current root readback proof.');
$assert(str_contains($service, '$subnet->gateway_ip === null')
&& str_contains($service, 'automaticSubnetRecordValid')
&& str_contains($service, "'private_ip_cidr'")
&& str_contains($service, "'next_hop_member_id'")
&& str_contains($service, "self::cidr(\$item['destination_cidr'] ?? null, 32, 32, '路由目标')")
&& str_contains($service, 'VPC 私网地址账本与成员不一致')
&& str_contains($service, 'firstFreeIp($subnet, $privateIps, $reservedRouteIps)')
&& str_contains($service, '路由目标不能与 VPC 成员私网 IP 重复'),
'VPC service lost no-gateway, /32 member or typed route boundaries.');
$assert(str_contains($service, 'privateMacForMember')
&& str_contains($service, "'private_mac' => \$privateMac")
&& str_contains($service, 'validateHostDataplaneEvidence')
&& str_contains($service, 'member_nics')
&& str_contains($service, 'restart_required')
&& str_contains($service, 'guest_network_verified')
&& str_contains($service, '($nic[\'link_state\'] ?? null) !== \'up\'')
&& str_contains($service, 'vpc_private_guest_link_mismatch')
&& str_contains($service, 'vpc_private_guest_probe_deadline_exceeded')
&& str_contains($service, 'vpc_private_guest_probe_reap_required')
&& str_contains($service, 'guest_private_ip_cidr')
&& str_contains($service, 'guest_routes')
&& str_contains($service, 'config_observed_digest')
&& str_contains($service, 'OBSERVATION_EVIDENCE_VERSION')
&& str_contains($service, "?->network_status ?? '') !== 'active'")
&& str_contains($service, 'CloudInstanceRuntimeService::forInstances')
&& str_contains($service, "['state_fresh'] ?? false")
&& str_contains($service, "['power_state'] ?? '') !== 'running'")
&& str_contains($service, "'state' => \$intentionalStopped ? 'stopped'")
&& str_contains($service, "'vpc_private_guest_stopped'")
&& str_contains($service, "'vpc_private_guest_shutdown_pending'")
&& str_contains($service, 'wg_allowed_ips')
&& str_contains($service, 'privateRouteTableForVpc')
&& str_contains($service, 'expectedRouteSet')
&& str_contains($service, 'desiredContractValid')
&& str_contains($service, "array_key_exists('observed_digest', \$item)")
&& str_contains($service, "base64_decode(\$publicKey, true)")
&& str_contains($service, 'FABRIC_INTERFACE')
&& str_contains($service, 'PRIVATE_DATAPLANE_OWNER'),
'VPC desired DTO or host dataplane readback contract lost stable NIC identity/ACL gates.');
$assert(str_contains($runtimeService, "'shutdown' => 'shutdown'")
&& str_contains($runtimeService, "'poweroff' => 'stopped'")
&& str_contains($runtimeService, "'start', 'reboot', 'reset' => 'running'"),
'Runtime cache lost bounded power-action transition semantics.');
$assert(str_contains($service, "['power_state'] ?? '') !== 'stopped'")
&& str_contains($service, "'vpc_member_requires_stopped'")
&& str_contains($service, "'vpc_member_power_unavailable'"),
'Stopped-only VPC admission does not use the normalized runtime vocabulary.');
$assert(str_contains(
$operationErrorCatalog,
'私网配置尚未写入当前实例;请完全关机,等待系统核对写入后再开机'
) && str_contains(
$operationErrorCatalog,
'来宾私网探测清理状态未确认;请完全关机再开机后继续核验'
) && !str_contains($operationErrorCatalog, '私网地址或路由已暂存'),
'VPC restart guidance must not claim the pending seed/XML was already staged.');
$assert(str_contains($operationErrorCatalog, "'vpc_member_requires_stopped'")
&& str_contains($operationErrorCatalog, "'vpc_member_power_unavailable'")
&& str_contains($operationErrorCatalog, "'vpc_vm_not_persistent'")
&& str_contains($operationErrorCatalog, "'vpc_vm_managed_save_present'")
&& str_contains($operationErrorCatalog, "'vpc_vm_native_snapshot_present'")
&& str_contains($operationErrorCatalog, "'vpc_vm_native_snapshot_state_unknown'"),
'Stopped-only VPC admission codes lost reviewed user-facing labels.');
$assert(str_contains($vpcWorkerService, "'waiting_observed'")
&& str_contains($vpcWorkerService, 'allowDeferredRetry')
&& str_contains($vpcWorkerService, "where('status', 'succeeded')")
&& str_contains($vpcWorkerService, 'current_vpc.last_operation_id')
&& str_contains($vpcWorkerService, "where('kind', '!=', 'vpc_delete')")
&& str_contains($vpcWorkerService, 'current_vpc.sync_state')
&& !str_contains($vpcWorkerService, 'vpc_private_guest_shutdown_pending')
&& !str_contains($vpcWorkerService, 'vpc_private_guest_stopped')
&& str_contains($vpcWorkerService, 'OBSERVATION_EVIDENCE_VERSION')
&& str_contains($vpcWorkerService, 'CloudVpcService::reconcile($vpcKey, $actor, $allowDeferredRetry)'),
'VPC worker must retry configuration uncertainty without polling guest-only health.');
$assert(str_contains($routes, "'/vpcs'")
&& str_contains($routes, "'/vpcs/{vpc_key:[0-9a-f]{32}}/reconcile'")
&& str_contains($controller, 'CloudVpcService::delete')
&& str_contains($controller, 'CloudVpcService::replaceRoutes')
&& str_contains($controller, 'CloudVpcService::replaceAcl')
&& preg_match('#/api/v1/vpcs#', $middleware) === 1,
'VPC API routes/controller/middleware are incomplete.');
$assert(str_contains(
$routes, "\$this->delete('/vpcs/{vpc_key:[0-9a-f]{32}}',"
), 'VPC root DELETE route is missing.');
$assert(str_contains($engineClient, 'function vpc(')
&& str_contains($engineClient, '/internal/v1/vpcs')
&& str_contains($engineClient, '(?:reconcile|delete)')
&& str_contains($engineClient, 'vpc_delete_manifest_invalid')
&& str_contains($engineClient, 'vpc_delete_manifest_mismatch')
&& str_contains($engineClient, 'vpc_member_requires_stopped')
&& str_contains($engineClient, 'vpc_member_power_unavailable')
&& str_contains($engineClient, 'vpc_vm_not_persistent')
&& str_contains($engineClient, 'vpc_vm_managed_save_present')
&& str_contains($engineClient, 'vpc_vm_native_snapshot_present')
&& str_contains($engineClient, 'vpc_vm_native_snapshot_state_unknown')
&& str_contains($engineClient, 'vpc_private_remove_requires_stopped')
&& str_contains($engineClient, 'vpc_private_remove_unsafe')
&& str_contains($engineClient, 'vpc_private_interface_conflict')
&& str_contains($engineClient, 'vpc_seed_missing')
&& str_contains($engineClient, 'vpc_seed_readback_invalid')
&& str_contains($engineClient, 'vpc_private_xml_invalid'),
'PHP engine client has no bounded VPC endpoint.');
$assert(str_contains($accountDeletion, "cloud_vpcs")
&& str_contains($accountDeletion, "cloud_private_networks")
&& str_contains($accountDeletion, 'assertVpcHistoryCleanable')
&& str_contains($accountDeletion, 'deleteVpcHistory')
&& str_contains($accountDeletion, 'VPC_HISTORY_TABLES')
&& str_contains($accountDeletion, 'VPC 私网子账本不完整')
&& str_contains($accountDeletion, '已释放私网仍有 CIDR 声明')
&& str_contains($jobService, 'assertInstanceCanBeDeleted')
&& str_contains($orderService, "private_expectation")
&& str_contains($workerService, '旧删除任务缺少 VPC 删除门禁'),
'Account/VM creation/deletion can bypass the independent VPC control-plane ledger.');
$legacyPrivateGate = strpos($workerService,
"if ((\$expectation['required'] ?? false) !== true && !\$hasPrivateState)");
$privateReadback = strpos($workerService,
"'vms/' . rawurlencode(\$uuid) . '/private-state'");
$assert(str_contains($workerService, '$hasPrivateState')
&& str_contains($workerService, "&& !\$hasPrivateState")
&& str_contains($workerService, "array_key_exists('private_state', \$result)")
&& str_contains($workerService, 'Pre-VPC engines')
&& $legacyPrivateGate !== false
&& $privateReadback !== false
&& $legacyPrivateGate < $privateReadback,
'Legacy public-only jobs without private_state must remain compatible while structured observations stay gated.');
$assert(str_contains($workerService, 'Missing/invalid vm_uuid')
&& str_contains($workerService, 'hash_equals(strtolower($uuid)')
&& str_contains($workerService, "\$candidate['vm_uuid']"),
'Host private-state readback must remain bound to the requested VM UUID.');
$assert(str_contains($workerService, 'Never accept stale nested evidence')
&& str_contains($workerService, "['succeeded', 'completed', 'done']")
&& str_contains($workerService, "array_key_exists('operation_id', \$result)")
&& str_contains($workerService, "array_key_exists('vm_uuid', \$result)"),
'A failed or misbound reconcile envelope must never supply private-state proof.');
$assert(str_contains($workerService, "'_private_policy_skipped' => true")
&& str_contains($workerService, 'Only the PHP policy short-circuit carries this private marker')
&& str_contains($workerService, "'link_state' => self::privateReconcileLinkState"),
'A superseded PHP policy must preserve the private link without weakening real engine target proof.');
$assert(str_contains($workerService, "'blocked_traffic', 'blocked_expired' => 'blocked'")
&& str_contains($workerService, "'_policy_' . \$networkPolicy")
&& str_contains($workerService, "'start_if_suspended'")
&& str_contains($workerService, "? 'start' : 'stopped'")
&& str_contains($service, "service_resume_stopped_policy_")
&& str_contains($service, "service_resume_start_policy_")
&& str_contains($service, "action_reboot_policy_")
&& str_contains($service, '$policyUnready || $unboundResume'),
'Power/service private readback is no longer bound to network policy and payload target.');
$assert(str_contains($service, '?string $expectedVmUuid = null')
&& str_contains($service, '$observedVmUuid')
&& str_contains($service, 'hash_equals(strtolower($expectedVmUuid)')
&& str_contains($workerService, "? 'policy_skipped' : \$lifecycleKind")
&& str_contains($service, "\$preserveTarget = \$kind === 'policy_skipped'"),
'Private observation validation must enforce the lifecycle VM UUID binding.');
$assert(str_contains($workerService, "'private_mac', 'desired_revision'")
&& str_contains($service, "'private_mac', 'desired_revision'"),
'Private MAC must remain part of the immutable lifecycle/VPC target tuple.');
$assert(
str_contains($workerService, 'deleteTombstoneDetached')
&& str_contains($workerService, "['delete', 'expiry_delete']")
&& str_contains($workerService, "'desired_state'] ?? null) !== 'removed'")
&& str_contains($workerService, "'link_state'] ?? null) !== 'absent'"),
'Destructive deletion must preserve a removed tombstone until host-side absent readback is confirmed.'
);
echo "VPC control-plane schema, API, typed DTO and independent operation contracts passed.\n";