Skip to content

armgit / ODS

Public Imported from GitHub
0

ODS V3 Pre-Release: Public testing and refinement ahead of the official V3 launch. Turn your PC, Mac, or Linux box into a private AI server.

57.4 KB
Raw Blame
import importlib.util
import json
from pathlib import Path


ROOT = Path(__file__).resolve().parents[1]
CATALOG = ROOT / "config" / "model-library.json"
HERMES_CONTEXT_FLOOR = 65536


def _download_artifacts(model):
    parts = model.get("gguf_parts")
    if isinstance(parts, list) and parts:
        return parts
    return [{
        "file": model.get("gguf_file"),
        "url": model.get("gguf_url"),
        "sha256": model.get("gguf_sha256"),
        "size_bytes": model.get("size_bytes"),
        "size_mb": model.get("size_mb"),
    }]


BLOCKING_AGENT_STATUSES = {
    "blocked",
    "incompatible",
    "not_agent_viable",
    "not_recommended",
    "not_supported",
    "unsupported",
    "unsupported_until_revalidated",
}


def _has_runtime_scope(entry):
    return any(
        key in entry
        for key in {
            "gpuBackendScope",
            "gpu_backend_scope",
            "llmBackendScope",
            "llm_backend_scope",
            "runtimeScope",
            "runtime_scope",
            "odsModeScope",
            "ods_mode_scope",
        }
    )


def _agent_viable_for_release(model, host=None):
    if str(model.get("source") or "").strip().lower() not in {"", "curated"}:
        return False
    compatibility = model.get("app_compatibility") or {}
    for key, entry in compatibility.items():
        # Pixel has a stricter real tool-loop verdict and its own selector.
        # Generic release viability remains the app/Talk compatibility view.
        if key == "pixel_agent":
            continue
        entry = entry or {}
        status = str((entry or {}).get("status") or "").strip().lower()
        if status not in BLOCKING_AGENT_STATUSES or _has_runtime_scope(entry):
            continue
        host_scope = entry.get("hostScope") or entry.get("host_scope")
        if host_scope:
            scoped_hosts = {str(value).strip().lower() for value in host_scope}
            if host is not None and str(host).strip().lower() in scoped_hosts:
                return False
            continue
        return False
    return True


def test_low_vram_catalog_has_six_agent_viable_downloadable_models():
    catalog = json.loads(CATALOG.read_text(encoding="utf-8"))
    models = catalog["models"]
    low_vram = [
        model
        for model in models
        # vLLM entries need a large NVIDIA GPU (min_gpu_mib) and download a
        # snapshot, not a GGUF; they are never low-VRAM downloads.
        if model.get("runtime") != "vllm"
        and int(model.get("vram_required_gb") or 0) <= 8
        and int(model.get("context_length") or 0) >= HERMES_CONTEXT_FLOOR
        and _agent_viable_for_release(model)
    ]

    assert len(low_vram) >= 6

    for model in low_vram:
        artifacts = _download_artifacts(model)
        assert artifacts, model["id"]
        for artifact in artifacts:
            assert artifact.get("file"), model["id"]
            assert str(artifact.get("url") or "").startswith("https://huggingface.co/"), model["id"]
            assert len(str(artifact.get("sha256") or "")) == 64, model["id"]
            assert int(artifact.get("size_bytes") or artifact.get("size_mb") or 0) > 0, model["id"]


def test_huggingface_import_is_not_agent_viable_for_release():
    assert not _agent_viable_for_release({"source": "huggingface"})


def test_release_model_switchboard_catalog_ids_exist():
    expected = {
        "phi4-mini-q4",
        "phi3.5-mini-q4",
        "qwen2.5-0.5b-instruct-q4",
        "qwen2.5-1.5b-instruct-q4",
        "granite3.3-2b-instruct-q4",
        "smollm3-3b-q4",
        "granite4.0-h-1b-q4",
        "falcon-h1-1.5b-instruct-q4",
        "falcon-h1-3b-instruct-q4",
        "nvidia-nemotron3-nano-4b-q4",
        "granite4.0-1b-q4",
        "granite4.0-h-350m-q4",
        "granite3.2-2b-instruct-q4",
        "granite3.1-2b-instruct-q4",
        "phi3-mini-128k-q4",
        "ministral3-8b-instruct-2512-q4",
        "llama3.2-1b-instruct-q4",
        "llama3.2-3b-instruct-q4",
        "qwen2.5-3b-instruct-q4",
        "qwen3-4b-q4",
        "qwen3-4b-instruct-2507-q4",
        "qwen3-4b-128k-q4",
        "qwen3-1.7b-q4",
        "qwen2.5-coder-1.5b-128k-q4",
        "qwen2.5-coder-3b-128k-q4",
        "qwen2.5-7b-instruct-q4",
        "llama3.1-8b-instruct-q4",
        "granite3.3-8b-instruct-q4",
        "mistral-nemo-12b-instruct-q4",
    }
    catalog = json.loads(CATALOG.read_text(encoding="utf-8"))
    ids = {model["id"] for model in catalog["models"]}

    assert expected <= ids


def test_llama32_1b_is_not_agent_viable_until_revalidated():
    catalog = json.loads(CATALOG.read_text(encoding="utf-8"))
    by_id = {model["id"]: model for model in catalog["models"]}
    compatibility = by_id["llama3.2-1b-instruct-q4"]["app_compatibility"]

    assert compatibility["agent_viability"]["status"] == "not_agent_viable"
    assert "cycle-004" in compatibility["agent_viability"]["evidence"]
    assert compatibility["hermes_talk"]["status"] == "unsupported_until_revalidated"
    assert not _agent_viable_for_release(by_id["llama3.2-1b-instruct-q4"])


def test_llama32_3b_is_not_agent_viable_until_revalidated():
    catalog = json.loads(CATALOG.read_text(encoding="utf-8"))
    by_id = {model["id"]: model for model in catalog["models"]}
    compatibility = by_id["llama3.2-3b-instruct-q4"]["app_compatibility"]

    assert compatibility["agent_viability"]["status"] == "not_agent_viable"
    assert compatibility["agent_viability"]["evidence"]
    assert compatibility["hermes_talk"]["status"] == "unsupported_until_revalidated"
    assert not _agent_viable_for_release(by_id["llama3.2-3b-instruct-q4"])


def test_phi4_mini_talk_pass_does_not_mask_later_strixy_pixel_failure():
    catalog = json.loads(CATALOG.read_text(encoding="utf-8"))
    by_id = {model["id"]: model for model in catalog["models"]}
    compatibility = by_id["phi4-mini-q4"]["app_compatibility"]

    assert compatibility["openai_chat"]["status"] == "verified"
    assert "42b3a95c" in compatibility["openai_chat"]["reason"]
    assert compatibility["agent_viability"]["status"] == "unsupported_until_revalidated"
    assert compatibility["agent_viability"]["hostScope"] == ["strixy"]
    assert "cycle-005/strixy-wsl-beta/model-ui.json" in compatibility["agent_viability"]["evidence"]
    assert compatibility["agent_viability"]["productSha"] == "e4fd1cae6232af0a9d7438317002b55f94bea2bc"
    assert compatibility["agent_viability"]["harnessSha"] == "30430271ba0b97c83056272a4f4877cb65dee122"
    assert compatibility["pixel_agent"]["status"] == "unsupported_until_revalidated"
    assert compatibility["pixel_agent"]["hostScope"] == ["strixy"]
    assert "dropped the leading O" in compatibility["pixel_agent"]["reason"]
    assert compatibility["open_webui"]["status"] == "unsupported_until_revalidated"
    assert compatibility["open_webui"]["hostScope"] == ["strixy"]
    assert "verification digit" in compatibility["open_webui"]["reason"]
    assert compatibility["hermes_talk"]["status"] == "verified"
    assert compatibility["hermes_talk"]["hostScope"] == ["strixy"]
    assert compatibility["hermes_talk"]["productSha"] == "e4fd1cae6232af0a9d7438317002b55f94bea2bc"
    assert compatibility["hermes_talk"]["harnessSha"] == "30430271ba0b97c83056272a4f4877cb65dee122"


