getMessage(), 'Missing required rescue recovery action' ); } $assert($missingRecoveryRejected, 'Integrity check accepted a failure state without its recovery exit.'); $mutated = $definition; $mutated['artifact']['publish_unknown']['transitions'][] = 'invented'; $unknownTransitionRejected = false; try { CloudRescueCatalogStateMachine::assertIntegrity($mutated); } catch (LogicException $error) { $unknownTransitionRejected = str_contains( $error->getMessage(), 'Unknown rescue state transition' ); } $assert($unknownTransitionRejected, 'Integrity check accepted a transition to an undefined state.'); CloudRescueCatalogStateMachine::assertTransition( 'catalog', 'preparing', 'validating' ); $invalidTransitionRejected = false; try { CloudRescueCatalogStateMachine::assertTransition( 'catalog', 'active', 'preparing' ); } catch (CloudError $error) { $invalidTransitionRejected = $error->httpStatus === 409; } $assert($invalidTransitionRejected, 'Catalog state machine accepted an impossible backward transition.'); $assert(CloudRescueCatalogStateMachine::recoveryActions( 'artifact', 'publish_unknown' ) === ['reconcile_publish'], 'Unknown publish state did not expose reconciliation only.'); $assert(CloudRescueCatalogStateMachine::recoveryActions( 'replica', 'failed' ) === ['retry_import', 'delete_replica'], 'Known-not-applied import failure did not expose the safe retry.'); $catalog = [ 'revision' => 3, 'generation_token' => str_repeat('a', 32), 'size_bytes' => 4096, 'sha256' => str_repeat('b', 64), ]; $exact = [ 'host_id' => 11, 'state' => 'active', 'revision' => 3, 'generation_token' => str_repeat('a', 32), 'size_bytes' => 4096, 'sha256' => str_repeat('b', 64), ]; $failed = $exact; $failed['host_id'] = 12; $failed['state'] = 'failed'; $assert(CloudRescueCatalogStateMachine::availability( $catalog, [$exact, $failed], [11, 12] ) === 'degraded', 'One exact replica and one failed replica were not degraded.'); $assert(CloudRescueCatalogStateMachine::availability( $catalog, [$exact], [11] ) === 'active', 'All eligible exact replicas were not active.'); $stale = $exact; $stale['generation_token'] = str_repeat('c', 32); $assert(CloudRescueCatalogStateMachine::availability( $catalog, [$stale], [11] ) === 'error', 'A mismatched immutable generation was exposed as usable.'); echo "Rescue catalog state-machine behavior passed.\n";