{
  "filename": "src/main/kotlin/example/ReceiptQueue.kt",
  "rule": "- name: receipt-queue-bounded\n  where: \"src/main/kotlin/example/ReceiptQueue.kt\"\n  ensure: >-\n    The ReceiptJob channel must have a finite capacity, not Channel.UNLIMITED, so overload is rejected rather than retained without bound.",
  "corrected": "package example\nimport kotlinx.coroutines.CoroutineScope\nimport kotlinx.coroutines.channels.Channel\nimport kotlinx.coroutines.async\n\ndata class ReceiptJob(val orderId: Long, val tenantId: String)\n\nclass ReceiptQueue(scope: CoroutineScope, send: suspend (ReceiptJob) -> Unit) {\n    private val jobs = Channel<ReceiptJob>(capacity = 64)\n    private val worker = scope.async {\n        for (job in jobs) send(job)\n    }\n    fun offer(job: ReceiptJob): Boolean = jobs.trySend(job).isSuccess\n    suspend fun close() {\n        jobs.close()\n        worker.await()\n    }\n}\n",
  "broken": "package example\nimport kotlinx.coroutines.CoroutineScope\nimport kotlinx.coroutines.channels.Channel\nimport kotlinx.coroutines.async\n\ndata class ReceiptJob(val orderId: Long, val tenantId: String)\n\nclass ReceiptQueue(scope: CoroutineScope, send: suspend (ReceiptJob) -> Unit) {\n    private val jobs = Channel<ReceiptJob>(capacity = Channel.UNLIMITED)\n    private val worker = scope.async {\n        for (job in jobs) send(job)\n    }\n    fun offer(job: ReceiptJob): Boolean = jobs.trySend(job).isSuccess\n    suspend fun close() {\n        jobs.close()\n        worker.await()\n    }\n}\n",
  "regression": [
    "Channel<ReceiptJob>(capacity = 64)",
    "Channel<ReceiptJob>(capacity = Channel.UNLIMITED)"
  ],
  "test_scenarios": [
    [
      "Queue has capacity",
      "Job accepted"
    ],
    [
      "64 pending jobs and blocked worker",
      "Next offer returns false"
    ],
    [
      "Shutdown requested",
      "Channel closes and worker is joined"
    ],
    [
      "Delivery throws",
      "Failure is observable; retry policy decides recovery"
    ]
  ],
  "test_source": null,
  "test_command": "./gradlew test --tests example.ReceiptQueueTest"
}