-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
89 lines (71 loc) · 3.05 KB
/
Copy pathtest.py
File metadata and controls
89 lines (71 loc) · 3.05 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
"""
CodeLens – basic smoke tests.
Run: pytest test.py -v
"""
import os
import pytest
from unittest.mock import patch, MagicMock
def test_tools_import():
"""Tools module must import without triggering model download."""
import tools
assert callable(tools.read_file)
assert callable(tools.write_file)
assert callable(tools.grep_search)
assert callable(tools.get_directory_tree)
assert callable(tools.get_file_outline)
assert callable(tools.codebase_search)
assert callable(tools.run_terminal_command)
assert len(tools.ALL_TOOLS) == 8
def test_write_and_read_file(tmp_path):
"""write_file then read_file should round-trip content."""
from tools import write_file, read_file
target = str(tmp_path / "hello.txt")
result = write_file.invoke({"file_path": target, "content": "hello codelens"})
assert "Successfully" in result
content = read_file.invoke({"file_path": target})
assert content == "hello codelens"
def test_write_file_no_dir(tmp_path):
"""write_file with no directory component should not raise."""
from tools import write_file
os.chdir(tmp_path)
result = write_file.invoke({"file_path": "plain.txt", "content": "test"})
assert "Successfully" in result
def test_get_directory_tree(tmp_path):
"""get_directory_tree should return a non-empty string."""
from tools import get_directory_tree
(tmp_path / "src").mkdir()
(tmp_path / "src" / "main.py").write_text("# main")
result = get_directory_tree.invoke({"directory": str(tmp_path), "max_depth": 2})
assert "main.py" in result
def test_get_file_outline(tmp_path):
"""get_file_outline should detect class and function definitions."""
from tools import get_file_outline
f = tmp_path / "sample.py"
f.write_text("class Foo:\n def bar(self):\n pass\n")
result = get_file_outline.invoke({"file_path": str(f)})
assert "class Foo" in result
assert "def bar" in result
def test_run_terminal_command_blocked():
"""Dangerous commands should be blocked."""
from tools import run_terminal_command
result = run_terminal_command.invoke({"command": "rm -rf /"})
assert "Blocked" in result
def test_run_terminal_command_allowed():
"""Safe commands should run normally."""
from tools import run_terminal_command
result = run_terminal_command.invoke({"command": "echo hello"})
assert "hello" in result
def test_codebase_search_no_db():
"""codebase_search should return a helpful error when DB is missing."""
from tools import codebase_search
with patch("os.path.exists", return_value=False):
result = codebase_search.invoke({"query": "authentication"})
assert "Error" in result or "not found" in result.lower()
def test_config_imports():
"""Config values should be strings/ints as expected."""
from config import DB_PATH, REPO_PATH, EMBED_MODEL, LLM_MODEL, BATCH_SIZE
assert isinstance(DB_PATH, str)
assert isinstance(REPO_PATH, str)
assert isinstance(EMBED_MODEL, str)
assert isinstance(LLM_MODEL, str)
assert isinstance(BATCH_SIZE, int)