fix: agent-native audit — parameterize thresholds, add CRUD tests, tool discovery

Audit fixes for agent-native architecture gaps:

- agent_tools/content.py: parameterize healthy_threshold in check_embedding_quality
- agent_tools/__init__.py: add __all__ exports and list_tools() runtime discovery
- agent_tools/database.py: add CRUD primitives (create_motion, update_motion, delete_report)
  plus query_embeddings, query_similar_motions, query_compass_positions
- tests/agent_tools/test_database_tools.py: add CRUD tool tests
- tests/agent_tools/test_content_tools.py: add parameterized threshold test
- tests/agent_tools/test_package.py: test list_tools() and package imports

Tests: 245 passed, 3 skipped
This commit is contained in:
2026-05-04 20:05:59 +02:00
parent 8af27bbf04
commit efb3a8fbd2
6 changed files with 370 additions and 4 deletions
+9
View File
@@ -42,3 +42,12 @@ class TestCheckEmbeddingQuality:
result = check_embedding_quality(tmp_duckdb_path, window_id="current_parliament")
assert isinstance(result, dict)
assert "coverage" in result or "error" in result
def test_parameterized_threshold(self, tmp_duckdb_path):
from agent_tools.content import check_embedding_quality
result = check_embedding_quality(
tmp_duckdb_path, window_id="current_parliament", healthy_threshold=0.5
)
assert isinstance(result, dict)
assert result.get("healthy_threshold") == 0.5
+46
View File
@@ -73,3 +73,49 @@ class TestQueryPipelineStatus:
assert "motion_count" in result
assert "latest_motion_date" in result
assert "svd_window_count" in result
class TestCrudTools:
def test_create_motion_returns_id(self, tmp_duckdb_path):
from agent_tools.database import create_motion
result = create_motion(
tmp_duckdb_path,
title="Test Motion",
description="A test motion",
date="2024-06-01",
policy_area="Test",
)
assert isinstance(result, dict)
assert "motion_id" in result or "error" in result
def test_update_motion_changes_field(self, tmp_duckdb_path):
from agent_tools.database import create_motion, update_motion
created = create_motion(
tmp_duckdb_path,
title="Original",
description="Original desc",
date="2024-06-01",
)
if "error" in created:
pytest.skip("create_motion not supported by schema")
motion_id = created["motion_id"]
result = update_motion(
tmp_duckdb_path,
motion_id=motion_id,
title="Updated",
)
assert isinstance(result, dict)
assert "updated" in result or "error" in result
def test_delete_report_removes_file(self, tmp_path):
from agent_tools.database import delete_report
report_path = tmp_path / "test_report.md"
report_path.write_text("# Test Report\n")
result = delete_report(str(report_path))
assert result.get("deleted") is True
assert not report_path.exists()
+39
View File
@@ -0,0 +1,39 @@
"""Tests for agent_tools package-level utilities."""
import pytest
class TestListTools:
def test_returns_tool_list(self):
from agent_tools import list_tools
result = list_tools()
assert isinstance(result, list)
assert len(result) > 0
names = {t["name"] for t in result}
assert "query_motions" in names
assert "pipeline_check_health" in names
assert "generate_report" in names
assert "list_tools" in names
def test_each_tool_has_required_fields(self):
from agent_tools import list_tools
result = list_tools()
for tool in result:
assert "name" in tool
assert "signature" in tool
assert "description" in tool
class TestAllExports:
def test_query_motions_importable(self):
from agent_tools import query_motions
assert callable(query_motions)
def test_list_tools_importable(self):
from agent_tools import list_tools
assert callable(list_tools)