Skip to content

Add comprehensive MCP tests with mocked API portions #1163

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
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
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ dependencies = [
"codeowners>=0.6.0",
"unidiff>=0.7.5",
"datamodel-code-generator>=0.26.5",
"mcp[cli]==1.9.4",
"fastmcp>=2.9.0",
# Utility dependencies
"colorlog>=6.9.0",
Expand Down
2 changes: 0 additions & 2 deletions src/codegen/cli/commands/mcp/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +0,0 @@


4 changes: 2 additions & 2 deletions src/codegen/cli/mcp/resources/system_prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -8439,10 +8439,10 @@ class FeatureFlags:

```python python
# Import datetime for timestamp
from datetime import datetime
from datetime import datetime, timezone

# Get current timestamp
timestamp = datetime.now().strftime("%B %d, %Y")
timestamp = datetime.now(timezone.utc).strftime("%B %d, %Y")

print("πŸ“š Generating and Updating Function Documentation")

Expand Down
7 changes: 4 additions & 3 deletions src/codegen/git/repo_operator/repo_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ def emptydir(self, path: str) -> None:
if os.path.isfile(file_path):
os.remove(file_path)

def get_file(self, path: str) -> str:
def get_file(self, path: str) -> str | None:
"""Returns the contents of a file"""
file_path = self.abspath(path)
try:
Expand Down Expand Up @@ -621,7 +621,7 @@ def get_filepaths_for_repo(self, ignore_list):
decoded_filepath, _ = codecs.escape_decode(raw_filepath)

# Step 4: Decode those bytes as UTF-8 to get the actual Unicode text
filepath = decoded_filepath.decode("utf-8")
filepath = decoded_filepath.decode("utf-8") # type: ignore[union-attr]

# Step 5: Replace the original filepath with the decoded filepath
filepaths[i] = filepath
Expand Down Expand Up @@ -754,7 +754,7 @@ def get_pr_data(self, pr_number: int) -> dict:
"""Returns the data associated with a PR"""
return self.remote_git_repo.get_pr_data(pr_number)

def create_pr_comment(self, pr_number: int, body: str) -> IssueComment:
def create_pr_comment(self, pr_number: int, body: str) -> IssueComment | None:
"""Create a general comment on a pull request.

Args:
Expand All @@ -765,6 +765,7 @@ def create_pr_comment(self, pr_number: int, body: str) -> IssueComment:
if pr:
comment = self.remote_git_repo.create_issue_comment(pr, body)
return comment
return None

def create_pr_review_comment(
self,
Expand Down
6 changes: 4 additions & 2 deletions src/codegen/git/schemas/repo_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@
@classmethod
def from_envs(cls) -> "RepoConfig":
default_repo_config = RepositoryConfig()
path = default_repo_config.path or os.getcwd()
language = default_repo_config.language or "python"

Check warning on line 35 in src/codegen/git/schemas/repo_config.py

View check run for this annotation

Codecov / codecov/patch

src/codegen/git/schemas/repo_config.py#L34-L35

Added lines #L34 - L35 were not covered by tests
return RepoConfig(
name=default_repo_config.name,
full_name=default_repo_config.full_name,
base_dir=os.path.dirname(default_repo_config.path),
language=ProgrammingLanguage(default_repo_config.language.upper()),
base_dir=os.path.dirname(path),
language=ProgrammingLanguage(language.upper()),
)

@classmethod
Expand Down
21 changes: 14 additions & 7 deletions src/codegen/git/utils/language.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,20 @@
ProgrammingLanguage: The dominant programming language, or OTHER if no matching files found
or if less than MIN_LANGUAGE_RATIO of files match the dominant language
"""
from codegen.sdk.python import PyFile
from codegen.sdk.typescript.file import TSFile

EXTENSIONS = {
ProgrammingLanguage.PYTHON: PyFile.get_extensions(),
ProgrammingLanguage.TYPESCRIPT: TSFile.get_extensions(),
}
try:
from codegen.sdk.python import PyFile
from codegen.sdk.typescript.file import TSFile

Check warning on line 51 in src/codegen/git/utils/language.py

View check run for this annotation

Codecov / codecov/patch

src/codegen/git/utils/language.py#L49-L51

Added lines #L49 - L51 were not covered by tests

EXTENSIONS = {

Check warning on line 53 in src/codegen/git/utils/language.py

View check run for this annotation

Codecov / codecov/patch

src/codegen/git/utils/language.py#L53

Added line #L53 was not covered by tests
ProgrammingLanguage.PYTHON: PyFile.get_extensions(),
ProgrammingLanguage.TYPESCRIPT: TSFile.get_extensions(),
}
except ImportError:

Check warning on line 57 in src/codegen/git/utils/language.py

View check run for this annotation

Codecov / codecov/patch

src/codegen/git/utils/language.py#L57

Added line #L57 was not covered by tests
# Fallback to hardcoded extensions if SDK modules are not available
EXTENSIONS = {

Check warning on line 59 in src/codegen/git/utils/language.py

View check run for this annotation

Codecov / codecov/patch

src/codegen/git/utils/language.py#L59

Added line #L59 was not covered by tests
ProgrammingLanguage.PYTHON: [".py", ".pyx", ".pyi"],
ProgrammingLanguage.TYPESCRIPT: [".ts", ".tsx", ".js", ".jsx"],
}

folder = Path(folder_path)
if not folder.exists() or not folder.is_dir():
Expand Down
4 changes: 2 additions & 2 deletions src/codegen/git/utils/pr_review.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import TYPE_CHECKING

from github import Repository
from github.PullRequest import PullRequest
from github.Repository import Repository
from unidiff import PatchSet

from codegen.git.models.pull_request_context import PullRequestContext
Expand Down Expand Up @@ -97,7 +97,7 @@ class CodegenPR:
_op: RepoOperator

# =====[ Computed ]=====
_modified_file_ranges: dict[str, list[tuple[int, int]]] = None
_modified_file_ranges: dict[str, list[tuple[int, int]]] | None = None

def __init__(self, op: RepoOperator, codebase: "Codebase", pr: PullRequest):
self._op = op
Expand Down
4 changes: 2 additions & 2 deletions src/codegen/shared/decorators/docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
import inspect
from collections.abc import Callable
from dataclasses import dataclass
from typing import TypeVar
from typing import Any, TypeVar


@dataclass
class DocumentedObject:
name: str
module: str
object: any
object: Any

def __lt__(self, other):
return self.module < other.module
Expand Down
1 change: 0 additions & 1 deletion tests/cli/mcp/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@

Loading