import com.correx.core.context.builder.DefaultContextPackBuilder
import com.correx.core.context.compression.DefaultContextCompressor
import com.correx.core.context.model.ContextEntry
import com.correx.core.context.model.ContextLayer
import com.correx.core.context.model.TokenBudget
import com.correx.core.events.types.ContextEntryId
import com.correx.core.events.types.ContextPackId
import com.correx.core.events.types.SessionId
import com.correx.core.events.types.StageId
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Test

class DecisionJournalPinningTest {

    private val compressor = DefaultContextCompressor()
    private val builder = DefaultContextPackBuilder(compressor)

    private val sessionId = SessionId("s1")
    private val stageId = StageId("stage-1")
    private val packId = ContextPackId("pack-1")

    @Test
    fun `decisionJournal entry survives an under-budget build`() = kotlinx.coroutines.runBlocking {
        val entries = listOf(
            ContextEntry(
                id = ContextEntryId("journal-1"),
                layer = ContextLayer.L1,
                content = "Decision: approved plan",
                sourceType = "decisionJournal",
                sourceId = "journal-1",
                tokenEstimate = 100
            )
        )
        val pack = builder.build(packId, sessionId, stageId, entries, TokenBudget(limit = 10))
        val allRetained = pack.layers.values.flatten()
        assertTrue(
            allRetained.any { it.sourceType == "decisionJournal" },
            "decisionJournal entry must be retained even when budget is exceeded"
        )
        Unit
    }
}
