open-swe/tests/test_team_settings_grouping.py
Johannes du Plessis 801f93b4de
feat: AI-sorted PR review view with diff grouping (#1544)
* feat: AI-sorted PR review view with diff grouping

Group a PR's changed files into a logical top-to-bottom walkthrough via a best-effort structured-output LLM pass, kicked off concurrently with the reviewer run (~0 added latency) and persisted on reviewer thread metadata. Results render in the review UI behind an AI sorted / file tree toggle that persists across PRs; the view falls back to the file tree when groups are absent or stale.

Adds a grouping-model team default (inherits the Reviewer subagent model when unset) and the admin RolePicker for it.

* feat(reviews): richer AI-sorted explanations + sidebar polish

Sidebar group rows get Devin-style spacing (dividers, padding), a per-group file list (click a file to jump to its diff), inline-code chips in titles, and an accent Read explanation link.

Group explanations are now rich markdown: the grouping prompt feeds per-hunk line ranges and asks for inline code, a short code block, and [path:line](#loc=...) references. The Markdown renderer turns those #loc= links into in-page buttons that scroll the diff to the hunk and highlight the range, reusing the existing selectedLines path.

* fix(reviews): drop stale diff groups from the AI-sorted view

When groups were generated for a previous head, a persisted "ai" view in localStorage still rendered the outdated walkthrough. groupedView now returns null on diff_groups_stale, so the file-tree fallback is used and the view toggle hides until fresh groups arrive.

---------

Co-authored-by: open-swe[bot] <open-swe@users.noreply.github.com>
2026-06-16 13:59:37 -07:00

83 lines
2.7 KiB
Python

from __future__ import annotations
from unittest.mock import AsyncMock, patch
import pytest
from pydantic import ValidationError
from agent.dashboard.team_settings import (
TeamSettingsUpdate,
get_team_default_grouping_model,
)
_REVIEWER_SUBAGENT_PAIR = ("openai:gpt-5.5", "low")
_GROUPING_PAIR = ("google_genai:gemini-3.5-flash", "low")
def _settings(**overrides: object) -> dict[str, object]:
base: dict[str, object] = {
"default_reviewer_subagent_model": _REVIEWER_SUBAGENT_PAIR[0],
"default_reviewer_subagent_reasoning_effort": _REVIEWER_SUBAGENT_PAIR[1],
"default_grouping_model": None,
"default_grouping_reasoning_effort": None,
}
base.update(overrides)
return base
@pytest.mark.asyncio
async def test_grouping_inherits_reviewer_subagent_when_unset() -> None:
with patch(
"agent.dashboard.team_settings.get_team_settings",
new_callable=AsyncMock,
return_value=_settings(),
):
assert await get_team_default_grouping_model() == _REVIEWER_SUBAGENT_PAIR
@pytest.mark.asyncio
async def test_grouping_uses_configured_model_when_set() -> None:
with patch(
"agent.dashboard.team_settings.get_team_settings",
new_callable=AsyncMock,
return_value=_settings(
default_grouping_model=_GROUPING_PAIR[0],
default_grouping_reasoning_effort=_GROUPING_PAIR[1],
),
):
assert await get_team_default_grouping_model() == _GROUPING_PAIR
@pytest.mark.asyncio
async def test_grouping_inherits_when_configured_model_invalid() -> None:
with patch(
"agent.dashboard.team_settings.get_team_settings",
new_callable=AsyncMock,
return_value=_settings(
default_grouping_model="bogus:model",
default_grouping_reasoning_effort="high",
),
):
assert await get_team_default_grouping_model() == _REVIEWER_SUBAGENT_PAIR
def test_team_settings_update_accepts_grouping_pair() -> None:
update = TeamSettingsUpdate(
default_grouping_model=_GROUPING_PAIR[0],
default_grouping_reasoning_effort=_GROUPING_PAIR[1],
)
assert update.default_grouping_model == _GROUPING_PAIR[0]
assert update.default_grouping_reasoning_effort == _GROUPING_PAIR[1]
def test_team_settings_update_rejects_grouping_effort_without_model() -> None:
with pytest.raises(ValidationError):
TeamSettingsUpdate(default_grouping_reasoning_effort="high")
def test_team_settings_update_rejects_unsupported_grouping_effort() -> None:
with pytest.raises(ValidationError):
TeamSettingsUpdate(
default_grouping_model=_GROUPING_PAIR[0],
default_grouping_reasoning_effort="max",
)