import sys
import unittest

from agent_gui.adapters import CliAdapter, EchoAdapter, adapter_for


class AdapterTests(unittest.TestCase):
    def test_echo_adapter(self):
        agent = {"id": "echo", "type": "echo"}
        result = EchoAdapter().run("hello", agent, "s1")
        self.assertEqual(result.avatar_state, "speaking")
        self.assertTrue(any(e["type"] == "assistant_message" for e in result.events))

    def test_cli_adapter_without_shell(self):
        agent = {
            "id": "py",
            "type": "cli",
            "command": [sys.executable, "-c", "import sys; print('ok:' + sys.argv[1])", "{prompt}"],
            "timeout_seconds": 10,
        }
        result = CliAdapter().run("hello", agent, "s1")
        self.assertEqual(result.avatar_state, "speaking")
        assistant = [e for e in result.events if e["type"] == "assistant_message"][0]
        self.assertIn("ok:hello", assistant["content"])

    def test_unknown_adapter_type(self):
        with self.assertRaises(ValueError):
            adapter_for({"id": "x", "type": "unknown"})


if __name__ == "__main__":
    unittest.main()
