-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_cache_name_formats.py
More file actions
83 lines (61 loc) · 2.47 KB
/
Copy pathtest_cache_name_formats.py
File metadata and controls
83 lines (61 loc) · 2.47 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
#!/usr/bin/env python3
"""Smoke tests for cache filename/slug generation.
This validates that the cache manager produces the desired filename pattern
for different processor/model combinations (CPU model-1, CPU model-2, GPU models,
MarkPDFdown, Sparrow).
"""
import os
from contextlib import contextmanager
from src.utils import CacheManager
@contextmanager
def _temp_env(**entries):
"""Temporarily patch environment variables."""
original = {key: os.environ.get(key) for key in entries}
try:
os.environ.update({k: v for k, v in entries.items() if v is not None})
yield
finally:
for key, value in original.items():
if value is None and key in os.environ:
os.environ.pop(key, None)
elif value is not None:
os.environ[key] = value
def expect(cache_key: str, expected_prefix: str):
if not cache_key.startswith(expected_prefix):
raise AssertionError(
f"Cache key '{cache_key}' does not start with expected prefix '{expected_prefix}'"
)
def main() -> int:
cm = CacheManager()
filename = "Example File.pdf"
# CPU Model-1 default
with _temp_env(CPU_MODEL="cpu-model-1"):
key = cm._get_cache_key(filename, "CPU")
print("CPU Model-1 key:", key)
expect(key, "cpu_model-1_")
# CPU Model-2
with _temp_env(CPU_MODEL="cpu-model-2"):
key = cm._get_cache_key(filename, "CPU")
print("CPU Model-2 key:", key)
expect(key, "cpu_model-2_")
# GPU model from environment (use first configured model)
from src.config import app_config # Imported lazily to avoid circular issues
gpu_models = app_config.get_available_gpu_models()
first_display, first_model = next(iter(gpu_models.items()))
with _temp_env(OPENROUTER_MODEL=first_model):
key = cm._get_cache_key(filename, "GPU")
print(f"GPU ({first_display}) key:", key)
expected_prefix = f"gpu_{first_display.lower().replace(' ', '_').replace('(', '').replace(')', '').replace('-', '_')}"
expect(key, f"{expected_prefix}_")
# MarkPDFdown
key = cm._get_cache_key(filename, "PDF to Markdown Converter")
print("MarkPDFdown key:", key)
expect(key, "markpdfdown_")
# Sparrow
key = cm._get_cache_key(filename, "Schema Support")
print("Sparrow key:", key)
expect(key, "sparrow_")
print("All cache key naming checks passed ✅")
return 0
if __name__ == "__main__":
raise SystemExit(main())