import Testing
import Foundation
@testable import 康康

struct ModelManifestTests {

    @Test func llmHasTenFunctionalFiles() {
        #expect(ModelManifest.files(for: .llm).count == 10)
    }

    @Test func vlHasFourteenFunctionalFiles() {
        #expect(ModelManifest.files(for: .vl).count == 14)
    }

    @Test func llmTotalBytesMatchesManifest() {
        #expect(ModelManifest.totalBytes(for: .llm) == 1_749_079_691)
    }

    @Test func vlTotalBytesMatchesManifest() {
        #expect(ModelManifest.totalBytes(for: .vl) == 3_109_729_929)
    }

    @Test func mnnHasSixFunctionalFiles() {
        #expect(ModelManifest.files(for: .mnnLLM).count == 6)
    }

    @Test func mnnTotalBytesMatchesManifest() {
        #expect(ModelManifest.totalBytes(for: .mnnLLM) == 1_185_759_005)
    }

    @Test func mnnHasEssentialRuntimeFiles() {
        let names = ModelManifest.files(for: .mnnLLM).map(\.path)
        #expect(names.contains("config.json"))
        #expect(names.contains("llm.mnn"))
        #expect(names.contains("llm.mnn.weight"))
        #expect(names.contains("tokenizer.txt"))
    }

    @Test func mnnFileURLUsesRepoPath() {
        let file = ModelFile(path: "config.json", bytes: 652)
        let url = ModelManifest.fileURL(for: .mnnLLM, file: file)
        #expect(url.absoluteString == "https://file.myv0.com/Qwen3.5-2B-MNN/config.json")
    }

    @Test func excludesReadmeAndGitattributes() {
        for kind in [ModelKind.llm, .vl] {
            let names = ModelManifest.files(for: kind).map(\.path)
            #expect(!names.contains("README.md"))
            #expect(!names.contains(".gitattributes"))
        }
    }

    @Test func includesEssentialFiles() {
        let llm = ModelManifest.files(for: .llm).map(\.path)
        #expect(llm.contains("config.json"))
        #expect(llm.contains("model.safetensors"))
        #expect(llm.contains("tokenizer.json"))

        let vl = ModelManifest.files(for: .vl).map(\.path)
        #expect(vl.contains("preprocessor_config.json"))  // VL 拍照识别必需
        #expect(vl.contains("model.safetensors"))
    }

    @Test func fileURLIsBaseSlashRepoSlashPath() {
        let file = ModelFile(path: "config.json", bytes: 3_113)
        let url = ModelManifest.fileURL(for: .llm, file: file)
        #expect(url.absoluteString == "https://file.myv0.com/Qwen3.5-2B-4bit/config.json")
    }
}
