diff --git a/server/src/__tests__/adapter-plugin-concurrency.test.ts b/server/src/__tests__/adapter-plugin-concurrency.test.ts index 2ad25f30..b126f4b8 100644 --- a/server/src/__tests__/adapter-plugin-concurrency.test.ts +++ b/server/src/__tests__/adapter-plugin-concurrency.test.ts @@ -2,6 +2,21 @@ import fs from "node:fs"; import os from "node:os"; import path from "node:path"; import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; + +vi.mock("hermes-paperclip-adapter/server", () => ({ + execute: vi.fn(), + testEnvironment: vi.fn(), + sessionCodec: vi.fn(), + listSkills: vi.fn(async () => []), + syncSkills: vi.fn(async () => []), + detectModel: vi.fn(), +})); + +vi.mock("hermes-paperclip-adapter", () => ({ + agentConfigurationDoc: vi.fn(), + models: [], +})); + import { withAdapterMutex } from "../routes/adapters.js"; // --------------------------------------------------------------------------- diff --git a/server/src/routes/adapters.ts b/server/src/routes/adapters.ts index 2af29f29..08aefb75 100644 --- a/server/src/routes/adapters.ts +++ b/server/src/routes/adapters.ts @@ -232,7 +232,7 @@ export function adapterRoutes() { // Strip version suffix if the UI sends "pkg@1.2.3" instead of separating it // e.g. "@henkey/hermes-paperclip-adapter@0.3.0" → packageName + version let canonicalName = packageName.trim(); - let explicitVersion = version; + let explicitVersion = typeof version === "string" ? version.trim() : version; const versionSuffix = packageName.match(/@(\d+\.\d+\.\d+.*)$/); if (versionSuffix) { // For scoped packages: "@scope/name@1.2.3" → "@scope/name" + "1.2.3" @@ -264,8 +264,7 @@ export function adapterRoutes() { // Read installed version from package.json try { const pkgJsonPath = path.join(pluginsDir, "node_modules", canonicalName, "package.json"); - const pkgContent = await import("node:fs/promises"); - const pkgRaw = await pkgContent.readFile(pkgJsonPath, "utf-8"); + const pkgRaw = await readFile(pkgJsonPath, "utf-8"); const pkg = JSON.parse(pkgRaw); const v = pkg.version; installedVersion = diff --git a/server/src/services/adapter-plugin-store.ts b/server/src/services/adapter-plugin-store.ts index 3df1ba7d..1e21acf2 100644 --- a/server/src/services/adapter-plugin-store.ts +++ b/server/src/services/adapter-plugin-store.ts @@ -89,7 +89,7 @@ function writeStore(records: AdapterPluginRecord[]): void { // Atomic write: write to a temp file in the same directory then rename. // rename() is atomic on POSIX when source and target are on the same // filesystem, preventing partial/corrupted reads from concurrent processes. - const tmpPath = `${ADAPTER_PLUGINS_STORE_PATH}.${process.pid}.tmp`; + const tmpPath = `${ADAPTER_PLUGINS_STORE_PATH}.tmp`; fs.writeFileSync(tmpPath, JSON.stringify(records, null, 2), "utf-8"); fs.renameSync(tmpPath, ADAPTER_PLUGINS_STORE_PATH); storeCache = records;