def test_qwen35_9b_open_webui_is_revalidated_on_strixy():
    catalog = json.loads(CATALOG.read_text(encoding="utf-8"))
    by_id = {model["id"]: model for model in catalog["models"]}
    compatibility = by_id["qwen3.5-9b-q4"]["app_compatibility"]

    assert compatibility["open_webui"]["status"] == "verified"
    assert compatibility["open_webui"]["hostScope"] == ["strixy"]
    assert "cycle-006/strixy-wsl-beta/model-ui.json" in compatibility["open_webui"]["evidence"]
    assert compatibility["open_webui"]["productSha"] == "e4fd1cae6232af0a9d7438317002b55f94bea2bc"
    assert compatibility["open_webui"]["harnessSha"] == "30430271ba0b97c83056272a4f4877cb65dee122"


def test_phi3_mini_128k_requires_perplexica_revalidation_after_strixy_failure():
    catalog = json.loads(CATALOG.read_text(encoding="utf-8"))
    by_id = {model["id"]: model for model in catalog["models"]}
    compatibility = by_id["phi3-mini-128k-q4"]["app_compatibility"]

    assert compatibility["agent_viability"]["status"] == "not_agent_viable"
    assert "tower2" in compatibility["agent_viability"]["hostScope"]
    assert "cycle-006" in compatibility["agent_viability"]["evidence"]
    assert compatibility["hermes_talk"]["status"] == "unsupported_until_revalidated"
    assert "generic assistant greeting" in compatibility["hermes_talk"]["reason"]
    assert compatibility["perplexica"]["status"] == "unsupported_until_revalidated"
    assert "hostScope" not in compatibility["perplexica"]
    assert "strixy" in compatibility["perplexica"]["reason"].lower()
    assert "apology prose" in compatibility["perplexica"]["reason"]
    assert "cycle-006/strixy" in compatibility["perplexica"]["evidence"]
    assert not _agent_viable_for_release(by_id["phi3-mini-128k-q4"])


def test_llama31_8b_is_not_agent_viable_until_revalidated():
    catalog = json.loads(CATALOG.read_text(encoding="utf-8"))
    by_id = {model["id"]: model for model in catalog["models"]}
    compatibility = by_id["llama3.1-8b-instruct-q4"]["app_compatibility"]

    assert compatibility["agent_viability"]["status"] == "not_agent_viable"
    assert compatibility["agent_viability"]["evidence"]
    assert compatibility["hermes_talk"]["status"] == "unsupported_until_revalidated"
    assert compatibility["hermes_talk"]["evidence"]
    assert not _agent_viable_for_release(by_id["llama3.1-8b-instruct-q4"])


def test_phi35_mini_requires_perplexica_revalidation_globally_and_runtime_revalidation_on_windows():
    catalog = json.loads(CATALOG.read_text(encoding="utf-8"))
    by_id = {model["id"]: model for model in catalog["models"]}
    compatibility = by_id["phi3.5-mini-q4"]["app_compatibility"]

    assert compatibility["openai_chat"]["status"] == "unsupported_until_revalidated"
    assert compatibility["openai_chat"]["evidence"]
    assert compatibility["perplexica"]["status"] == "unsupported_until_revalidated"
    assert compatibility["perplexica"]["globalScope"] is True
    assert "tower2" in compatibility["perplexica"]["reason"]
    assert "strix-halo" in compatibility["perplexica"]["reason"]
    assert "cycle-001/{tower2,strix-halo}" in compatibility["perplexica"]["evidence"]
    assert not _agent_viable_for_release(by_id["phi3.5-mini-q4"])
    assert not _agent_viable_for_release(by_id["phi3.5-mini-q4"], host="windows-laptop")


def test_qwen25_15b_is_not_agent_viable_until_revalidated():
    catalog = json.loads(CATALOG.read_text(encoding="utf-8"))
    by_id = {model["id"]: model for model in catalog["models"]}
    compatibility = by_id["qwen2.5-1.5b-instruct-q4"]["app_compatibility"]

    assert compatibility["agent_viability"]["status"] == "not_agent_viable"
    assert compatibility["agent_viability"]["evidence"]
    assert compatibility["hermes_talk"]["status"] == "unsupported_until_revalidated"
    assert not _agent_viable_for_release(by_id["qwen2.5-1.5b-instruct-q4"])


def test_qwen25_05b_is_not_agent_viable_until_revalidated():
    catalog = json.loads(CATALOG.read_text(encoding="utf-8"))
    by_id = {model["id"]: model for model in catalog["models"]}
    compatibility = by_id["qwen2.5-0.5b-instruct-q4"]["app_compatibility"]

    assert compatibility["agent_viability"]["status"] == "not_agent_viable"
    assert "cycle-003" in compatibility["agent_viability"]["evidence"]
    assert compatibility["hermes_talk"]["status"] == "unsupported_until_revalidated"
    assert not _agent_viable_for_release(by_id["qwen2.5-0.5b-instruct-q4"])


def test_qwen25_3b_runtime_context_conflict_blocks_agent_coverage():
    catalog = json.loads(CATALOG.read_text(encoding="utf-8"))
    by_id = {model["id"]: model for model in catalog["models"]}

    model = by_id["qwen2.5-3b-instruct-q4"]
    compatibility = model["app_compatibility"]

    assert model["vram_required_gb"] <= 4
    assert model["context_length"] == 32768
    assert compatibility["openai_chat"]["status"] == "verified"
    assert compatibility["agent_viability"]["status"] == "not_agent_viable"
    assert "32,768" in compatibility["agent_viability"]["reason"]
    assert compatibility["hermes_talk"]["status"] == "unsupported_until_revalidated"
    assert not _agent_viable_for_release(model)


def test_granite33_2b_is_not_agent_viable_until_revalidated():
    catalog = json.loads(CATALOG.read_text(encoding="utf-8"))
    by_id = {model["id"]: model for model in catalog["models"]}
    compatibility = by_id["granite3.3-2b-instruct-q4"]["app_compatibility"]

    assert compatibility["agent_viability"]["status"] == "not_agent_viable"
    assert "windows-laptop" in compatibility["agent_viability"]["evidence"]
    assert compatibility["hermes_talk"]["status"] == "unsupported_until_revalidated"
    assert not _agent_viable_for_release(by_id["granite3.3-2b-instruct-q4"])


def test_smollm3_3b_runtime_context_is_64k_and_it_remains_a_revalidation_candidate():
    catalog = json.loads(CATALOG.read_text(encoding="utf-8"))
    by_id = {model["id"]: model for model in catalog["models"]}
    model = by_id["smollm3-3b-q4"]
    compatibility = model["app_compatibility"]

    assert model["context_length"] == 65536
    assert compatibility["openai_chat"]["status"] == "verified"
    assert "58944ba461fb" in compatibility["openai_chat"]["evidence"]
    assert compatibility["hermes_talk"]["status"] == "verified"
    assert compatibility["hermes_talk"]["productSha"] == "58944ba461fb87b87b1ce6fa854e32d15aeb8efa"
    assert compatibility["perplexica"]["status"] == "unsupported_until_revalidated"
    assert "llmBackendScope" not in compatibility["perplexica"]
    assert "hostScope" not in compatibility["perplexica"]
    assert "cycle-003/tower2" in compatibility["perplexica"]["evidence"]
    assert "cycle-003/strix-halo" in compatibility["perplexica"]["evidence"]
    assert "cycle-003/spark" in compatibility["perplexica"]["evidence"]
    assert "cycle-003/m5-mbp" in compatibility["perplexica"]["evidence"]
    assert "cycle-003/windows-laptop" in compatibility["perplexica"]["evidence"]
    assert "cycle-003/strixy" in compatibility["perplexica"]["evidence"]
    assert "agent_viability" not in compatibility
    assert not _agent_viable_for_release(model)


def test_qwen3_4b_128k_talk_block_is_global_after_linux_revalidation():
    catalog = json.loads(CATALOG.read_text(encoding="utf-8"))
    by_id = {model["id"]: model for model in catalog["models"]}
    model = by_id["qwen3-4b-128k-q4"]
    compatibility = model["app_compatibility"]["hermes_talk"]

    assert compatibility["status"] == "unsupported_until_revalidated"
    assert compatibility["globalScope"] is True
    assert "hostScope" not in compatibility
    assert "cycle-006/m5-mbp" in compatibility["evidence"]
    assert "cycle-005/windows-laptop" in compatibility["evidence"]
    assert "cycle-006/tower2" in compatibility["evidence"]
    assert ".MEDIA" in compatibility["reason"]
    assert "180-second" in compatibility["reason"]
    assert "3.9 seconds" in compatibility["reason"]
    assert not _agent_viable_for_release(model)
    assert not _agent_viable_for_release(model, host="m5-mbp")
    assert not _agent_viable_for_release(model, host="windows-laptop")


