instance ->') && str_contains($apply, '->lockForUpdate()->first();'), 'The canonical compensation lock order is no longer explicit.'); $assert(substr_count($apply, "->orderByDesc('ends_at')") >= 2 && substr_count($apply, "->orderByDesc('id')") >= 2 && str_contains($apply, "'service_period_changed'"), 'Compensation no longer revalidates the latest tail service period.'); foreach ([ 'CloudInstanceMigrationService::hasOpenMigration(', 'CloudJobService::blockingQueryForInstance(', "'finalization_incident'", "'instance_operation_open'", "'instance_operation_uncertain'", 'CloudJobService::blockingQueryForInvoice(', "['creating', 'pending']", "['failed', 'expired', 'not_created']", "'renewal_payment_open'", "'renewal_payment_uncertain'", ] as $fence) { $assert(str_contains($source, $fence), 'Compensation execution lost fence: ' . $fence); } $invoiceProjection = strpos($apply, 'reconcileRenewalAfterCompensationLocked('); $trafficProjection = strpos($apply, 'extendEntitlementWindowForCompensationLocked(', (int) $invoiceProjection); $backupProjection = $trafficProjection === false ? false : strpos( $apply, 'extendEntitlementWindowForCompensationLocked(', $trafficProjection + 1 ); $periodSave = strpos($apply, '$lockedPeriod->save();'); $instanceSave = strpos($apply, '$instance->save();'); $audit = strpos($apply, '$job = $this->auditJob('); $itemSave = strpos($apply, '$item->save();', (int) $audit); $recalculate = strpos($apply, '->recalculateLocked($batch, $now);'); $assert($invoiceProjection !== false && $trafficProjection !== false && $backupProjection !== false && $periodSave !== false && $instanceSave !== false && $audit !== false && $itemSave !== false && $recalculate !== false && $invoiceProjection < $trafficProjection && $trafficProjection < $backupProjection && $backupProjection < $periodSave && $periodSave < $instanceSave && $instanceSave < $audit && $audit < $itemSave && $itemSave < $recalculate, 'Commercial projections, core rows and audit do not converge in order.'); $assert(str_contains($apply, "DB::connection('default')->transaction(") && str_contains($apply, "\$item->state = 'applied'") && str_contains($apply, '$item->audit_job_id = (int) $job->id'), 'The atomic compensation transaction lost its applied audit linkage.'); $auditMethod = $section( $source, 'private function auditJob(', 'private function finishLocked(' ); foreach ([ "\$job->kind = 'service_compensation'", "\$job->execution_mode = 'local'", "\$job->host_id = null", 'CloudJobService::completeWithoutDispatchLocked($job, [', "'seconds_added' => (int) \$item->requested_seconds", "'previous_expires_at' => \$oldExpiry", "'new_expires_at' => \$newExpiry", ] as $auditContract) { $assert(str_contains($auditMethod, $auditContract), 'Local audit contract is missing: ' . $auditContract); } $recovery = $section( $source, 'private function recoverAfterApplyError(', 'private function decision(' ); $latest = strpos($recovery, '$latest = CloudServiceCompensationItem::find($itemId);'); $applied = strpos($recovery, "(string) \$latest->state === 'applied'"); $transition = strpos($recovery, 'return $this->transitionClaim('); $assert($latest !== false && $applied !== false && $transition !== false && $latest < $applied && $applied < $transition, 'Error recovery may replay before checking for an already committed item.'); foreach ([ 'public const MAX_ATTEMPTS = 8;', 'public const LEASE_SECONDS = 120;', "->where('attempts', '<', self::MAX_ATTEMPTS)", "? 'retry_exhausted' : 'worker_lease_expired'", "'deferred', 'rejected', 'attention'", 'min(3600, 30 * (2 ** max(0, min(7, $attempts - 1))))', ] as $leaseContract) { $assert(str_contains($source, $leaseContract), 'Bounded retry contract is missing: ' . $leaseContract); } $assert(!str_contains($source, 'new CloudTrafficEntitlement') && !str_contains($source, 'new CloudBackupPeriodEntitlement') && !str_contains($source, 'new CloudBackupSubscription') && !str_contains($source, 'granted_bytes =') && !str_contains($source, 'traffic_quota_bytes =') && !str_contains($source, '->money =') && !str_contains($source, 'Wallet'), 'Compensation execution may grant traffic/backup cover or mutate wallet.'); echo "Service compensation execution contracts passed.\n";