fix(volumes): unmount existing mounts before remounting

This commit is contained in:
Nicolas Meienberger 2026-04-20 22:34:58 +02:00
parent 694f1c212f
commit 118a67e230
No known key found for this signature in database
2 changed files with 25 additions and 0 deletions

View file

@ -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();

View file

@ -113,6 +113,7 @@ const mountVolume = async (shortId: ShortId) => {
}
const backend = createVolumeBackend(volume);
await backend.unmount();
const { error, status } = await backend.mount();
await db