Adds the pydantic-settings Settings with validated GITEA_URL, OAuth scopes and toolsets, the argparse CLI skeleton, catalog.model, identity and GiteaAPIError. Test fixtures now isolate env, cwd and state paths in tmp.
47 lines
1.4 KiB
Python
47 lines
1.4 KiB
Python
"""Tests for response size bounds."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import pytest
|
|
|
|
from aegis_gitea_mcp.config import reset_settings
|
|
from aegis_gitea_mcp.response_limits import ResponseLimitError, limit_items, limit_text
|
|
|
|
|
|
def test_limit_items_uses_configured_default(
|
|
mock_env: None, monkeypatch: pytest.MonkeyPatch
|
|
) -> None:
|
|
monkeypatch.setenv("MAX_TOOL_RESPONSE_ITEMS", "3")
|
|
reset_settings()
|
|
items = [{"i": n} for n in range(5)]
|
|
|
|
trimmed, omitted = limit_items(items)
|
|
|
|
assert trimmed == items[:3]
|
|
assert omitted == 2
|
|
|
|
|
|
def test_limit_items_within_bound(mock_env: None) -> None:
|
|
items = [{"i": 1}]
|
|
assert limit_items(items) == (items, 0)
|
|
assert limit_items(items, configured_limit=1) == (items, 0)
|
|
assert limit_items([{"i": 1}, {"i": 2}], configured_limit=1) == ([{"i": 1}], 1)
|
|
|
|
|
|
def test_limit_text(mock_env: None) -> None:
|
|
assert limit_text("abcdef", configured_limit=3) == "abc"
|
|
assert limit_text("abc", configured_limit=10) == "abc"
|
|
|
|
|
|
def test_limit_text_default_from_settings(mock_env: None, monkeypatch: pytest.MonkeyPatch) -> None:
|
|
monkeypatch.setenv("MAX_TOOL_RESPONSE_CHARS", "5")
|
|
reset_settings()
|
|
assert limit_text("abcdefghij") == "abcde"
|
|
|
|
|
|
def test_invalid_limits_raise(mock_env: None) -> None:
|
|
with pytest.raises(ResponseLimitError):
|
|
limit_items([], configured_limit=-1)
|
|
with pytest.raises(ResponseLimitError):
|
|
limit_text("x", configured_limit=-1)
|