refactor: remove redundant comments and docstrings (#6527)
* refactor: remove redundant comments and docstrings * fix(signal): annotate async context manager as a generator
This commit is contained in:
1 parent
cb3ba45317
commit
a4d2430140
922 files changed
+406
-7738
No files matched your search
@@ -21,20 +21,17 @@ class TestNextCursorRecovery:
|
||||
cursor is corrupted (non-int)."""
|
||||
|
||||
def test_string_cursor_falls_back_to_scan(self, store):
|
||||
"""Last entry has a string cursor — scan backwards to find a valid int."""
|
||||
store.history_file.write_text(
|
||||
'{"cursor": 5, "timestamp": "2026-04-01 10:00", "content": "good"}\n'
|
||||
'{"cursor": 6, "timestamp": "2026-04-01 10:01", "content": "also good"}\n'
|
||||
'{"cursor": "bad", "timestamp": "2026-04-01 10:02", "content": "corrupted"}\n',
|
||||
encoding="utf-8",
|
||||
)
|
||||
# Delete .cursor file so _next_cursor falls back to reading JSONL
|
||||
store._cursor_file.unlink(missing_ok=True)
|
||||
cursor = store.append_history("recovered event")
|
||||
assert cursor == 7
|
||||
|
||||
def test_all_corrupted_cursors_return_one(self, store):
|
||||
"""Every entry has a non-int cursor — should restart at 1."""
|
||||
store.history_file.write_text(
|
||||
'{"cursor": "a", "timestamp": "2026-04-01 10:00", "content": "bad1"}\n'
|
||||
'{"cursor": "b", "timestamp": "2026-04-01 10:01", "content": "bad2"}\n',
|
||||
@@ -45,7 +42,6 @@ class TestNextCursorRecovery:
|
||||
assert cursor == 1
|
||||
|
||||
def test_non_int_cursor_types(self, store):
|
||||
"""Float, None, list — all non-int types handled gracefully."""
|
||||
store.history_file.write_text(
|
||||
'{"cursor": 3, "timestamp": "2026-04-01 10:00", "content": "valid"}\n'
|
||||
'{"cursor": 3.5, "timestamp": "2026-04-01 10:01", "content": "float"}\n'
|
||||
@@ -58,9 +54,7 @@ class TestNextCursorRecovery:
|
||||
assert cursor == 4
|
||||
|
||||
def test_cursor_file_with_string_content(self, store):
|
||||
"""Cursor file contains a non-numeric string — should fall back."""
|
||||
store._cursor_file.write_text("not_a_number", encoding="utf-8")
|
||||
# Also add valid JSONL so the fallback scan finds something
|
||||
store.history_file.write_text(
|
||||
'{"cursor": 10, "timestamp": "2026-04-01 10:00", "content": "valid"}\n',
|
||||
encoding="utf-8",
|
||||
@@ -69,7 +63,6 @@ class TestNextCursorRecovery:
|
||||
assert cursor == 11
|
||||
|
||||
def test_stale_cursor_file_does_not_reuse_history_cursor(self, store):
|
||||
"""A stale .cursor file must not allocate a duplicate cursor."""
|
||||
store.history_file.write_text(
|
||||
'{"cursor": 10, "timestamp": "2026-04-01 10:00", "content": "valid"}\n',
|
||||
encoding="utf-8",
|
||||
@@ -83,7 +76,6 @@ class TestNextCursorRecovery:
|
||||
assert [e["cursor"] for e in entries] == [10, 11]
|
||||
|
||||
def test_cursor_file_stays_ahead_after_history_compaction(self, store):
|
||||
"""A cursor counter ahead of the tail preserves monotonic allocation."""
|
||||
store.history_file.write_text(
|
||||
'{"cursor": 10, "timestamp": "2026-04-01 10:00", "content": "valid"}\n',
|
||||
encoding="utf-8",
|
||||
@@ -95,7 +87,6 @@ class TestNextCursorRecovery:
|
||||
assert cursor == 101
|
||||
|
||||
def test_negative_cursor_file_content_falls_back(self, store):
|
||||
"""A negative .cursor value is corrupt and should not produce negative IDs."""
|
||||
store._cursor_file.write_text("-5", encoding="utf-8")
|
||||
|
||||
cursor = store.append_history("after negative cursor file")
|
||||
@@ -108,7 +99,6 @@ class TestReadUnprocessedWithCorruption:
|
||||
instead of crashing on comparison."""
|
||||
|
||||
def test_skips_string_cursor_entries(self, store):
|
||||
"""Entries with string cursors are silently skipped."""
|
||||
store.history_file.write_text(
|
||||
'{"cursor": 1, "timestamp": "2026-04-01 10:00", "content": "valid1"}\n'
|
||||
'{"cursor": "bad", "timestamp": "2026-04-01 10:01", "content": "corrupted"}\n'
|
||||
@@ -120,7 +110,6 @@ class TestReadUnprocessedWithCorruption:
|
||||
assert [e["cursor"] for e in entries] == [1, 3]
|
||||
|
||||
def test_mixed_corruption_preserves_order(self, store):
|
||||
"""Valid entries maintain correct order despite corrupt neighbors."""
|
||||
store.history_file.write_text(
|
||||
'{"cursor": "x", "timestamp": "2026-04-01 10:00", "content": "bad"}\n'
|
||||
'{"cursor": 2, "timestamp": "2026-04-01 10:01", "content": "good2"}\n'
|
||||
@@ -132,7 +121,6 @@ class TestReadUnprocessedWithCorruption:
|
||||
assert [e["cursor"] for e in entries] == [2, 4]
|
||||
|
||||
def test_all_valid_still_works(self, store):
|
||||
"""Normal operation unaffected — baseline regression check."""
|
||||
store.append_history("event 1")
|
||||
store.append_history("event 2")
|
||||
store.append_history("event 3")
|
||||
@@ -169,7 +157,6 @@ class TestCursorValidationInvariant:
|
||||
assert [e["cursor"] for e in entries] == [4, 5]
|
||||
|
||||
def test_negative_history_cursor_rejected(self, store):
|
||||
"""A negative history cursor is corrupt and must not seed new writes."""
|
||||
store.history_file.write_text(
|
||||
'{"cursor": -5, "timestamp": "2026-04-01 10:00", "content": "negative"}\n',
|
||||
encoding="utf-8",
|
||||
|
||||
Reference in new issue
Block a user