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.
249 lines
11 KiB
PHP
249 lines
11 KiB
PHP
<?php
|
|
|
|
$root = dirname(__DIR__);
|
|
$schema = file_get_contents($root . '/sql/cloud.sql');
|
|
$setup = file_get_contents($root . '/app/Command/CloudSetup.php');
|
|
$service = file_get_contents(
|
|
$root . '/app/Services/Cloud/CloudPublicIpPoolReplacementBatchService.php'
|
|
);
|
|
$itemModel = file_get_contents(
|
|
$root . '/app/Models/CloudPublicIpPoolReplacementBatchItem.php'
|
|
);
|
|
$jobs = file_get_contents($root . '/app/Services/Cloud/CloudJobService.php');
|
|
$workflow = file_get_contents(
|
|
$root . '/app/Services/Cloud/CloudPublicNetworkTransitionWorkflow.php'
|
|
);
|
|
$batchPlan = file_get_contents(
|
|
$root . '/app/Services/Cloud/CloudPublicNetworkTransitionBatchPlan.php'
|
|
);
|
|
$worker = file_get_contents($root . '/app/Services/Cloud/CloudWorkerService.php');
|
|
$recovery = file_get_contents(
|
|
$root . '/app/Services/Cloud/CloudOperationRecoveryService.php'
|
|
);
|
|
$automaticRecovery = file_get_contents(
|
|
$root . '/app/Services/Cloud/CloudAutomaticOperationRecoveryService.php'
|
|
);
|
|
|
|
$assert = static function (bool $condition, string $message): void {
|
|
if (!$condition) {
|
|
throw new RuntimeException($message);
|
|
}
|
|
};
|
|
$method = static function (string $contents, string $start, string $end) use (
|
|
$assert
|
|
): string {
|
|
$offset = strpos($contents, $start);
|
|
$limit = $offset === false ? false : strpos($contents, $end, $offset + 1);
|
|
$assert($offset !== false && $limit !== false && $limit > $offset,
|
|
'Replacement method source is missing: ' . $start);
|
|
return substr($contents, $offset, $limit - $offset);
|
|
};
|
|
|
|
$assert(is_string($schema)
|
|
&& str_contains($schema,
|
|
'CREATE TABLE cloud_public_ip_pool_replacement_batches')
|
|
&& str_contains($schema,
|
|
'CREATE TABLE cloud_public_ip_pool_replacement_batch_items')
|
|
&& str_contains($schema, 'cloud_public_pool_replacement_active')
|
|
&& str_contains($schema, 'source_initial_state')
|
|
&& str_contains($schema,
|
|
"source_initial_state IN ('active','draining')")
|
|
&& str_contains($schema, 'source_public_ip_pool_id, active_claim')
|
|
&& str_contains($schema, 'target_public_ip_pool_id, active_claim, id')
|
|
&& str_contains($schema, 'cloud_public_pool_replacement_child')
|
|
&& str_contains($schema, 'address_family TINYINT UNSIGNED NOT NULL')
|
|
&& str_contains($schema, 'child_job_id BIGINT UNSIGNED DEFAULT NULL')
|
|
&& str_contains($schema,
|
|
'chk_cloud_public_pool_replacement_item_family')
|
|
&& str_contains($schema, 'address_family IN (4,6)')
|
|
&& str_contains($schema,
|
|
"state = 'preparing' AND child_job_id IS NULL")
|
|
&& str_contains($schema,
|
|
"state IN ('queued','succeeded','failed','unknown')")
|
|
&& str_contains($schema, 'AND child_job_id IS NOT NULL')
|
|
&& str_contains($schema, "state IN ('running','blocked','succeeded','failed')"),
|
|
'Public-pool replacement lacks durable batch, child, or active-claim schema.');
|
|
$assert(is_string($setup)
|
|
&& str_contains($setup,
|
|
"SCHEMA_VERSION = 'go-agent-wss-v31-restore-migration-ledgers'")
|
|
&& str_contains($setup,
|
|
"'cloud_public_ip_pool_replacement_batches'")
|
|
&& str_contains($setup,
|
|
"'cloud_public_ip_pool_replacement_batch_items'")
|
|
&& str_contains($setup,
|
|
"'chk_cloud_public_pool_replacement_source_initial'")
|
|
&& str_contains($setup,
|
|
"'chk_cloud_public_pool_replacement_item_family'")
|
|
&& str_contains($setup,
|
|
"'chk_cloud_public_pool_replacement_claim'"),
|
|
'CloudSetup does not enforce the replacement batch schema.');
|
|
$assert(is_string($itemModel)
|
|
&& str_contains($itemModel, "'address_family' => 'int'")
|
|
&& str_contains($itemModel, "'child_job_id' => 'int'"),
|
|
'Replacement batch-item model lost family or nullable-child identity.');
|
|
$assert(is_string($service)
|
|
&& str_contains($service, 'expected_source_revision')
|
|
&& str_contains($service, 'expected_target_revision')
|
|
&& str_contains($service, 'confirm_replacement')
|
|
&& str_contains($service, "->where('active_claim', 1)")
|
|
&& str_contains($service,
|
|
"'source_public_ip_pool_id', \$replacementPoolIds")
|
|
&& str_contains($service,
|
|
"'target_public_ip_pool_id', \$replacementPoolIds")
|
|
&& str_contains($service, "\$batch->state = 'blocked'")
|
|
&& str_contains($service, 'projectTransitionEvidenceLocked')
|
|
&& !str_contains($service, 'finishResolvedChildLocked')
|
|
&& str_contains($service, "self::setPoolStateLocked(\$source, 'disabled')")
|
|
&& str_contains($service,
|
|
'self::setPoolStateLocked($source, $sourceInitialState)')
|
|
&& str_contains($service, "'replacement_locked'")
|
|
&& str_contains($service, 'CloudAccess::manage($actor)')
|
|
&& str_contains($service, 'self::assertAdminRead($actor)'),
|
|
'Replacement service lost revision fencing, overlap locking, or unknown-effect convergence.');
|
|
$assert(is_string($jobs)
|
|
&& !str_contains($jobs, 'enqueuePoolReplacementNetworkChangeLocked')
|
|
&& is_string($workflow)
|
|
&& str_contains($workflow, 'beginPoolReplacementBatch(')
|
|
&& str_contains($workflow, 'CloudPublicNetworkTransitionBatchPlan $plan')
|
|
&& str_contains($workflow,
|
|
'$transition->pool_replacement_batch_item_id =')
|
|
&& str_contains($workflow,
|
|
'$job->parent_job_id = $command->parentJobId()')
|
|
&& is_string($batchPlan)
|
|
&& str_contains($batchPlan, 'final class CloudPublicNetworkTransitionBatchPlan'),
|
|
'Replacement children do not use the canonical dual-stack transition seam.');
|
|
$assert(is_string($worker)
|
|
&& !str_contains($worker,
|
|
'CloudPublicIpPoolReplacementBatchService::finishChildLocked')
|
|
&& str_contains($worker,
|
|
'CloudPublicNetworkTransitionWorkflow::finishJobLocked')
|
|
&& str_contains($worker, '$aggregateParent')
|
|
&& str_contains($worker,
|
|
"'public_ip_pool_replacement_batch'")
|
|
&& !str_contains($jobs, 'finishResolvedChildLocked'),
|
|
'Worker no longer uses the transition projector or excludes the local parent from dispatch.');
|
|
|
|
$projector = $method(
|
|
$service,
|
|
'public static function projectTransitionEvidenceLocked(',
|
|
'public static function display('
|
|
);
|
|
$start = $method(
|
|
$service,
|
|
'public static function start(',
|
|
'public static function projectTransitionEvidenceLocked('
|
|
);
|
|
$transactionOffset = strpos(
|
|
$start,
|
|
'->transaction(static function () use ('
|
|
);
|
|
$assert($transactionOffset !== false,
|
|
'Replacement start transaction source is missing.');
|
|
$lockedStart = substr($start, $transactionOffset);
|
|
$startPositions = array_map(
|
|
static fn (string $needle): int|false => strpos($lockedStart, $needle),
|
|
[
|
|
'$actorUser = User::where(',
|
|
'$prior = CloudJob::where(',
|
|
'$instances = CloudInstance::whereIn(',
|
|
'$host = CloudHost::where(',
|
|
'$agent = CloudHostAgent::where(',
|
|
'$resourcePools = CloudResourcePool::whereIn(',
|
|
'$attachments = CloudHostNetworkAttachment::whereIn(',
|
|
'$pools = CloudPublicIpPool::whereIn(',
|
|
'$reservations = CloudResourceReservation::whereIn(',
|
|
'$ips = CloudPublicIp::where(',
|
|
]
|
|
);
|
|
$sortedStartPositions = $startPositions;
|
|
sort($sortedStartPositions, SORT_NUMERIC);
|
|
$assert(!in_array(false, $startPositions, true)
|
|
&& $startPositions === $sortedStartPositions
|
|
&& count(array_unique($startPositions)) === count($startPositions),
|
|
'Replacement start reversed actor/job/instance/host/catalog locks.');
|
|
$ipCatalogStart = strpos($lockedStart, '$allClaims = DB::table(');
|
|
$ipCatalogEnd = strpos($lockedStart, '$sourceIpIds = [];',
|
|
$ipCatalogStart === false ? 0 : $ipCatalogStart);
|
|
$ipCatalogLock = $ipCatalogStart === false || $ipCatalogEnd === false
|
|
? '' : substr(
|
|
$lockedStart,
|
|
$ipCatalogStart,
|
|
$ipCatalogEnd - $ipCatalogStart
|
|
);
|
|
$assert($ipCatalogLock !== ''
|
|
&& !str_contains($ipCatalogLock, '$catalogIpIds')
|
|
&& str_contains($ipCatalogLock, "->orWhereIn(\n"
|
|
. " 'public_ip_pool_id'")
|
|
&& str_contains($ipCatalogLock,
|
|
"->orderBy('id')->lockForUpdate()->get()->keyBy('id')"),
|
|
'Replacement start can discover IP catalog rows outside its current locking read.');
|
|
$converge = $method(
|
|
$service,
|
|
'private static function convergeLocked(',
|
|
'private static function setPoolStateLocked('
|
|
);
|
|
$markUnknown = $method(
|
|
$workflow,
|
|
'public static function markJobUncertain(',
|
|
'public static function recordEvidence('
|
|
);
|
|
$recordEvidence = $method(
|
|
$workflow,
|
|
'public static function recordEvidence(',
|
|
'public static function finishJobLocked('
|
|
);
|
|
$finishTransition = $method(
|
|
$workflow,
|
|
'public static function finishJobLocked(',
|
|
'public static function publishPreparedLocked('
|
|
);
|
|
$publishPrepared = $method(
|
|
$workflow,
|
|
'public static function publishPreparedLocked(',
|
|
'public static function retryPendingFinalization('
|
|
);
|
|
$retryFinalization = $method(
|
|
$workflow,
|
|
'public static function retryPendingFinalization(',
|
|
'private static function lockHostBoundaryLocked('
|
|
);
|
|
$positions = array_map(
|
|
static fn (string $needle): int|false => strpos($projector, $needle),
|
|
[
|
|
'$source = CloudPublicIpPool::where(',
|
|
'$batch = CloudPublicIpPoolReplacementBatch::where(',
|
|
'$items = CloudPublicIpPoolReplacementBatchItem::where(',
|
|
'$item = $items->first(',
|
|
]
|
|
);
|
|
$sortedPositions = $positions;
|
|
sort($sortedPositions, SORT_NUMERIC);
|
|
$assert(!in_array(false, $positions, true)
|
|
&& $positions === $sortedPositions
|
|
&& count(array_unique($positions)) === count($positions)
|
|
&& str_contains($projector, 'assertItemTransitionTopology(')
|
|
&& str_contains($projector, 'transitionProjection($transition)')
|
|
&& str_contains($projector, 'transactionLevel() < 1')
|
|
&& !str_contains($projector, '$catalogStatus')
|
|
&& !str_contains($projector, '$job->status')
|
|
&& !str_contains($projector, '$job->error_code')
|
|
&& str_contains($service, "(string) \$transition->kind !== 'pool_replacement'")
|
|
&& str_contains($service,
|
|
"(string) \$child->execution_mode !== 'agent'")
|
|
&& !str_contains($converge, 'lockForUpdate()'),
|
|
'Replacement projector trusts mutable job catalogs or reverses pool/batch locks.');
|
|
$assert(str_contains($markUnknown, 'projectTransitionEvidenceLocked(')
|
|
&& str_contains($recordEvidence, 'projectTransitionEvidenceLocked(')
|
|
&& str_contains($finishTransition, 'projectTransitionEvidenceLocked(')
|
|
&& str_contains($publishPrepared, 'projectTransitionEvidenceLocked(')
|
|
&& str_contains($retryFinalization, 'self::finishJobLocked(')
|
|
&& str_contains($retryFinalization, '$parent')
|
|
&& is_string($recovery)
|
|
&& str_contains($recovery, 'publishPreparedLocked(')
|
|
&& str_contains($recovery, '$aggregateParent')
|
|
&& is_string($automaticRecovery)
|
|
&& str_contains($automaticRecovery, 'retryPendingFinalization('),
|
|
'Worker, late receipt, or recovery paths bypass the transition projector.');
|
|
|
|
echo "Cloud public IP pool replacement schema contract tests passed\n";
|