def test_windows_8gb_revalidation_models_have_64k_compressed_kv_profiles():
    catalog = json.loads(CATALOG.read_text(encoding="utf-8"))
    by_id = {model["id"]: model for model in catalog["models"]}

    # The Qwen3.5 4B gate is 8 GB: it is the 8 GB-card pick below the 9B
    # profile's 15 GB gate, and its checkpoint/cache caps bound host RAM.
    expected = {
        "qwen3-4b-instruct-2507-q4": ("nvidia-8gb-64k-q4-kv", "q4_0", 7.2, 31),
        "qwen3.5-4b-q4": ("nvidia-8gb-64k-q4-kv", "q4_0", 7.2, 8),
    }
    for model_id, (profile_id, cache_type, required_gb, ram_min_gb) in expected.items():
        model = by_id[model_id]
        profiles = {profile["id"]: profile for profile in model["runtime_profiles"]}
        profile = profiles[profile_id]

        assert profile["backend"] == "nvidia"
        assert profile["host_arch"] == ["amd64"]
        assert profile["memory_type"] == "discrete"
        assert profile["vram_min_gb"] == 7.5
        assert profile["vram_max_gb"] == 8.5
        assert profile["system_ram_min_gb"] == ram_min_gb
        assert profile["context_length"] == HERMES_CONTEXT_FLOOR
        assert profile["estimated_required_gb"] == required_gb
        assert profile["env"]["LLAMA_PARALLEL"] == "1"
        assert profile["env"]["LLAMA_ARG_FLASH_ATTN"] == "on"
        assert profile["env"]["LLAMA_ARG_CACHE_TYPE_K"] == cache_type
        assert profile["env"]["LLAMA_ARG_CACHE_TYPE_V"] == cache_type


def test_default_qwen_9b_has_live_proven_64k_and_compatible_32k_runtime_profiles():
    catalog = json.loads(CATALOG.read_text(encoding="utf-8"))
    model = next(model for model in catalog["models"] if model["id"] == "qwen3.5-9b-q4")
    profiles = {profile["id"]: profile for profile in model["runtime_profiles"]}
    profile = profiles["nvidia-8gb-64k-q8-kv"]

    assert profile["backend"] == "nvidia"
    assert profile["host_arch"] == ["amd64"]
    assert profile["memory_type"] == "discrete"
    assert profile["vram_min_gb"] == 7.5
    assert profile["vram_max_gb"] == 8.5
    assert profile["system_ram_min_gb"] == 15
    assert profile["context_length"] == HERMES_CONTEXT_FLOOR
    assert profile["estimated_required_gb"] == 7.2
    assert profile["env"] == {
        "LLAMA_PARALLEL": "1",
        "LLAMA_ARG_FLASH_ATTN": "on",
        "LLAMA_ARG_CACHE_TYPE_K": "q8_0",
        "LLAMA_ARG_CACHE_TYPE_V": "q8_0",
        "LLAMA_SERVER_MEMORY_LIMIT": "12G",
    }

    fallback = profiles["nvidia-8gb-32k-q8-kv"]
    assert fallback["context_length"] == 32768
    assert fallback["estimated_required_gb"] == 6.8


def test_ministral_has_a_constrained_wsl_8gb_runtime_profile():
    catalog = json.loads(CATALOG.read_text(encoding="utf-8"))
    model = next(
        model
        for model in catalog["models"]
        if model["id"] == "ministral3-8b-instruct-2512-q4"
    )
    profiles = {profile["id"]: profile for profile in model["runtime_profiles"]}
    profile = profiles["nvidia-8gb-32k-q8-kv"]

    assert profile["backend"] == "nvidia"
    assert profile["host_arch"] == ["amd64"]
    assert profile["memory_type"] == "discrete"
    assert profile["vram_min_gb"] == 7.5
    assert profile["vram_max_gb"] == 8.5
    assert profile["system_ram_min_gb"] == 15
    assert profile["context_length"] == 32768
    assert profile["estimated_required_gb"] == 6.8
    assert profile["env"] == {
        "LLAMA_PARALLEL": "1",
        "LLAMA_ARG_FLASH_ATTN": "on",
        "LLAMA_ARG_CACHE_TYPE_K": "q8_0",
        "LLAMA_ARG_CACHE_TYPE_V": "q8_0",
        "LLAMA_SERVER_MEMORY_LIMIT": "12G",
    }


def test_windows_8gb_revalidation_models_have_verified_app_evidence():
    catalog = json.loads(CATALOG.read_text(encoding="utf-8"))
    by_id = {model["id"]: model for model in catalog["models"]}
    expected_cycles = {
        "qwen3-4b-instruct-2507-q4": "cycle-001/windows-laptop",
        "qwen3.5-4b-q4": "cycle-002/windows-laptop",
    }

    for model_id, cycle_path in expected_cycles.items():
        compatibility = by_id[model_id]["app_compatibility"]
        for app in ("openai_chat", "hermes_talk", "perplexica", "agent_viability"):
            verdict = compatibility[app]
            assert verdict["status"] == "verified"
            assert verdict["hostScope"] == ["windows-laptop"]
            assert verdict["productSha"] == "449cf84d866d8bdedd8046d3c58faab6c07b5f03"
            assert verdict["harnessSha"] == "954deb755b0730719512ac3675a748474180e01c"
            assert cycle_path in verdict["evidence"]


def test_granite31_requires_global_perplexica_revalidation_after_strixy_failure():
    catalog = json.loads(CATALOG.read_text(encoding="utf-8"))
    by_id = {model["id"]: model for model in catalog["models"]}

    model = by_id["granite3.1-2b-instruct-q4"]
    compatibility = model["app_compatibility"]["perplexica"]

    assert compatibility["status"] == "unsupported_until_revalidated"
    assert "hostScope" not in compatibility
    assert "tower2" in compatibility["reason"]
    assert "strixy" in compatibility["reason"]
    assert "cycle-006/strixy" in compatibility["evidence"]
    assert not _agent_viable_for_release(model)


def test_granite4_h_1b_requires_perplexica_revalidation_after_m5_partial_reply():
    catalog = json.loads(CATALOG.read_text(encoding="utf-8"))
    by_id = {model["id"]: model for model in catalog["models"]}

    model = by_id["granite4.0-h-1b-q4"]
    compatibility = model["app_compatibility"]
    assert model["vram_required_gb"] <= 3
    assert model["context_length"] >= HERMES_CONTEXT_FLOOR
    assert model["gguf_sha256"] == "da3d737121a96f3c9a316685212376257a7f167b74380855666dd488d6af3bcb"
    assert model["gguf_url"].startswith("https://huggingface.co/ibm-granite/granite-4.0-h-1b-GGUF/")
    assert compatibility["perplexica"]["status"] == "unsupported_until_revalidated"
    assert "m5-mbp" in compatibility["perplexica"]["reason"]
    assert "Perplexica" in compatibility["perplexica"]["reason"]
    assert "cycle-003" in compatibility["perplexica"]["evidence"]
    assert _agent_viable_for_release(model)
    assert not _agent_viable_for_release(model, host="m5-mbp")


def test_falcon_h1_15b_is_not_low_vram_agent_viable_after_opencode_failure():
    catalog = json.loads(CATALOG.read_text(encoding="utf-8"))
    by_id = {model["id"]: model for model in catalog["models"]}

    model = by_id["falcon-h1-1.5b-instruct-q4"]
    compatibility = model["app_compatibility"]
    assert model["vram_required_gb"] <= 3
    assert model["context_length"] >= HERMES_CONTEXT_FLOOR
    assert model["gguf_sha256"] == "8b51aa2aa34a0373fd0cd64c02eb91d1bc1da681c09e955ad769d4a9b2d8385f"
    assert model["gguf_url"].startswith("https://huggingface.co/tiiuae/Falcon-H1-1.5B-Instruct-GGUF/")
    assert model["size_bytes"] == 944786656
    assert compatibility["opencode"]["status"] == "unsupported_until_revalidated"
    assert compatibility["agent_viability"]["status"] == "not_agent_viable"
    assert not _agent_viable_for_release(model)


