31622400", "!is_bool(\$notify)", "'/^[a-f0-9]{64}\$/D'", "'/^[a-z0-9][a-z0-9._:-]{0,127}\$/D'", 'mb_strlen($reason) > 500', "(\$startsAt === null) !== (\$endsAt === null)", "\$endsAt <= \$startsAt", ] as $validationContract) { $assert(str_contains($service, $validationContract), 'Request validation lost contract: ' . $validationContract); } foreach ([ "hash('sha256', self::json(\$request))", "'requested_by_user_id', \$actorId", "'request_idempotency_key', \$idempotencyKey", "hash_equals((string) \$batch->request_fingerprint, \$fingerprint)", "'幂等键已用于其他实例补偿请求'", ] as $idempotencyContract) { $assert(str_contains($service, $idempotencyContract), 'Idempotency contract is missing: ' . $idempotencyContract); } $previewPosition = strpos($service, '$plan = $this->planner->preview('); $digestPosition = strpos($service, "!hash_equals(\n \$request['audience_digest']"); $batchSavePosition = strpos($service, '$batch->save();'); $assert($previewPosition !== false && $digestPosition !== false && $batchSavePosition !== false && $previewPosition < $digestPosition && $digestPosition < $batchSavePosition, 'Audience digest must be recalculated and checked before freezing a batch.'); $assert(str_contains($service, "'受影响实例或服务周期已变化,请重新预览后再补偿'"), 'Audience drift no longer has a stable conflict response.'); foreach ([ "CloudServiceCompensationItem::where(\n 'incident_key', \$request['incident_key']", "->whereIn('instance_id', \$instanceIds)->exists()", "'同一事故已经包含这些实例,不能重复补偿'", ] as $incidentContract) { $assert(str_contains($service, $incidentContract), 'Incident overlap contract is missing: ' . $incidentContract); } $incidentWhere = strpos($service, "'incident_key', \$request['incident_key']"); $incidentOverlap = strpos($service, "->whereIn('instance_id', \$instanceIds)"); $incidentConflict = strpos($service, "'同一事故已经包含这些实例,不能重复补偿'"); $assert($incidentWhere !== false && $incidentOverlap !== false && $incidentConflict !== false && $incidentWhere < $incidentOverlap && $incidentOverlap < $incidentConflict, 'Incident-key conflicts must be narrowed to overlapping instances.'); foreach ([ "->count() !== (int) \$batch->instance_count", "'实例补偿明细冻结不完整'", "\$items->count() !== (int) \$batch->instance_count", "\$batch->state = 'attention'", "\$batch->last_error_code = 'item_catalog_incomplete'", ] as $catalogContract) { $assert(str_contains($service, $catalogContract), 'Frozen-item catalog contract is missing: ' . $catalogContract); } foreach ([ "\$open = \$count('pending') + \$count('applying') + \$count('deferred')", "\$applied = \$count('applied')", "\$rejected = \$count('rejected') + \$count('cancelled')", "\$attention = \$count('attention')", "\$batch->state = 'completed'", "\$batch->state = 'partial'", "\$batch->last_error_code = 'item_attention'", "'终态补偿批次不能重新进入执行状态'", ] as $projectionContract) { $assert(str_contains($service, $projectionContract), 'Batch-state projection lost contract: ' . $projectionContract); } $assert(substr_count($catalog, "'service_compensation'") >= 2, 'Service compensation must be registered in labels and instance logs.'); $assert(str_contains($catalog, "'service_compensation' => '实例可用时间补偿'"), 'Service-compensation task label is missing.'); echo "Service compensation service contracts passed.\n";