package com.correx.core.kernel.orchestration

import com.correx.core.context.model.EntryRole
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertNull
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Test

class RemainingDeltaEntryTest {

    @Test
    fun `empty failing set yields no entry (list empty means done)`() {
        assertNull(buildRemainingDeltaEntry(emptyList()))
    }

    @Test
    fun `entry lists each failing assertion as an unchecked forward item`() {
        val entry = buildRemainingDeltaEntry(
            listOf(
                Triple("frontend/src/views/TaskView.tsx", "exports_default_component", "no default export"),
                Triple("frontend/src/views/SessionView.tsx", "exports_default_component", "no default export"),
            ),
        )!!
        assertEquals("remainingDelta", entry.sourceType)
        // #312: USER, not SYSTEM — it is recomputed every turn a write lands, so it must stay out
        // of the cached system prefix, and PromptRenderer routes it to the trailing slot.
        assertEquals(EntryRole.USER, entry.role)
        // Forward-looking framing, not a history of what was done.
        assertTrue(entry.content.contains("Remaining to finish this stage"))
        assertTrue(entry.content.contains("- [ ] frontend/src/views/TaskView.tsx — exports_default_component"))
        assertTrue(entry.content.contains("SessionView.tsx"))
        // Must state that re-reading doesn't change it — the spiral-starver.
        assertTrue(entry.content.contains("re-reading files does NOT change it", ignoreCase = true))
    }
}