def test_granite32_2b_is_direct_chat_only_after_windows_talk_timeout():
    catalog = json.loads(CATALOG.read_text(encoding="utf-8"))
    by_id = {model["id"]: model for model in catalog["models"]}

    model = by_id["granite3.2-2b-instruct-q4"]
    compatibility = model["app_compatibility"]

    assert compatibility["openai_chat"]["status"] == "verified"
    assert "0.73 tok/s" in compatibility["openai_chat"]["reason"]
    assert compatibility["agent_viability"]["status"] == "not_agent_viable"
    assert "19,349-token Hermes prompt" in compatibility["agent_viability"]["reason"]
    assert compatibility["hermes_talk"]["status"] == "unsupported_until_revalidated"
    assert "cycle-004" in compatibility["hermes_talk"]["evidence"]
    assert compatibility["perplexica"]["hostScope"] == [
        "tower2",
        "m5-mbp",
        "tower3",
        "tower1",
        "mac-mini",
    ]
    assert "release-mac-native-93a2c4bc-h6ab9611-r417" in compatibility["perplexica"]["evidence"]
    assert _agent_viable_for_release(model)
    assert not _agent_viable_for_release(model, host="windows-laptop")
    assert not _agent_viable_for_release(model, host="mac-mini")


def test_granite4_h_tiny_opencode_warning_is_scoped_to_tower1():
    catalog = json.loads(CATALOG.read_text(encoding="utf-8"))
    by_id = {model["id"]: model for model in catalog["models"]}

    model = by_id["granite4.0-h-tiny-q4"]
    opencode = model["app_compatibility"]["opencode"]

    assert opencode["status"] == "unsupported_until_revalidated"
    assert opencode["hostScope"] == ["tower1"]
    assert "cycle-002/tower1/model-ui.json" in opencode["evidence"]
    assert not _agent_viable_for_release(model, host="tower1")
    assert _agent_viable_for_release(model, host="tower3")


def test_granite4_h_tiny_pixel_warning_is_scoped_to_observed_hosts():
    catalog = json.loads(CATALOG.read_text(encoding="utf-8"))
    by_id = {model["id"]: model for model in catalog["models"]}

    model = by_id["granite4.0-h-tiny-q4"]
    pixel = model["app_compatibility"]["pixel_agent"]

    assert pixel["status"] == "unsupported_until_revalidated"
    assert pixel["hostScope"] == ["tower2", "tower3", "windows-laptop"]
    assert "returned delivery instructions" in pixel["reason"]
    assert "cycle-002/tower3/model-ui.json" in pixel["evidence"]
    assert "cycle-003/tower2/model-ui.json" in pixel["evidence"]
    assert "cycle-005/windows-laptop-wsl-beta/model-ui.json" in pixel["evidence"]
    assert pixel["productSha"] == "9381eff2822390ea0dd44f9471f27c5cffb346e4"
    assert pixel["harnessSha"] == "66659802985da37d3289ca33bb815d375b307323"


def test_granite4_h_350m_is_not_agent_viable_after_talk_probe_failure():
    catalog = json.loads(CATALOG.read_text(encoding="utf-8"))
    by_id = {model["id"]: model for model in catalog["models"]}

    model = by_id["granite4.0-h-350m-q4"]
    compatibility = model["app_compatibility"]

    assert model["vram_required_gb"] <= 3
    assert model["context_length"] >= HERMES_CONTEXT_FLOOR
    assert model["gguf_sha256"] == "0a8d6a7373602fadfba274a640ba784b86cc6847f1c67f1b0a90fa2ec266b7fb"
    assert model["gguf_url"].startswith("https://huggingface.co/ibm-granite/granite-4.0-h-350m-GGUF/")
    assert compatibility["agent_viability"]["status"] == "not_agent_viable"
    assert "cycle-005" in compatibility["agent_viability"]["evidence"]
    assert compatibility["hermes_talk"]["status"] == "unsupported_until_revalidated"
    assert not _agent_viable_for_release(model)


def test_replacement_low_vram_long_context_models_are_cataloged_for_validation():
    catalog = json.loads(CATALOG.read_text(encoding="utf-8"))
    by_id = {model["id"]: model for model in catalog["models"]}

    expected = {
        "qwen3-4b-instruct-2507-q4": (
            "https://huggingface.co/unsloth/Qwen3-4B-Instruct-2507-GGUF/",
            "3605803b982cb64aead44f6c1b2ae36e3acdb41d8e46c8a94c6533bc4c67e597",
        ),
        "qwen3-4b-128k-q4": (
            "https://huggingface.co/unsloth/Qwen3-4B-128K-GGUF/",
            "f145a1bd60fec420ca4d9b7645ebcdf657e301463bc4dd3af4a8c0b548b5eb1a",
        ),
        "granite3.1-2b-instruct-q4": (
            "https://huggingface.co/bartowski/granite-3.1-2b-instruct-GGUF/",
            "774269c82fde2720ea18dcf457fb5bd028fe096139a0735f4ad59c0a270cfc9c",
        ),
        "phi3-mini-128k-q4": (
            "https://huggingface.co/QuantFactory/Phi-3-mini-128k-instruct-GGUF/",
            "3b27c1a245243b3eadf6db453ddefd419a31e388820824beeba1c60eee17d05e",
        ),
    }

    for model_id, (url_prefix, sha256) in expected.items():
        model = by_id[model_id]
        assert model["vram_required_gb"] <= 5
        assert model["context_length"] >= HERMES_CONTEXT_FLOOR
        assert model["gguf_sha256"] == sha256
        assert model["gguf_url"].startswith(url_prefix)
        if model_id in {
            "granite3.1-2b-instruct-q4",
            "phi3-mini-128k-q4",
            "qwen3-4b-128k-q4",
        }:
            assert not _agent_viable_for_release(model)
        else:
            assert _agent_viable_for_release(model)


def test_granite33_8b_has_visible_nvidia_8gb_release_profile():
    catalog = json.loads(CATALOG.read_text(encoding="utf-8"))
    by_id = {model["id"]: model for model in catalog["models"]}

    model = by_id["granite3.3-8b-instruct-q4"]
    profiles = {profile["id"]: profile for profile in model["runtime_profiles"]}
    profile = profiles["nvidia-8gb-64k"]

    assert model["gguf_url"].startswith("https://huggingface.co/ibm-granite/granite-3.3-8b-instruct-GGUF/")
    assert model["gguf_sha256"] == "77bcee066a76dcdd10d0d123c87e32c8ec2c74e31b6ffd87ebee49c9ac215dca"
    assert model["size_bytes"] == 4942873344
    assert model["context_length"] == 128000
    assert profile["backend"] == "nvidia"
    assert profile["memory_type"] == "discrete"
    assert profile["vram_min_gb"] == 7.5
    assert profile["vram_max_gb"] == 8.5
    assert profile["context_length"] == HERMES_CONTEXT_FLOOR
    assert profile["estimated_required_gb"] < 8
    compatibility = model["app_compatibility"]
    assert compatibility["agent_viability"]["status"] == "not_agent_viable"
    assert "cycle-006" in compatibility["agent_viability"]["evidence"]
    assert compatibility["hermes_talk"]["status"] == "unsupported_until_revalidated"
    assert not _agent_viable_for_release(model)


def test_granite4_dense_1b_is_direct_chat_only_until_talk_revalidated():
    catalog = json.loads(CATALOG.read_text(encoding="utf-8"))
    by_id = {model["id"]: model for model in catalog["models"]}

    model = by_id["granite4.0-1b-q4"]
    compatibility = model["app_compatibility"]

    assert model["vram_required_gb"] <= 3
    assert model["context_length"] >= HERMES_CONTEXT_FLOOR
    assert model["gguf_sha256"] == "22ec0f9cc99a90185312de3c882c84e7bd6789bdd050389844380a01a831d7f1"
    assert model["gguf_url"].startswith("https://huggingface.co/ibm-granite/granite-4.0-1b-GGUF/")
    assert compatibility["openai_chat"]["status"] == "verified"
    assert "0.93 tok/s" in compatibility["agent_viability"]["reason"]
    assert compatibility["agent_viability"]["status"] == "not_agent_viable"
    assert compatibility["hermes_talk"]["status"] == "unsupported_until_revalidated"
    assert not _agent_viable_for_release(model)


