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

64 lines
2.9 KiB
PHP

<?php
// Source-only migration/write-boundary checks. Production columns stay
// nullable for upgraded rows, while every current model create is fail closed.
$root = dirname(__DIR__);
$read = static function (string $path) use ($root): string {
$contents = file_get_contents($root . '/' . $path);
if (!is_string($contents)) {
throw new RuntimeException('Unable to read ' . $path);
}
return $contents;
};
$assert = static function (bool $condition, string $message): void {
if (!$condition) {
throw new RuntimeException($message);
}
};
$schema = $read('sql/cloud.sql');
$membership = $read('app/Services/Cloud/CloudHostPoolMembershipService.php');
$inventory = $read('app/Services/Cloud/CloudHostInventorySyncService.php');
$publicIp = $read('app/Models/CloudPublicIp.php');
$reservation = $read('app/Models/CloudResourceReservation.php');
$assert(str_contains($schema,
'INSERT IGNORE INTO cloud_host_resource_pool_memberships')
&& str_contains($schema, 'LEFT JOIN cloud_host_resource_pool_memberships')
&& str_contains($schema,
'WHERE h.resource_pool_id IS NOT NULL AND membership.id IS NULL')
&& str_contains($schema,
"CASE WHEN h.scheduler_state IN ('active', 'draining', 'disabled')")
&& str_contains($schema, '0, 100, GREATEST(0, h.created_at)'),
'The idempotent legacy host-membership import is missing or unsafe.');
$assert(str_contains($membership, 'lockForUpdate()->get()')
&& str_contains($membership, '$row->priority = self::SAFE_PRIORITY;')
&& str_contains($membership, '$row->weight = self::SAFE_WEIGHT;')
&& str_contains($membership, '$host->resource_pool_id =')
&& str_contains($membership, '$host->scheduler_state ='),
'Membership authority does not lock, normalize and mirror safely.');
$assert(str_contains($publicIp, 'protected static function booted(): void')
&& str_contains($publicIp, 'static::creating(')
&& str_contains($publicIp, "\$row->public_ip_pool_id ?? 0")
&& str_contains($reservation, 'protected static function booted(): void')
&& str_contains($reservation, 'static::creating(')
&& str_contains($reservation, "'network_attachment_id', 'public_ip_pool_id'")
&& str_contains($reservation, "'public_ip_id'")
&& str_contains($inventory,
"\$publicPool->network_attachment_id = (int) \$attachment->id;")
&& str_contains($inventory,
"\$row->public_ip_pool_id = \$identity['public_ip_pool_id'];"),
'New reservation, pool or concrete-IP writes can omit a required relation.');
$assert(str_contains($schema,
'network_attachment_id BIGINT UNSIGNED DEFAULT NULL')
&& str_contains($schema,
'public_ip_pool_id BIGINT UNSIGNED DEFAULT NULL')
&& str_contains($schema,
'public_ip_pool_id BIGINT UNSIGNED NULL AFTER host_id'),
'Legacy upgrade columns must remain nullable until existing rows are backfilled.');
echo "Cloud inventory relationship write contracts passed.\n";