$method->getName(), array_filter( $workflow->getMethods(ReflectionMethod::IS_PUBLIC), static fn (ReflectionMethod $method): bool => $method->getDeclaringClass()->getName() === CloudPublicNetworkTransitionWorkflow::class ) )); $assert($workflow->isFinal() && $public === [ 'begin', 'markDispatched', 'markJobUncertain', 'recordEvidence', 'finishJobLocked', 'publishPreparedLocked', 'retryPendingFinalization', ], 'Stage 4 transition seam drifted.'); $command = new ReflectionClass(CloudPublicNetworkTransitionCommand::class); foreach (['userPaidAutomatic', 'adminExact', 'poolReplacement'] as $factory) { $assert($command->hasMethod($factory) && $command->getMethod($factory)->isStatic(), 'Transition command factory is missing: ' . $factory); } $ordered = [ "User::where('id', \$command->actorUserId())", "CloudInstance::where('id', \$command->instanceId())", "'transition_key', \$command->transitionKey()", "CloudHost::where('id', (int) \$instance->host_id)", "CloudHostAgent::where('host_id', (int) \$instance->host_id)", "CloudResourcePool::where(\n 'id', (int) \$instance->resource_pool_id", 'CloudHostNetworkAttachment::whereIn(', "CloudPublicIpPool::whereIn('id', \$poolIds)", "CloudResourceReservation::where(\n 'id', \$reservationId", "->where('reservation_id', \$reservationId)\n ->orderBy('address_family')", "CloudPublicIp::where('host_id', (int) \$instance->host_id)", ]; $cursor = -1; foreach ($ordered as $needle) { $position = strpos($source, $needle); $assert($position !== false && $position > $cursor, 'Transition lock order drifted at: ' . $needle); $cursor = $position; } $assert(str_contains($source, "\$transition->state = 'reserved';") && str_contains($source, "'active_claim' => null") && str_contains($source, "'state' => 'reserved'") && str_contains($source, "\$transition->state = 'queued';") && strpos($source, "\$transition->state = 'reserved';") < strpos($source, "\$transition->state = 'queued';"), 'Transition must fence targets before atomically becoming queued.'); $assert(str_contains($source, 'CloudInstanceMigrationService::assertInstanceMutationAvailable(') && str_contains($source, "DB::table('cloud_backup_recoveries')") && str_contains($source, 'CloudJobService::blockingQueryForInstance('), 'Open migration, recovery, or job work is not fenced before writes.'); $assert(str_contains($source, "(\$spec['managed'] ?? false) !== true") && str_contains($source, "(\$spec['os_source'] ?? null) !== 'cloud_template'"), 'The deep workflow seam does not enforce managed cloud-template admission.'); $assert(str_contains($source, "\$job->kind = 'network_change';") && str_contains($source, "\$job->public_network_transition_id = (int) \$transition->id;") && str_contains($source, "'public_network' => \$targetSnapshot->toArray()") && str_contains($source, "'price_cents' => \$command->priceCents()") && str_contains($source, "'charged_amount' => \$invoice === null") && !str_contains($source, "'source_public_ip_id' =>") && !str_contains($source, "'target_public_ip_id' =>"), 'Queued job does not freeze the complete transition contract.'); $assert(str_contains($billing, 'CloudPublicNetworkTransitionCommand $command') && str_contains($billing, "\$command->kind() !== 'user_paid'") && str_contains($activeIdentity, 'CloudPublicNetworkClaimSetIdentity::fromLedger('), 'Billing or claim-set identity is not delegated through the deep seam.'); $assert(str_contains($worker, 'markDispatched($job)') && str_contains($worker, 'recordEvidence(') && str_contains($worker, 'finishJobLocked(') && str_contains($worker, 'markJobUncertain(') && str_contains($recovery, 'publishPreparedLocked('), 'Worker or recovery coordinator bypasses the Stage 4 transition seam.'); $allowedBeginCallers = [ realpath($root . '/app/Controllers/CloudApiController.php'), realpath($root . '/app/Controllers/CloudAdminInstanceController.php'), ]; $actualBeginCallers = []; foreach ([$root . '/app', $root . '/config'] as $directory) { $iterator = new RecursiveIteratorIterator( new RecursiveDirectoryIterator( $directory, FilesystemIterator::SKIP_DOTS ) ); foreach ($iterator as $file) { if (!$file->isFile() || $file->getExtension() !== 'php' || $file->getPathname() === $root . '/app/Services/Cloud/' . 'CloudPublicNetworkTransitionWorkflow.php') { continue; } $contents = file_get_contents($file->getPathname()); if (is_string($contents) && str_contains( $contents, 'CloudPublicNetworkTransitionWorkflow::begin(' )) { $actualBeginCallers[] = realpath($file->getPathname()); } } } $actualBeginCallers = array_values(array_unique($actualBeginCallers)); sort($actualBeginCallers); sort($allowedBeginCallers); $assert($actualBeginCallers === $allowedBeginCallers, 'Production workflow callers escaped the two Stage 5 controller seams.'); $assert(str_contains($tenantController, 'CloudPublicNetworkTransitionCommand::') && str_contains($tenantController, 'userPaidAutomatic(') && str_contains($tenantController, 'CloudPublicNetworkTransitionWorkflow::begin($command)') && !str_contains($tenantController, "CloudJobService::enqueue(\n \$instance,\n \$actor,\n 'network_change'") && str_contains($adminController, 'CloudPublicNetworkTransitionCommand::adminExact(') && str_contains($adminController, 'CloudPublicNetworkTransitionWorkflow::begin($command)'), 'A Stage 5 controller bypasses the command plus transition seam.'); echo "Public-network transition workflow contract tests passed.\n";