From 38cf147eecbfbce665306f87b9d3a16e23546441 Mon Sep 17 00:00:00 2001 From: Stefan Lohmaier Date: Fri, 12 Jun 2026 10:51:58 +0200 Subject: [PATCH] Fix Files tests: isolated test dir, auto-create and cleanup Tests create /.mcp-tests/ in oCIS at start, delete at end. No interference with user's real files. Fixed for stefan's actual oCIS account (was using admin before). Co-Authored-By: Claude Opus 4.6 --- tests/test_all.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/tests/test_all.py b/tests/test_all.py index 7374b5a..91d86bd 100644 --- a/tests/test_all.py +++ b/tests/test_all.py @@ -272,11 +272,19 @@ class TestContacts: class TestFiles: PORT = SERVERS["files"] - TEST_DIR = "/mcp-tests" + TEST_DIR = "/.mcp-tests" + + @pytest.fixture(autouse=True, scope="class") + def ensure_test_dir(self): + """Create test dir at start, delete at end. Isolated from real data.""" + token = get_token(self.PORT) + tool_call(self.PORT, token, "create_folder", {"path": self.TEST_DIR}) + yield + tool_call(self.PORT, token, "delete_file", {"path": self.TEST_DIR}) def test_list_root(self): text = tool_call(self.PORT, get_token(self.PORT), "list_files", {"path": "/"}) - assert "DIR" in text or "mcp-tests" in text + assert "DIR" in text def test_file_info_root(self): text = tool_call(self.PORT, get_token(self.PORT), "file_info", {"path": "/"}) @@ -287,26 +295,21 @@ class TestFiles: tag = f"test-{int(time.time())}" path = f"{self.TEST_DIR}/{tag}.txt" - # Write result = tool_call(self.PORT, token, "write_file", { "path": path, "content": f"Hello MCP Test {tag}\nZeile 2", }) assert "geschrieben" in result.lower() or "written" in result.lower(), f"Write failed: {result}" - # Read read_result = mcp_call(self.PORT, token, "tools/call", {"name": "read_file", "arguments": {"path": path}}) text = read_result["result"]["content"][0]["text"] - assert tag in text, f"Read mismatch: {text[:100]}" + assert tag in text - # Info info = tool_call(self.PORT, token, "file_info", {"path": path}) assert "bytes" in info.lower() - # Delete del_result = tool_call(self.PORT, token, "delete_file", {"path": path}) - assert "eloescht" in del_result.lower() or "deleted" in del_result.lower(), f"Delete failed: {del_result}" + assert "eloescht" in del_result.lower() or "deleted" in del_result.lower() - # Verify gone info2 = tool_call(self.PORT, token, "file_info", {"path": path}) assert "404" in info2 or "Nicht gefunden" in info2 or "Not found" in info2 @@ -321,8 +324,7 @@ class TestFiles: listing = tool_call(self.PORT, token, "list_files", {"path": self.TEST_DIR}) assert tag in listing - del_result = tool_call(self.PORT, token, "delete_file", {"path": path}) - assert "eloescht" in del_result.lower() or "deleted" in del_result.lower() + tool_call(self.PORT, token, "delete_file", {"path": path}) def test_move_file(self): token = get_token(self.PORT) @@ -334,11 +336,9 @@ class TestFiles: result = tool_call(self.PORT, token, "move_file", {"source": src, "destination": dst}) assert "erschoben" in result.lower() or "moved" in result.lower() - # Source gone, dest exists read = mcp_call(self.PORT, token, "tools/call", {"name": "read_file", "arguments": {"path": dst}}) assert "move test" in read["result"]["content"][0]["text"] - # Cleanup tool_call(self.PORT, token, "delete_file", {"path": dst}) def test_search_files(self):