Skip to content

Commit e18e281

Browse files
KhrulkovVclaude
andcommitted
test: integration test for ideas_tracker dict aliases (Bug #2, PR #161)
Added tests that verify normalize_memory_card and load_memory_cards handle ideas_tracker's structured alias format (list[dict] version history) without crashing. This test would have caught the Pydantic type mismatch that crashed the memory write pipeline (aliases: list[str] → list[dict]). Tests added: - test_aliases_with_ideas_tracker_dict_format (test_normalize_memory_card.py) - test_aliases_mixed_types (test_normalize_memory_card.py) - test_ideas_tracker_dict_aliases_preserved (test_memory_write_example_extended.py) All 91 tests pass. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent c497afd commit e18e281

2 files changed

Lines changed: 74 additions & 0 deletions

File tree

tests/memory/test_card_normalization.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,43 @@ def test_explanation_with_extra_keys_preserved(self):
357357
# Only explanations and summary are extracted
358358
assert "extra" not in MemoryCardExplanation.model_fields
359359

360+
def test_aliases_with_ideas_tracker_dict_format(self):
361+
"""Ideas tracker stores aliases as list[dict] version history, not list[str].
362+
363+
RecordCardExtended.aliases appends dicts like:
364+
{"exp1-prog1": {"description": "old", "programs": ["p1"], "explanations": ["e"]}}
365+
This must pass through normalize_memory_card without crashing (Bug #2, PR #161).
366+
"""
367+
aliases = [
368+
{
369+
"exp1-prog1": {
370+
"description": "old description",
371+
"programs": ["p1", "p2"],
372+
"explanations": ["initial explanation"],
373+
}
374+
},
375+
{
376+
"exp2-prog3": {
377+
"description": "updated description",
378+
"programs": ["p3"],
379+
"explanations": ["revised"],
380+
}
381+
},
382+
]
383+
result = normalize_memory_card(
384+
{"id": "idea-1", "description": "current", "aliases": aliases}
385+
)
386+
assert isinstance(result, MemoryCard)
387+
assert result.aliases == aliases
388+
assert len(result.aliases) == 2
389+
assert isinstance(result.aliases[0], dict)
390+
391+
def test_aliases_mixed_types(self):
392+
"""Aliases can mix strings and dicts (legacy + ideas_tracker)."""
393+
aliases = ["simple-alias", {"exp1-prog1": {"description": "old"}}]
394+
result = normalize_memory_card({"id": "idea-2", "aliases": aliases})
395+
assert result.aliases == aliases
396+
360397
def test_nested_dict_in_evolution_statistics(self):
361398
stats = {"nested": {"deep": True}}
362399
result = normalize_memory_card({"evolution_statistics": stats})

tests/memory/test_write_pipeline.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,43 @@ def test_program_without_fitness_skipped(self, tmp_path):
220220
assert len(program_cards) == 1
221221
assert program_cards[0].program_id == "p2"
222222

223+
def test_ideas_tracker_dict_aliases_preserved(self, tmp_path):
224+
"""Integration: ideas_tracker writes aliases as list[dict] version history.
225+
226+
This is the boundary where ideas_tracker output enters Pydantic land.
227+
Bug #2 (PR #161): MemoryCard.aliases was list[str], crashed on list[dict].
228+
Fixed by changing to list[Any].
229+
"""
230+
aliases = [
231+
{
232+
"exp1-prog1": {
233+
"description": "old description",
234+
"programs": ["p1"],
235+
"explanations": ["initial"],
236+
}
237+
},
238+
]
239+
banks = _make_banks(
240+
tmp_path,
241+
active_bank=[
242+
{
243+
"id": "idea-1",
244+
"description": "current description",
245+
"aliases": aliases,
246+
"keywords": ["retrieval"],
247+
}
248+
],
249+
)
250+
best = _make_best_ideas(
251+
tmp_path,
252+
best_ideas=[{"idea_id": "idea-1"}],
253+
)
254+
cards = load_memory_cards(banks, best)
255+
assert len(cards) == 1
256+
assert cards[0].id == "idea-1"
257+
assert cards[0].aliases == aliases
258+
assert isinstance(cards[0].aliases[0], dict)
259+
223260
def test_missing_banks_file_raises(self, tmp_path):
224261
best = _make_best_ideas(tmp_path)
225262
with pytest.raises(FileNotFoundError):

0 commit comments

Comments
 (0)