Skip to content

[Tests] Add unit tests for memory2 formatting helpers#3064

Open
xiaoyaoqilan wants to merge 2 commits into
dimensionalOS:mainfrom
xiaoyaoqilan:add-memory2-formatting-tests
Open

[Tests] Add unit tests for memory2 formatting helpers#3064
xiaoyaoqilan wants to merge 2 commits into
dimensionalOS:mainfrom
xiaoyaoqilan:add-memory2-formatting-tests

Conversation

@xiaoyaoqilan

Copy link
Copy Markdown
Contributor

Summary

  • dimos/memory2/utils/formatting.py (rich rendering helpers render_text / _colorize / FilterRepr mixin) has no test coverage. This adds dimos/memory2/utils/test_formatting.py covering: rendered text keeps its plain content, _colorize preserves the plain string while wrapping names in the cyan style, and the FilterRepr mixin renders its __str__ via the colored repr.

Why

Pure rich-only helper (no torch/ros); a cheap coverage win that matches the repo's per-module test_*.py convention.

Test plan

  • uv run pytest dimos/memory2/utils/test_formatting.py (verified locally with rich installed).

AI disclosure

AI-assisted: drafted with WorkBuddy (Claude) and reviewed by a human before submission, per the AI Usage Policy.

## Summary
- `dimos/memory2/utils/formatting.py` (rich rendering helpers `render_text` / `_colorize` / `FilterRepr` mixin) has no test coverage. This adds `dimos/memory2/utils/test_formatting.py` covering: rendered text keeps its plain content, `_colorize` preserves the plain string while wrapping names in the cyan style, and the `FilterRepr` mixin renders its `__str__` via the colored repr.

## Why
Pure rich-only helper (no torch/ros); a cheap coverage win that matches the repo's per-module `test_*.py` convention.

## Test plan
- `uv run pytest dimos/memory2/utils/test_formatting.py` (verified locally with rich installed).

## AI disclosure
AI-assisted: drafted with WorkBuddy (Claude) and reviewed by a human before submission, per the AI Usage Policy.
@greptile-apps

greptile-apps Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds unit coverage for the memory2 rich-formatting helpers.

  • Tests rendered text preserves plain content.
  • Tests pipe and arrow formatting paths.
  • Tests FilterRepr output for a simple formatted value.

Confidence Score: 5/5

This looks safe to merge.

  • No blocking issues found in the changed code.

Important Files Changed

Filename Overview
dimos/memory2/utils/test_formatting.py Adds focused tests for text rendering, colorization, and FilterRepr formatting.

Reviews (2): Last reviewed commit: "Merge branch 'main' into add-memory2-for..." | Re-trigger Greptile

Comment on lines +29 to +40
def test_colorize_preserves_plain_and_colors() -> None:
t = _colorize("a | b")
# plain text is preserved, and the names are wrapped with the cyan style
assert t.plain == "a | b"
styles = [span.style for span in t.spans]
assert "cyan" in styles


def test_colorize_pipeline_with_arrow() -> None:
t = _colorize("a -> b")
assert t.plain == "a -> b"
assert "cyan" in [span.style for span in t.spans]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Color targets remain untested

Both tests pass when any part of the result has a cyan span, including a separator or only one name. A regression that stops styling one endpoint or styles | / -> as cyan would still satisfy these assertions, so the tests do not verify the stated name-coloring behavior.

Suggested change
def test_colorize_preserves_plain_and_colors() -> None:
t = _colorize("a | b")
# plain text is preserved, and the names are wrapped with the cyan style
assert t.plain == "a | b"
styles = [span.style for span in t.spans]
assert "cyan" in styles
def test_colorize_pipeline_with_arrow() -> None:
t = _colorize("a -> b")
assert t.plain == "a -> b"
assert "cyan" in [span.style for span in t.spans]
def test_colorize_preserves_plain_and_colors() -> None:
t = _colorize("a | b")
assert t.plain == "a | b"
assert [(span.start, span.end, span.style) for span in t.spans] == [
(0, 1, "cyan"),
(1, 4, "dim"),
(4, 5, "cyan"),
]
def test_colorize_pipeline_with_arrow() -> None:
t = _colorize("a -> b")
assert t.plain == "a -> b"
assert [(span.start, span.end, span.style) for span in t.spans] == [
(0, 1, "cyan"),
(1, 5, "dim"),
(5, 6, "cyan"),
]

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Comment on lines +53 to +55
plain = re.sub(r"\x1b\[[0-9;]*m", "", rendered)
assert plain == "foo(a | b)"
assert isinstance(rendered, str)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Colored repr is not asserted

This only verifies that removing ANSI sequences yields the original text. If FilterRepr.__repr__ regresses to returning unstyled plain text, the regex is a no-op and this test still passes, despite the test's purpose being to cover colored rendering.

Suggested change
plain = re.sub(r"\x1b\[[0-9;]*m", "", rendered)
assert plain == "foo(a | b)"
assert isinstance(rendered, str)
plain = re.sub(r"\x1b\[[0-9;]*m", "", rendered)
assert plain == "foo(a | b)"
assert "\x1b[" in rendered
assert isinstance(rendered, str)

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.

1 participant