package com.correx.core.kernel.orchestration

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

class PackageNotFoundAdvisoryTest {

    @Test
    fun `npm quoted-spec 404 names the scoped package without its version`() {
        val out = "npm error code E404\nnpm error 404  '@types/vite@^4.0.0' is not in this registry."
        val advisory = packageNotFoundAdvisory(out)
        assertTrue(advisory.contains("'@types/vite'"), advisory)
        assertTrue(advisory.contains("Edit the manifest"), advisory)
    }

    @Test
    fun `npm GET-url 404 decodes the scope slash`() {
        val out = "npm error 404 Not Found - GET https://registry.npmjs.org/@types%2fvite - Not found"
        assertTrue(packageNotFoundAdvisory(out).contains("'@types/vite'"))
    }

    @Test
    fun `pnpm registry 404 names the package`() {
        val out = "ERR_PNPM_FETCH_404  GET https://registry.npmjs.org/leftpad-nope: Not Found - 404"
        assertTrue(packageNotFoundAdvisory(out).contains("'leftpad-nope'"))
    }

    @Test
    fun `unrelated failures produce no advisory`() {
        assertTrue(packageNotFoundAdvisory("tsc: type error in App.tsx").isEmpty())
        assertTrue(packageNotFoundAdvisory("npm warn deprecated foo@1.0.0").isEmpty())
    }
}
