import os from pathlib import Path from typing import Any import pytest from automation.patcher import ModelConfig import automation.agents as agents @pytest.fixture(autouse=True) def reset_model_cache(monkeypatch: pytest.MonkeyPatch) -> None: agents._MODEL_CACHE = None # type: ignore[attr-defined] cwd = Path.cwd() monkeypatch.chdir(cwd) # ensure repo root def make_model(commands: list[str]) -> ModelConfig: return ModelConfig(commands=commands, sentinel="CASCADINGDEV_NO_CHANGES") def test_normalize_discussion_simple(monkeypatch: pytest.MonkeyPatch) -> None: commands = ["bash -lc 'printf \"{\\\"votes\\\": []}\"'"] monkeypatch.setattr(agents, "_get_model", lambda: make_model(commands)) result = agents.normalize_discussion("Example discussion text") assert isinstance(result, dict) assert result.get("votes") == [] def test_fallback_skips_sentinel(monkeypatch: pytest.MonkeyPatch) -> None: commands = [ "bash -lc 'printf CASCADINGDEV_NO_CHANGES'", "bash -lc 'printf \"{\\\"votes\\\": []}\"'", ] monkeypatch.setattr(agents, "_get_model", lambda: make_model(commands)) result = agents.normalize_discussion("Example discussion text") assert isinstance(result, dict) assert result["votes"] == [] def test_track_action_items(monkeypatch: pytest.MonkeyPatch) -> None: commands = ["bash -lc 'printf \"{\\\"new_items\\\": []}\"'"] monkeypatch.setattr(agents, "_get_model", lambda: make_model(commands)) result = agents.track_action_items("content", []) assert isinstance(result, dict) assert result["new_items"] == []