File size: 1,679 Bytes
de6f25f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import pytest

from app.agents.quality_agent import QualityAgent
from app.schemas import CodeChunk, Severity


@pytest.mark.anyio
async def test_quality_agent_flags_todo_comments():
    chunk = CodeChunk(
        file_path="service.py",
        language="Python",
        line_start=12,
        line_end=12,
        content="# TODO: handle retry failures",
    )

    output = await QualityAgent().analyze([chunk])

    assert output.findings[0].title == "Unresolved maintenance comment"
    assert output.findings[0].severity == Severity.low
    assert output.findings[0].line_start == 12


@pytest.mark.anyio
async def test_quality_agent_flags_high_branch_density():
    lines = [f"if condition_{index}:" for index in range(30)]
    chunk = CodeChunk(
        file_path="rules.py",
        language="Python",
        line_start=1,
        line_end=len(lines),
        content="\n".join(lines),
    )

    output = await QualityAgent().analyze([chunk])

    assert output.findings[0].title == "High branching complexity"
    assert output.findings[0].severity == Severity.medium


@pytest.mark.anyio
async def test_quality_agent_flags_long_function():
    lines = ["def process_everything():"]
    lines.extend(f"    value_{index} = {index}" for index in range(85))
    chunk = CodeChunk(
        file_path="processor.py",
        language="Python",
        line_start=30,
        line_end=30 + len(lines) - 1,
        content="\n".join(lines),
    )

    output = await QualityAgent().analyze([chunk])

    assert output.findings[0].title == "Long function or class body"
    assert output.findings[0].severity == Severity.medium
    assert output.findings[0].line_start == 30