invoke( null, 'automatic_recovery:v1:1700000000:13:pending' ); $assert(is_array($state) && ($state['attempts'] ?? null) === 13, 'A recovery marker was still capped at twelve attempts.'); $saturated = $attemptState->invoke( null, 'automatic_recovery:v1:1700000000:' . str_repeat('9', 80) . ':pending' ); $assert(is_array($saturated) && ($saturated['attempts'] ?? null) === PHP_INT_MAX, 'A durable saturated recovery attempt counter was rejected.'); $errorCode = new ReflectionMethod( CloudAutomaticOperationRecoveryService::class, 'recoveryErrorCode' ); $assert($errorCode->invoke(null, new CloudAgentError( 'invalid inspection', 502, 'agent_invalid_inspection', false, 200 )) === 'recovery_evidence_invalid' && $errorCode->invoke( null, new CloudRecoveryInstanceStateConflict('state conflict', 409) ) === 'recovery_instance_state_conflict', 'Concrete evidence/state anomalies collapsed into a generic retry code.'); $operationId = str_repeat('a', 32); $identity = [ 'action' => 'change-network', 'resource_id' => '11111111-1111-4111-8111-111111111111', 'request_fingerprint' => str_repeat('f', 64), ]; $job = new CloudJob(); $job->operation_id = $operationId; $job->kind = 'network_change'; $job->phase = 'terminal'; $job->effect_resolution = 'not_applied'; $job->sealed_payload = CloudSecrets::encrypt([ '_operation_identity' => ['version' => 1] + $identity, ], 'job-payload'); $notApplied = new ReflectionMethod( CloudOperationRecoveryService::class, 'assertNotAppliedOperationIdentity' ); $notApplied->invoke(null, $job, [ 'operation_id' => $operationId, 'status' => 'failed', 'effect_may_have_applied' => false, 'safe_to_resubmit' => true, 'error_code' => 'network_not_committed', 'result' => null, ] + $identity); $event = new CloudAgentCompletionEvent(); $event->operation_id = $operationId; $event->outcome = 'failed'; $event->effect_may_have_applied = 0; $event->safe_to_resubmit = 1; $event->error_code = 'network_not_committed'; $event->result_json = json_encode([ 'schema' => 'virt_cloud_completion_event', 'version' => 1, 'identity' => $identity, 'result' => ['public_ip_cidr' => '203.0.113.10/24'], ], JSON_THROW_ON_ERROR); $lateOperation = new ReflectionMethod( CloudOperationRecoveryService::class, 'lateReceiptOperation' ); $rebuilt = $lateOperation->invoke(null, $job, $event, 'not_applied'); $assert($rebuilt === CloudOperationCompletionService::operation($event) && ($rebuilt['safe_to_resubmit'] ?? null) === true && ($rebuilt['error_code'] ?? null) === 'network_not_committed', 'Late receipt recovery replaced the exact kind-specific Agent result.'); $preparedMarker = new ReflectionMethod( CloudOperationRecoveryService::class, 'preparedMarker' ); $baseOperation = [ 'operation_id' => $operationId, 'status' => 'succeeded', 'effect_may_have_applied' => false, 'safe_to_resubmit' => false, 'error_code' => '', 'result' => ['snapshot_key' => str_repeat('b', 32), 'deleted' => true], ]; $otherOperation = $baseOperation; $otherOperation['result']['snapshot_key'] = str_repeat('c', 32); $source = 'automatic_applied_succeeded_nofence:' . str_repeat('d', 64); $assert($preparedMarker->invoke(null, $baseOperation, $source) !== $preparedMarker->invoke(null, $otherOperation, $source), 'Prepared evidence ignored a non-settings ledger result field.'); $payloadJob = new CloudJob(); $payloadJob->kind = 'network_change'; $payloadJob->phase = 'terminal'; $payloadJob->effect_resolution = 'applied'; $payloadJob->sealed_payload = CloudSecrets::encrypt([ 'body' => ['hostname' => 'vm.example'], 'credential' => ['password' => 'never-persist'], '_operation_identity' => ['version' => 1] + $identity, '_operation_recovery' => [ 'operation' => $baseOperation, 'resolution' => 'applied', ], ], 'job-payload'); $finalizedPayload = new ReflectionMethod( CloudOperationRecoveryService::class, 'finalizedRecoveryPayload' ); $clean = CloudSecrets::decrypt( $finalizedPayload->invoke(null, $payloadJob), 'job-payload' ); $assert(!array_key_exists('_operation_recovery', $clean) && !array_key_exists('credential', $clean) && ($clean['body']['hostname'] ?? null) === 'vm.example', 'Recovery commit retained prepared evidence or a credential.'); echo "Cloud operation recovery policy contract passed.\n"; }