From 8cd6288d1970ae86d9c8d57850b246c177a7dd94 Mon Sep 17 00:00:00 2001 From: ZacharyZcR Date: Tue, 28 Jul 2026 01:49:17 +0800 Subject: [PATCH] stop session-log route test importing the real repository layer (#1125) The test mocks db, logger and AuthManager, but the route module also calls PermissionManager.getInstance() at import time and pulls in the repository factory, which loads the drizzle schema and the better-sqlite3 native binding. Importing that costs seconds when the full suite runs its projects concurrently, and the test times out at 5s. On its own it passes, so it read as flaky rather than as a missing mock. Mock both. None of it is under test here, and the file now imports in milliseconds regardless of load. --- .../routes/session-log-routes.test.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/backend/tests/database/routes/session-log-routes.test.ts b/src/backend/tests/database/routes/session-log-routes.test.ts index 1bbbbf54..73dfe884 100644 --- a/src/backend/tests/database/routes/session-log-routes.test.ts +++ b/src/backend/tests/database/routes/session-log-routes.test.ts @@ -28,6 +28,25 @@ vi.mock("../../../utils/auth-manager.js", () => ({ }, })); +// The route module calls PermissionManager.getInstance() at import time and +// pulls in the repository factory, which loads the drizzle schema and the +// better-sqlite3 native binding. Importing that tree costs seconds under a +// concurrent full run — enough to blow the 5s test timeout — and none of it is +// under test here. +vi.mock("../../../utils/permission-manager.js", () => ({ + PermissionManager: { + getInstance: () => ({ + canAccessHost: vi.fn(), + }), + }, +})); + +vi.mock("../../../database/repositories/factory.js", () => ({ + createCurrentSessionRecordingRepository: vi.fn(), + createCurrentSettingsRepository: vi.fn(), + getCurrentSettingValue: vi.fn(), +})); + const mockReadFile = vi.fn(); const mockStat = vi.fn(); const mockUnlink = vi.fn();