def test_qwen3_4b_is_blocked_after_windows_talk_timeout():
    catalog = json.loads(CATALOG.read_text(encoding="utf-8"))
    by_id = {model["id"]: model for model in catalog["models"]}

    model = by_id["qwen3-4b-q4"]
    compatibility = model["app_compatibility"]

    assert model["vram_required_gb"] <= 5
    assert model["context_length"] == 40960
    assert model["gguf_sha256"] == "7485fe6f11af29433bc51cab58009521f205840f5b4ae3a32fa7f92e8534fdf5"
    assert model["gguf_url"].startswith("https://huggingface.co/Qwen/Qwen3-4B-GGUF/")
    assert compatibility["agent_viability"]["status"] == "not_agent_viable"
    assert "0.5 tok/s" in compatibility["agent_viability"]["reason"]
    assert compatibility["hermes_talk"]["status"] == "unsupported_until_revalidated"
    assert not _agent_viable_for_release(model)


def test_qwen3_17b_is_below_release_context_floor_without_yarn_policy():
    catalog = json.loads(CATALOG.read_text(encoding="utf-8"))
    by_id = {model["id"]: model for model in catalog["models"]}

    model = by_id["qwen3-1.7b-q4"]
    compatibility = model["app_compatibility"]

    assert model["vram_required_gb"] <= 3
    assert model["context_length"] == 40960
    assert model["gguf_sha256"] == "d2387ca2dbfee2ffabce7120d3770dadca0b293052bc2f0e138fdc940d9bc7b5"
    assert model["gguf_url"].startswith("https://huggingface.co/ggml-org/Qwen3-1.7B-GGUF/")
    assert compatibility["agent_viability"]["status"] == "not_agent_viable"
    assert "max_position_embeddings=40960" in compatibility["agent_viability"]["reason"]
    assert compatibility["hermes_talk"]["status"] == "unsupported_until_revalidated"
    assert not _agent_viable_for_release(model)


def test_qwen25_coder_3b_is_verified_on_windows_and_host_failures_are_scoped():
    catalog = json.loads(CATALOG.read_text(encoding="utf-8"))
    by_id = {model["id"]: model for model in catalog["models"]}
    model = by_id["qwen2.5-coder-3b-128k-q4"]
    compatibility = model["app_compatibility"]

    assert compatibility["agent_viability"]["status"] == "verified"
    assert compatibility["agent_viability"]["hostScope"] == ["windows-laptop"]
    assert "18-23-guardrail-fullapp" in compatibility["agent_viability"]["evidence"]
    assert compatibility["hermes_talk"]["status"] == "unsupported_until_revalidated"
    assert compatibility["hermes_talk"]["hostScope"] == ["tower2", "m5-mbp"]
    assert "23-54-27Z-release" in compatibility["hermes_talk"]["evidence"]
    assert "Final15" in compatibility["hermes_talk"]["reason"]
    assert "cycle-005/m5-mbp" in compatibility["hermes_talk"]["evidence"]
    assert "ODSVAL-8DB490CA32-3FC971DE20" in compatibility["hermes_talk"]["reason"]
    assert "acknowledged" in compatibility["hermes_talk"]["reason"]
    assert compatibility["opencode"]["status"] == "unsupported_until_revalidated"
    assert compatibility["opencode"]["hostScope"] == ["strix-halo", "spark"]
    assert "07-36-57Z-release" in compatibility["opencode"]["evidence"]
    assert "/cycle-006/spark" in compatibility["opencode"]["evidence"]
    assert "02-56-13Z-release" in compatibility["opencode"]["reason"]
    assert "ODES verify" in compatibility["opencode"]["reason"]
    assert _agent_viable_for_release(model)
    assert _agent_viable_for_release(model, host="windows-laptop")
    assert not _agent_viable_for_release(model, host="tower2")
    assert not _agent_viable_for_release(model, host="strix-halo")
    assert not _agent_viable_for_release(model, host="spark")
    assert not _agent_viable_for_release(model, host="m5-mbp")


def test_falcon_h1_15b_is_not_talk_or_opencode_agent_viable_until_revalidated():
    catalog = json.loads(CATALOG.read_text(encoding="utf-8"))
    by_id = {model["id"]: model for model in catalog["models"]}
    compatibility = by_id["falcon-h1-1.5b-instruct-q4"]["app_compatibility"]

    assert compatibility["hermes_talk"]["status"] == "unsupported_until_revalidated"
    assert "strixy" in compatibility["hermes_talk"]["reason"]
    assert "cycle-004" in compatibility["hermes_talk"]["evidence"]
    assert compatibility["opencode"]["status"] == "unsupported_until_revalidated"
    assert "OpenCode" in compatibility["opencode"]["reason"]
    assert "cycle-004" in compatibility["opencode"]["evidence"]
    assert compatibility["agent_viability"]["status"] == "not_agent_viable"
    assert "OpenCode" in compatibility["agent_viability"]["reason"]
    assert "ODS Talk" in compatibility["agent_viability"]["reason"]
    assert "hostScope" not in compatibility["agent_viability"]
    assert not _agent_viable_for_release(by_id["falcon-h1-1.5b-instruct-q4"])


def test_falcon_h1_3b_is_not_talk_agent_viable_until_revalidated():
    catalog = json.loads(CATALOG.read_text(encoding="utf-8"))
    by_id = {model["id"]: model for model in catalog["models"]}
    compatibility = by_id["falcon-h1-3b-instruct-q4"]["app_compatibility"]

    assert compatibility["hermes_talk"]["status"] == "unsupported_until_revalidated"
    assert "random_uuid" in compatibility["hermes_talk"]["reason"]
    assert "cycle-004" in compatibility["hermes_talk"]["evidence"]
    assert "hostScope" not in compatibility["hermes_talk"]
    assert compatibility["agent_viability"]["status"] == "not_agent_viable"
    assert "tool-call payload" in compatibility["agent_viability"]["reason"]
    assert "hostScope" not in compatibility["agent_viability"]
    assert not _agent_viable_for_release(by_id["falcon-h1-3b-instruct-q4"])


def test_nemotron3_nano_4b_is_recommended_after_six_host_validation():
    catalog = json.loads(CATALOG.read_text(encoding="utf-8"))
    by_id = {model["id"]: model for model in catalog["models"]}
    model = by_id["nvidia-nemotron3-nano-4b-q4"]

    assert model["family"] == "nemotron"
    assert model["gguf_file"] == "NVIDIA-Nemotron3-Nano-4B-Q4_K_M.gguf"
    assert model["gguf_url"] == (
        "https://huggingface.co/nvidia/NVIDIA-Nemotron-3-Nano-4B-GGUF/"
        "resolve/ba223d14e45525f7fae81db77ea8cabeb2fc6c25/"
        "NVIDIA-Nemotron3-Nano-4B-Q4_K_M.gguf"
    )
    assert model["gguf_sha256"] == "be5d9a656a51922f24f1f09a759cebb694e1f5d9728bf0ef9f8c972c5a0b5ef2"
    assert model["size_bytes"] == 2837072864
    assert model["vram_required_gb"] <= 5
    # 64K operating default (the Apple 8 GB pick); the model supports 256K.
    assert model["context_length"] == HERMES_CONTEXT_FLOOR
    assert model["max_context_length"] == 262144
    assert model.get("install_recommendation") is True
    compatibility = model["app_compatibility"]
    assert compatibility["openai_chat"]["status"] == "verified"
    assert compatibility["hermes_talk"]["status"] == "verified"
    assert compatibility["perplexica"]["status"] == "verified"
    assert compatibility["agent_viability"]["status"] == "verified"
    assert "2026-07-27T02-32-10Z" in compatibility["agent_viability"]["evidence"]
    assert compatibility["agent_viability"]["hostScope"] == [
        "tower2", "strix-halo", "spark", "m5-mbp", "windows-laptop", "strixy"
    ]
    assert _agent_viable_for_release(model)


