Skip to content

Commit 54b30c5

Browse files
Merge upstream dev into Diogenes
1 parent 911c5f6 commit 54b30c5

3 files changed

Lines changed: 15 additions & 15 deletions

File tree

‎docker-compose.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ services:
7777
- ODYSSEUS_EMAIL_COMPOSE_UPLOAD_MAX_BYTES=${ODYSSEUS_EMAIL_COMPOSE_UPLOAD_MAX_BYTES:-26214400}
7878
- ODYSSEUS_STT_MAX_AUDIO_BYTES=${ODYSSEUS_STT_MAX_AUDIO_BYTES:-26214400}
7979
- ODYSSEUS_ICS_MAX_BYTES=${ODYSSEUS_ICS_MAX_BYTES:-10485760}
80-
- ODYSSEUS_TTS_CACHE_MAX_BYTES=${ODYSSEUS_TTS_CACHE_MAX_BYTES}
80+
- ODYSSEUS_TTS_CACHE_MAX_BYTES=${ODYSSEUS_TTS_CACHE_MAX_BYTES:-524288000}
8181
- DATA_BRAVE_API_KEY=${DATA_BRAVE_API_KEY:-}
8282
- GOOGLE_API_KEY=${GOOGLE_API_KEY:-}
8383
- GOOGLE_PSE_CX=${GOOGLE_PSE_CX:-}

‎services/tts/tts_service.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def __init__(self, cache_dir: str = TTS_CACHE_DIR):
4242
self.cache_dir = Path(cache_dir)
4343
self.cache_dir.mkdir(parents=True, exist_ok=True)
4444
self._kokoro = None # lazy-init
45-
45+
4646
try:
4747
self.max_cache_bytes = int(os.getenv("ODYSSEUS_TTS_CACHE_MAX_BYTES", 500 * 1024 * 1024))
4848
except ValueError:

‎tests/test_tts_service_enforce_cache_limit.py‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ def test_cache_under_limit(tmp_path, monkeypatch):
1010
"""Test that writing a file under the size limit does not trigger eviction."""
1111
# Set a tiny limit: 100 bytes
1212
monkeypatch.setenv("ODYSSEUS_TTS_CACHE_MAX_BYTES", "100")
13-
13+
1414
# Initialize service with pytest's temporary directory
1515
service = TTSService(cache_dir=str(tmp_path))
16-
16+
1717
# Write a 40-byte file (under the 100-byte limit)
1818
service._put_cache("test_key", b"x" * 40)
19-
19+
2020
# Verify the file was written and nothing was deleted
2121
files = list(tmp_path.glob("*.*"))
2222
assert len(files) == 1
@@ -27,32 +27,32 @@ def test_cache_exceeds_limit_triggers_eviction(tmp_path, monkeypatch):
2727
# Set limit to 100 bytes. 80% target capacity will be 80 bytes.
2828
monkeypatch.setenv("ODYSSEUS_TTS_CACHE_MAX_BYTES", "100")
2929
service = TTSService(cache_dir=str(tmp_path))
30-
30+
3131
# 1. Setup: Manually create two older files (40 bytes each)
3232
file1 = tmp_path / "oldest.wav"
3333
file2 = tmp_path / "middle.wav"
34-
34+
3535
file1.write_bytes(b"a" * 40)
3636
file2.write_bytes(b"b" * 40)
37-
37+
3838
# Spoof timestamps so file1 is explicitly older than file2
3939
now = time.time()
4040
os.utime(file1, (now - 100, now - 100)) # 100 seconds ago
4141
os.utime(file2, (now - 50, now - 50)) # 50 seconds ago
42-
42+
4343
# 2. Action: Write a 3rd file using the service method (40 bytes)
4444
# Total cache is now 120 bytes, which exceeds 100.
4545
# It should delete oldest (file1) to drop to 80 bytes (which matches the 80% target).
4646
service._put_cache("newest", b"c" * 40)
47-
47+
4848
# 3. Assertions
4949
# The newest file should exist (saved as .wav because it lacks MP3 magic bytes)
5050
newest_file = tmp_path / "newest.wav"
51-
51+
5252
assert not file1.exists(), "The oldest file should have been evicted."
5353
assert file2.exists(), "The middle file should still exist."
5454
assert newest_file.exists(), "The newest file should have been saved."
55-
55+
5656
# Verify the final directory size is <= 80 bytes
5757
total_size = sum(f.stat().st_size for f in tmp_path.glob("*.*"))
5858
assert total_size <= 80
@@ -61,12 +61,12 @@ def test_cache_limit_disabled(tmp_path, monkeypatch):
6161
"""Test that setting max bytes to 0 disables eviction."""
6262
monkeypatch.setenv("ODYSSEUS_TTS_CACHE_MAX_BYTES", "0")
6363
service = TTSService(cache_dir=str(tmp_path))
64-
64+
6565
# Write 3 large files that would normally trigger eviction
6666
service._put_cache("file1", b"x" * 1000)
6767
service._put_cache("file2", b"x" * 1000)
6868
service._put_cache("file3", b"x" * 1000)
69-
69+
7070
# Ensure nothing was deleted
7171
files = list(tmp_path.glob("*.*"))
7272
assert len(files) == 3
@@ -94,4 +94,4 @@ def mock_unlink(self_path):
9494
pytest.fail(f"_put_cache raised an exception during failed eviction: {e}")
9595

9696
# The new file should still be written successfully
97-
assert (tmp_path / "new_key.wav").exists()
97+
assert (tmp_path / "new_key.wav").exists()

0 commit comments

Comments
 (0)