mirror of
https://github.com/pewdiepie-archdaemon/odysseus.git
synced 2026-07-08 11:56:59 +00:00
refactor(routes): move memory domain into routes/memory/ subpackage (#5007)
Slice 2c of the route-domain reorganization (#4082/#4071, per specs/architecture-runtime-inventory.md §6.3). Moves memory_routes.py into routes/memory/, leaving a backward-compat sys.modules shim at the old path. Pure file reorganization, no behavior change. The shim uses sys.modules replacement (same pattern as the merged gallery #4903 and research #4975 slices) so that `import routes.memory_routes`, `from routes.memory_routes import X`, `importlib.import_module(...)`, and the `import ... as mr` + `monkeypatch.setattr(mr, ...)` pattern used by test_memory_routes_session_owner.py / test_memory_owner_isolation.py all operate on the same module object the application uses. The canonical module does NOT depend on the shim — routes/memory/ memory_routes.py imports only from services/, core/, src/, and stdlib (zero internal routes/ coupling). Four source-introspection test sites repointed to the new canonical path: - test_direct_upload_limits.py - test_upload_limits_centralized.py (two dict keys) - test_vision_owner_scope.py Adds tests/test_memory_routes_shim.py to pin the sys.modules shim contract (legacy and canonical paths resolve to the same module object; monkeypatch via legacy alias reaches the canonical module). Verified: compileall clean; full suite 4219 passed, 3 skipped.
This commit is contained in:
@@ -44,7 +44,7 @@ def test_direct_upload_routes_use_bounded_reads():
|
||||
"read_upload_limited(file, GALLERY_UPLOAD_MAX_BYTES",
|
||||
"read_upload_limited(file, GALLERY_TRANSFORM_UPLOAD_MAX_BYTES",
|
||||
],
|
||||
"routes/memory_routes.py": [
|
||||
"routes/memory/memory_routes.py": [
|
||||
"read_upload_limited(file, MEMORY_IMPORT_MAX_BYTES",
|
||||
],
|
||||
"routes/calendar_routes.py": [
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
"""Regression test for the memory route shim (slice 2c, #4082/#4071).
|
||||
|
||||
The backward-compat shim at ``routes/memory_routes.py`` uses ``sys.modules``
|
||||
replacement so the legacy import path and the canonical ``routes.memory.*``
|
||||
path resolve to the *same* module object. This is required because
|
||||
``test_memory_routes_session_owner.py`` and ``test_memory_owner_isolation.py``
|
||||
do ``import routes.memory_routes as mr`` followed by
|
||||
``monkeypatch.setattr(mr, "get_current_user", ...)`` — for those patches to
|
||||
take effect at runtime, the legacy module object and the canonical one must
|
||||
be identical. This test pins that contract.
|
||||
"""
|
||||
|
||||
import importlib
|
||||
|
||||
import routes.memory_routes as _shim_memory # noqa: F401
|
||||
|
||||
|
||||
def test_legacy_and_canonical_memory_module_are_same_object():
|
||||
"""``import routes.memory_routes`` must alias the canonical module."""
|
||||
legacy = importlib.import_module("routes.memory_routes")
|
||||
canonical = importlib.import_module("routes.memory.memory_routes")
|
||||
assert legacy is canonical, (
|
||||
"routes.memory_routes shim must resolve to the canonical "
|
||||
"routes.memory.memory_routes module object"
|
||||
)
|
||||
|
||||
|
||||
def test_monkeypatch_via_legacy_alias_reaches_canonical(monkeypatch):
|
||||
"""Patching through the legacy alias must reach the canonical module.
|
||||
|
||||
Several memory tests do ``import routes.memory_routes as mr`` followed by
|
||||
``monkeypatch.setattr(mr, "get_current_user", ...)``. For that to take
|
||||
effect at runtime, the legacy module object and the canonical one must be
|
||||
identical.
|
||||
"""
|
||||
legacy = importlib.import_module("routes.memory_routes")
|
||||
canonical = importlib.import_module("routes.memory.memory_routes")
|
||||
|
||||
sentinel = object()
|
||||
monkeypatch.setattr(legacy, "setup_memory_routes", sentinel)
|
||||
assert canonical.setup_memory_routes is sentinel, (
|
||||
"monkeypatch via legacy alias did not reach the canonical module"
|
||||
)
|
||||
@@ -84,7 +84,7 @@ def test_routes_import_from_upload_limits_not_local_defs():
|
||||
'int(os.getenv("ODYSSEUS_GALLERY_UPLOAD_MAX_BYTES"',
|
||||
'int(os.getenv("ODYSSEUS_GALLERY_TRANSFORM_UPLOAD_MAX_BYTES"',
|
||||
],
|
||||
"routes/memory_routes.py": ['int(os.getenv("ODYSSEUS_MEMORY_IMPORT_MAX_BYTES"'],
|
||||
"routes/memory/memory_routes.py": ['int(os.getenv("ODYSSEUS_MEMORY_IMPORT_MAX_BYTES"'],
|
||||
"routes/personal_routes.py": ['os.getenv("ODYSSEUS_PERSONAL_UPLOAD_MAX_BYTES"'],
|
||||
"routes/email_routes.py": ["EMAIL_COMPOSE_UPLOAD_MAX_BYTES = 25 * 1024 * 1024"],
|
||||
"routes/stt_routes.py": ["STT_MAX_AUDIO_BYTES = 25 * 1024 * 1024"],
|
||||
@@ -98,7 +98,7 @@ def test_routes_import_from_upload_limits_not_local_defs():
|
||||
# And each imports from upload_limits.
|
||||
imports = {
|
||||
"routes/gallery/gallery_routes.py": "GALLERY_UPLOAD_MAX_BYTES",
|
||||
"routes/memory_routes.py": "MEMORY_IMPORT_MAX_BYTES",
|
||||
"routes/memory/memory_routes.py": "MEMORY_IMPORT_MAX_BYTES",
|
||||
"routes/personal_routes.py": "PERSONAL_UPLOAD_MAX_BYTES",
|
||||
"routes/email_routes.py": "EMAIL_COMPOSE_UPLOAD_MAX_BYTES",
|
||||
"routes/stt_routes.py": "STT_MAX_AUDIO_BYTES",
|
||||
|
||||
@@ -90,7 +90,7 @@ def test_request_vision_call_sites_pass_owner():
|
||||
upload_source = (ROOT / "routes" / "upload_routes.py").read_text()
|
||||
document_source = (ROOT / "routes" / "document_routes.py").read_text()
|
||||
gallery_source = (ROOT / "routes" / "gallery" / "gallery_routes.py").read_text()
|
||||
memory_source = (ROOT / "routes" / "memory_routes.py").read_text()
|
||||
memory_source = (ROOT / "routes" / "memory" / "memory_routes.py").read_text()
|
||||
|
||||
assert 'analyze_image_with_vl_result(file_info["path"], owner=owner)' in chat_source
|
||||
assert "analyze_image_with_vl(path, owner=current_user)" in upload_source
|
||||
|
||||
Reference in New Issue
Block a user