fix: prevent nested project paths to avoid data conflicts (#338) · basicmachines-co/basic-memory@795e339 · GitHub
Skip to content

Commit 795e339

Browse files
phernandezclaude
andauthored
fix: prevent nested project paths to avoid data conflicts (#338)
Signed-off-by: phernandez <paul@basicmachines.co> Co-authored-by: Claude <noreply@anthropic.com>
1 parent 07e304c commit 795e339

8 files changed

Lines changed: 1347 additions & 991 deletions

src/basic_memory/services/project_service.py

Lines changed: 57 additions & 0 deletions
Lines changed: 56 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
"""Integration tests for project CLI commands."""
22

3+
import tempfile
4+
from pathlib import Path
5+
36
from typer.testing import CliRunner
47

58
from basic_memory.cli.main import app
@@ -52,61 +55,67 @@ def test_project_info_json(app_config, test_project, config_manager):
5255
assert "system" in data
5356

5457

55-
def test_project_add_and_remove(app_config, tmp_path, config_manager):
58+
def test_project_add_and_remove(app_config, config_manager):
5659
"""Test adding and removing a project."""
5760
runner = CliRunner()
58-
new_project_path = tmp_path / "new-project"
59-
new_project_path.mkdir()
6061

61-
# Add project
62-
result = runner.invoke(app, ["project", "add", "new-project", str(new_project_path)])
62+
# Use a separate temporary directory to avoid nested path conflicts
63+
with tempfile.TemporaryDirectory() as temp_dir:
64+
new_project_path = Path(temp_dir) / "new-project"
65+
new_project_path.mkdir()
6366

64-
if result.exit_code != 0:
65-
print(f"STDOUT: {result.stdout}")
66-
print(f"STDERR: {result.stderr}")
67-
assert result.exit_code == 0
68-
assert (
69-
"Project 'new-project' added successfully" in result.stdout
70-
or "added" in result.stdout.lower()
71-
)
67+
# Add project
68+
result = runner.invoke(app, ["project", "add", "new-project", str(new_project_path)])
7269

73-
# Verify it shows up in list
74-
result = runner.invoke(app, ["project", "list"])
75-
assert result.exit_code == 0
76-
assert "new-project" in result.stdout
70+
if result.exit_code != 0:
71+
print(f"STDOUT: {result.stdout}")
72+
print(f"STDERR: {result.stderr}")
73+
assert result.exit_code == 0
74+
assert (
75+
"Project 'new-project' added successfully" in result.stdout
76+
or "added" in result.stdout.lower()
77+
)
7778

78-
# Remove project
79-
result = runner.invoke(app, ["project", "remove", "new-project"])
80-
assert result.exit_code == 0
81-
assert "removed" in result.stdout.lower() or "deleted" in result.stdout.lower()
79+
# Verify it shows up in list
80+
result = runner.invoke(app, ["project", "list"])
81+
assert result.exit_code == 0
82+
assert "new-project" in result.stdout
83+
84+
# Remove project
85+
result = runner.invoke(app, ["project", "remove", "new-project"])
86+
assert result.exit_code == 0
87+
assert "removed" in result.stdout.lower() or "deleted" in result.stdout.lower()
8288

8389

84-
def test_project_set_default(app_config, tmp_path, config_manager):
90+
def test_project_set_default(app_config, config_manager):
8591
"""Test setting default project."""
8692
runner = CliRunner()
87-
new_project_path = tmp_path / "another-project"
88-
new_project_path.mkdir()
8993

90-
# Add a second project
91-
result = runner.invoke(app, ["project", "add", "another-project", str(new_project_path)])
92-
if result.exit_code != 0:
93-
print(f"STDOUT: {result.stdout}")
94-
print(f"STDERR: {result.stderr}")
95-
assert result.exit_code == 0
96-
97-
# Set as default
98-
result = runner.invoke(app, ["project", "default", "another-project"])
99-
if result.exit_code != 0:
100-
print(f"STDOUT: {result.stdout}")
101-
print(f"STDERR: {result.stderr}")
102-
assert result.exit_code == 0
103-
assert "default" in result.stdout.lower()
104-
105-
# Verify in list
106-
result = runner.invoke(app, ["project", "list"])
107-
assert result.exit_code == 0
108-
# The new project should have the checkmark now
109-
lines = result.stdout.split("\n")
110-
for line in lines:
111-
if "another-project" in line:
112-
assert "✓" in line
94+
# Use a separate temporary directory to avoid nested path conflicts
95+
with tempfile.TemporaryDirectory() as temp_dir:
96+
new_project_path = Path(temp_dir) / "another-project"
97+
new_project_path.mkdir()
98+
99+
# Add a second project
100+
result = runner.invoke(app, ["project", "add", "another-project", str(new_project_path)])
101+
if result.exit_code != 0:
102+
print(f"STDOUT: {result.stdout}")
103+
print(f"STDERR: {result.stderr}")
104+
assert result.exit_code == 0
105+
106+
# Set as default
107+
result = runner.invoke(app, ["project", "default", "another-project"])
108+
if result.exit_code != 0:
109+
print(f"STDOUT: {result.stdout}")
110+
print(f"STDERR: {result.stderr}")
111+
assert result.exit_code == 0
112+
assert "default" in result.stdout.lower()
113+
114+
# Verify in list
115+
result = runner.invoke(app, ["project", "list"])
116+
assert result.exit_code == 0
117+
# The new project should have the checkmark now
118+
lines = result.stdout.split("\n")
119+
for line in lines:
120+
if "another-project" in line:
121+
assert "✓" in line

test-int/mcp/test_project_management_integration.py

Lines changed: 39 additions & 0 deletions

0 commit comments

Comments
 (0)