import json import re from pathlib import Path import pytest import agent from agent.tools.builtin.content.platforms import x from agent.tools.builtin.content.quality import set_post_evaluator_factory class FakeEvaluator: def evaluate_post(self, post): return {"total_score": 88, "grade": "A"} class FakeResponse: def raise_for_status(self): return None def json(self): return { "code": 0, "data": { "data": [{ "body_text": "generic post", "channel_account_name": "author", "link": "https://example.test/post", }] }, } class FakeClient: async def __aenter__(self): return self async def __aexit__(self, exc_type, exc, tb): return None async def post(self, *args, **kwargs): return FakeResponse() @pytest.mark.asyncio async def test_host_injected_content_evaluator_preserves_optional_scoring(monkeypatch): import agent.tools.builtin.content.transcription as transcription async def noop_probe(*args, **kwargs): return None async def no_collage(*args, **kwargs): return None monkeypatch.setattr(x.httpx, "AsyncClient", lambda *args, **kwargs: FakeClient()) monkeypatch.setattr(x, "_build_tweet_collage", no_collage) monkeypatch.setattr(transcription, "probe_durations_for_posts", noop_probe) set_post_evaluator_factory(FakeEvaluator) try: result = await x.search("x", "topic", max_count=1) row = json.loads(result.output)["data"][0] assert row["quality_score"] == 88 assert row["quality_grade"] == "A" finally: set_post_evaluator_factory(None) def test_installable_framework_has_no_examples_business_imports(): package_root = Path(agent.__file__).resolve().parent forbidden = re.compile( r"(?:from\s+examples\b|import\s+examples\b|import_module\([^\n]*examples)" ) violations = [] for path in package_root.rglob("*.py"): if forbidden.search(path.read_text(encoding="utf-8")): violations.append(str(path.relative_to(package_root))) assert violations == []