Files
odysseus/tests/test_memory_routes_shim.py
T
Tal.Yuan 41420c59fc 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.
2026-06-30 17:52:14 +02:00

44 lines
1.8 KiB
Python

"""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"
)