Files
odysseus/tests/test_note_routes_shim.py
Tal.Yuan 88e0ce3037 refactor(routes): move note domain into routes/note/ subpackage (#5236)
Slice 2f of the route-domain reorganization (#4082/#4071, per
specs/architecture-runtime-inventory.md §6.3). Moves note_routes.py into
routes/note/, 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, research #4975, memory #5007, history #5090, and contacts #5227
slices) so that `import routes.note_routes`, `from routes.note_routes import
X`, `importlib.import_module(...)`, and the `import ... as note_routes` +
`monkeypatch.setattr(note_routes, "SessionLocal", ...)` pattern used by
test_note_reminder_fire_scope.py / test_notes_fail_closed_auth.py all
operate on the same module object the application uses.

The canonical module does NOT depend on the shim — routes/note/note_routes.py
imports only from core/, src/, and stdlib. The outbound email cross-domain
imports (routes.email_routes._get_email_config, routes.email_helpers.
_send_smtp_message) are function-local lazy imports that keep resolving
through the email module's own path (email is not yet migrated).

One source-introspection test site repointed to the new canonical path:
- test_model_helper_owner_scope.py (shared with history; history entry
  already repointed in #5090, note entry repointed here)

Adds tests/test_note_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 4487 passed, 3 skipped.
2026-07-20 13:52:30 +02:00

44 lines
1.8 KiB
Python

"""Regression test for the note route shim (slice 2f, #4082/#4071).
The backward-compat shim at ``routes/note_routes.py`` uses ``sys.modules``
replacement so the legacy import path and the canonical ``routes.note.*``
path resolve to the *same* module object. This is required because
``test_note_reminder_fire_scope.py`` and ``test_notes_fail_closed_auth.py``
do ``import routes.note_routes as note_routes`` followed by
``monkeypatch.setattr(note_routes, "SessionLocal", ...)`` — 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.note_routes as _shim_note # noqa: F401
def test_legacy_and_canonical_note_module_are_same_object():
"""``import routes.note_routes`` must alias the canonical module."""
legacy = importlib.import_module("routes.note_routes")
canonical = importlib.import_module("routes.note.note_routes")
assert legacy is canonical, (
"routes.note_routes shim must resolve to the canonical "
"routes.note.note_routes module object"
)
def test_monkeypatch_via_legacy_alias_reaches_canonical(monkeypatch):
"""Patching through the legacy alias must reach the canonical module.
Several note tests do ``import routes.note_routes as note_routes``
followed by ``monkeypatch.setattr(note_routes, "SessionLocal", ...)``.
For that to take effect at runtime, the legacy module object and the
canonical one must be identical.
"""
legacy = importlib.import_module("routes.note_routes")
canonical = importlib.import_module("routes.note.note_routes")
sentinel = object()
monkeypatch.setattr(legacy, "setup_note_routes", sentinel)
assert canonical.setup_note_routes is sentinel, (
"monkeypatch via legacy alias did not reach the canonical module"
)