-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathtest_example.py
More file actions
61 lines (47 loc) · 1.68 KB
/
test_example.py
File metadata and controls
61 lines (47 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env python3
"""
Test for the filesystem_context example.
This example runs synchronously and tests the FileSystemContext API for:
- Creating an MCP-based context
- Searching a local directory
- Using search_and_ask for Q&A and code review
- Properly closing the MCP connection
"""
import subprocess
import sys
from pathlib import Path
def main():
"""Run the filesystem_context example and verify it completes successfully."""
# Get the package directory and run from parent so module execution works
package_dir = Path(__file__).parent
context_dir = package_dir.parent
print("Running: python -m filesystem_context")
print(f"Working directory: {context_dir}")
result = subprocess.run(
[sys.executable, "-m", "filesystem_context"],
capture_output=True,
text=True,
timeout=300, # 5 minutes - multiple LLM API calls via search_and_ask
cwd=str(context_dir),
)
# Print output for debugging
if result.stdout:
print("=== stdout ===")
print(result.stdout)
if result.stderr:
print("=== stderr ===")
print(result.stderr)
# Verify success
if result.returncode != 0:
print(f"❌ Example failed with exit code {result.returncode}")
sys.exit(1)
# Verify expected output
if "=== Sample Complete ===" not in result.stdout:
print("❌ Example did not complete successfully (missing completion message)")
sys.exit(1)
if "MCP connection closed" not in result.stdout:
print("❌ Example did not properly close MCP connection")
sys.exit(1)
print("✅ filesystem_context example passed")
if __name__ == "__main__":
main()