def test_ministral3_8b_is_recommended_after_six_host_validation():
    catalog = json.loads(CATALOG.read_text(encoding="utf-8"))
    by_id = {model["id"]: model for model in catalog["models"]}
    model = by_id["ministral3-8b-instruct-2512-q4"]

    assert model["family"] == "mistral"
    assert model["gguf_file"] == "Ministral-3-8B-Instruct-2512-Q4_K_M.gguf"
    assert model["gguf_url"] == (
        "https://huggingface.co/mistralai/Ministral-3-8B-Instruct-2512-GGUF/"
        "resolve/0102285ad796bd99af90f58de616092e5630e970/"
        "Ministral-3-8B-Instruct-2512-Q4_K_M.gguf"
    )
    assert model["gguf_sha256"] == "33e7a72cf5e6e2cfc2f2847075acc013d68bba023e35310cef86b5cf8fdca761"
    assert model["size_bytes"] == 5198911904
    # Dense attention on all 34 layers: 136 KiB of f16 KV per token, so the
    # 64K operating default needs about 13.8 GiB (256K would need 38.5).
    assert model["vram_required_gb"] == 14
    assert model["context_length"] == HERMES_CONTEXT_FLOOR
    assert model["max_context_length"] == 262144
    profiles = {item["id"]: item for item in model["runtime_profiles"]}
    cpu_profile = profiles["cpu-16k-agent-memory"]
    assert cpu_profile["backend"] == "cpu"
    assert cpu_profile["system_ram_min_gb"] == 16
    assert cpu_profile["context_length"] == 16384
    assert cpu_profile["estimated_required_gb"] == 7.8
    assert cpu_profile["env"] == {
        "LLAMA_PARALLEL": "1",
        "LLAMA_ARG_FLASH_ATTN": "auto",
        "LLAMA_ARG_CACHE_TYPE_K": "f16",
        "LLAMA_ARG_CACHE_TYPE_V": "f16",
        "LLAMA_SERVER_MEMORY_LIMIT": "8G",
    }
    nvidia_profile = profiles["nvidia-8gb-64k-q4-kv"]
    assert nvidia_profile["backend"] == "nvidia"
    assert nvidia_profile["host_arch"] == ["amd64"]
    assert nvidia_profile["memory_type"] == "discrete"
    assert nvidia_profile["vram_min_gb"] == 7.5
    assert nvidia_profile["vram_max_gb"] == 8.5
    assert nvidia_profile["system_ram_min_gb"] == 31
    assert nvidia_profile["context_length"] == 65536
    assert nvidia_profile["estimated_required_gb"] == 7.4
    assert nvidia_profile["env"] == {
        "LLAMA_PARALLEL": "1",
        "LLAMA_ARG_FLASH_ATTN": "on",
        "LLAMA_ARG_CACHE_TYPE_K": "q4_0",
        "LLAMA_ARG_CACHE_TYPE_V": "q4_0",
    }
    compatibility = model["app_compatibility"]
    assert model.get("install_recommendation") is True
    assert {
        app: entry["status"]
        for app, entry in compatibility.items()
        if app != "pixel_agent"
    } == {
        "openai_chat": "verified",
        "hermes_talk": "verified",
        "perplexica": "verified",
        "agent_viability": "verified",
    }
    assert compatibility["pixel_agent"]["status"] == "not_agent_viable"
    evidence = compatibility["agent_viability"]
    assert "2026-07-27T06-31-36Z" in evidence["evidence"]
    assert evidence["productSha"] == "7629cd20c0ec75a274187aea52b8cc9ad6fa2a2a"
    assert evidence["harnessSha"] == "19d43e6f9f2533e8768ed85b33de9f4ace232129"
    assert evidence["hostScope"] == [
        "tower2", "strix-halo", "spark", "m5-mbp", "windows-laptop", "strixy"
    ]
    assert _agent_viable_for_release(model)


def test_qwen25_coder_15b_128k_has_scoped_app_blocks_until_revalidated():
    catalog = json.loads(CATALOG.read_text(encoding="utf-8"))
    by_id = {model["id"]: model for model in catalog["models"]}
    model = by_id["qwen2.5-coder-1.5b-128k-q4"]
    compatibility = model["app_compatibility"]

    assert model["gguf_sha256"] == "0fbff4d39395fab063c51377ba522928af2574b1f998d66012c1caed7b8f91d6"
    assert model["context_length"] >= HERMES_CONTEXT_FLOOR
    assert model["vram_required_gb"] <= 3
    assert compatibility["hermes_talk"]["status"] == "unsupported_until_revalidated"
    assert "generic assistant prose" in compatibility["hermes_talk"]["reason"]
    assert "cycle-006" in compatibility["hermes_talk"]["evidence"]
    assert compatibility["hermes_talk"]["hostScope"] == ["tower2"]
    assert compatibility["opencode"]["status"] == "unsupported_until_revalidated"
    assert "webfetch tool payload" in compatibility["opencode"]["reason"]
    assert compatibility["opencode"]["hostScope"] == ["strix-halo", "spark"]
    assert compatibility["perplexica"]["status"] == "unsupported_until_revalidated"
    assert "unrelated research output" in compatibility["perplexica"]["reason"]
    assert compatibility["perplexica"]["hostScope"] == ["strix-halo", "m5-mbp", "windows-laptop"]
    assert compatibility["agent_viability"]["status"] == "not_agent_viable"
    assert compatibility["agent_viability"]["hostScope"] == [
        "tower2",
        "strix-halo",
        "spark",
        "m5-mbp",
        "windows-laptop",
    ]
    assert _agent_viable_for_release(model)
    assert not _agent_viable_for_release(model, host="tower2")
    assert not _agent_viable_for_release(model, host="strix-halo")
    assert not _agent_viable_for_release(model, host="spark")
    assert not _agent_viable_for_release(model, host="m5-mbp")
    assert not _agent_viable_for_release(model, host="windows-laptop")


def test_mistral_nemo_talk_block_is_scoped_to_apple_llama_server():
    catalog = json.loads(CATALOG.read_text(encoding="utf-8"))
    by_id = {model["id"]: model for model in catalog["models"]}
    model = by_id["mistral-nemo-12b-instruct-q4"]
    compatibility = model["app_compatibility"]

    assert compatibility["hermes_talk"]["status"] == "unsupported_until_revalidated"
    assert compatibility["hermes_talk"]["gpuBackendScope"] == ["apple"]
    assert compatibility["hermes_talk"]["llmBackendScope"] == ["llama-server"]
    assert "m5-mbp" in compatibility["hermes_talk"]["hostScope"]
    assert "cycle-006" in compatibility["hermes_talk"]["evidence"]
    assert _agent_viable_for_release(model)


def test_qwen3_4b_long_context_replacements_are_release_candidates():
    catalog = json.loads(CATALOG.read_text(encoding="utf-8"))
    by_id = {model["id"]: model for model in catalog["models"]}

    expected = {
        "qwen3.5-4b-q4": {
            "sha": "00fe7986ff5f6b463e62455821146049db6f9313603938a70800d1fb69ef11a4",
            # 64K operating default; 256K native (max_context_length).
            "context": 65536,
            "max_context": 262144,
            "size_bytes": 2740937888,
            "url": "https://huggingface.co/unsloth/Qwen3.5-4B-GGUF/",
        },
        "qwen3-4b-instruct-2507-q4": {
            "sha": "3605803b982cb64aead44f6c1b2ae36e3acdb41d8e46c8a94c6533bc4c67e597",
            "context": 262144,
            "url": "https://huggingface.co/unsloth/Qwen3-4B-Instruct-2507-GGUF/",
        },
        "qwen3-4b-128k-q4": {
            "sha": "f145a1bd60fec420ca4d9b7645ebcdf657e301463bc4dd3af4a8c0b548b5eb1a",
            "context": 131072,
            "url": "https://huggingface.co/unsloth/Qwen3-4B-128K-GGUF/",
        },
    }

    for model_id, expected_model in expected.items():
        model = by_id[model_id]
        assert model["gguf_sha256"] == expected_model["sha"]
        assert model["context_length"] == expected_model["context"]
        assert model["vram_required_gb"] <= 5
        assert model["gguf_url"].startswith(expected_model["url"])
        if "size_bytes" in expected_model:
            assert model["size_bytes"] == expected_model["size_bytes"]
        if "max_context" in expected_model:
            assert model["max_context_length"] == expected_model["max_context"]
        if model_id != "qwen3.5-4b-q4":
            assert model.get("install_recommendation") is False
        if model_id == "qwen3-4b-128k-q4":
            assert not _agent_viable_for_release(model)
        else:
            assert _agent_viable_for_release(model)


