test(mcp): Add tests for C/C++ skeleton and outline tools

This commit is contained in:
2026-05-05 19:07:17 -04:00
parent 6490be7616
commit 3bb850aca9
4 changed files with 232 additions and 2 deletions
+71
View File
@@ -0,0 +1,71 @@
import pytest
from pathlib import Path
import os
import sys
# Add project root to sys.path
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
from src.mcp_client import ts_cpp_get_skeleton, ts_cpp_get_code_outline
def test_ts_cpp_get_skeleton(tmp_path):
cpp_code = """#include <iostream>
#include <vector>
template<typename T>
class Box {
public:
Box(T val) : value(val) {}
T getValue() {
return value;
}
private:
T value;
};
void globalFunc() {
std::cout << "Global" << std::endl;
}
"""
cpp_file = tmp_path / "test.cpp"
cpp_file.write_text(cpp_code)
from src import mcp_client
original_resolve = mcp_client._resolve_and_check
mcp_client._resolve_and_check = lambda path: (Path(path), None)
try:
skeleton = ts_cpp_get_skeleton(str(cpp_file))
assert "class Box" in skeleton
assert "Box(T val) ..." in skeleton
assert "T getValue() ..." in skeleton
assert "void globalFunc() ..." in skeleton
assert "std::cout" not in skeleton
finally:
mcp_client._resolve_and_check = original_resolve
def test_ts_cpp_get_code_outline(tmp_path):
cpp_code = """
class MyClass {
void method1() {
}
};
template<typename T>
void templateFunc(T t) {
}
"""
cpp_file = tmp_path / "test.cpp"
cpp_file.write_text(cpp_code)
from src import mcp_client
original_resolve = mcp_client._resolve_and_check
mcp_client._resolve_and_check = lambda path: (Path(path), None)
try:
outline = ts_cpp_get_code_outline(str(cpp_file))
assert "[Class] MyClass (Lines 2-5)" in outline
assert "[Method] method1 (Lines 3-4)" in outline
assert "[Func] templateFunc (Lines 8-9)" in outline
finally:
mcp_client._resolve_and_check = original_resolve