package com.correx.core.config

import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue

class WorkspaceConfigTest {

    @Test
    fun `defaults when keys absent`() {
        val tools = ToolsConfig()
        assertEquals("", tools.workspaceRoot)
        assertTrue(tools.privilegedLocations.contains("/etc"))
        assertTrue(tools.privilegedLocations.contains("/usr"))
    }

    @Test
    fun `default privileged locations includes system paths`() {
        val defaults = ToolsConfig.DEFAULT_PRIVILEGED_LOCATIONS
        assertTrue(defaults.contains("/etc"))
        assertTrue(defaults.contains("/usr"))
        assertTrue(defaults.contains("/bin"))
        assertTrue(defaults.contains("/root"))
    }

    @Test
    fun `parseToml parses workspace_root from tools section`() {
        val toml = """
            [tools]
            workspace_root = "/my/workspace"
            privileged_locations = ["/etc", "/usr", "/custom"]
        """.trimIndent()

        val parseTomlMethod = ConfigLoader::class.java.getDeclaredMethod("parseToml", String::class.java)
        parseTomlMethod.isAccessible = true
        val result = parseTomlMethod.invoke(ConfigLoader, toml) as CorrexConfig

        assertEquals("/my/workspace", result.tools.workspaceRoot)
        assertEquals(listOf("/etc", "/usr", "/custom"), result.tools.privilegedLocations)
    }

    @Test
    fun `parseToml uses default privileged locations when key absent`() {
        val toml = """
            [tools]
            workspace_root = "/x"
        """.trimIndent()

        val parseTomlMethod = ConfigLoader::class.java.getDeclaredMethod("parseToml", String::class.java)
        parseTomlMethod.isAccessible = true
        val result = parseTomlMethod.invoke(ConfigLoader, toml) as CorrexConfig

        assertEquals(ToolsConfig.DEFAULT_PRIVILEGED_LOCATIONS, result.tools.privilegedLocations)
    }
}
