"""Tests for the optional llama.cpp smoke-test helper.""" from __future__ import annotations import tempfile import unittest from pathlib import Path from unittest.mock import patch from scripts.check_llama_cpp_smoke import run_llama_cpp_smoke class FakeLlamaModel: def __init__(self, responses: list[str]) -> None: self.responses = responses def create_chat_completion(self, **_: object) -> dict: response = self.responses.pop(0) return {"choices": [{"message": {"content": response}}]} class LlamaCppSmokeTest(unittest.TestCase): def test_smoke_passes_when_pipeline_uses_llama_cpp_without_fallback(self) -> None: fake_llama = FakeLlamaModel( [ """ {"persona":{"object_name":"coffee mug","character_name":"Mugworth","mood":"dry and suspicious","secret_fear":"being left empty forever","core_memory":"It remembers every late-night refill.","complaint":"I am treated like a ceramic fuel tank.","tags":["desk witness","warm archive","quiet judgment"]},"diary":{"title":"Secret Diary - Day 418","english":"Today I held another bitter storm and called it service.","chinese":"今天我又装下一场苦涩风暴,并被称为有用。"}} """, """ {"reply":"Mugworth: I saw another deadline dissolve into a coffee ring."} """, ] ) with tempfile.TemporaryDirectory() as tmp_dir: model_path = Path(tmp_dir) / "model.gguf" model_path.write_text("fake", encoding="utf-8") with patch("src.models.llama_cpp_runner._load_llama_model", return_value=fake_llama): result = run_llama_cpp_smoke( model_path=model_path, description="old white coffee mug", mode="Cynical", save_trace=False, ) self.assertEqual(result["status"], "pass") self.assertEqual(result["model_runtime"]["text"], "llama-cpp text generation") self.assertNotIn("text-fallback-to-mock", result["fallbacks"]) self.assertNotIn("text-fallback-to-mock", result["chat_fallbacks"]) def test_smoke_fails_when_model_path_is_missing(self) -> None: with self.assertRaises(FileNotFoundError): run_llama_cpp_smoke( model_path=Path("/tmp/objectverse-missing-model.gguf"), description="old white coffee mug", mode="Cynical", save_trace=False, ) if __name__ == "__main__": unittest.main()