import com.correx.core.journal.ProjectMemoryDistiller
import com.correx.core.journal.model.DecisionJournalState
import com.correx.core.journal.model.DecisionKind
import com.correx.core.journal.model.DecisionRecord
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Test

class ProjectMemoryDistillerTest {

    @Test
    fun `distils records into repo-namespaced lines`() {
        val state = DecisionJournalState(
            records = listOf(
                DecisionRecord(1, DecisionKind.STEERING, "User steering: use jwt"),
                DecisionRecord(2, DecisionKind.TRANSITION, "Advanced plan → impl (t1)"),
            ),
        )
        val lines = ProjectMemoryDistiller().distill(state, "/home/me/repo")

        assertEquals(2, lines.size)
        assertEquals("[/home/me/repo] [STEERING] User steering: use jwt", lines[0])
        assertTrue(lines[1].startsWith("[/home/me/repo] [TRANSITION]"))
    }

    @Test
    fun `keepLast bounds the distilled output`() {
        val records = (1..50).map { DecisionRecord(it.toLong(), DecisionKind.ARTIFACT, "v$it") }
        val lines = ProjectMemoryDistiller(keepLast = 10).distill(DecisionJournalState(records), "/r")

        assertEquals(10, lines.size)
        assertTrue(lines.last().contains("v50"))
        assertTrue(lines.first().contains("v41"))
    }
}
