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_c_get_skeleton, ts_c_get_code_outline

def test_ts_c_get_skeleton(tmp_path):
 c_code = """#include <stdio.h>

void hello() {
 printf("Hello, World!\\n");
}

int add(int a, int b) {
 return a + b;
}

struct Point {
 int x;
 int y;
};
"""
 c_file = tmp_path / "test.c"
 c_file.write_text(c_code)
 
 # Mock _resolve_and_check to allow tmp_path
 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_c_get_skeleton(str(c_file))
  assert "void hello() { ... }" in skeleton
  assert "int add(int a, int b) { ... }" in skeleton
  assert "struct Point" in skeleton
  assert "printf" not in skeleton
 finally:
  mcp_client._resolve_and_check = original_resolve

def test_ts_c_get_code_outline(tmp_path):
 c_code = """
void func1() {
}

int func2(int x) {
 return x * 2;
}
"""
 c_file = tmp_path / "test.c"
 c_file.write_text(c_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_c_get_code_outline(str(c_file))
  assert "[Func] func1 (Lines 2-3)" in outline
  assert "[Func] func2 (Lines 5-7)" in outline
 finally:
  mcp_client._resolve_and_check = original_resolve
