Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backend/app/modules/code/code_context_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

class BuildContextRequest(BaseModel):
"""Request to build repository context."""
repoPath: str = Field(..., description="Absolute path to repository")
repoPath: str = Field(..., max_length=1024, description="Absolute path to repository")
includeGlobs: List[str] = Field(default=["*"], description="Glob patterns to include")
excludeGlobs: List[str] = Field(default=[], description="Additional glob patterns to exclude")
maxFileSize: int = Field(default=1024*1024, description="Maximum file size in bytes")
Expand Down
35 changes: 35 additions & 0 deletions backend/tests/test_pr_16_code_context_validation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""Tests for code_context_api BuildContextRequest repoPath validation (PR-B16)."""
import sys
import os
import pytest

sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))

from app.modules.code.code_context_api import BuildContextRequest


class TestBuildContextRequestRepoPathMaxLength:
"""repoPath must reject values longer than 1024 characters."""

def test_normal_repopath_accepted(self):
req = BuildContextRequest(repoPath="/home/user/repos/project")
assert req.repoPath == "/home/user/repos/project"

def test_repopath_at_max_length_accepted(self):
path = "a" * 1024
req = BuildContextRequest(repoPath=path)
assert len(req.repoPath) == 1024

def test_repopath_over_max_length_rejected(self):
from pydantic import ValidationError
path = "a" * 1025
with pytest.raises(ValidationError) as exc_info:
BuildContextRequest(repoPath=path)
errors = exc_info.value.errors()
assert any("repoPath" in str(e.get("loc", "")) for e in errors)

def test_repopath_massively_over_rejected(self):
from pydantic import ValidationError
path = "z" * 50000
with pytest.raises(ValidationError):
BuildContextRequest(repoPath=path)