mirror of
https://github.com/rennf93/roboco.git
synced 2026-08-03 07:23:24 +02:00
* [f8480831] refactor(api): extract route-layer helpers into services/schemas/utils (batch B) Moves 28 non-@router-decorated helper functions out of 15 route files (optimal, project, release, dashboard, pitch, x, docs, git, playbooks, product, provider, research, secretary, system, work_session) into their paired services module (DB/service-calling helpers), the route's schemas module as a converter (pure response/request shaping, mirroring the existing project_to_response/assignment_to_response pattern), or roboco/utils/converters.py (pure generic helpers). Adds two small shared role-check helpers to api/deps.py (require_auditor_or_ceo, require_role_in) for endpoint-specific role gates that had no existing home. Placement-only: no route paths, schemas, or observable behavior changed. Fixes the handful of tests that imported the old private helper names directly. * [f8480831] docs(map): document Batch B route-helper relocation in api-routes-schemas.md * [f8480831] docs(map): add Key Symbols rows for require_auditor_or_ceo/require_role_in --------- Co-authored-by: Backend Developer 2 <be-dev-2@roboco.tech> Co-authored-by: Backend Documenter <be-doc@roboco.tech>
108 lines
3.3 KiB
Python
108 lines
3.3 KiB
Python
"""Unit tests for the /git/file range computation (roboco.utils.converters).
|
|
|
|
Pure logic — no DB, no git. Covers the line/context windowing, explicit
|
|
range, whole-file cap, and truncation flag.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from roboco.api.routes.git import _FILE_MAX_LINES
|
|
from roboco.utils.converters import compute_file_range
|
|
|
|
|
|
class TestComputeFileRange:
|
|
def test_line_centers_context_window(self) -> None:
|
|
s, e_, trunc = compute_file_range(
|
|
total=100,
|
|
line=50,
|
|
context=10,
|
|
explicit_range=None,
|
|
max_lines=_FILE_MAX_LINES,
|
|
)
|
|
assert (s, e_, trunc) == (40, 60, True)
|
|
|
|
def test_line_window_clamps_to_file_start(self) -> None:
|
|
s, e_, trunc = compute_file_range(
|
|
total=100,
|
|
line=3,
|
|
context=10,
|
|
explicit_range=None,
|
|
max_lines=_FILE_MAX_LINES,
|
|
)
|
|
assert (s, e_, trunc) == (1, 13, True)
|
|
|
|
def test_line_window_clamps_to_file_end(self) -> None:
|
|
s, e_, trunc = compute_file_range(
|
|
total=100,
|
|
line=98,
|
|
context=10,
|
|
explicit_range=None,
|
|
max_lines=_FILE_MAX_LINES,
|
|
)
|
|
assert (s, e_, trunc) == (88, 100, False)
|
|
|
|
def test_explicit_start_end_override_line(self) -> None:
|
|
s, e_, trunc = compute_file_range(
|
|
total=100,
|
|
line=50,
|
|
context=10,
|
|
explicit_range=(5, 8),
|
|
max_lines=_FILE_MAX_LINES,
|
|
)
|
|
assert (s, e_, trunc) == (5, 8, True)
|
|
|
|
def test_whole_file_when_no_range_args(self) -> None:
|
|
s, e_, trunc = compute_file_range(
|
|
total=50,
|
|
line=None,
|
|
context=10,
|
|
explicit_range=None,
|
|
max_lines=_FILE_MAX_LINES,
|
|
)
|
|
assert (s, e_, trunc) == (1, 50, False)
|
|
|
|
def test_whole_file_capped_when_huge(self) -> None:
|
|
total = _FILE_MAX_LINES + 500
|
|
s, e_, trunc = compute_file_range(
|
|
total=total,
|
|
line=None,
|
|
context=10,
|
|
explicit_range=None,
|
|
max_lines=_FILE_MAX_LINES,
|
|
)
|
|
assert (s, e_, trunc) == (1, _FILE_MAX_LINES, True)
|
|
|
|
def test_empty_file(self) -> None:
|
|
s, e_, trunc = compute_file_range(
|
|
total=0,
|
|
line=None,
|
|
context=10,
|
|
explicit_range=None,
|
|
max_lines=_FILE_MAX_LINES,
|
|
)
|
|
assert (s, e_, trunc) == (1, 1, False)
|
|
|
|
def test_near_whole_file_explicit_range_still_capped(self) -> None:
|
|
# start=1, end=total-1 is not the exact-whole-file shape, but the
|
|
# resolved window is still oversized and must be capped.
|
|
total = 50000
|
|
s, e_, trunc = compute_file_range(
|
|
total=total,
|
|
line=None,
|
|
context=10,
|
|
explicit_range=(1, total - 1),
|
|
max_lines=_FILE_MAX_LINES,
|
|
)
|
|
assert (s, e_, trunc) == (1, _FILE_MAX_LINES, True)
|
|
|
|
def test_oversized_line_context_window_is_capped(self) -> None:
|
|
total = 10000
|
|
s, e_, trunc = compute_file_range(
|
|
total=total,
|
|
line=5000,
|
|
context=3000,
|
|
explicit_range=None,
|
|
max_lines=_FILE_MAX_LINES,
|
|
)
|
|
assert (s, e_, trunc) == (2000, 2000 + _FILE_MAX_LINES - 1, True)
|