From f967450eea8cda58a55b294478b12d02d512d6c4 Mon Sep 17 00:00:00 2001 From: Nicolas Meienberger Date: Mon, 20 Apr 2026 22:34:58 +0200 Subject: [PATCH] fix(volumes): unmount existing mounts before remounting --- .../volumes/__tests__/volumes.service.test.ts | 24 +++++++++++++++++++ app/server/modules/volumes/volume.service.ts | 1 + 2 files changed, 25 insertions(+) diff --git a/app/server/modules/volumes/__tests__/volumes.service.test.ts b/app/server/modules/volumes/__tests__/volumes.service.test.ts index 3dce96d2..264d7e4f 100644 --- a/app/server/modules/volumes/__tests__/volumes.service.test.ts +++ b/app/server/modules/volumes/__tests__/volumes.service.test.ts @@ -131,6 +131,30 @@ describe("volumeService.listFiles security", () => { }); }); +describe("volumeService.mountVolume", () => { + test("unmounts any existing mount before mounting", async () => { + const { organizationId, user } = await createTestSession(); + const volume = await createTestVolume({ organizationId, status: "mounted" }); + const unmount = vi.fn().mockResolvedValue({ status: "unmounted" }); + const mount = vi.fn().mockResolvedValue({ status: "mounted" }); + + vi.spyOn(backendModule, "createVolumeBackend").mockImplementation(() => ({ + mount, + unmount, + checkHealth: vi.fn().mockResolvedValue({ status: "mounted" }), + })); + + await withContext({ organizationId, userId: user.id }, async () => { + const result = await volumeService.mountVolume(volume.shortId); + + expect(result.status).toBe("mounted"); + expect(unmount).toHaveBeenCalledOnce(); + expect(mount).toHaveBeenCalledOnce(); + expect(unmount.mock.invocationCallOrder[0]).toBeLessThan(mount.mock.invocationCallOrder[0]); + }); + }); +}); + describe("volumeService.ensureHealthyVolume", () => { test("returns ready when the mounted volume passes its health check", async () => { const { organizationId, user } = await createTestSession(); diff --git a/app/server/modules/volumes/volume.service.ts b/app/server/modules/volumes/volume.service.ts index 835d3d71..4a3c0efe 100644 --- a/app/server/modules/volumes/volume.service.ts +++ b/app/server/modules/volumes/volume.service.ts @@ -113,6 +113,7 @@ const mountVolume = async (shortId: ShortId) => { } const backend = createVolumeBackend(volume); + await backend.unmount(); const { error, status } = await backend.mount(); await db