61 lines
2.0 KiB
Python
61 lines
2.0 KiB
Python
|
|
"""Tests for the context builder."""
|
||
|
|
|
||
|
|
from atocore.context.builder import build_context, get_last_context_pack
|
||
|
|
from atocore.ingestion.pipeline import ingest_file
|
||
|
|
from atocore.models.database import init_db
|
||
|
|
|
||
|
|
|
||
|
|
def test_build_context_returns_pack(tmp_data_dir, sample_markdown):
|
||
|
|
"""Test that context builder returns a valid pack."""
|
||
|
|
init_db()
|
||
|
|
ingest_file(sample_markdown)
|
||
|
|
|
||
|
|
pack = build_context("What is AtoCore?")
|
||
|
|
assert pack.total_chars > 0
|
||
|
|
assert len(pack.chunks_used) > 0
|
||
|
|
assert pack.budget_remaining >= 0
|
||
|
|
assert "--- AtoCore Context ---" in pack.formatted_context
|
||
|
|
assert "--- End Context ---" in pack.formatted_context
|
||
|
|
|
||
|
|
|
||
|
|
def test_context_respects_budget(tmp_data_dir, sample_markdown):
|
||
|
|
"""Test that context builder respects character budget."""
|
||
|
|
init_db()
|
||
|
|
ingest_file(sample_markdown)
|
||
|
|
|
||
|
|
pack = build_context("What is AtoCore?", budget=500)
|
||
|
|
assert pack.total_chars <= 500
|
||
|
|
|
||
|
|
|
||
|
|
def test_context_with_project_hint(tmp_data_dir, sample_markdown):
|
||
|
|
"""Test that project hint boosts relevant chunks."""
|
||
|
|
init_db()
|
||
|
|
ingest_file(sample_markdown)
|
||
|
|
|
||
|
|
pack = build_context("What is the architecture?", project_hint="atocore")
|
||
|
|
assert len(pack.chunks_used) > 0
|
||
|
|
# With project hint, we should still get results
|
||
|
|
assert pack.total_chars > 0
|
||
|
|
|
||
|
|
|
||
|
|
def test_last_context_pack_stored(tmp_data_dir, sample_markdown):
|
||
|
|
"""Test that last context pack is stored for debug."""
|
||
|
|
init_db()
|
||
|
|
ingest_file(sample_markdown)
|
||
|
|
|
||
|
|
build_context("test prompt")
|
||
|
|
last = get_last_context_pack()
|
||
|
|
assert last is not None
|
||
|
|
assert last.query == "test prompt"
|
||
|
|
|
||
|
|
|
||
|
|
def test_full_prompt_structure(tmp_data_dir, sample_markdown):
|
||
|
|
"""Test that the full prompt has correct structure."""
|
||
|
|
init_db()
|
||
|
|
ingest_file(sample_markdown)
|
||
|
|
|
||
|
|
pack = build_context("What are memory types?")
|
||
|
|
assert "knowledge base" in pack.full_prompt.lower()
|
||
|
|
assert "--- AtoCore Context ---" in pack.full_prompt
|
||
|
|
assert "What are memory types?" in pack.full_prompt
|