haiku.rag/tests/test_reader.py
Yiorgis Gozadinos e8f00fcff4
Make get_config the only configuration lookup
haiku.rag.config exported two configuration instances: the lazy _config
behind get_config/set_config, and Config, loaded at import time. Nothing
linked them, and eleven signatures captured Config as a default argument,
so set_config could not reach the factories, the client, the store or the
MCP server. reranking/base.py went further and snapshotted the configured
reranker name into a class attribute at import.

Config is removed. Internal defaults are config: AppConfig | None = None,
resolved through get_config() per call. RerankerBase._model is None and
CohereReranker takes its model name as an argument, like every other
reranker.

The suite patched attributes on Config while production read the instance
get_config() returns, a different object, so those patches were no-ops
waiting to happen. They now go through get_config().
2026-08-19 14:43:40 +03:00

28 lines
808 B
Python

import tempfile
from pathlib import Path
import pytest
from haiku.rag.config import get_config
from haiku.rag.converters import get_converter
@pytest.mark.asyncio
async def test_code_file_wrapped_in_code_block():
"""Test that code files are wrapped in markdown code blocks."""
python_code = '''def hello_world():
print("Hello, World!")
return "success"'''
with tempfile.NamedTemporaryFile(mode="w", suffix=".py") as f:
f.write(python_code)
f.flush()
temp_path = Path(f.name)
converter = get_converter(get_config())
document = await converter.convert_file(temp_path)
result = document.export_to_markdown()
assert result.startswith("```\n")
assert result.endswith("\n```")
assert "def hello_world():" in result