def test_qwen25_7b_is_not_agent_viable_on_low_vram_windows_until_revalidated():
    catalog = json.loads(CATALOG.read_text(encoding="utf-8"))
    by_id = {model["id"]: model for model in catalog["models"]}
    compatibility = by_id["qwen2.5-7b-instruct-q4"]["app_compatibility"]

    assert compatibility["agent_viability"]["status"] == "not_agent_viable"
    assert "windows-laptop" in compatibility["agent_viability"]["evidence"]
    assert compatibility["hermes_talk"]["status"] == "unsupported_until_revalidated"
    assert not _agent_viable_for_release(by_id["qwen2.5-7b-instruct-q4"])


def test_qwen35_9b_meets_hermes_context_floor():
    catalog = json.loads(CATALOG.read_text(encoding="utf-8"))
    by_id = {model["id"]: model for model in catalog["models"]}

    assert by_id["qwen3.5-9b-q4"]["context_length"] >= HERMES_CONTEXT_FLOOR


def test_qwen35_2b_records_exact_artifact_and_failed_fleet_evidence():
    catalog = json.loads(CATALOG.read_text(encoding="utf-8"))
    by_id = {model["id"]: model for model in catalog["models"]}
    model = by_id["qwen3.5-2b-q4"]

    assert model["gguf_url"] == (
        "https://huggingface.co/unsloth/Qwen3.5-2B-GGUF/"
        "resolve/f6d5376be1edb4d416d56da11e5397a961aca8ae/"
        "Qwen3.5-2B-Q4_K_M.gguf"
    )
    assert model["gguf_sha256"] == "aaf42c8b7c3cab2bf3d69c355048d4a0ee9973d48f16c731c0520ee914699223"
    assert model["size_bytes"] == 1280835840
    assert model["size_mb"] == 1281
    assert model["vram_required_gb"] == 3
    assert model["context_length"] == HERMES_CONTEXT_FLOOR
    assert model["max_context_length"] == 262144
    assert "install_recommendation" not in model
    compatibility = model["app_compatibility"]
    assert compatibility["hermes_talk"]["status"] == "verified"
    assert compatibility["openai_chat"]["status"] == "unsupported_until_revalidated"
    assert compatibility["perplexica"]["status"] == "unsupported_until_revalidated"
    assert compatibility["agent_viability"]["status"] == "not_agent_viable"
    assert compatibility["agent_viability"]["productSha"] == (
        "b5da3792c281e0ba8f679e33876ee3de902a7dd6"
    )
    assert compatibility["agent_viability"]["harnessSha"] == (
        "19d43e6f9f2533e8768ed85b33de9f4ace232129"
    )
    assert not _agent_viable_for_release(model)


def test_jamba_reasoning_3b_records_fleet_compatibility_without_recommendation():
    catalog = json.loads(CATALOG.read_text(encoding="utf-8"))
    by_id = {model["id"]: model for model in catalog["models"]}
    model = by_id["jamba-reasoning-3b-q4"]

    assert model["gguf_url"] == (
        "https://huggingface.co/ai21labs/AI21-Jamba-Reasoning-3B-GGUF/"
        "resolve/462e08a43c3c32f6b8b85f79ff0796e484d7b65a/"
        "jamba-reasoning-3b-Q4_K_M.gguf"
    )
    assert model["gguf_sha256"] == "5c8edf36ec3ad9792a639db8d6865e479038226cf8fc71ef47331c611854f6c8"
    assert model["size_bytes"] == 1932698048
    assert model["size_mb"] == 1933
    assert model["vram_required_gb"] == 3
    assert model["context_length"] == HERMES_CONTEXT_FLOOR
    assert model["max_context_length"] == 262144
    assert model["install_recommendation"] is False
    assert model["app_compatibility"]["openai_chat"]["status"] == "verified"
    assert model["app_compatibility"]["hermes_talk"]["status"] == "verified"
    assert model["app_compatibility"]["opencode"]["status"] == "unsupported_until_revalidated"
    assert model["app_compatibility"]["agent_viability"]["status"] == "not_agent_viable"
    assert model["app_compatibility"]["agent_viability"]["productSha"] == (
        "ca730791cacaadb0280f63f3fc9f8b8ef70e4ebb"
    )
    assert model["app_compatibility"]["agent_viability"]["harnessSha"] == (
        "19d43e6f9f2533e8768ed85b33de9f4ace232129"
    )
    assert not _agent_viable_for_release(model)


def test_kat_coder_v25_dev_records_pinned_evidence_without_recommendation():
    catalog = json.loads(CATALOG.read_text(encoding="utf-8"))
    by_id = {model["id"]: model for model in catalog["models"]}
    model = by_id["kat-coder-v2.5-dev-apex-q4"]

    assert model["gguf_url"] == (
        "https://huggingface.co/mudler/KAT-Coder-V2.5-Dev-APEX-GGUF/"
        "resolve/be23ff3a49eee0d5160e3fd4f5d58062160856c2/"
        "KAT-Coder-V2.5-Dev-APEX-I-Balanced.gguf"
    )
    assert model["gguf_sha256"] == (
        "ee6e0ec15964c42ba91831d13e9709239f1b74da3dc49dd3edec4ad6aed8029f"
    )
    assert model["size_bytes"] == 25268441472
    assert model["size_mb"] == 25269
    assert model["vram_required_gb"] == 32
    assert model["context_length"] == 131072
    assert model["max_context_length"] == 262144
    assert model["total_params_b"] == 35
    assert model["active_params_b"] == 3
    assert model["architecture"] == "hybrid-moe"
    assert model["quantization"] == "APEX-I-Balanced"
    assert model["install_recommendation"] is False

    quality = model["quality_evidence"]
    assert quality["independent"] is True
    assert quality["score"] == "29/30"
    assert "120-run" in quality["benchmark"]
    assert "quantization confound" in quality["note"]

    publisher = model["publisher_evidence"]
    assert publisher["independent"] is False
    assert publisher["swe_bench_verified"] == 69.4
    assert publisher["swe_bench_pro"] == 45.96

    source = model["source_evidence"]
    assert source["model_revision"] == (
        "7be56fe773e72b6f5ca93c1ae45d828ddb893922"
    )
    assert source["weights_revision"] == (
        "68466af897fddf5539a9a7179b42868645457a95"
    )
    assert source["gguf_revision"] == (
        "be23ff3a49eee0d5160e3fd4f5d58062160856c2"
    )
    assert source["license"] == "apache-2.0"
    assert "40 model blocks" in source["gguf_metadata_note"]
    assert "no grafted MTP draft layer" in source["gguf_metadata_note"]
    assert "pre-fix chat template" in source["gguf_metadata_note"]
    assert "3a7d874090df0cd4399401982eca67df2c5a7e82" in (
        source["gguf_metadata_note"]
    )

    rejected = model["rejected_artifacts"]
    assert len(rejected) == 1
    assert rejected[0]["revision"] == (
        "b5d04175d9c1d014d61a0c26eef987f50656d8b4"
    )
    assert rejected[0]["sha256"] == (
        "cce1395f842b99c147cc99025267c866aaaec5cd7b8c2c9c11d5530dc10c5e7b"
    )
    assert rejected[0]["verdict"] == "runtime_incompatible"
    assert "blk.40.ssm_conv1d.weight" in rejected[0]["reason"]
    assert rejected[0]["evidence"]["product_sha"] == (
        "333b08c4f65de6534c46a45e2fd646732629c76f"
    )
    assert rejected[0]["evidence"]["harness_sha"] == (
        "65a24267982811bc72e45db219e09e6e547c9628"
    )
    assert rejected[0]["evidence"]["hosts"] == ["tower2", "strix-halo"]


QWEN36_27B_CANDIDATE = "qwen3.6-27b-ud-q4-k-xl"
QWEN36_27B_REVISION = "82d411acf4a06cfb8d9b073a5211bf410bfc29bf"


def _load_selector():
    spec = importlib.util.spec_from_file_location(
        "ods_select_model_coverage", ROOT / "scripts" / "select-model.py"
    )
    module = importlib.util.module_from_spec(spec)
    spec.loader.exec_module(module)
    return module


