🧪 Add tests for _memory_entry helper function in memory_mcp.py#56
Conversation
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
There was a problem hiding this comment.
Sorry @sheepdestroyer, you have reached your weekly rate limit of 500000 diff characters.
Please try again later or upgrade to continue using Sourcery
|
Warning Review limit reached
More reviews will be available in 5 minutes and 26 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Code Review
This pull request introduces a new test suite test_memory_mcp.py to verify the behavior of the _memory_entry helper function in router/memory_mcp.py, covering the happy path, invalid keys, malformed JSON values, and missing fields. The feedback suggests refactoring the test that handles missing fields to avoid 'Assertion Roulette' by splitting it into separate test cases or using pytest.mark.parametrize, which also utilizes the currently unused pytest import.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| def test_memory_entry_missing_fields(): | ||
| """Test gracefully handling dictionaries with missing keys.""" | ||
| # Missing 'value' and 'memory_id' | ||
| lmem1 = { | ||
| "key": "memory:global:ideas::123:hash" | ||
| } | ||
| result1 = _memory_entry(lmem1) | ||
| assert result1 is not None | ||
| assert result1["data"] == "" | ||
| assert result1["tags"] == [] | ||
| assert result1["memory_id"] == "" | ||
|
|
||
| # Missing 'key' | ||
| lmem2 = { | ||
| "value": json.dumps({"data": "test", "tags": []}) | ||
| } | ||
| result2 = _memory_entry(lmem2) | ||
| assert result2 is None | ||
|
|
||
| # Empty dict | ||
| result3 = _memory_entry({}) | ||
| assert result3 is None |
There was a problem hiding this comment.
The test function test_memory_entry_missing_fields bundles multiple independent test scenarios (missing optional fields, missing required keys, and empty dictionaries) into a single test. This is a test smell known as Assertion Roulette, where a failure in an earlier assertion prevents subsequent independent scenarios from running, making debugging more difficult.
Since pytest is already imported in this file, we can leverage pytest.mark.parametrize to cleanly separate these test cases. This also makes use of the currently unused pytest import.
def test_memory_entry_missing_optional_fields():
"""Test gracefully handling dictionaries with missing optional fields."""
lmem = {
"key": "memory:global:ideas::123:hash"
}
result = _memory_entry(lmem)
assert result is not None
assert result["data"] == ""
assert result["tags"] == []
assert result["memory_id"] == ""
@pytest.mark.parametrize(
"lmem",
[
{"value": json.dumps({"data": "test", "tags": []})},
{},
]
)
def test_memory_entry_missing_required_key(lmem):
"""Test that missing the required 'key' field returns None."""
assert _memory_entry(lmem) is None
|
I have successfully added tests for the |
Co-authored-by: sheepdestroyer <1377479+sheepdestroyer@users.noreply.github.com>
4189d34 to
34281b0
Compare
🎯 What: The
_memory_entryhelper function inrouter/memory_mcp.pywas previously completely untested. This function is responsible for converting a raw dictionary representation of a memory entry from LiteLLM into a structured dictionary used by the MCP.📊 Coverage: The new
test_memory_mcp.pyfile covers several scenarios for the_memory_entrydictionary translation helper:"memory:", the function properly returnsNone.datafield and initializes an emptytagsarray without throwing a JSON decode error."key"or"value"or both to ensure graceful behavior, fallback values, and early exits withoutKeyErrors.✨ Result: Increased code reliability and coverage for the core memory data transformation logic with pure, isolated dictionary tests ensuring zero runtime side effects.
PR created automatically by Jules for task 9074601772171428400 started by @sheepdestroyer