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.
142 lines
6.7 KiB
PHP
142 lines
6.7 KiB
PHP
<?php
|
|
|
|
$root = dirname(__DIR__);
|
|
$read = static function (string $path) use ($root): string {
|
|
$contents = file_get_contents($root . '/' . $path);
|
|
if (!is_string($contents)) {
|
|
throw new RuntimeException('Unreadable contract source: ' . $path);
|
|
}
|
|
return $contents;
|
|
};
|
|
$assert = static function (bool $condition, string $message): void {
|
|
if (!$condition) {
|
|
throw new RuntimeException($message);
|
|
}
|
|
};
|
|
|
|
$order = $read('app/Services/Cloud/CloudOrderService.php');
|
|
$placement = $read('app/Services/Cloud/CloudPlacementService.php');
|
|
$worker = $read('app/Services/Cloud/CloudWorkerService.php');
|
|
$invoice = $read('app/Services/Cloud/CloudInvoiceService.php');
|
|
$recovery = $read('app/Services/Cloud/CloudOperationRecoveryIdentity.php');
|
|
$reservation = $read('app/Models/CloudResourceReservation.php');
|
|
|
|
$assert(!str_contains($order, "'public_pool_key' => ''")
|
|
&& !str_contains($order, "'public_pool_cidr' => ''")
|
|
&& !str_contains($order, "'public_ip_cidr' => ''")
|
|
&& !str_contains($order, "'gateway' => ''"),
|
|
'Unpaid orders still define the retired scalar public-network contract.');
|
|
$purchaseTransaction = strpos($order,
|
|
"return (new User())->getConnection()->transaction(");
|
|
$assert($purchaseTransaction !== false
|
|
&& !str_contains($order,
|
|
'云快照创建实例正在升级双栈网络,暂不可用')
|
|
&& str_contains($order,
|
|
'CloudDeploymentSnapshotService::resolveForOrder('),
|
|
'Cloud-snapshot purchase remains behind the retired compatibility gate.');
|
|
$paymentStart = strpos($order,
|
|
'public static function queuePaidProvision(');
|
|
$paymentPlacement = strpos($order,
|
|
'CloudPlacementService::reserve(',
|
|
$paymentStart === false ? 0 : $paymentStart);
|
|
$paymentPath = $paymentStart === false || $paymentPlacement === false
|
|
? '' : substr($order, $paymentStart,
|
|
$paymentPlacement - $paymentStart);
|
|
$assert($paymentPath !== ''
|
|
&& str_contains($paymentPath,
|
|
"} elseif (\$source === 'deployment_snapshot') {")
|
|
&& str_contains($paymentPath,
|
|
'CloudDeploymentSnapshotService::resolveForOrder(')
|
|
&& str_contains($paymentPath,
|
|
'CloudBackupService::provisioningSource('),
|
|
'Paid cloud-snapshot provisioning does not revalidate its immutable source before placement.');
|
|
$backupIdentityStart = strpos($recovery,
|
|
'private static function backupProvisionIdentity(');
|
|
$backupIdentityEnd = strpos($recovery,
|
|
'private static function backingBackupIdentity(',
|
|
$backupIdentityStart === false ? 0 : $backupIdentityStart);
|
|
$backupIdentity = $backupIdentityStart === false
|
|
|| $backupIdentityEnd === false
|
|
? '' : substr($recovery, $backupIdentityStart,
|
|
$backupIdentityEnd - $backupIdentityStart);
|
|
$assert($backupIdentity !== ''
|
|
&& str_contains($backupIdentity, "'public_network'")
|
|
&& str_contains($backupIdentity,
|
|
'CloudPublicNetworkSnapshot::fromArray(')
|
|
&& str_contains($backupIdentity,
|
|
'$requestedPublicNetwork->fingerprint()')
|
|
&& str_contains($backupIdentity, '$reservation->operation_id')
|
|
&& !str_contains($backupIdentity, "'public_pool_key'")
|
|
&& !str_contains($backupIdentity, "'public_ip_cidr'"),
|
|
'Cloud-snapshot create recovery still trusts the retired scalar network contract.');
|
|
$compactOrder = preg_replace('/\s+/', ' ', $order) ?? $order;
|
|
$assert(str_contains($compactOrder,
|
|
"\$orderSpec['public_network'] = \$placement['public_network']->toArray();")
|
|
&& str_contains($order,
|
|
"\$placement['payload']['body']['public_network']"),
|
|
'Paid order and dispatched job do not freeze the same public-network snapshot.');
|
|
|
|
foreach (['reserveBundle(', 'commitBundle(', 'fenceBundle(',
|
|
'releaseBundle(', 'releaseCommittedBundle('] as $call) {
|
|
$assert(preg_match(
|
|
'/CloudPublicNetworkAllocationService::\s*'
|
|
. preg_quote($call, '/') . '/',
|
|
$placement
|
|
) === 1,
|
|
'Provisioning placement does not use bundle operation: ' . $call);
|
|
}
|
|
$assert(str_contains($placement,
|
|
"\$payload['body']['public_network'] = \$publicNetwork->toArray();")
|
|
&& str_contains($placement,
|
|
"'public_network' => \$publicNetwork"),
|
|
'Placement does not return and dispatch one immutable dual-stack snapshot.');
|
|
$assert(!str_contains($reservation,
|
|
"foreach (['network_attachment_id', 'public_ip_pool_id',")
|
|
&& str_contains($reservation, 'cloud_resource_reservation_ips'),
|
|
'Resource reservations still treat one public_ip_id as network authority.');
|
|
|
|
$compactWorker = preg_replace('/\s+/', ' ', $worker) ?? $worker;
|
|
$workerFinalizationStart = strpos($worker,
|
|
'$provisionInvoice = CloudInvoice::where(');
|
|
$workerCommit = strpos($worker, 'CloudPlacementService::commit(',
|
|
$workerFinalizationStart === false ? 0 : $workerFinalizationStart);
|
|
$workerPreCommit = $workerFinalizationStart === false || $workerCommit === false
|
|
? '' : substr($worker, $workerFinalizationStart,
|
|
$workerCommit - $workerFinalizationStart);
|
|
$assert($workerPreCommit !== ''
|
|
&& !str_contains($workerPreCommit, 'CloudResourceReservation::where('),
|
|
'Create success locks the reservation before canonical placement commit.');
|
|
$tryHostStart = strpos($placement, 'private static function tryHost(');
|
|
$allocatorCall = strpos(
|
|
$placement,
|
|
'CloudPublicNetworkAllocationService::reserveBundle(',
|
|
$tryHostStart === false ? 0 : $tryHostStart
|
|
);
|
|
$preAllocator = $tryHostStart === false || $allocatorCall === false
|
|
? '' : substr($placement, $tryHostStart,
|
|
$allocatorCall - $tryHostStart);
|
|
$assert($preAllocator !== ''
|
|
&& !str_contains($preAllocator, 'lockedCandidates(')
|
|
&& !str_contains($preAllocator, 'hasCompleteDualStackCandidate('),
|
|
'tryHost can bypass the canonical allocator through a stale precheck.');
|
|
$assert(substr_count($worker,
|
|
'CloudPublicNetworkSnapshot::fromArray(') >= 2
|
|
&& str_contains($compactWorker,
|
|
"\$instanceSpec['public_network'] = \$confirmedPublicNetwork->toArray();")
|
|
&& str_contains($worker,
|
|
"\$requestedPublicNetwork->fingerprint()")
|
|
&& str_contains($worker,
|
|
"\$confirmedPublicNetwork->fingerprint()"),
|
|
'Create finalization does not compare and persist the exact dual-stack identity.');
|
|
$assert(str_contains($invoice, 'CloudPublicNetworkSnapshot::fromArray(')
|
|
&& str_contains($invoice, "\$spec['public_network']")
|
|
&& !str_contains($invoice, "\$spec['public_ip_cidr']"),
|
|
'Provision-success mail still treats scalar public_ip_cidr as authoritative.');
|
|
$assert(substr_count($recovery,
|
|
'CloudPublicNetworkSnapshot::fromArray(') >= 2
|
|
&& str_contains($recovery, "\$orderSpec['public_network']")
|
|
&& str_contains($recovery, "\$body['public_network']"),
|
|
'Create recovery identity is not bound to the frozen dual-stack snapshot.');
|
|
|
|
echo "Dual-stack provisioning call-chain contract passed.\n";
|