def test_qwen36_27b_candidate_records_pinned_artifact_without_recommendation():
    catalog = json.loads(CATALOG.read_text(encoding="utf-8"))
    by_id = {model["id"]: model for model in catalog["models"]}
    model = by_id[QWEN36_27B_CANDIDATE]

    assert model["gguf_file"] == "Qwen3.6-27B-UD-Q4_K_XL.gguf"
    assert model["gguf_url"] == (
        "https://huggingface.co/unsloth/Qwen3.6-27B-GGUF/"
        f"resolve/{QWEN36_27B_REVISION}/"
        "Qwen3.6-27B-UD-Q4_K_XL.gguf"
    )
    assert model["source_repo"] == "unsloth/Qwen3.6-27B-GGUF"
    assert model["source_revision"] == QWEN36_27B_REVISION
    assert model["gguf_sha256"] == (
        "ff6941ded525b34eb159496762c29dd0ec6e71dc31b74d57e75d871a03eec259"
    )
    assert model["size_bytes"] == 17612564704
    assert model["size_mb"] == 17613
    assert model["license"] == "apache-2.0"
    assert model["quantization"] == "UD-Q4_K_XL"
    assert model["llm_model_name"] == "qwen3.6-27b"

    # Candidate only: no install default and no fleet app verdicts yet.
    assert model["install_recommendation"] is False
    assert not model.get("app_compatibility")
    assert "not an install default" in model["description"]
    for risk in ("thinking mode", "reasoning off", "#27767", "3 of 216 MMBT"):
        assert risk in model["description"], risk

    # Served like the Qwen 3.5 27B baseline after the Hermes raise.
    assert model["context_length"] == HERMES_CONTEXT_FLOOR
    assert model["max_context_length"] == 262144

    # Hybrid attention: only every fourth block (3, 7, ... 63) holds KV cache.
    kv_heads = model["attention_head_count_kv"]
    assert model["block_count"] == 64
    assert len(kv_heads) == model["block_count"]
    assert [index for index, heads in enumerate(kv_heads) if heads] == list(range(3, 64, 4))
    assert set(kv_heads) == {0, 4}
    assert model["attention_key_length"] == model["attention_value_length"] == 256

    selector = _load_selector()
    normalized = selector.normalize_model(model)
    # 16 layers x 4 KV heads x (256 + 256) x 2 bytes = 64 KiB per token.
    assert selector.estimated_context_kv_gb(normalized, 65536) == 4.0
    assert selector.estimated_context_kv_gb(normalized, 131072) == 8.0
    assert selector.selector_required_memory_gb(normalized) == 22.0
    assert model["vram_required_gb"] == 22

    publisher = model["publisher_evidence"]
    assert publisher["independent"] is False
    assert QWEN36_27B_REVISION not in publisher["source_url"]
    assert "6a9e13bd6fc8f0983b9b99948120bc37f49c13e9" in publisher["source_url"]
    assert publisher["terminal_bench_2_0"] == 59.3
    assert publisher["baseline_terminal_bench_2_0"] == 41.6
    assert publisher["swe_bench_verified"] == 77.2
    assert publisher["baseline_swe_bench_verified"] == 75.0
    assert "LLAMA_ARG_REASONING=off" in publisher["note"]


def test_qwen36_27b_candidate_never_replaces_the_24_to_32gb_default():
    selector = _load_selector()
    catalog = selector.load_catalog(CATALOG)
    promoted = [
        {**model, "install_recommendation": True}
        if model["id"] == QWEN36_27B_CANDIDATE
        else model
        for model in catalog
    ]

    for backend in ("nvidia", "amd"):
        for vram_mb in (24576, 32607):
            capacity, _ = selector.usable_memory_gb(backend, "discrete", vram_mb, 64)
            # Tier 3 size ceiling on non-Pixel hosts; uncapped on Pixel hosts.
            for max_size_mb in (18600, 0):
                case = (backend, vram_mb, max_size_mb)
                ranked = selector.rank_models(
                    catalog, capacity, "qwen", True, backend, "discrete",
                    vram_mb, 64, "amd64", max_size_mb=max_size_mb,
                )
                assert ranked[0]["id"] == "qwen3.5-27b-q4", case
                assert QWEN36_27B_CANDIDATE not in {m["id"] for m in ranked}, case

                # The candidate fits this hardware, so install_recommendation
                # is the guard that keeps it out of the installable pool.
                promoted_ranked = selector.rank_models(
                    promoted, capacity, "qwen", True, backend, "discrete",
                    vram_mb, 64, "amd64", max_size_mb=max_size_mb,
                )
                assert QWEN36_27B_CANDIDATE in {m["id"] for m in promoted_ranked}, case


def test_new_switchboard_models_do_not_change_install_recommendations():
    expected_switchboard_only = {
        "phi3.5-mini-q4",
        "qwen2.5-0.5b-instruct-q4",
        "qwen2.5-1.5b-instruct-q4",
        "granite3.3-2b-instruct-q4",
        "smollm3-3b-q4",
        "granite4.0-h-1b-q4",
        "falcon-h1-1.5b-instruct-q4",
        "falcon-h1-3b-instruct-q4",
        "granite4.0-1b-q4",
        "granite4.0-h-350m-q4",
        "granite3.2-2b-instruct-q4",
        "granite3.1-2b-instruct-q4",
        "phi3-mini-128k-q4",
        "llama3.2-1b-instruct-q4",
        "llama3.2-3b-instruct-q4",
        "qwen2.5-3b-instruct-q4",
        "qwen3-4b-q4",
        "qwen3-4b-instruct-2507-q4",
        "qwen3-4b-128k-q4",
        "qwen3-1.7b-q4",
        "qwen2.5-coder-1.5b-128k-q4",
        "qwen2.5-coder-3b-128k-q4",
        "qwen2.5-7b-instruct-q4",
        "llama3.1-8b-instruct-q4",
        "granite3.3-8b-instruct-q4",
        "mistral-nemo-12b-instruct-q4",
        "kat-coder-v2.5-dev-apex-q4",
    }
    catalog = json.loads(CATALOG.read_text(encoding="utf-8"))
    by_id = {model["id"]: model for model in catalog["models"]}

    assert expected_switchboard_only <= set(by_id)
    for model_id in expected_switchboard_only:
        assert by_id[model_id].get("install_recommendation") is False, model_id


def test_real_pixel_verdicts_are_separate_from_generic_agent_evidence():
    catalog = json.loads(CATALOG.read_text(encoding="utf-8"))
    by_id = {model["id"]: model for model in catalog["models"]}
    expected_failures = {
        "nvidia-nemotron3-nano-4b-q4": "nvidia-nemotron-3-nano-4b",
        "ministral3-8b-instruct-2512-q4": "ministral-3-8b-instruct-2512",
        "qwen2.5-coder-3b-128k-q4": "qwen-25-coder-3b-128k",
        "qwen3.5-4b-q4": "qwen-35-4b",
    }

    for model_id, evidence_anchor in expected_failures.items():
        compatibility = by_id[model_id]["app_compatibility"]
        assert compatibility["agent_viability"]["status"] == "verified"
        pixel = compatibility["pixel_agent"]
        assert pixel["status"] == "not_agent_viable"
        assert pixel["hostScope"] == ["windows-laptop"]
        assert pixel["productSha"] == "df05a732ed7aedac6c527e1f9e7eeeeccfed3a5b"
        assert pixel["pixelSha"] == "f1f811d02bffd5a1589eb6feb34323f6dadf7832"
        assert pixel["evidence"].endswith(f"#{evidence_anchor}")

    qwen_9b = by_id["qwen3.5-9b-q4"]["app_compatibility"]["pixel_agent"]
    assert qwen_9b["status"] == "verified"
    assert qwen_9b["hostScope"] == ["windows-laptop"]
    assert qwen_9b["productSha"] == "d0808d08645841ffcbb3cf3919a9c81fe485937b"
    assert qwen_9b["pixelSha"] == "d99923246e5ea22c0f1c8c8fc7b0927ac8b523fe"
    assert qwen_9b["harnessSha"] == "d99923246e5ea22c0f1c8c8fc7b0927ac8b523fe"
    assert qwen_9b["evidence"].endswith("#qwen-35-9b-revalidation-2026-09-02")
    assert "background process" in qwen_9b["reason"]
    assert "9/9" in qwen_9b["reason"]
    assert "historical evidence" in qwen_9b["reason"]