|
9 | 9 |
|
10 | 10 | import pytest |
11 | 11 | from fastmcp import Client |
| 12 | +from unittest.mock import patch |
| 13 | + |
| 14 | +from basic_memory.config import ConfigManager |
12 | 15 |
|
13 | 16 |
|
14 | 17 | @pytest.mark.asyncio |
@@ -282,3 +285,64 @@ async def test_write_note_preserve_frontmatter(mcp_server, app): |
282 | 285 | assert "# Created note" in response_text |
283 | 286 | assert "file_path: test/Frontmatter Note.md" in response_text |
284 | 287 | assert "permalink: test/frontmatter-note" in response_text |
| 288 | + |
| 289 | + |
| 290 | +@pytest.mark.asyncio |
| 291 | +async def test_write_note_kebab_filenames_basic(mcp_server): |
| 292 | + """Test note creation with kebab_filenames=True and invalid filename characters.""" |
| 293 | + |
| 294 | + config = ConfigManager().config |
| 295 | + curr_config_val = config.kebab_filenames |
| 296 | + config.kebab_filenames = True |
| 297 | + |
| 298 | + with patch.object(ConfigManager, "config", config): |
| 299 | + async with Client(mcp_server) as client: |
| 300 | + result = await client.call_tool( |
| 301 | + "write_note", |
| 302 | + { |
| 303 | + "title": "My Note: With/Invalid|Chars?", |
| 304 | + "folder": "my-folder", |
| 305 | + "content": "Testing kebab-case and invalid characters.", |
| 306 | + "tags": "kebab,invalid,filename", |
| 307 | + }, |
| 308 | + ) |
| 309 | + |
| 310 | + assert len(result.content) == 1 |
| 311 | + response_text = result.content[0].text |
| 312 | + |
| 313 | + # File path and permalink should be kebab-case and sanitized |
| 314 | + assert "file_path: my-folder/my-note-with-invalid-chars.md" in response_text |
| 315 | + assert "permalink: my-folder/my-note-with-invalid-chars" in response_text |
| 316 | + |
| 317 | + # Restore original config value |
| 318 | + config.kebab_filenames = curr_config_val |
| 319 | + |
| 320 | + |
| 321 | +@pytest.mark.asyncio |
| 322 | +async def test_write_note_kebab_filenames_repeat_invalid(mcp_server): |
| 323 | + """Test note creation with multiple invalid and repeated characters.""" |
| 324 | + |
| 325 | + config = ConfigManager().config |
| 326 | + curr_config_val = config.kebab_filenames |
| 327 | + config.kebab_filenames = True |
| 328 | + |
| 329 | + with patch.object(ConfigManager, "config", config): |
| 330 | + async with Client(mcp_server) as client: |
| 331 | + result = await client.call_tool( |
| 332 | + "write_note", |
| 333 | + { |
| 334 | + "title": 'Crazy<>:"|?*Note/Name', |
| 335 | + "folder": "my-folder", |
| 336 | + "content": "Should be fully kebab-case and safe.", |
| 337 | + "tags": "crazy,filename,test", |
| 338 | + }, |
| 339 | + ) |
| 340 | + |
| 341 | + assert len(result.content) == 1 |
| 342 | + response_text = result.content[0].text |
| 343 | + |
| 344 | + assert "file_path: my-folder/crazy-note-name.md" in response_text |
| 345 | + assert "permalink: my-folder/crazy-note-name" in response_text |
| 346 | + |
| 347 | + # Restore original config value |
| 348 | + config.kebab_filenames = curr_config_val |
0 commit comments