package com.correx.core.kernel.orchestration

import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertFalse
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Test

class StageCheckpointReconcilerTest {

    @Test
    fun `all expected produced - passed with no missing`() {
        val cp = StageCheckpointReconciler.reconcile(
            expected = setOf("plan.json", "diff.patch"),
            produced = setOf("plan.json", "diff.patch"),
        )
        assertTrue(cp.passed)
        assertTrue(cp.missing.isEmpty())
    }

    @Test
    fun `one missing - not passed with correct missing set`() {
        val cp = StageCheckpointReconciler.reconcile(
            expected = setOf("plan.json", "diff.patch"),
            produced = setOf("plan.json"),
        )
        assertFalse(cp.passed)
        assertEquals(setOf("diff.patch"), cp.missing)
    }

    @Test
    fun `empty expected - passed`() {
        val cp = StageCheckpointReconciler.reconcile(
            expected = emptySet(),
            produced = setOf("plan.json"),
        )
        assertTrue(cp.passed)
        assertTrue(cp.missing.isEmpty())
    }

    @Test
    fun `extra produced beyond expected - still passed`() {
        val cp = StageCheckpointReconciler.reconcile(
            expected = setOf("plan.json"),
            produced = setOf("plan.json", "notes.md", "scratch.txt"),
        )
        assertTrue(cp.passed)
        assertTrue(cp.missing.isEmpty())
    }
}
