|
| 1 | +from tabulate import tabulate |
| 2 | +import pytest |
| 3 | +import os |
| 4 | + |
| 5 | +from agents.triage_agent import run_workflow, TriageState |
| 6 | +from agents.observability import setup_observability |
| 7 | +from common.models import TriageOutputSchema, Resolution, BackportData |
| 8 | + |
| 9 | + |
| 10 | +class TriageAgentTestCase: |
| 11 | + def __init__(self, input, expected_output): |
| 12 | + self.input = input |
| 13 | + self.expected_output = expected_output |
| 14 | + self.metrics: dict = None |
| 15 | + |
| 16 | + async def run(self) -> TriageState: |
| 17 | + return await run_workflow(self.input, False) |
| 18 | + |
| 19 | + |
| 20 | +test_cases=[ |
| 21 | + TriageAgentTestCase(input="RHEL-15216", |
| 22 | + expected_output=TriageOutputSchema(resolution=Resolution.BACKPORT, |
| 23 | + data=BackportData(package="dnsmasq", |
| 24 | + patch_urls=["http://thekelleys.org.uk/gitweb/?p=dnsmasq.git;a=patch;h=dd33e98da09c487a58b6cb6693b8628c0b234a3b"], |
| 25 | + justification="not-implemented", |
| 26 | + jira_issue="RHEL-15216", |
| 27 | + cve_id=None, |
| 28 | + fix_version="rhel-8.10")) |
| 29 | + ), |
| 30 | + TriageAgentTestCase(input="RHEL-112546", |
| 31 | + expected_output=TriageOutputSchema(resolution=Resolution.BACKPORT, |
| 32 | + data=BackportData(package="libtiff", |
| 33 | + patch_urls=["https://gitlab.com/libtiff/libtiff/-/commit/d1c0719e004fbb223c571d286c73911569d4dbb6.patch"], |
| 34 | + justification="not-implemented", |
| 35 | + jira_issue="RHEL-112546", |
| 36 | + cve_id="CVE-2025-9900", |
| 37 | + fix_version="rhel-9.6.z")) |
| 38 | + ), |
| 39 | + TriageAgentTestCase(input="RHEL-61943", |
| 40 | + expected_output=TriageOutputSchema(resolution=Resolution.BACKPORT, |
| 41 | + data=BackportData(package="dnsmasq", |
| 42 | + patch_urls=["http://thekelleys.org.uk/gitweb/?p=dnsmasq.git;a=patch;h=eb1fe15ca80b6bc43cd6bfdf309ec6c590aff811"], |
| 43 | + justification="not-implemented", |
| 44 | + jira_issue="RHEL-61943", |
| 45 | + cve_id=None, |
| 46 | + fix_version="rhel-8.10.z")) |
| 47 | + ), |
| 48 | + TriageAgentTestCase(input="RHEL-29712", |
| 49 | + expected_output=TriageOutputSchema(resolution=Resolution.BACKPORT, |
| 50 | + data=BackportData(package="bind", |
| 51 | + patch_urls=["https://gitlab.isc.org/isc-projects/bind9/-/commit/7e2f50c36958f8c98d54e6d131f088a4837ce269"], |
| 52 | + justification="not-implemented", |
| 53 | + jira_issue="RHEL-29712", |
| 54 | + cve_id=None, |
| 55 | + fix_version="rhel-8.10.z")) |
| 56 | + ), |
| 57 | +] |
| 58 | + |
| 59 | + |
| 60 | +@pytest.fixture(scope="session", autouse=True) |
| 61 | +def observability_fixture(): |
| 62 | + return setup_observability(os.environ["COLLECTOR_ENDPOINT"]) |
| 63 | + |
| 64 | + |
| 65 | +@pytest.fixture(scope="session", autouse=True) |
| 66 | +def mydata(request): |
| 67 | + yield |
| 68 | + collected_metrics = [[test_case.input] + list(test_case.metrics.values()) for test_case in test_cases] |
| 69 | + request.config.stash["metrics"] = tabulate(collected_metrics, ["Issue", "Time"]) |
| 70 | + |
| 71 | + |
| 72 | +@pytest.mark.asyncio |
| 73 | +@pytest.mark.parametrize( |
| 74 | + "test_case", |
| 75 | + test_cases, |
| 76 | +) |
| 77 | +async def test_triage_agent(test_case: TriageAgentTestCase): |
| 78 | + def verify_result(real_output: TriageOutputSchema, expected_output: TriageOutputSchema): |
| 79 | + assert real_output.resolution == expected_output.resolution |
| 80 | + assert real_output.data.package == expected_output.data.package |
| 81 | + assert real_output.data.patch_urls == expected_output.data.patch_urls |
| 82 | + assert real_output.data.jira_issue == expected_output.data.jira_issue |
| 83 | + assert real_output.data.cve_id == expected_output.data.cve_id |
| 84 | + assert real_output.data.fix_version == expected_output.data.fix_version |
| 85 | + |
| 86 | + finished_state = await test_case.run() |
| 87 | + test_case.metrics = finished_state.metrics |
| 88 | + verify_result(finished_state.triage_result, test_case.expected_output) |
0 commit comments