Skip to content

test(core): regression guard for long relation_type values (#721)#770

Merged
phernandez merged 2 commits intomainfrom
fix/issue-721-regression-test
Apr 29, 2026
Merged

test(core): regression guard for long relation_type values (#721)#770
phernandez merged 2 commits intomainfrom
fix/issue-721-regression-test

Conversation

@phernandez
Copy link
Copy Markdown
Member

Summary

Why test-only

The original symptom (validation error → poisoned note) is fixed. The reporter's secondary suggestion — a parse_relation() heuristic to fall back to links_to when prose-before-link looks like a sentence — is a knowledge-graph quality improvement, not a correctness fix, and is intentionally out of scope here.

Test plan

  • pytest test-int/mcp/test_long_relation_type_integration.py --no-cov — passes
  • Confirmed: RelationType = Annotated[str, MinLen(1)] in schemas/base.py:181 (no MaxLen)
  • Confirmed: 271-char prose-before-link reproduces the historical input shape; edit succeeds
  • ruff check clean

Closes #721

🤖 Generated with Claude Code

Adds an integration test that exercises the failure mode reported in #721:
a markdown bullet with >200 chars of prose preceding an inline `[[wikilink]]`
gets parsed as a relation whose `relation_type` is the entire prose. With
the historical `MaxLen(200)` constraint on `RelationType`, the response
model would reject this on re-index, breaking edit_note for any note
matching that pattern.

Commit 01cbad1 removed the cap. This test locks the fix in so a future
contributor reintroducing `MaxLen` on `RelationType` will see the test
fail before shipping.

Closes #721

Signed-off-by: phernandez <paul@basicmachines.co>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 29, 2026

Claude finished @phernandez's task in 1m 23s —— View job


Code Review

  • Gather context and understand the PR
  • Read the new test file
  • Check related schema/model files for context
  • Review against team checklist
  • Post final review

Summary: Clean, well-scoped regression guard. The module docstring is excellent — it explains the historical bug, the fix commit, and what's explicitly out of scope. The test follows project conventions and will catch any reintroduction of MaxLen on RelationType.

Team Checklist

Category Status Notes
Coding conventions (CLAUDE.md) Follows conventions
Python 3.12+ type annotations / async async with Client(...) pattern
100-char line length All lines within limit
No commented-out code
Integration test added Placed correctly in test-int/mcp/
100% coverage maintained Test-only PR, no new production code
No DB/Alembic migration needed No schema changes
No hardcoded secrets
Windows path compatibility No path comparisons
No emojis/unicode in output
Local-first architecture preserved

Minor observations

1. Assertion specificity (test_long_relation_type_integration.py:75)

assert "Edited note" in edit_result.content[0].text

Other tests (e.g., test_edit_note_integration.py) use the more specific "Edited note (append)" since the operation is append. The current assertion would pass even if the response message changed unexpectedly. Low-impact, but worth aligning:

assert "Edited note (append)" in edit_result.content[0].text

Fix this →

2. No len(content) == 1 guard on write_result (test_long_relation_type_integration.py:60)

write_text = write_result.content[0].text

Other integration tests first assert len(result.content) == 1 before indexing. Not critical since the test would still fail clearly on an IndexError, but it's inconsistent with surrounding tests.

3. No read-back verification (optional, not blocking)

The test proves edit_note doesn't raise a validation error, which is exactly the regression being guarded. A follow-up read_note call to confirm the long relation_type is properly indexed in the response model would add depth, but it's not required for the stated goal.

Verdict

Approve. The core regression guard is correct and sufficient. Observations 1 and 2 are cosmetic nits — either address them here or leave them; neither affects correctness or the guard's purpose.

Address review nits on PR #770:
- Match the precise edit_note success string ("Edited note (append)")
  rather than the prefix, mirroring other edit_note integration tests.
- Add len(content) == 1 guards before indexing, consistent with
  surrounding integration tests.

Signed-off-by: phernandez <paul@basicmachines.co>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 29, 2026

Claude finished @phernandez's task in 1m 8s —— View job


Code Review

  • Gather context and understand the PR
  • Read the updated test file (post-fixup commit)
  • Check related schema/model files for context
  • Review against team checklist
  • Post final review

Summary: The fixup commit (e1376ca) addressed both nits from the previous review. The test is clean, well-scoped, and ready to merge.

What changed in the fixup commit

Previous Updated
assert "Edited note" in edit_result.content[0].text assert "Edited note (append)" in edit_result.content[0].text
No len() guard before write_result.content[0] assert len(write_result.content) == 1 added at line 60
No len() guard before edit_result.content[0] assert len(edit_result.content) == 1 added at line 76

Both indexing sites are now guarded, and the edit assertion matches the specificity used in other edit_note integration tests.

Schema verification

RelationType in src/basic_memory/schemas/base.py:181:

RelationType = Annotated[str, MinLen(1)]
# No MaxLen - matches DB Text column which has no length restriction

No MaxLen — the regression guard is testing the right constraint.

Team Checklist

Category Status Notes
Coding conventions (CLAUDE.md) Literate module docstring explains the bug, fix commit, and explicit out-of-scope
Python 3.12+ type annotations / async async def + @pytest.mark.asyncio
SQLAlchemy 2.0 / FastAPI / Typer N/A Test-only PR
100-char line length All lines within limit
No commented-out code
Integration test added Correctly placed in test-int/mcp/
100% coverage maintained No new production code
No DB/Alembic migration needed No schema changes
No hardcoded secrets
Windows path compatibility No path comparisons
No emojis/unicode in output
Local-first architecture preserved

Verdict

Approve. All previous nits resolved. The regression guard is correct, the len() guards are consistent with surrounding tests, and the assertion specificity now matches the operation. No further changes needed.

@phernandez phernandez merged commit 26e74ea into main Apr 29, 2026
25 checks passed
@phernandez phernandez deleted the fix/issue-721-regression-test branch April 29, 2026 03:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

edit_note fails on notes with long text around inline wikilinks (relation_type exceeds MaxLen)

1 participant