Files
roboco/tests/unit/runtime/test_external_pr_classify.py
T

35 lines
1.5 KiB
Python
Raw Normal View History

"""External-PR author/fork classification — the inbound trust decision.
``_is_external_pr`` decides whether an open PR was authored by the org itself
or by an outside contributor. It must default to *external* (the cautious
side) for anything it does not positively recognize as internal.
"""
from __future__ import annotations
import pytest
from roboco.runtime.orchestrator import AgentOrchestrator
@pytest.mark.parametrize(
("pr", "expected"),
[
# A fork head is always external, regardless of association.
({"is_fork": True, "author_association": "OWNER"}, True),
# Same-repo branch from a trusted association is internal (the org).
({"is_fork": False, "author_association": "OWNER"}, False),
({"is_fork": False, "author_association": "MEMBER"}, False),
({"is_fork": False, "author_association": "COLLABORATOR"}, False),
({"is_fork": False, "author_association": "member"}, False), # case-insensitive
# Outside associations are external even on a same-repo branch.
({"is_fork": False, "author_association": "CONTRIBUTOR"}, True),
({"is_fork": False, "author_association": "FIRST_TIME_CONTRIBUTOR"}, True),
({"is_fork": False, "author_association": "NONE"}, True),
({"is_fork": False, "author_association": None}, True),
# Unknown/empty shape defaults to external (cautious).
({}, True),
],
)
def test_is_external_pr(pr: dict[str, object], *, expected: bool) -> None:
assert AgentOrchestrator._is_external_pr(pr) is expected