feat(aggregate): Support custom view mode with annotated slices

This commit is contained in:
2026-05-11 18:52:22 -04:00
parent d22c98c9ac
commit 1303fc1402
2 changed files with 55 additions and 0 deletions
+39
View File
@@ -124,3 +124,42 @@ def test_files_section_rendering(tmp_path):
assert "```txt\n**Summary** content\n```" not in sections
assert "**Summary** content" in sections
def test_view_mode_custom(tmp_path):
base_dir = tmp_path / "project"
base_dir.mkdir()
test_file = base_dir / "test.py"
content = "line1\nline2\nline3\nline4\nline5\n"
test_file.write_text(content, encoding="utf-8")
slices = [
{"start_line": 1, "end_line": 2, "tag": "top", "comment": "header"},
{"start_line": 4, "end_line": 5, "tag": "bottom", "comment": "footer"}
]
files = [{"path": "test.py", "view_mode": "custom", "custom_slices": slices}]
items = aggregate.build_file_items(base_dir, files)
assert len(items) == 1
assert items[0]["view_mode"] == "custom"
# Check formatting
expected_1 = "---\n[Slice: top] (header)\nLines 1-2:\nline1\nline2"
expected_2 = "---\n[Slice: bottom] (footer)\nLines 4-5:\nline4\nline5"
assert expected_1 in items[0]["content"]
assert expected_2 in items[0]["content"]
assert "line3" not in items[0]["content"]
def test_view_mode_custom_empty_default_to_summary(tmp_path):
base_dir = tmp_path / "project"
base_dir.mkdir()
test_file = base_dir / "test.py"
test_file.write_text("def hello():\n print('world')\n", encoding="utf-8")
files = [{"path": "test.py", "view_mode": "custom", "custom_slices": []}]
items = aggregate.build_file_items(base_dir, files)
assert len(items) == 1
assert items[0]["view_mode"] == "custom"
# Should default to summary
assert "**Python**" in items[0]["content"]