import pytest from src.agent_app import CreditCardFraudAgent, create_agent, Tool def test_agent_initialization(): agent = CreditCardFraudAgent(model_dir="models", model_name="random_forest") assert agent.inference is not None assert len(agent.tools) == 2 def test_create_agent(): agent = create_agent(model_dir="models", model_name="random_forest") assert isinstance(agent, CreditCardFraudAgent) def test_list_tools(): agent = create_agent() tools = agent.list_tools() assert len(tools) == 2 tool_names = [tool["name"] for tool in tools] assert "predict_fraud" in tool_names assert "analyze_transaction" in tool_names def test_tool_structure(): agent = create_agent() for tool in agent.tools: assert hasattr(tool, "name") assert hasattr(tool, "description") assert hasattr(tool, "func") assert callable(tool.func) def test_analyze_transaction(): agent = create_agent() transaction = [ 0, -1.36, -0.07, 2.54, 1.38, -0.34, 0.46, 0.24, 0.10, 0.36, 0.09, -0.55, -0.62, -0.99, -0.31, 1.47, -0.47, 0.21, 0.03, 0.40, 0.25, -0.02, 0.28, -0.11, 0.07, 0.13, -0.19, 0.13, -0.02, 149.62 ] analysis = agent._analyze_transaction(transaction) assert "feature_count" in analysis assert "amount" in analysis assert "time" in analysis assert "statistics" in analysis assert "anomalies" in analysis assert analysis["feature_count"] == 30 assert analysis["amount"] == 149.62 def test_process_transaction(): agent = create_agent() transaction = [ 0, -1.36, -0.07, 2.54, 1.38, -0.34, 0.46, 0.24, 0.10, 0.36, 0.09, -0.55, -0.62, -0.99, -0.31, 1.47, -0.47, 0.21, 0.03, 0.40, 0.25, -0.02, 0.28, -0.11, 0.07, 0.13, -0.19, 0.13, -0.02, 149.62 ] result = agent.process_transaction(transaction) assert result.evaluation is not None assert result.explanation is not None assert result.action_plan is not None assert hasattr(result.evaluation, "predicted_class") assert hasattr(result.evaluation, "fraud_probability") assert hasattr(result.action_plan, "actions")