fix(cli): handle null memory fields in output formatters (#5957)
This commit is contained in:
@@ -20,8 +20,8 @@ def format_memories_text(console: Console, memories: list[dict], title: str = "m
|
|||||||
console.print(f"\n[{BRAND_COLOR}]Found {count} {title}:[/]\n")
|
console.print(f"\n[{BRAND_COLOR}]Found {count} {title}:[/]\n")
|
||||||
|
|
||||||
for i, mem in enumerate(memories, 1):
|
for i, mem in enumerate(memories, 1):
|
||||||
memory_text = mem.get("memory", mem.get("text", ""))
|
memory_text = mem.get("memory") or mem.get("text") or ""
|
||||||
mem_id = mem.get("id", "")[:8]
|
mem_id = (mem.get("id") or "")[:8]
|
||||||
score = mem.get("score")
|
score = mem.get("score")
|
||||||
created = _format_date(mem.get("created_at"))
|
created = _format_date(mem.get("created_at"))
|
||||||
category = mem.get("categories", [None])
|
category = mem.get("categories", [None])
|
||||||
@@ -67,8 +67,8 @@ def format_memories_table(
|
|||||||
table.add_column("Created", max_width=12)
|
table.add_column("Created", max_width=12)
|
||||||
|
|
||||||
for mem in memories:
|
for mem in memories:
|
||||||
mem_id = mem.get("id", "")
|
mem_id = mem.get("id") or ""
|
||||||
memory_text = mem.get("memory", mem.get("text", ""))
|
memory_text = mem.get("memory") or mem.get("text") or ""
|
||||||
if len(memory_text) > 60:
|
if len(memory_text) > 60:
|
||||||
memory_text = memory_text[:57] + "..."
|
memory_text = memory_text[:57] + "..."
|
||||||
categories = mem.get("categories", [])
|
categories = mem.get("categories", [])
|
||||||
@@ -104,8 +104,8 @@ def format_single_memory(console: Console, mem: dict, output: str = "text") -> N
|
|||||||
format_json(console, mem)
|
format_json(console, mem)
|
||||||
return
|
return
|
||||||
|
|
||||||
memory_text = mem.get("memory", mem.get("text", ""))
|
memory_text = mem.get("memory") or mem.get("text") or ""
|
||||||
mem_id = mem.get("id", "")
|
mem_id = mem.get("id") or ""
|
||||||
|
|
||||||
lines = []
|
lines = []
|
||||||
lines.append(f" [white bold]{memory_text}[/]")
|
lines.append(f" [white bold]{memory_text}[/]")
|
||||||
|
|||||||
@@ -54,6 +54,11 @@ class TestTextFormat:
|
|||||||
output = buf.getvalue()
|
output = buf.getvalue()
|
||||||
assert "Found 0" in output
|
assert "Found 0" in output
|
||||||
|
|
||||||
|
def test_format_memories_text_handles_null_fields(self):
|
||||||
|
console, buf = _make_console()
|
||||||
|
format_memories_text(console, [{"id": None, "memory": None, "created_at": None}])
|
||||||
|
assert "Found 1 memories" in buf.getvalue()
|
||||||
|
|
||||||
|
|
||||||
class TestTableFormat:
|
class TestTableFormat:
|
||||||
def test_format_memories_table(self):
|
def test_format_memories_table(self):
|
||||||
@@ -70,6 +75,13 @@ class TestTableFormat:
|
|||||||
# Should still render (empty table)
|
# Should still render (empty table)
|
||||||
assert "ID" in output
|
assert "ID" in output
|
||||||
|
|
||||||
|
def test_format_memories_table_handles_null_fields(self):
|
||||||
|
console, buf = _make_console()
|
||||||
|
format_memories_table(console, [{"id": None, "memory": None, "created_at": None}])
|
||||||
|
output = buf.getvalue()
|
||||||
|
assert "ID" in output
|
||||||
|
assert "Memory" in output
|
||||||
|
|
||||||
|
|
||||||
class TestSingleMemory:
|
class TestSingleMemory:
|
||||||
def test_format_single_memory_text(self):
|
def test_format_single_memory_text(self):
|
||||||
@@ -87,6 +99,17 @@ class TestSingleMemory:
|
|||||||
output = buf.getvalue()
|
output = buf.getvalue()
|
||||||
assert '"memory"' in output
|
assert '"memory"' in output
|
||||||
|
|
||||||
|
def test_format_single_memory_handles_null_fields(self):
|
||||||
|
console, buf = _make_console()
|
||||||
|
format_single_memory(
|
||||||
|
console,
|
||||||
|
{"id": None, "memory": None, "text": "Fallback memory", "created_at": None},
|
||||||
|
"text",
|
||||||
|
)
|
||||||
|
output = buf.getvalue()
|
||||||
|
assert "Fallback memory" in output
|
||||||
|
assert "ID:" not in output
|
||||||
|
|
||||||
|
|
||||||
class TestAddResult:
|
class TestAddResult:
|
||||||
def test_format_add_result_text(self):
|
def test_format_add_result_text(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user