Skip to content

DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.

Isolate sidebar auth fixtures and verify shared runtime home reset

Bingxi Zhao (Frank)3b672dac89da
diff --git a/tests/runtime/test_runtime_home_reset.py b/tests/runtime/test_runtime_home_reset.py
new file mode 100644
index 000000000..490aff4f0
--- /dev/null
+++ b/tests/runtime/test_runtime_home_reset.py
@@ -0,0 +1,38 @@
+"""CLI and launcher home switches must refresh pre-imported account paths."""
+
+from __future__ import annotations
+
+import importlib
+
+import pytest
+
+
[email protected]("entrypoint", ["deeptutor_cli.init_cmd", "deeptutor.runtime.launcher"])
+def test_home_switch_rebinds_existing_account_path_services(tmp_path, monkeypatch, entrypoint):
+ from deeptutor.multi_user import paths
+
+ old_home = tmp_path / "old"
+ new_home = tmp_path / "new"
+ # Restore every modified module cache when the test ends.
+ for name, value in {
+ "PROJECT_ROOT": old_home,
+ "ADMIN_WORKSPACE_ROOT": old_home / "data",
+ "USERS_ROOT": old_home / "data" / "users",
+ "SYSTEM_ROOT": old_home / "data" / "system",
+ "LEGACY_MULTI_USER_ROOT": old_home / "multi-user",
+ "_path_services": {},
+ "_legacy_migration_done": True,
+ }.items():
+ monkeypatch.setattr(paths, name, value)
+ previous = paths.get_admin_path_service()
+ monkeypatch.setenv("DEEPTUTOR_HOME", str(new_home))
+
+ importlib.import_module(entrypoint)._reset_runtime_singletons()
+
+ selected = paths.get_admin_path_service()
+ assert selected is not previous
+ assert selected.get_settings_file("system.json").is_relative_to(new_home / "data")
+ assert paths.SYSTEM_ROOT == new_home / "data" / "system"
+ assert paths.USERS_ROOT == new_home / "data" / "users"
+ assert paths.LEGACY_MULTI_USER_ROOT == new_home / "multi-user"
+ assert paths._legacy_migration_done is False
diff --git a/web/tests/sidebar-lazy-history.spec.tsx b/web/tests/sidebar-lazy-history.spec.tsx
index b74a35260..95e17564a 100644
--- a/web/tests/sidebar-lazy-history.spec.tsx
+++ b/web/tests/sidebar-lazy-history.spec.tsx
@@ -4,6 +4,18 @@ import { SidebarShell } from "@/components/sidebar/SidebarShell";
const fixture = vi.hoisted(() => ({ push: vi.fn(), close: vi.fn() }));
+vi.mock("@/hooks/useAuthStatus", () => ({
+ useAuthStatus: () => ({
+ enabled: false,
+ authenticated: false,
+ isAdmin: false,
+ userId: null,
+ statusAvailable: true,
+ loading: false,
+ learningPolicy: null,
+ }),
+}));
+
vi.mock("@/hooks/useChatWorkspaces", () => ({ useChatWorkspaces: () => ({ workspaces: [], error: "" }) }));
vi.mock("next/navigation", () => ({
diff --git a/web/tests/sidebar-prefetch.spec.tsx b/web/tests/sidebar-prefetch.spec.tsx
index 68b66c4fa..90ef72e96 100644
--- a/web/tests/sidebar-prefetch.spec.tsx
+++ b/web/tests/sidebar-prefetch.spec.tsx
@@ -11,6 +11,18 @@ const fixture = vi.hoisted(() => ({
setCollapsed: vi.fn(),
}));
+vi.mock("@/hooks/useAuthStatus", () => ({
+ useAuthStatus: () => ({
+ enabled: false,
+ authenticated: false,
+ isAdmin: false,
+ userId: null,
+ statusAvailable: true,
+ loading: false,
+ learningPolicy: null,
+ }),
+}));
+
vi.mock("next/link", () => ({
default: ({
children,