checkpoint: massive refactor
This commit is contained in:
@@ -3,134 +3,113 @@ from pathlib import Path
|
||||
from aggregate import build_tier1_context, build_tier2_context, build_tier3_context
|
||||
|
||||
def test_build_tier1_context_exists():
|
||||
# This should fail if the function is not defined
|
||||
file_items = [
|
||||
{"path": Path("conductor/product.md"), "entry": "conductor/product.md", "content": "Product content", "error": False},
|
||||
{"path": Path("other.py"), "entry": "other.py", "content": "Other content", "error": False}
|
||||
]
|
||||
history = ["User: hello", "AI: hi"]
|
||||
|
||||
result = build_tier1_context(file_items, Path("."), [], history)
|
||||
|
||||
assert "Product content" in result
|
||||
# other.py should be summarized, not full content in a code block
|
||||
assert "Other content" not in result or "Summarized" in result # Assuming summary format
|
||||
# This should fail if the function is not defined
|
||||
file_items = [
|
||||
{"path": Path("conductor/product.md"), "entry": "conductor/product.md", "content": "Product content", "error": False},
|
||||
{"path": Path("other.py"), "entry": "other.py", "content": "Other content", "error": False}
|
||||
]
|
||||
history = ["User: hello", "AI: hi"]
|
||||
result = build_tier1_context(file_items, Path("."), [], history)
|
||||
assert "Product content" in result
|
||||
# other.py should be summarized, not full content in a code block
|
||||
assert "Other content" not in result or "Summarized" in result # Assuming summary format
|
||||
|
||||
def test_build_tier2_context_exists():
|
||||
file_items = [
|
||||
{"path": Path("other.py"), "entry": "other.py", "content": "Other content", "error": False}
|
||||
]
|
||||
history = ["User: hello"]
|
||||
result = build_tier2_context(file_items, Path("."), [], history)
|
||||
assert "Other content" in result
|
||||
file_items = [
|
||||
{"path": Path("other.py"), "entry": "other.py", "content": "Other content", "error": False}
|
||||
]
|
||||
history = ["User: hello"]
|
||||
result = build_tier2_context(file_items, Path("."), [], history)
|
||||
assert "Other content" in result
|
||||
|
||||
def test_build_tier3_context_ast_skeleton(monkeypatch):
|
||||
from unittest.mock import MagicMock
|
||||
import aggregate
|
||||
import file_cache
|
||||
|
||||
# Mock ASTParser
|
||||
mock_parser_instance = MagicMock()
|
||||
mock_parser_instance.get_skeleton.return_value = "def other():\n ..."
|
||||
mock_parser_class = MagicMock(return_value=mock_parser_instance)
|
||||
|
||||
# Mock file_cache.ASTParser in aggregate module
|
||||
monkeypatch.setattr("aggregate.ASTParser", mock_parser_class)
|
||||
|
||||
file_items = [
|
||||
{"path": Path("other.py"), "entry": "other.py", "content": "def other():\n pass", "error": False}
|
||||
]
|
||||
history = []
|
||||
|
||||
# New behavior check: it should use ASTParser for .py files not in focus
|
||||
result = build_tier3_context(file_items, Path("."), [], history, focus_files=[])
|
||||
|
||||
assert "def other():" in result
|
||||
assert "..." in result
|
||||
assert "Python" not in result # summarize.py output should not be there if AST skeleton is used
|
||||
mock_parser_class.assert_called_once_with("python")
|
||||
mock_parser_instance.get_skeleton.assert_called_once_with("def other():\n pass")
|
||||
from unittest.mock import MagicMock
|
||||
import aggregate
|
||||
import file_cache
|
||||
# Mock ASTParser
|
||||
mock_parser_instance = MagicMock()
|
||||
mock_parser_instance.get_skeleton.return_value = "def other():\n ..."
|
||||
mock_parser_class = MagicMock(return_value=mock_parser_instance)
|
||||
# Mock file_cache.ASTParser in aggregate module
|
||||
monkeypatch.setattr("aggregate.ASTParser", mock_parser_class)
|
||||
file_items = [
|
||||
{"path": Path("other.py"), "entry": "other.py", "content": "def other():\n pass", "error": False}
|
||||
]
|
||||
history = []
|
||||
# New behavior check: it should use ASTParser for .py files not in focus
|
||||
result = build_tier3_context(file_items, Path("."), [], history, focus_files=[])
|
||||
assert "def other():" in result
|
||||
assert "..." in result
|
||||
assert "Python" not in result # summarize.py output should not be there if AST skeleton is used
|
||||
mock_parser_class.assert_called_once_with("python")
|
||||
mock_parser_instance.get_skeleton.assert_called_once_with("def other():\n pass")
|
||||
|
||||
def test_build_tier3_context_exists():
|
||||
file_items = [
|
||||
{"path": Path("focus.py"), "entry": "focus.py", "content": "def focus():\n pass", "error": False},
|
||||
{"path": Path("other.py"), "entry": "other.py", "content": "def other():\n pass", "error": False}
|
||||
]
|
||||
history = ["User: hello"]
|
||||
result = build_tier3_context(file_items, Path("."), [], history, focus_files=["focus.py"])
|
||||
|
||||
assert "def focus():" in result
|
||||
assert "pass" in result
|
||||
# other.py should have skeletonized content, not full "pass" (if get_skeleton works)
|
||||
# However, for a simple "pass", the skeleton might be the same or similar.
|
||||
# Let's check for the header
|
||||
assert "other.py" in result
|
||||
assert "AST Skeleton" in result
|
||||
file_items = [
|
||||
{"path": Path("focus.py"), "entry": "focus.py", "content": "def focus():\n pass", "error": False},
|
||||
{"path": Path("other.py"), "entry": "other.py", "content": "def other():\n pass", "error": False}
|
||||
]
|
||||
history = ["User: hello"]
|
||||
result = build_tier3_context(file_items, Path("."), [], history, focus_files=["focus.py"])
|
||||
assert "def focus():" in result
|
||||
assert "pass" in result
|
||||
# other.py should have skeletonized content, not full "pass" (if get_skeleton works)
|
||||
# However, for a simple "pass", the skeleton might be the same or similar.
|
||||
# Let's check for the header
|
||||
assert "other.py" in result
|
||||
assert "AST Skeleton" in result
|
||||
|
||||
def test_build_file_items_with_tiers(tmp_path):
|
||||
from aggregate import build_file_items
|
||||
|
||||
# Create some dummy files
|
||||
file1 = tmp_path / "file1.txt"
|
||||
file1.write_text("content1")
|
||||
file2 = tmp_path / "file2.txt"
|
||||
file2.write_text("content2")
|
||||
|
||||
files_config = [
|
||||
"file1.txt",
|
||||
{"path": "file2.txt", "tier": 3}
|
||||
]
|
||||
|
||||
items = build_file_items(tmp_path, files_config)
|
||||
|
||||
assert len(items) == 2
|
||||
|
||||
item1 = next(i for i in items if i["entry"] == "file1.txt")
|
||||
assert item1["content"] == "content1"
|
||||
assert "tier" in item1
|
||||
assert item1["tier"] is None
|
||||
|
||||
item2 = next(i for i in items if i["entry"] == "file2.txt")
|
||||
assert item2["content"] == "content2"
|
||||
assert item2["tier"] == 3
|
||||
from aggregate import build_file_items
|
||||
# Create some dummy files
|
||||
file1 = tmp_path / "file1.txt"
|
||||
file1.write_text("content1")
|
||||
file2 = tmp_path / "file2.txt"
|
||||
file2.write_text("content2")
|
||||
files_config = [
|
||||
"file1.txt",
|
||||
{"path": "file2.txt", "tier": 3}
|
||||
]
|
||||
items = build_file_items(tmp_path, files_config)
|
||||
assert len(items) == 2
|
||||
item1 = next(i for i in items if i["entry"] == "file1.txt")
|
||||
assert item1["content"] == "content1"
|
||||
assert "tier" in item1
|
||||
assert item1["tier"] is None
|
||||
item2 = next(i for i in items if i["entry"] == "file2.txt")
|
||||
assert item2["content"] == "content2"
|
||||
assert item2["tier"] == 3
|
||||
|
||||
def test_build_files_section_with_dicts(tmp_path):
|
||||
from aggregate import build_files_section
|
||||
|
||||
file1 = tmp_path / "file1.txt"
|
||||
file1.write_text("content1")
|
||||
|
||||
files_config = [
|
||||
{"path": str(file1)}
|
||||
]
|
||||
|
||||
result = build_files_section(tmp_path, files_config)
|
||||
assert "content1" in result
|
||||
assert "file1.txt" in result
|
||||
from aggregate import build_files_section
|
||||
file1 = tmp_path / "file1.txt"
|
||||
file1.write_text("content1")
|
||||
files_config = [
|
||||
{"path": str(file1)}
|
||||
]
|
||||
result = build_files_section(tmp_path, files_config)
|
||||
assert "content1" in result
|
||||
assert "file1.txt" in result
|
||||
|
||||
def test_tiered_context_by_tier_field():
|
||||
file_items = [
|
||||
{"path": Path("tier1_file.txt"), "entry": "tier1_file.txt", "content": "Full Tier 1 Content\nLine 2", "tier": 1},
|
||||
{"path": Path("tier3_file.txt"), "entry": "tier3_file.txt", "content": "Full Tier 3 Content\nLine 2\nLine 3\nLine 4\nLine 5\nLine 6\nLine 7\nLine 8\nLine 9\nLine 10", "tier": 3},
|
||||
{"path": Path("other.txt"), "entry": "other.txt", "content": "Other Content\nLine 2\nLine 3\nLine 4\nLine 5\nLine 6\nLine 7\nLine 8\nLine 9\nLine 10", "tier": None}
|
||||
]
|
||||
|
||||
# Test Tier 1 Context
|
||||
result_t1 = build_tier1_context(file_items, Path("."), [], [])
|
||||
assert "Full Tier 1 Content" in result_t1
|
||||
assert "Line 2" in result_t1 # In full
|
||||
|
||||
# tier3_file.txt should be summarized
|
||||
assert "tier3_file.txt" in result_t1
|
||||
assert "preview:" in result_t1
|
||||
assert "Line 9" not in result_t1 # Only first 8 lines in preview
|
||||
|
||||
# Test Tier 3 Context
|
||||
result_t3 = build_tier3_context(file_items, Path("."), [], [], focus_files=[])
|
||||
assert "Full Tier 3 Content" in result_t3
|
||||
assert "Line 10" in result_t3 # In full
|
||||
|
||||
# tier1_file.txt should be summarized
|
||||
assert "tier1_file.txt" in result_t3
|
||||
assert "preview:" in result_t3
|
||||
assert "Full Tier 1 Content" in result_t3 # It's short, so it's in preview
|
||||
file_items = [
|
||||
{"path": Path("tier1_file.txt"), "entry": "tier1_file.txt", "content": "Full Tier 1 Content\nLine 2", "tier": 1},
|
||||
{"path": Path("tier3_file.txt"), "entry": "tier3_file.txt", "content": "Full Tier 3 Content\nLine 2\nLine 3\nLine 4\nLine 5\nLine 6\nLine 7\nLine 8\nLine 9\nLine 10", "tier": 3},
|
||||
{"path": Path("other.txt"), "entry": "other.txt", "content": "Other Content\nLine 2\nLine 3\nLine 4\nLine 5\nLine 6\nLine 7\nLine 8\nLine 9\nLine 10", "tier": None}
|
||||
]
|
||||
# Test Tier 1 Context
|
||||
result_t1 = build_tier1_context(file_items, Path("."), [], [])
|
||||
assert "Full Tier 1 Content" in result_t1
|
||||
assert "Line 2" in result_t1 # In full
|
||||
# tier3_file.txt should be summarized
|
||||
assert "tier3_file.txt" in result_t1
|
||||
assert "preview:" in result_t1
|
||||
assert "Line 9" not in result_t1 # Only first 8 lines in preview
|
||||
# Test Tier 3 Context
|
||||
result_t3 = build_tier3_context(file_items, Path("."), [], [], focus_files=[])
|
||||
assert "Full Tier 3 Content" in result_t3
|
||||
assert "Line 10" in result_t3 # In full
|
||||
# tier1_file.txt should be summarized
|
||||
assert "tier1_file.txt" in result_t3
|
||||
assert "preview:" in result_t3
|
||||
assert "Full Tier 1 Content" in result_t3 # It's short, so it's in preview
|
||||
|
||||
Reference in New Issue
Block a user