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.
This commit is contained in:
ZacharyZcR
2026-07-28 01:49:17 +08:00
committed by GitHub
parent f2055caa5b
commit 8cd6288d19
@@ -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();