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

75 lines
3.7 KiB
PHP

<?php
// Source-boundary checks: no application bootstrap, database or engine needed.
$root = dirname(__DIR__);
$service = file_get_contents(
$root . '/app/Services/Cloud/CloudHostInventorySyncService.php'
);
$actor = file_get_contents($root . '/app/Services/Cloud/CloudDaemonActor.php');
$runtime = file_get_contents(
$root . '/app/Services/Cloud/CloudInstanceRuntimeSyncService.php'
);
$lifecycle = file_get_contents($root . '/app/Services/Cloud/CloudLifecycleService.php');
$heartbeat = file_get_contents($root . '/app/Services/Cloud/CloudRuntimeHeartbeat.php');
$assert = static function ($condition, string $message): void {
if (!$condition) {
throw new RuntimeException($message);
}
};
$assert(str_contains($service, "'GET', 'host/capacity'")
&& str_contains($service, "'GET', 'host/network-options'")
&& str_contains($service, 'public_ip_available_count')
&& str_contains($service, "->where('state', 'available')")
&& str_contains($service, "['available', 'disabled']")
&& str_contains($service, "['degraded', self::ERROR_INVALID_NETWORK]")
&& str_contains($service, "['unavailable', self::ERROR_UNAVAILABLE]")
&& str_contains($service, '$attemptedAt = $this->now();')
&& str_contains($service, 'private function beginAttempt')
&& str_contains($service,
'(int) $snapshot->attempt_generation !== $attemptGeneration')
&& str_contains($service, '$snapshot->last_attempt_at = $attemptedAt;')
&& str_contains($service, "\$host->last_seen_at = \$now;")
&& substr_count($service, "\$host->last_seen_at =") === 1,
'Capacity/IP observation, local-state preservation or last-seen boundary changed.');
$failureStart = strpos($service, 'private function markFailure');
$validationStart = strpos($service, 'private static function capacity', $failureStart);
$failure = $failureStart === false || $validationStart === false ? ''
: substr($service, $failureStart, $validationStart - $failureStart);
$assert($failure !== ''
&& str_contains($failure, "\$snapshot->sync_state = 'failed';")
&& str_contains($failure, "\$snapshot->last_error_code = \$code;")
&& !str_contains($failure, 'cpu_total_cores')
&& !str_contains($failure, 'CloudPublicIp::'),
'Failure handling may clear last-known capacity or mutate the IP library.');
$assert(str_contains($actor, "Config::get('super_admin', '')")
&& str_contains($actor, "->where('enable', 1)->where('is_admin', 1)")
&& str_contains($runtime,
"CloudDaemonActor::resolve('cloud-runtime-sync')")
&& !str_contains($runtime, 'private function systemActor')
&& str_contains($service,
"CloudDaemonActor::resolve('cloud-host-inventory-sync')"),
'Daemon engine actors no longer share one permission resolver.');
$assert(str_contains($lifecycle, "busy('host_inventory_sync')")
&& str_contains($lifecycle, 'new CloudHostInventorySyncService()')
&& str_contains($lifecycle, 'min(10, $batchSize)')
&& str_contains($service, 'public function syncOne(int $hostId): array')
&& str_contains($service, "Config::get('cloud_host_inventory_interval_seconds', 30)")
&& str_contains($service, 'private const MAX_HOSTS_PER_PASS = 10;')
&& str_contains($heartbeat,
"'host_inventory_sync' => '宿主容量与公网 IP 同步'")
&& str_contains($heartbeat, "'host_inventory_sync_failed'")
&& str_contains($heartbeat, "'host_inventory_sync_unconfigured'"),
'Lifecycle heartbeat phase or fixed inventory diagnostics are missing.');
$assert(!str_contains($service, 'getMessage()')
&& !str_contains($service, "['error']")
&& !str_contains($service, "['detail']"),
'Raw engine diagnostics can cross the inventory persistence boundary.');
echo "Cloud host inventory source contracts passed.\n";