package com.correx.core.validation.artifact

import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonObject
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test

class ArtifactFailureTest {

    private fun obj(json: String) = Json.parseToJsonElement(json) as JsonObject

    @Test
    fun `unquoted-but-repairable never reaches here — unparsed is FORMATTING`() {
        assertEquals(ArtifactFailure.FORMATTING, classify("not json at all", null, emptyList()))
    }

    @Test
    fun `missing required field is MISSING_INFO`() {
        assertEquals(
            ArtifactFailure.MISSING_INFO,
            classify("{}", obj("""{"path":"a"}"""), listOf("missing required property 'content'")),
        )
    }

    @Test
    fun `wrong shape without missing-required is SCHEMA`() {
        assertEquals(
            ArtifactFailure.SCHEMA,
            classify("{}", obj("""{"path":1}"""), listOf("property 'path': expected string, got primitive")),
        )
    }

    @Test
    fun `path traversal is UNSAFE and wins over other signals`() {
        assertEquals(
            ArtifactFailure.UNSAFE,
            classify("{}", obj("""{"path":"../../etc/passwd"}"""), listOf("missing required property 'content'")),
        )
    }
}
