|
1 | 1 | """Integration tests for project CLI commands.""" |
2 | 2 |
|
| 3 | +import tempfile |
| 4 | +from pathlib import Path |
| 5 | + |
3 | 6 | from typer.testing import CliRunner |
4 | 7 |
|
5 | 8 | from basic_memory.cli.main import app |
@@ -52,61 +55,67 @@ def test_project_info_json(app_config, test_project, config_manager): |
52 | 55 | assert "system" in data |
53 | 56 |
|
54 | 57 |
|
55 | | -def test_project_add_and_remove(app_config, tmp_path, config_manager): |
| 58 | +def test_project_add_and_remove(app_config, config_manager): |
56 | 59 | """Test adding and removing a project.""" |
57 | 60 | runner = CliRunner() |
58 | | - new_project_path = tmp_path / "new-project" |
59 | | - new_project_path.mkdir() |
60 | 61 |
|
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() |
63 | 66 |
|
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)]) |
72 | 69 |
|
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 | + ) |
77 | 78 |
|
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() |
82 | 88 |
|
83 | 89 |
|
84 | | -def test_project_set_default(app_config, tmp_path, config_manager): |
| 90 | +def test_project_set_default(app_config, config_manager): |
85 | 91 | """Test setting default project.""" |
86 | 92 | runner = CliRunner() |
87 | | - new_project_path = tmp_path / "another-project" |
88 | | - new_project_path.mkdir() |
89 | 93 |
|
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 |
0 commit comments