-
Notifications
You must be signed in to change notification settings - Fork 216
fix(core): split comma-separated tags in parse_tags #911
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
81 changes: 81 additions & 0 deletions
81
test-int/bughunt_fixes/test_parse_tags_comma_split_integration.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| """Bug: CLI `write-note --tags "a,b"` does NOT split the comma string, but the | ||
| MCP write_note(tags="a,b") DOES (parse_tags splits a bare string but treats each | ||
| list element as a single literal tag). | ||
|
|
||
| Typer collects a single --tags value into a one-element list ['a,b'], and | ||
| parse_tags(['a,b']) returns ['a,b'] (no per-element comma split). The MCP tool | ||
| receives the bare string 'a,b' and parse_tags('a,b') returns ['a','b']. | ||
|
|
||
| Result: the SAME comma-string input yields different tags on CLI vs MCP, even | ||
| though write_note's docstring promises comma-separated-string support. | ||
| """ | ||
|
|
||
| import json | ||
| import pytest | ||
| from fastmcp import Client | ||
| from typer.testing import CliRunner | ||
| from basic_memory.cli.main import app as cli_app | ||
|
|
||
| runner = CliRunner() | ||
|
|
||
|
|
||
| def test_cli_write_note_comma_tags_split_matches_mcp(app, app_config, test_project, config_manager): | ||
| # CLI: single --tags value containing a comma | ||
| write = runner.invoke( | ||
| cli_app, | ||
| [ | ||
| "tool", | ||
| "write-note", | ||
| "--title", | ||
| "CLI Comma Split", | ||
| "--folder", | ||
| "cli-comma-split", | ||
| "--content", | ||
| "# CLI Comma Split\n\nbody", | ||
| "--tags", | ||
| "alpha,beta", | ||
| ], | ||
| ) | ||
| assert write.exit_code == 0, write.output | ||
| permalink = json.loads(write.stdout)["permalink"] | ||
|
|
||
| read = runner.invoke( | ||
| cli_app, | ||
| ["tool", "read-note", permalink, "--include-frontmatter", "--local"], | ||
| ) | ||
| assert read.exit_code == 0, read.output | ||
| content = json.loads(read.stdout)["content"] | ||
|
|
||
| # Correct behavior: two distinct tags (matching MCP write_note semantics). | ||
| # splitlines() is line-ending agnostic (Windows CRLF vs POSIX LF). | ||
| content_lines = content.splitlines() | ||
| assert "- alpha" in content_lines and "- beta" in content_lines, ( | ||
| "CLI --tags 'alpha,beta' should split into two tags like MCP write_note does; " | ||
| f"got frontmatter:\n{content}" | ||
| ) | ||
| assert "alpha,beta" not in content, "comma string must not survive as a single literal tag" | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_mcp_write_note_comma_tags_split_baseline(mcp_server, app, test_project): | ||
| """Baseline: MCP write_note DOES split comma strings (the behavior CLI should match).""" | ||
| async with Client(mcp_server) as client: | ||
| await client.call_tool( | ||
| "write_note", | ||
| { | ||
| "project": test_project.name, | ||
| "title": "MCP Comma Split", | ||
| "directory": "mcp-comma-split", | ||
| "content": "# MCP Comma Split\n\nbody", | ||
| "tags": "alpha,beta", | ||
| }, | ||
| ) | ||
| read = await client.call_tool( | ||
| "read_note", | ||
| {"project": test_project.name, "identifier": "MCP Comma Split"}, | ||
| ) | ||
| text = read.content[0].text | ||
| text_lines = text.splitlines() | ||
| assert "- alpha" in text_lines and "- beta" in text_lines, ( | ||
| f"MCP write_note should split comma string into two tags; got:\n{text}" | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When frontmatter or a JSON tag array contains a null entry, e.g.
tags: [alpha, null],normalize_frontmatter_metadata()preserves thatNoneand passes the list intoparse_tags(). The old list branch skipped falsy entries, but this change stringifies each raw item before filtering, soNonebecomes the literal tag"None"and can be indexed or written back as a real tag. Filterraw/Nonebefore splitting so comma-separated strings are still flattened without reviving previously ignored null tag values.Useful? React with 👍 / 👎.