Skip to content

Commit 8142f89

Browse files
fix(tests): update test_auto_compact.py for timestamp-based naming (#797)
The _get_compacted_name() function was changed from hex-suffix naming (-before-compact-XXXX) to timestamp-based naming (-compacted-YYYYMMDD-HHMMSS), but the tests weren't updated. Changes: - Update all regex patterns to match new timestamp format - Update test docstrings and comments - Add time.sleep() in uniqueness test for timestamp resolution - Fix all references to old naming convention All 14 tests now pass.
1 parent 8e11c24 commit 8142f89

File tree

1 file changed

+51
-51
lines changed

1 file changed

+51
-51
lines changed

tests/test_auto_compact.py

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from gptme.llm.models import get_default_model, get_model
1010
from gptme.message import Message, len_tokens
1111
from gptme.tools.autocompact import (
12-
_get_backup_name,
12+
_get_compacted_name,
1313
auto_compact_log,
1414
should_auto_compact,
1515
)
@@ -161,97 +161,97 @@ def test_auto_compact_preserves_pinned_messages():
161161
assert compacted[2].pinned
162162

163163

164-
def test_get_backup_name_no_suffix():
165-
"""Test backup name generation for conversation without existing suffix."""
164+
def test_get_compacted_name_no_suffix():
165+
"""Test compacted name generation for conversation without existing suffix."""
166166
import re
167167

168-
name = _get_backup_name("2025-10-13-flying-yellow-alien")
169-
# Should match: base-name-before-compact-XXXX where XXXX is 4 hex chars
170-
assert re.match(
171-
r"^2025-10-13-flying-yellow-alien-before-compact-[0-9a-f]{4}$", name
172-
)
168+
name = _get_compacted_name("2025-10-13-flying-yellow-alien")
169+
# Should match: base-name-compacted-YYYYMMDD-HHMMSS
170+
assert re.match(r"^2025-10-13-flying-yellow-alien-compacted-\d{8}-\d{6}$", name)
173171

174172

175-
def test_get_backup_name_one_suffix():
176-
"""Test backup name generation when suffix already exists (gets new unique suffix)."""
173+
def test_get_compacted_name_one_suffix():
174+
"""Test compacted name generation when suffix already exists (gets new unique suffix)."""
177175
import re
178176

179-
name = _get_backup_name("2025-10-13-flying-yellow-alien-before-compact")
180-
# Should strip old suffix and add new one with random suffix
181-
assert re.match(
182-
r"^2025-10-13-flying-yellow-alien-before-compact-[0-9a-f]{4}$", name
177+
name = _get_compacted_name(
178+
"2025-10-13-flying-yellow-alien-compacted-20251028-120000"
183179
)
180+
# Should strip old timestamp suffix and add new timestamp
181+
assert re.match(r"^2025-10-13-flying-yellow-alien-compacted-\d{8}-\d{6}$", name)
184182

185183

186-
def test_get_backup_name_multiple_suffixes():
187-
"""Test backup name generation with multiple accumulated suffixes (should strip all)."""
184+
def test_get_compacted_name_multiple_suffixes():
185+
"""Test compacted name generation with multiple accumulated timestamp suffixes (should strip all)."""
188186
import re
189187

190-
name = _get_backup_name(
191-
"2025-10-13-flying-yellow-alien-before-compact-before-compact-before-compact"
192-
)
193-
assert re.match(
194-
r"^2025-10-13-flying-yellow-alien-before-compact-[0-9a-f]{4}$", name
188+
name = _get_compacted_name(
189+
"2025-10-13-flying-yellow-alien-compacted-20251027-100000-compacted-20251028-110000-compacted-20251028-120000"
195190
)
191+
assert re.match(r"^2025-10-13-flying-yellow-alien-compacted-\d{8}-\d{6}$", name)
196192

197193

198-
def test_get_backup_name_edge_cases():
199-
"""Test backup name generation with various edge cases."""
194+
def test_get_compacted_name_edge_cases():
195+
"""Test compacted name generation with various edge cases."""
200196
import re
201197

202198
# Short name
203-
name = _get_backup_name("conv")
204-
assert re.match(r"^conv-before-compact-[0-9a-f]{4}$", name)
199+
name = _get_compacted_name("conv")
200+
assert re.match(r"^conv-compacted-\d{8}-\d{6}$", name)
205201

206202
# Name containing 'compact' but not as suffix
207-
name = _get_backup_name("compact-test")
208-
assert re.match(r"^compact-test-before-compact-[0-9a-f]{4}$", name)
203+
name = _get_compacted_name("compact-test")
204+
assert re.match(r"^compact-test-compacted-\d{8}-\d{6}$", name)
209205

210206
# Name ending with similar but different suffix
211-
name = _get_backup_name("test-before-compaction")
212-
assert re.match(r"^test-before-compaction-before-compact-[0-9a-f]{4}$", name)
207+
name = _get_compacted_name("test-before-compaction")
208+
assert re.match(r"^test-before-compaction-compacted-\d{8}-\d{6}$", name)
209+
213210

211+
def test_get_compacted_name_uniqueness():
212+
"""Test that multiple calls produce unique compacted names with timestamps."""
213+
import time
214214

215-
def test_get_backup_name_uniqueness():
216-
"""Test that multiple calls produce unique backup names."""
217-
name1 = _get_backup_name("my-conversation")
218-
name2 = _get_backup_name("my-conversation")
219-
name3 = _get_backup_name("my-conversation")
215+
name1 = _get_compacted_name("my-conversation")
216+
time.sleep(1.1) # Ensure different second for timestamp
217+
name2 = _get_compacted_name("my-conversation")
218+
time.sleep(1.1) # Ensure different second for timestamp
219+
name3 = _get_compacted_name("my-conversation")
220220

221-
# All should have the same base but different random suffixes
221+
# All should have the same base but different timestamps
222222
assert name1 != name2
223223
assert name2 != name3
224224
assert name1 != name3
225225

226-
# All should start with the same base
227-
assert name1.startswith("my-conversation-before-compact-")
228-
assert name2.startswith("my-conversation-before-compact-")
229-
assert name3.startswith("my-conversation-before-compact-")
226+
# All should have compacted suffix with timestamp
227+
assert name1.startswith("my-conversation-compacted-")
228+
assert name2.startswith("my-conversation-compacted-")
229+
assert name3.startswith("my-conversation-compacted-")
230230

231231

232-
def test_get_backup_name_with_hex_suffix():
233-
"""Test that backup names with hex suffixes are correctly stripped.
232+
def test_get_compacted_name_with_hex_suffix():
233+
"""Test that compacted names with timestamp suffixes are correctly stripped.
234234
235235
This is a regression test for the bug where:
236-
"my-conversation-before-compact-a7c9" would become
237-
"my-conversation-before-compact-a7c9-before-compact-k2p5"
236+
"my-conversation-compacted-20251028-120000" would become
237+
"my-conversation-compacted-20251028-120000-compacted-20251029-130000"
238238
instead of
239-
"my-conversation-before-compact-k2p5"
239+
"my-conversation-compacted-20251029-140000"
240240
"""
241241
import re
242242

243243
# Test with a backup that has a valid hex suffix (only 0-9a-f)
244-
name = _get_backup_name("my-conversation-before-compact-a7c9")
244+
name = _get_compacted_name("my-conversation-compacted-20251028-120000")
245245
# Should strip the old suffix and add a new one
246-
assert re.match(r"^my-conversation-before-compact-[0-9a-f]{4}$", name)
247-
# Should NOT contain the old hex suffix
248-
assert "a7c9" not in name
246+
assert re.match(r"^my-conversation-compacted-\d{8}-\d{6}$", name)
247+
# Should NOT contain the old timestamp
248+
assert "20251028-120000" not in name
249249

250250

251-
def test_get_backup_name_empty_string():
252-
"""Test backup name generation with empty string raises ValueError."""
251+
def test_get_compacted_name_empty_string():
252+
"""Test compacted name generation with empty string raises ValueError."""
253253
with pytest.raises(ValueError, match="conversation name cannot be empty"):
254-
_get_backup_name("")
254+
_get_compacted_name("")
255255

256256

257257
if __name__ == "__main__":

0 commit comments

Comments
 (0)