package wang.yaojia.webterm.wiring

import kotlinx.coroutines.test.runTest
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
import wang.yaojia.webterm.hostregistry.Host
import wang.yaojia.webterm.hostregistry.InMemoryHostStore

/**
 * The [DefaultColdStartPolicy] routing rule (plan §5 A29 Verify): the FIRST cold-launch destination is
 * derived from persisted host presence ALONE — no paired host → [ColdStartRoute.PAIRING], at least one →
 * [ColdStartRoute.SESSIONS]. The "continue-last-session" banner is layered on top of a SESSIONS landing
 * (A29), so the policy itself only chooses pairing-vs-sessions. Pure JVM over [InMemoryHostStore].
 */
class ColdStartPolicyTest {

    private fun host(id: String): Host =
        Host.create(id = id, name = "dev", baseUrl = "http://localhost:3000")!!

    @Test
    fun `no paired host routes to pairing`() = runTest {
        val policy = DefaultColdStartPolicy(InMemoryHostStore())

        assertEquals(ColdStartRoute.PAIRING, policy.initialRoute())
    }

    @Test
    fun `a paired host routes to sessions`() = runTest {
        val policy = DefaultColdStartPolicy(InMemoryHostStore(listOf(host("h1"))))

        assertEquals(ColdStartRoute.SESSIONS, policy.initialRoute())
    }
}
