addConnection([ 'driver' => 'sqlite', 'database' => ':memory:', ], 'default'); $capsule->setAsGlobal(); $capsule->bootEloquent(); $schema = $capsule->schema('default'); $schema->create('cloud_hosts', static function (Blueprint $t): void { $t->increments('id'); $t->string('name'); $t->string('region'); $t->boolean('enabled'); }); $schema->create('cloud_host_agents', static function (Blueprint $t): void { $t->integer('host_id')->primary(); $t->boolean('enabled'); $t->integer('revision'); $t->integer('tested_revision'); $t->string('last_test_status'); $t->text('network_selectors_json'); $t->text('public_network_capabilities_json'); }); $schema->create('cloud_resource_pools', static function (Blueprint $t): void { $t->increments('id'); $t->integer('line_id'); }); $schema->create('cloud_host_network_attachments', static function ( Blueprint $t ): void { $t->increments('id'); $t->integer('host_id'); $t->integer('line_id'); $t->string('name'); $t->string('network_selector'); $t->string('state'); $t->integer('priority'); $t->string('verification_state'); $t->integer('verified_agent_revision'); $t->integer('last_verified_at'); }); $schema->create('cloud_public_ip_pools', static function ( Blueprint $t ): void { $t->increments('id'); $t->string('pool_key'); $t->integer('host_id'); $t->integer('network_attachment_id'); $t->integer('address_family'); $t->string('name'); $t->string('cidr'); $t->string('gateway'); $t->boolean('gateway_on_link'); $t->integer('guest_prefix_length'); $t->text('dns_servers_json'); $t->text('reserved_ips_json'); $t->string('allocation_start')->nullable(); $t->string('allocation_end')->nullable(); $t->string('allocation_cursor')->nullable(); $t->integer('max_allocations'); $t->string('state'); $t->integer('priority'); $t->integer('desired_revision'); $t->integer('observed_revision'); $t->string('sync_state'); }); $schema->create('cloud_public_ips', static function (Blueprint $t): void { $t->increments('id'); $t->integer('host_id'); $t->integer('public_ip_pool_id'); $t->integer('address_family'); $t->string('address'); $t->binary('address_binary'); $t->integer('prefix_length'); $t->string('state'); $t->integer('reservation_id')->nullable(); $t->integer('reservation_ip_claim_id')->nullable(); $t->integer('instance_id')->nullable(); $t->string('operation_id')->nullable(); }); $schema->create('cloud_resource_reservations', static function ( Blueprint $t ): void { $t->increments('id'); $t->integer('resource_pool_id'); $t->integer('host_id'); $t->integer('user_id'); $t->integer('instance_id'); $t->string('state'); }); $schema->create('cloud_resource_reservation_ips', static function ( Blueprint $t ): void { $t->increments('id'); $t->integer('reservation_id'); $t->integer('address_family'); $t->integer('claim_generation'); $t->integer('active_claim')->nullable(); $t->integer('network_attachment_id'); $t->integer('public_ip_pool_id'); $t->integer('public_ip_id'); $t->string('operation_id'); $t->string('state'); }); $schema->create('cloud_instances', static function (Blueprint $t): void { $t->increments('id'); $t->integer('host_id'); $t->integer('user_id'); $t->integer('reservation_id'); $t->integer('resource_pool_id'); $t->string('status'); $t->string('service_status'); $t->integer('expires_at'); $t->text('spec_json'); }); $schema->create('cloud_public_network_transitions', static function ( Blueprint $t ): void { $t->increments('id'); $t->integer('instance_id'); $t->integer('active_transition')->nullable(); }); $schema->create('cloud_instance_migrations', static function ( Blueprint $t ): void { $t->increments('id'); $t->integer('instance_id'); $t->string('state'); }); $schema->create('cloud_backup_recoveries', static function ( Blueprint $t ): void { $t->increments('id'); $t->integer('instance_id'); $t->string('state'); }); $schema->create('cloud_jobs', static function (Blueprint $t): void { $t->increments('id'); $t->string('operation_id')->nullable(); $t->string('request_idempotency_key')->nullable(); $t->string('request_fingerprint')->nullable(); $t->integer('instance_id')->nullable(); $t->integer('parent_job_id')->nullable(); $t->integer('host_id')->nullable(); $t->string('kind'); $t->string('execution_mode')->nullable(); $t->string('phase'); $t->string('outcome')->nullable(); $t->string('status'); $t->text('sealed_payload')->nullable(); $t->integer('attempts')->nullable(); $t->integer('dispatch_attempts')->nullable(); $t->integer('dispatch_deadline_at')->nullable(); $t->integer('dispatch_started_at')->nullable(); $t->integer('agent_accepted_at')->nullable(); $t->integer('dispatched_at')->nullable(); $t->integer('receipt_deadline_at')->nullable(); $t->integer('terminal_at')->nullable(); $t->boolean('effect_may_have_applied')->nullable(); $t->boolean('safe_to_resubmit')->nullable(); $t->string('effect_resolution')->nullable(); $t->integer('effect_resolved_at')->nullable(); $t->boolean('finalization_incident')->default(false); $t->string('finalization_error_code')->nullable(); $t->string('completion_event_id')->nullable(); $t->integer('read_at')->nullable(); $t->string('error_code')->nullable(); $t->text('result_json')->nullable(); $t->integer('available_at')->default(0); $t->integer('created_at')->default(0); $t->integer('updated_at'); }); $now = time(); Capsule::table('cloud_hosts')->insert([ 'id' => 1, 'name' => 'HKG-A', 'region' => 'Hong Kong', 'enabled' => 1, ]); Capsule::table('cloud_host_agents')->insert([ 'host_id' => 1, 'enabled' => 1, 'revision' => 7, 'tested_revision' => 7, 'last_test_status' => 'healthy', 'network_selectors_json' => '["bridge:br0","bridge:br1",' . '"bridge:cross-line","bridge:stale"]', 'public_network_capabilities_json' => json_encode([ 'contract' => 1, 'dual_stack_required' => true, 'project_owned_filter' => true, 'ndp_guard' => true, ], JSON_THROW_ON_ERROR), ]); Capsule::table('cloud_resource_pools')->insert([ 'id' => 10, 'line_id' => 1, ]); foreach ([ [1, 1, 'Current uplink', 'bridge:br0', 10, 7], [2, 1, 'Alternative uplink', 'bridge:br1', 20, 7], [3, 2, 'Other line', 'bridge:cross-line', 0, 7], [4, 1, 'Stale evidence', 'bridge:stale', 0, 6], ] as [$id, $line, $name, $selector, $priority, $revision]) { Capsule::table('cloud_host_network_attachments')->insert([ 'id' => $id, 'host_id' => 1, 'line_id' => $line, 'name' => $name, 'network_selector' => $selector, 'state' => 'active', 'priority' => $priority, 'verification_state' => 'verified', 'verified_agent_revision' => $revision, 'last_verified_at' => $now, ]); } $pool = static function (int $id, int $attachmentId, int $family, string $key, string $cidr, string $gateway, bool $gatewayOnLink = false, int $desired = 1, int $observed = 1): array { $base = explode('/', $cidr, 2)[0]; return [ 'id' => $id, 'pool_key' => str_repeat($key, 32), 'host_id' => 1, 'network_attachment_id' => $attachmentId, 'address_family' => $family, 'name' => 'pool-' . $id, 'cidr' => $cidr, 'gateway' => $gateway, 'gateway_on_link' => $gatewayOnLink ? 1 : 0, 'guest_prefix_length' => $family === 4 ? 24 : 64, 'dns_servers_json' => $family === 4 ? '["1.1.1.1"]' : '["2606:4700:4700::1111"]', 'reserved_ips_json' => '[]', 'allocation_start' => $family === 6 ? str_replace('::', '::1000', $base) : null, 'allocation_end' => $family === 6 ? str_replace('::', '::10ff', $base) : null, 'max_allocations' => $family === 6 ? 64 : 0, 'state' => 'active', 'priority' => 0, 'desired_revision' => $desired, 'observed_revision' => $observed, 'sync_state' => 'applied', ]; }; Capsule::table('cloud_public_ip_pools')->insert([ $pool(11, 1, 4, 'a', '8.8.8.0/24', '8.8.8.1'), // Real provider contract: the on-link gateway is outside this /64. $pool(12, 1, 6, 'b', '2404:c140:156:3a::/64', '2404:c140:156::1', true), $pool(21, 2, 4, 'c', '9.9.9.0/24', '9.9.9.1'), $pool(22, 2, 6, 'd', '2404:c140:156:3b::/64', '2404:c140:156::1', true), $pool(31, 3, 4, 'e', '11.0.0.0/24', '11.0.0.1'), $pool(41, 4, 4, 'f', '12.0.0.0/24', '12.0.0.1'), ]); Capsule::table('cloud_public_ip_pools')->where('id', 22)->update([ 'dns_servers_json' => '["2404:c140:156:3b::1001"]', 'reserved_ips_json' => '["2404:c140:156:3b::1002"]', ]); $ip = static function (int $id, int $poolId, int $family, string $address, string $state = 'available', ?int $reservationId = null, ?int $claimId = null, ?int $instanceId = null, ?string $operationId = null): array { return [ 'id' => $id, 'host_id' => 1, 'public_ip_pool_id' => $poolId, 'address_family' => $family, 'address' => $address, 'address_binary' => inet_pton($address), 'prefix_length' => $family === 4 ? 24 : 64, 'state' => $state, 'reservation_id' => $reservationId, 'reservation_ip_claim_id' => $claimId, 'instance_id' => $instanceId, 'operation_id' => $operationId, ]; }; $op4 = str_repeat('4', 32); $op6 = str_repeat('6', 32); Capsule::table('cloud_public_ips')->insert([ $ip(101, 11, 4, '8.8.8.10', 'assigned', 20, 201, 30, $op4), $ip(102, 12, 6, '2404:c140:156:3a::1000', 'assigned', 20, 202, 30, $op6), $ip(111, 11, 4, '8.8.8.20'), $ip(121, 21, 4, '9.9.9.20'), $ip(131, 31, 4, '11.0.0.20'), $ip(141, 41, 4, '12.0.0.20'), ]); Capsule::table('cloud_resource_reservations')->insert([ 'id' => 20, 'resource_pool_id' => 10, 'host_id' => 1, 'user_id' => 7, 'instance_id' => 30, 'state' => 'committed', ]); Capsule::table('cloud_resource_reservation_ips')->insert([ [ 'id' => 201, 'reservation_id' => 20, 'address_family' => 4, 'claim_generation' => 1, 'active_claim' => 1, 'network_attachment_id' => 1, 'public_ip_pool_id' => 11, 'public_ip_id' => 101, 'operation_id' => $op4, 'state' => 'committed', ], [ 'id' => 202, 'reservation_id' => 20, 'address_family' => 6, 'claim_generation' => 1, 'active_claim' => 1, 'network_attachment_id' => 1, 'public_ip_pool_id' => 12, 'public_ip_id' => 102, 'operation_id' => $op6, 'state' => 'committed', ], ]); $publicNetwork = [ 'contract' => 1, 'network_selector' => 'bridge:br0', 'ipv4' => [ 'pool_key' => str_repeat('a', 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('b', 32), 'pool_cidr' => '2404:c140:156:3a::/64', 'address_cidr' => '2404:c140:156:3a::1000/64', 'gateway' => '2404:c140:156::1', 'gateway_on_link' => true, ], 'dns_servers' => ['1.1.1.1', '2606:4700:4700::1111'], ]; Capsule::table('cloud_instances')->insert([ 'id' => 30, 'host_id' => 1, 'user_id' => 7, 'reservation_id' => 20, 'resource_pool_id' => 10, 'status' => 'active', 'service_status' => 'active', 'expires_at' => $now + 86400, 'spec_json' => json_encode([ 'managed' => true, 'os_source' => 'cloud_template', 'public_network' => $publicNetwork, ], JSON_THROW_ON_ERROR | JSON_UNESCAPED_SLASHES), ]); $instance = CloudInstance::findOrFail(30); $tenant = CloudNetworkChangeOptionsService::tenantQuote($instance); $assert(($tenant['address_family'] ?? null) === 4 && ($tenant['can_change'] ?? null) === true && ($tenant['configuration_state'] ?? null) === 'ready', 'Tenant quote lost its IPv4-only contract or current availability.'); foreach ([ 'host_id', 'host_name', 'region', 'current_public_network', 'current_attachment_id', 'attachments', 'available_ip_options', 'available_count', 'public_ip_cidr', 'pool_key', ] as $privateKey) { $assert(!array_key_exists($privateKey, $tenant), 'Tenant quote leaked network inventory key: ' . $privateKey); } $admin = CloudNetworkChangeOptionsService::adminOptions($instance); $assert(($admin['can_change'] ?? null) === true && ($admin['current_attachment_id'] ?? null) === '1' && count($admin['attachments'] ?? []) === 2, 'Administrator attachment catalog is incomplete or unfiltered.'); $byId = []; foreach ($admin['attachments'] as $attachment) { $byId[$attachment['attachment_id']] = $attachment; } $assert(($byId['1']['current'] ?? null) === true && ($byId['2']['current'] ?? null) === false && ($byId['1']['ipv4']['pools'][0]['available_options'][0] ['address_cidr'] ?? null) === '8.8.8.20/24' && ($byId['2']['ipv4']['pools'][0]['available_options'][0] ['address_cidr'] ?? null) === '9.9.9.20/24', 'Exact IPv4 choices were not grouped by verified attachment.'); $currentV6 = $byId['1']['ipv6']['pools'][0] ?? []; $alternativeV6 = $byId['2']['ipv6']['pools'][0] ?? []; $assert(($currentV6['cidr'] ?? null) === '2404:c140:156:3a::/64' && ($currentV6['gateway'] ?? null) === '2404:c140:156::1' && ($currentV6['gateway_on_link'] ?? null) === true && ($currentV6['sparse'] ?? null) === true && ($currentV6['allocation_start'] ?? null) === '2404:c140:156:3a::1000' && ($currentV6['allocation_end'] ?? null) === '2404:c140:156:3a::10ff' && !array_key_exists('available_options', $currentV6), 'Sparse IPv6 metadata rejected the real off-prefix on-link gateway.'); $assert(in_array('2404:c140:156:3b::1001', $alternativeV6['excluded_addresses'] ?? [], true) && in_array('2404:c140:156:3b::1002', $alternativeV6['excluded_addresses'] ?? [], true), 'IPv6 DNS or reserved address was not excluded from exact input.'); // More than the former global 4096-row cap is still a valid catalog: // the administrator limit permits up to 32 /24 pools. Later attachments // must not be starved by addresses ordered earlier in the global ledger. $scalePools = []; $scaleIps = []; $scaleIpId = 10000; for ($index = 0; $index < 17; $index++) { $poolId = 100 + $index; $cidr = '20.' . $index . '.0.0/24'; $row = $pool( $poolId, 1, 4, 'a', $cidr, '20.' . $index . '.0.1' ); $row['pool_key'] = substr(hash('sha256', 'scale-' . $index), 0, 32); $scalePools[] = $row; for ($last = 2; $last <= 243; $last++) { $scaleIps[] = $ip( $scaleIpId++, $poolId, 4, '20.' . $index . '.0.' . $last ); } } Capsule::table('cloud_public_ip_pools')->insert($scalePools); foreach (array_chunk($scaleIps, 100) as $chunk) { Capsule::table('cloud_public_ips')->insert($chunk); } $largeTenant = CloudNetworkChangeOptionsService::tenantQuote( $instance->fresh() ); $largeAdmin = CloudNetworkChangeOptionsService::adminOptions( $instance->fresh() ); $largeAlternative = collect($largeAdmin['attachments'] ?? []) ->firstWhere('attachment_id', '2'); $assert(($largeTenant['can_change'] ?? null) === true && ($largeTenant['configuration_state'] ?? null) === 'ready' && ($largeAdmin['configuration_state'] ?? null) === 'ready' && ($largeAlternative['ipv4']['pools'][0]['available_options'][0] ['address_cidr'] ?? null) === '9.9.9.20/24', 'A valid catalog above 4096 IPv4 rows starved a later attachment.'); Capsule::table('cloud_public_ips')->where('id', '>=', 10000)->delete(); Capsule::table('cloud_public_ip_pools')->whereBetween('id', [100, 116]) ->delete(); // Pool revisions are an atomic PHP-owned contract. An observed revision // ahead of desired is catalog drift, not a successfully applied target. Capsule::table('cloud_public_ip_pools')->where('id', 11)->update([ 'observed_revision' => 2, ]); $driftTenant = CloudNetworkChangeOptionsService::tenantQuote( $instance->fresh() ); $driftAdmin = CloudNetworkChangeOptionsService::adminOptions( $instance->fresh() ); $driftCurrent = collect($driftAdmin['attachments'] ?? [])->firstWhere( 'attachment_id', '1' ); $assert(($driftTenant['can_change'] ?? null) === false && ($driftCurrent['ipv4']['pools'] ?? []) === [], 'A pool with observed revision ahead of desired was advertised.'); Capsule::table('cloud_public_ip_pools')->where('id', 11)->update([ 'observed_revision' => 1, ]); $validPools = [ 21 => [ 'cidr' => '9.9.9.0/24', 'gateway' => '9.9.9.1', 'gateway_on_link' => 0, 'guest_prefix_length' => 24, 'dns_servers_json' => '["1.1.1.1"]', 'reserved_ips_json' => '[]', 'allocation_start' => null, 'allocation_end' => null, 'allocation_cursor' => null, 'max_allocations' => 0, ], 22 => [ 'cidr' => '2404:c140:156:3b::/64', 'gateway' => '2404:c140:156::1', 'gateway_on_link' => 1, 'guest_prefix_length' => 64, 'dns_servers_json' => '["2404:c140:156:3b::1001"]', 'reserved_ips_json' => '["2404:c140:156:3b::1002"]', 'allocation_start' => '2404:c140:156:3b::1000', 'allocation_end' => '2404:c140:156:3b::10ff', 'allocation_cursor' => null, 'max_allocations' => 64, ], ]; $corruptPoolCases = [ 'guest prefix drift' => [22, 2, 6, ['guest_prefix_length' => 65]], 'IPv4 on-link gateway' => [21, 2, 4, ['gateway_on_link' => 1]], 'IPv4 invalid boolean gateway flag' => [21, 2, 4, [ 'gateway_on_link' => 2, ]], 'IPv4 /23 prefix' => [21, 2, 4, [ 'cidr' => '9.9.8.0/23', 'guest_prefix_length' => 23, ]], 'IPv6 /121 prefix' => [22, 2, 6, [ 'cidr' => '2404:c140:156:3b::/121', 'guest_prefix_length' => 121, ]], 'private DNS' => [21, 2, 4, [ 'dns_servers_json' => '["10.0.0.1"]', ]], 'duplicate DNS' => [21, 2, 4, [ 'dns_servers_json' => '["1.1.1.1","1.1.1.1"]', ]], 'empty DNS' => [21, 2, 4, ['dns_servers_json' => '[]']], 'five DNS addresses' => [21, 2, 4, [ 'dns_servers_json' => '["1.1.1.1","8.8.8.8",' . '"9.9.9.9","2606:4700:4700::1111",' . '"2001:4860:4860::8888"]', ]], 'private reserved address' => [21, 2, 4, [ 'reserved_ips_json' => '["10.0.0.1"]', ]], 'duplicate reserved address' => [21, 2, 4, [ 'reserved_ips_json' => '["9.9.9.2","9.9.9.2"]', ]], 'off-pool reserved address' => [21, 2, 4, [ 'reserved_ips_json' => '["8.8.8.2"]', ]], 'network reserved address' => [21, 2, 4, [ 'reserved_ips_json' => '["9.9.9.0"]', ]], 'off-prefix gateway without on-link' => [22, 2, 6, [ 'gateway_on_link' => 0, ]], 'IPv6 invalid boolean gateway flag' => [22, 2, 6, [ 'gateway_on_link' => 'false', ]], 'zero sparse allocation limit' => [22, 2, 6, [ 'max_allocations' => 0, ]], 'excess sparse allocation limit' => [22, 2, 6, [ 'max_allocations' => 65536, ]], 'insufficient sparse range' => [22, 2, 6, [ 'allocation_end' => '2404:c140:156:3b::1002', 'max_allocations' => 2, ]], 'cursor outside sparse range' => [22, 2, 6, [ 'allocation_cursor' => '2404:c140:156:3b::1100', ]], ]; foreach ($corruptPoolCases as $label => $case) { [$poolId, $attachmentId, $family, $corruption] = $case; Capsule::table('cloud_public_ip_pools')->where('id', $poolId) ->update($corruption); $corruptPoolOptions = CloudNetworkChangeOptionsService::adminOptions( $instance->fresh() ); $corruptAlternative = collect( $corruptPoolOptions['attachments'] ?? [] )->firstWhere('attachment_id', (string) $attachmentId); $familyKey = $family === 4 ? 'ipv4' : 'ipv6'; $assert(($corruptPoolOptions['configuration_state'] ?? null) === 'invalid' && ($corruptAlternative[$familyKey]['pools'] ?? []) === [], 'A corrupt public-IP pool was advertised: ' . $label); Capsule::table('cloud_public_ip_pools')->where('id', $poolId) ->update($validPools[$poolId]); } CloudPanelUsageService::$managementAddress = '2404:c140:156:3b::1003'; $managementOptions = CloudNetworkChangeOptionsService::adminOptions( $instance->fresh() ); $managementAttachment = collect( $managementOptions['attachments'] ?? [] )->firstWhere('attachment_id', '2'); $managementIpv6Pool = $managementAttachment['ipv6']['pools'][0] ?? null; $assert(is_array($managementIpv6Pool) && in_array( '2404:c140:156:3b::1003', $managementIpv6Pool['excluded_addresses'] ?? [], true ), 'The host management address was not excluded from sparse input.'); CloudPanelUsageService::$managementAddress = null; // A tenant replacement is deliberately confined to the current // attachment even though administrators may move both families elsewhere. Capsule::table('cloud_public_ips')->where('id', 111)->update([ 'state' => 'disabled', ]); $tenantWithoutLocalIpv4 = CloudNetworkChangeOptionsService::tenantQuote( $instance->fresh() ); $adminWithAlternative = CloudNetworkChangeOptionsService::adminOptions( $instance->fresh() ); $assert(($tenantWithoutLocalIpv4['can_change'] ?? null) === false && ($adminWithAlternative['can_change'] ?? null) === true, 'Tenant automatic selection escaped its current attachment boundary.'); Capsule::table('cloud_public_ip_pools')->where('id', 12)->update([ 'max_allocations' => 1, ]); Capsule::table('cloud_public_ip_pools')->where('id', 22)->update([ 'state' => 'disabled', ]); $singleFamilyAlternative = CloudNetworkChangeOptionsService::adminOptions($instance->fresh()); $assert(($singleFamilyAlternative['can_change'] ?? null) === false, 'A single-family alternative attachment was advertised as usable.'); Capsule::table('cloud_public_ip_pools')->where('id', 12)->update([ 'max_allocations' => 64, ]); Capsule::table('cloud_public_ip_pools')->where('id', 22)->update([ 'state' => 'active', ]); Capsule::table('cloud_public_ips')->where('id', 111)->update([ 'state' => 'available', ]); Capsule::table('cloud_instance_migrations')->insert([ 'id' => 1, 'instance_id' => 30, 'state' => 'preparing_source', ]); $migrationBusy = CloudNetworkChangeOptionsService::tenantQuote( $instance->fresh() ); $assert(($migrationBusy['can_change'] ?? null) === false && str_contains( (string) ($migrationBusy['message'] ?? ''), '维护迁移' ), 'An active migration did not disable the network quote.'); Capsule::table('cloud_instance_migrations')->delete(); Capsule::table('cloud_backup_recoveries')->insert([ 'id' => 1, 'instance_id' => 30, 'state' => 'recovering', ]); $recoveryBusy = CloudNetworkChangeOptionsService::tenantQuote( $instance->fresh() ); $assert(($recoveryBusy['can_change'] ?? null) === false && str_contains( (string) ($recoveryBusy['message'] ?? ''), '恢复备份' ), 'An active backup recovery did not disable the network quote.'); Capsule::table('cloud_backup_recoveries')->delete(); $job = new CloudJob(); $job->id = 88; $job->instance_id = 30; $job->host_id = 1; $job->kind = 'action'; $job->execution_mode = 'agent'; $job->sealed_payload = '{}'; $job->available_at = $now; $job->created_at = $job->updated_at = $now; $job->save(); $busy = CloudNetworkChangeOptionsService::tenantQuote($instance->fresh()); $assert(($busy['can_change'] ?? null) === false && ($busy['active_job']['id'] ?? null) === '88', 'An active instance job did not disable the network quote.'); $job->delete(); Capsule::table('cloud_public_network_transitions')->insert([ 'id' => 1, 'instance_id' => 30, 'active_transition' => 1, ]); $transitionBusy = CloudNetworkChangeOptionsService::tenantQuote( $instance->fresh() ); $assert(($transitionBusy['can_change'] ?? null) === false, 'An active public-network transition did not disable the quote.'); Capsule::table('cloud_public_network_transitions')->delete(); Capsule::table('cloud_public_ips')->where('id', 111)->update([ 'address_binary' => inet_pton('8.8.8.21'), ]); $corrupt = CloudNetworkChangeOptionsService::tenantQuote( $instance->fresh() ); $assert(($corrupt['configuration_state'] ?? null) === 'invalid' && ($corrupt['can_change'] ?? null) === false, 'An IPv4 row with mismatched packed identity remained selectable.'); Capsule::table('cloud_public_ips')->where('id', 111)->update([ 'address_binary' => inet_pton('8.8.8.20'), ]); $schema->drop('cloud_backup_recoveries'); $missingCatalog = CloudNetworkChangeOptionsService::tenantQuote( $instance->fresh() ); $assert(($missingCatalog['can_change'] ?? null) === false && str_contains( (string) ($missingCatalog['message'] ?? ''), '运行态目录不可用' ), 'A missing runtime catalog failed open in tenant options.'); $schema->create('cloud_backup_recoveries', static function ( Blueprint $t ): void { $t->increments('id'); $t->integer('instance_id'); $t->string('state'); }); $broken = $publicNetwork; $broken['ipv4']['address_cidr'] = '8.8.8.99/24'; Capsule::table('cloud_instances')->where('id', 30)->update([ 'spec_json' => json_encode([ 'managed' => true, 'os_source' => 'cloud_template', 'public_network' => $broken, ], JSON_THROW_ON_ERROR | JSON_UNESCAPED_SLASHES), ]); $rejects( static fn () => CloudNetworkChangeOptionsService::tenantQuote( CloudInstance::findOrFail(30) ), 'A spec/ledger public-network mismatch remained quotable.' ); echo "Cloud network-change options behavior passed.\n"; }