Padmanav commited on
Commit
c2eb49d
·
1 Parent(s): cef359a

test: expand coverage to tools layer and model validators

Browse files
Files changed (1) hide show
  1. tests/test_agents.py +52 -1
tests/test_agents.py CHANGED
@@ -1,6 +1,8 @@
1
  from unittest.mock import AsyncMock, patch
2
  import pytest
3
  from app.agents import repo_analysis_agent, bug_detection_agent
 
 
4
 
5
 
6
  @pytest.mark.asyncio
@@ -22,4 +24,53 @@ async def test_bug_detection_agent_returns_report():
22
  patch("app.agents.bug_detection_agent.call_llm", new=AsyncMock(return_value="{}")),
23
  ):
24
  result = await bug_detection_agent.run("/tmp/fake")
25
- assert result.total_critical == 0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  from unittest.mock import AsyncMock, patch
2
  import pytest
3
  from app.agents import repo_analysis_agent, bug_detection_agent
4
+ from app.models.issue import IssueReport, Bug, Warning, Suggestion
5
+ from app.models.repository import RepositoryRequest
6
 
7
 
8
  @pytest.mark.asyncio
 
24
  patch("app.agents.bug_detection_agent.call_llm", new=AsyncMock(return_value="{}")),
25
  ):
26
  result = await bug_detection_agent.run("/tmp/fake")
27
+ assert result.total_critical == 0
28
+
29
+ def test_issue_report_totals_computed_automatically():
30
+ report = IssueReport(
31
+ critical=[Bug(description="null ptr", file="main.py")],
32
+ warnings=[Warning(description="unused var", file="utils.py")],
33
+ suggestions=[Suggestion(description="use walrus operator", file="utils.py")],
34
+ )
35
+ assert report.total_critical == 1
36
+ assert report.total_warnings == 1
37
+ assert report.total_suggestions == 1
38
+
39
+
40
+ def test_issue_report_totals_empty():
41
+ report = IssueReport()
42
+ assert report.total_critical == 0
43
+ assert report.total_warnings == 0
44
+ assert report.total_suggestions == 0
45
+
46
+
47
+ def test_repository_request_rejects_invalid_url():
48
+ with pytest.raises(Exception):
49
+ RepositoryRequest(github_url="http://not-github.com/owner/repo")
50
+
51
+
52
+ def test_repository_request_rejects_bare_domain():
53
+ with pytest.raises(Exception):
54
+ RepositoryRequest(github_url="https://github.com")
55
+
56
+
57
+ def test_repository_request_accepts_valid_url():
58
+ req = RepositoryRequest(github_url="https://github.com/owner/repo")
59
+ assert req.github_url == "https://github.com/owner/repo"
60
+
61
+
62
+ @pytest.mark.asyncio
63
+ async def test_code_review_agent_no_source_files():
64
+ from unittest.mock import patch
65
+ from app.agents import code_review_agent
66
+ from app.models.repository import RepositoryMetadata
67
+
68
+ metadata = RepositoryMetadata(
69
+ url="https://github.com/test/repo",
70
+ name="repo",
71
+ local_path="/tmp/fake",
72
+ )
73
+ with patch("app.agents.code_review_agent.get_python_files", return_value=[]):
74
+ result = await code_review_agent.run("/tmp/fake", metadata)
75
+ assert result.overall_score == 0.0
76
+ assert "No source files" in result.summary