feat(mcp): Validate C++ tools against real-world gencpp components and improve enum support
This commit is contained in:
@@ -71,7 +71,7 @@ void templateFunc(T t) {
|
||||
mcp_client._resolve_and_check = original_resolve
|
||||
|
||||
def test_exhaustive_gencpp_corpus():
|
||||
base_dir = Path(__file__).parent / "assets" / "gencpp_samples"
|
||||
base_dir = Path(__file__).parent / "assets" / "cpp_samples"
|
||||
files_to_test = {
|
||||
"base_component.h": [
|
||||
"BaseComponent",
|
||||
@@ -126,7 +126,7 @@ def test_exhaustive_gencpp_corpus():
|
||||
mcp_client._resolve_and_check = original_resolve
|
||||
|
||||
def test_ts_cpp_update_definition(tmp_path):
|
||||
asset_path = Path(__file__).parent / "assets" / "gencpp_samples" / "component_registry.cpp"
|
||||
asset_path = Path(__file__).parent / "assets" / "cpp_samples" / "component_registry.cpp"
|
||||
cpp_content = asset_path.read_text(encoding="utf-8")
|
||||
cpp_file = tmp_path / "component_registry.cpp"
|
||||
cpp_file.write_text(cpp_content, encoding="utf-8")
|
||||
@@ -157,3 +157,86 @@ def test_ts_cpp_update_definition(tmp_path):
|
||||
assert "DEBUG: Registering" in definition
|
||||
finally:
|
||||
mcp_client._resolve_and_check = original_resolve
|
||||
|
||||
def test_exhaustive_gencpp_samples():
|
||||
base_dir = Path(__file__).parent / "assets" / "gencpp_samples"
|
||||
files_to_test = {
|
||||
"ast.hpp": [
|
||||
"AST",
|
||||
"AST_Body",
|
||||
"AST_Class",
|
||||
"AST_Fn",
|
||||
"AST_Struct"
|
||||
],
|
||||
"parser.cpp": [
|
||||
"parser_push",
|
||||
"parser_pop",
|
||||
"parser_to_strbuilder",
|
||||
"lex__eat"
|
||||
],
|
||||
"types.hpp": [
|
||||
"LogLevel",
|
||||
"loglevel_to_str",
|
||||
"AccessSpec",
|
||||
"access_spec_to_str",
|
||||
"ModuleFlag"
|
||||
]
|
||||
}
|
||||
|
||||
from src import mcp_client
|
||||
original_resolve = mcp_client._resolve_and_check
|
||||
mcp_client._resolve_and_check = lambda path: (Path(path), None)
|
||||
|
||||
try:
|
||||
for filename, symbols in files_to_test.items():
|
||||
path = base_dir / filename
|
||||
assert path.exists(), f"{path} does not exist"
|
||||
|
||||
# 1. Verify skeleton executes without errors
|
||||
skeleton = ts_cpp_get_skeleton(str(path))
|
||||
assert skeleton and not skeleton.startswith("ERROR")
|
||||
|
||||
# 2. Verify code outline executes without errors
|
||||
outline = ts_cpp_get_code_outline(str(path))
|
||||
assert outline and not outline.startswith("ERROR")
|
||||
|
||||
# 3. Verify specific complex symbols can be retrieved via ts_cpp_get_definition
|
||||
for symbol in symbols:
|
||||
definition = ts_cpp_get_definition(str(path), symbol)
|
||||
assert definition and not definition.startswith("ERROR"), f"Failed for {symbol} in {filename}: {definition}"
|
||||
simple_name = symbol.split("::")[-1]
|
||||
assert simple_name in definition
|
||||
finally:
|
||||
mcp_client._resolve_and_check = original_resolve
|
||||
|
||||
def test_ts_cpp_update_definition_gencpp(tmp_path):
|
||||
asset_path = Path(__file__).parent / "assets" / "gencpp_samples" / "parser.cpp"
|
||||
cpp_content = asset_path.read_text(encoding="utf-8")
|
||||
cpp_file = tmp_path / "parser.cpp"
|
||||
cpp_file.write_text(cpp_content, encoding="utf-8")
|
||||
|
||||
from src import mcp_client
|
||||
original_resolve = mcp_client._resolve_and_check
|
||||
mcp_client._resolve_and_check = lambda path: (Path(path), None)
|
||||
|
||||
try:
|
||||
# Update parser_pop
|
||||
new_pop_body = """void parser_pop(ParseContext* ctx)
|
||||
{
|
||||
#if 0 && GEN_BUILD_DEBUG
|
||||
log_fmt("\\tPopping parser: %.*s\\n", Scope->ProcName.Len, Scope->ProcName.Ptr );
|
||||
#endif
|
||||
// HELLO FROM TEST
|
||||
ctx->scope = ctx->scope->prev;
|
||||
}"""
|
||||
result = ts_cpp_update_definition(str(cpp_file), "parser_pop", new_pop_body)
|
||||
assert "Successfully updated" in result
|
||||
|
||||
updated_content = cpp_file.read_text(encoding="utf-8")
|
||||
assert "// HELLO FROM TEST" in updated_content
|
||||
|
||||
# Verify retrieval
|
||||
definition = ts_cpp_get_definition(str(cpp_file), "parser_pop")
|
||||
assert "// HELLO FROM TEST" in definition
|
||||
finally:
|
||||
mcp_client._resolve_and_check = original_resolve
|
||||
|
||||
Reference in New Issue
Block a user