diff --git a/backend/app/modules/code/code_context_api.py b/backend/app/modules/code/code_context_api.py index 644c889e..db3cd495 100644 --- a/backend/app/modules/code/code_context_api.py +++ b/backend/app/modules/code/code_context_api.py @@ -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") diff --git a/backend/tests/test_pr_16_code_context_validation.py b/backend/tests/test_pr_16_code_context_validation.py new file mode 100644 index 00000000..5a2cf35e --- /dev/null +++ b/backend/tests/test_pr_16_code_context_validation.py @@ -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)