File size: 1,696 Bytes
a3ecd30
 
 
 
 
 
 
 
 
 
 
 
3e631d0
0e9cb33
 
 
 
a3ecd30
 
 
 
 
 
 
 
 
 
 
3e631d0
de6f25f
0e9cb33
a3ecd30
3e631d0
 
 
de6f25f
0e9cb33
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
from pathlib import Path

import pytest

from app.agents.graph import AuditGraph
from app.config import Settings
from app.schemas import AuditReport


@pytest.mark.anyio
async def test_run_with_progress_yields_real_stages_and_report(tmp_path: Path):
    source = tmp_path / "app.py"
    source.write_text("API_KEY = '1234567890abcdef'\nresponse = requests.get(url)\n", encoding="utf-8")
    (tmp_path / "README.md").write_text(
        "# Demo\n\n## Quick Start\nInstall and run it.\n## Tests\nRun pytest.\n## Configuration\nCopy .env.example.",
        encoding="utf-8",
    )
    graph = AuditGraph(Settings(max_files=10, max_file_size_kb=10, max_chars_per_chunk=1000))

    graph.crawler.clone_and_scan = lambda repo_url: graph.crawler.scan_local_repo(repo_url, tmp_path)
    graph.crawler.cleanup = lambda scan_result: None

    events = []
    async for event in graph.run_with_progress("https://github.com/example/project"):
        events.append(event)

    assert any("Crawler Agent" in event for event in events if isinstance(event, str))
    assert any("Security Agent" in event for event in events if isinstance(event, str))
    assert any("Performance Agent" in event for event in events if isinstance(event, str))
    assert any("Quality Agent" in event for event in events if isinstance(event, str))
    assert any("Docs Agent" in event for event in events if isinstance(event, str))
    assert isinstance(events[-1], AuditReport)
    assert len(events[-1].findings) == 2
    assert "Security Agent" in events[-1].agents_run
    assert "Performance Agent" in events[-1].agents_run
    assert "Quality Agent" in events[-1].agents_run
    assert "Docs Agent" in events[-1].agents_run