-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtest_session_summary.py
More file actions
145 lines (120 loc) · 5.98 KB
/
Copy pathtest_session_summary.py
File metadata and controls
145 lines (120 loc) · 5.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
"""Tests for one-line session summary feature (#1036).
Tests generate_one_line_summary() and its integration in render_session_summary().
"""
import os
import sys
import pytest
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "hooks", "lib"))
from buddy_renderer import generate_one_line_summary, render_session_summary
class TestGenerateOneLineSummary:
"""Tests for generate_one_line_summary() function."""
def test_files_and_commands(self):
"""Should generate summary with files modified and commands run."""
tool_names = {"Edit": 5, "Write": 2, "Bash": 10, "Read": 20}
result = generate_one_line_summary(tool_names, "", "en")
assert "7 files modified" in result
assert "10 commands" in result
def test_files_only(self):
"""Should generate summary with only file modifications."""
tool_names = {"Edit": 3, "Read": 10}
result = generate_one_line_summary(tool_names, "", "en")
assert "3 files modified" in result
assert "command" not in result
def test_commands_only(self):
"""Should generate summary with only commands run."""
tool_names = {"Bash": 8, "Read": 5}
result = generate_one_line_summary(tool_names, "", "en")
assert "8 commands" in result
assert "file" not in result.lower() or "modified" not in result
def test_exploration_only(self):
"""Should generate exploration summary when only reads/greps."""
tool_names = {"Read": 15, "Grep": 8, "Glob": 3}
result = generate_one_line_summary(tool_names, "", "en")
assert result # Should produce something, not empty
def test_empty_tool_names(self):
"""Should handle empty tool_names gracefully."""
result = generate_one_line_summary({}, "", "en")
assert result # Should still return something
def test_with_agent_name(self):
"""Should include agent name in summary."""
tool_names = {"Edit": 4, "Bash": 6}
result = generate_one_line_summary(tool_names, "Frontend Developer", "en")
assert "Frontend Developer" in result
def test_korean_language(self):
"""Should generate Korean summary."""
tool_names = {"Edit": 3, "Write": 1, "Bash": 5}
result = generate_one_line_summary(tool_names, "", "ko")
assert "수정" in result or "파일" in result
def test_japanese_language(self):
"""Should generate Japanese summary."""
tool_names = {"Edit": 2, "Bash": 3}
result = generate_one_line_summary(tool_names, "", "ja")
assert result
# Should not be English fallback tokens only
assert any(ord(c) > 127 for c in result)
def test_chinese_language(self):
"""Should generate Chinese summary."""
tool_names = {"Edit": 2, "Bash": 3}
result = generate_one_line_summary(tool_names, "", "zh")
assert result
assert any(ord(c) > 127 for c in result)
def test_spanish_language(self):
"""Should generate Spanish summary."""
tool_names = {"Edit": 2, "Bash": 3}
result = generate_one_line_summary(tool_names, "", "es")
assert result
def test_unknown_language_falls_back_to_english(self):
"""Should fall back to English for unknown language codes."""
tool_names = {"Edit": 5, "Bash": 3}
result = generate_one_line_summary(tool_names, "", "xx")
en_result = generate_one_line_summary(tool_names, "", "en")
assert result == en_result
def test_single_file_singular(self):
"""Should use singular form for 1 file."""
tool_names = {"Edit": 1}
result = generate_one_line_summary(tool_names, "", "en")
assert "1 file modified" in result
assert "files" not in result
def test_agent_with_korean(self):
"""Should include agent name with Korean summary."""
tool_names = {"Edit": 3, "Bash": 5}
result = generate_one_line_summary(tool_names, "Backend Developer", "ko")
assert "Backend Developer" in result
assert ("수정" in result or "파일" in result)
class TestRenderSessionSummaryWithOneLine:
"""Tests for one-line summary integration in render_session_summary()."""
def test_includes_one_line_summary(self):
"""Should include one-line summary in rendered output."""
stats = {"duration_minutes": 10, "tool_count": 20, "files_changed": 5}
tool_names = {"Edit": 3, "Write": 2, "Bash": 10}
agents = []
result = render_session_summary(
stats, agents, "casual", "en", tool_names=tool_names,
)
assert "5 files modified" in result or "files modified" in result
def test_no_summary_without_tool_names(self):
"""Should still work without tool_names (backward compatible)."""
stats = {"duration_minutes": 5, "tool_count": 10, "files_changed": 3}
agents = []
result = render_session_summary(stats, agents, "casual", "en")
# Should render without error, just no one-line summary
assert "Session Summary" in result or "세션 요약" in result or result
def test_summary_with_agent_in_output(self):
"""Should include agent context in one-line summary."""
stats = {"duration_minutes": 10, "tool_count": 15, "files_changed": 4}
tool_names = {"Edit": 4, "Bash": 8}
agents = [{"name": "Test Engineer", "eye": "●", "colorAnsi": "green"}]
result = render_session_summary(
stats, agents, "casual", "en", tool_names=tool_names,
)
# The one-line summary should be present
assert "files modified" in result or "commands" in result
def test_korean_session_summary(self):
"""Should render Korean one-line summary."""
stats = {"duration_minutes": 5, "tool_count": 8, "files_changed": 2}
tool_names = {"Edit": 2, "Bash": 4}
agents = []
result = render_session_summary(
stats, agents, "casual", "ko", tool_names=tool_names,
)
assert ("수정" in result or "파일" in result)