From 3584ab989634d73185b9b652f914e54a505620e8 Mon Sep 17 00:00:00 2001 From: Nicolas Meienberger Date: Thu, 7 May 2026 20:36:57 +0200 Subject: [PATCH] chore: pr feedbacks --- app/server/modules/lifecycle/shutdown.ts | 10 ++---- app/server/modules/volumes/volume.service.ts | 34 ++++++-------------- apps/agent/src/volume-host/operations.ts | 8 +++-- 3 files changed, 18 insertions(+), 34 deletions(-) diff --git a/app/server/modules/lifecycle/shutdown.ts b/app/server/modules/lifecycle/shutdown.ts index 02f180c8..66ec7bf2 100644 --- a/app/server/modules/lifecycle/shutdown.ts +++ b/app/server/modules/lifecycle/shutdown.ts @@ -3,11 +3,7 @@ import { db } from "../../db/db"; import { logger } from "@zerobyte/core/node"; import { stopApplicationRuntime } from "./bootstrap"; import { decryptVolumeConfig } from "../volumes/volume-config-secrets"; -import { - createVolumeBackend, - type AgentVolume, - type BackendConfig as HostBackendConfig, -} from "../../../../apps/agent/src/volume-host"; +import { createVolumeBackend } from "../../../../apps/agent/src/volume-host"; export const shutdown = async () => { await Scheduler.stop(); @@ -20,9 +16,9 @@ export const shutdown = async () => { for (const volume of volumes) { const backend = createVolumeBackend({ ...volume, - config: (await decryptVolumeConfig(volume.config)) as HostBackendConfig, + config: await decryptVolumeConfig(volume.config), provisioningId: volume.provisioningId ?? null, - } satisfies AgentVolume); + }); const { status, error } = await backend.unmount(); logger.info(`Volume ${volume.name} unmount status: ${status}${error ? `, error: ${error}` : ""}`); diff --git a/app/server/modules/volumes/volume.service.ts b/app/server/modules/volumes/volume.service.ts index 41b91562..d53cff21 100644 --- a/app/server/modules/volumes/volume.service.ts +++ b/app/server/modules/volumes/volume.service.ts @@ -18,18 +18,13 @@ import { getOrganizationId } from "~/server/core/request-context"; import { type ShortId } from "~/server/utils/branded"; import { decryptVolumeConfig, encryptVolumeConfig } from "./volume-config-secrets"; import type { VolumeCommand, VolumeCommandResult } from "@zerobyte/contracts/agent-protocol"; -import { - createVolumeBackend, - getStatFs, - getVolumePath, - type AgentVolume, - type BackendConfig as HostBackendConfig, -} from "../../../../apps/agent/src/volume-host"; +import { createVolumeBackend, getStatFs, getVolumePath } from "../../../../apps/agent/src/volume-host"; import { browseFilesystem as browseHostFilesystem, listVolumeFiles, testVolumeConnection, } from "../../../../apps/agent/src/volume-host/operations"; +import { Effect } from "effect"; type EnsureHealthyVolumeResult = | { ready: true; volume: Volume; remounted: boolean } @@ -68,10 +63,10 @@ const volumeForAgent = async (volume: Volume): Promise => ({ config: await decryptVolumeConfig(volume.config), }); -const volumeForHost = async (volume: Volume): Promise => ({ +const volumeForHost = async (volume: Volume): Promise => ({ ...volume, shortId: volume.shortId, - config: (await decryptVolumeConfig(volume.config)) as HostBackendConfig, + config: await decryptVolumeConfig(volume.config), provisioningId: volume.provisioningId ?? null, }); @@ -101,17 +96,6 @@ const runVolumeBackendCommand = async ( return command.result; }; -const mapAgentFileError = (error: unknown) => { - const message = toMessage(error); - if (message === "Invalid path") { - throw new BadRequestError("Invalid path"); - } - if (message === "Directory not found") { - throw new NotFoundError("Directory not found"); - } - throw error; -}; - const createVolume = async (name: string, backendConfig: BackendConfig) => { const organizationId = getOrganizationId(); const trimmedName = name.trim(); @@ -219,9 +203,10 @@ const getVolume = async (shortId: ShortId) => { if (volume.status === "mounted") { statfs = await withTimeout( shouldRunViaAgent(volume) - ? runVolumeCommand(volume.agentId, { name: "volume.statfs", volume: await volumeForAgent(volume) }).then( - (command) => command.result, - ) + ? runVolumeCommand(volume.agentId, { + name: "volume.statfs", + volume: await volumeForAgent(volume), + }).then((command) => command.result) : volumeForHost(volume).then((hostVolume) => getStatFs(getVolumePath(hostVolume))), 1000, "volume.statfs", @@ -295,7 +280,7 @@ const updateVolume = async (shortId: ShortId, volumeData: UpdateVolumeBody) => { const testConnection = async (backendConfig: BackendConfig) => { if (!config.flags.enableLocalAgent) { - return testVolumeConnection(backendConfig as HostBackendConfig); + return Effect.runPromise(testVolumeConnection(backendConfig)); } const command = await runVolumeCommand(LOCAL_AGENT_ID, { name: "volume.testConnection", backendConfig }); @@ -404,7 +389,6 @@ const listFiles = async (shortId: ShortId, subPath?: string, offset: number = 0, }); return command.result; } catch (error) { - mapAgentFileError(error); throw new InternalServerError(`Failed to list files: ${toMessage(error)}`); } }; diff --git a/apps/agent/src/volume-host/operations.ts b/apps/agent/src/volume-host/operations.ts index f99615ce..e2ad0f7e 100644 --- a/apps/agent/src/volume-host/operations.ts +++ b/apps/agent/src/volume-host/operations.ts @@ -20,7 +20,11 @@ export const listVolumeFiles = async ( const normalizedPath = path.normalize(requestedPath); const requestedRelativePath = path.relative(volumePath, normalizedPath); - if (requestedRelativePath.startsWith("..") || path.isAbsolute(requestedRelativePath)) { + if ( + requestedRelativePath === ".." || + requestedRelativePath.startsWith(`..${path.sep}`) || + path.isAbsolute(requestedRelativePath) + ) { throw new Error("Invalid path"); } @@ -32,7 +36,7 @@ export const listVolumeFiles = async ( const realRequestedPath = await fs.realpath(requestedPath); const relative = path.relative(realVolumeRoot, realRequestedPath); - if (relative.startsWith("..") || path.isAbsolute(relative)) { + if (relative === ".." || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative)) { throw new Error("Invalid path"); }