open-swe/tests/test_team_settings_org_guidelines.py
Johannes du Plessis f3512841fc
feat: inject org-wide guidelines into reviewer prompt (#1431)
Adds an admin-managed, org-wide review guidelines field to team settings
that the reviewer injects into every PR review across all repos, alongside
the existing per-repo style prompt and AGENTS.md context. Repo-specific
rules take precedence when they conflict.

Co-authored-by: open-swe[bot] <open-swe@users.noreply.github.com>
2026-06-05 13:49:30 -07:00

47 lines
1.5 KiB
Python

from __future__ import annotations
from unittest.mock import AsyncMock, patch
import pytest
from pydantic import ValidationError
from agent.dashboard.team_settings import (
ORG_GUIDELINES_MAX_CHARS,
TeamSettingsUpdate,
get_org_review_guidelines,
)
def test_org_guidelines_blank_normalizes_to_none() -> None:
assert TeamSettingsUpdate(org_guidelines=" ").org_guidelines is None
assert TeamSettingsUpdate(org_guidelines=None).org_guidelines is None
def test_org_guidelines_trimmed() -> None:
update = TeamSettingsUpdate(org_guidelines=" Flag CI gate removals.\n")
assert update.org_guidelines == "Flag CI gate removals."
def test_org_guidelines_rejects_oversized() -> None:
with pytest.raises(ValidationError):
TeamSettingsUpdate(org_guidelines="x" * (ORG_GUIDELINES_MAX_CHARS + 1))
@pytest.mark.asyncio
async def test_get_org_review_guidelines_returns_trimmed_text() -> None:
with patch(
"agent.dashboard.team_settings.get_team_settings",
new_callable=AsyncMock,
return_value={"org_guidelines": " Always check auth.\n"},
):
assert await get_org_review_guidelines() == "Always check auth."
@pytest.mark.asyncio
async def test_get_org_review_guidelines_returns_none_when_unset() -> None:
with patch(
"agent.dashboard.team_settings.get_team_settings",
new_callable=AsyncMock,
return_value={"org_guidelines": None},
):
assert await get_org_review_guidelines() is None