forked from farhoodlabs/paperclip
Address Greptile review: trim version, remove redundant fs/promises import, use fixed .tmp suffix
This commit is contained in:
@@ -2,6 +2,21 @@ import fs from "node:fs";
|
|||||||
import os from "node:os";
|
import os from "node:os";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
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";
|
import { withAdapterMutex } from "../routes/adapters.js";
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -232,7 +232,7 @@ export function adapterRoutes() {
|
|||||||
// Strip version suffix if the UI sends "pkg@1.2.3" instead of separating it
|
// 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
|
// e.g. "@henkey/hermes-paperclip-adapter@0.3.0" → packageName + version
|
||||||
let canonicalName = packageName.trim();
|
let canonicalName = packageName.trim();
|
||||||
let explicitVersion = version;
|
let explicitVersion = typeof version === "string" ? version.trim() : version;
|
||||||
const versionSuffix = packageName.match(/@(\d+\.\d+\.\d+.*)$/);
|
const versionSuffix = packageName.match(/@(\d+\.\d+\.\d+.*)$/);
|
||||||
if (versionSuffix) {
|
if (versionSuffix) {
|
||||||
// For scoped packages: "@scope/name@1.2.3" → "@scope/name" + "1.2.3"
|
// 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
|
// Read installed version from package.json
|
||||||
try {
|
try {
|
||||||
const pkgJsonPath = path.join(pluginsDir, "node_modules", canonicalName, "package.json");
|
const pkgJsonPath = path.join(pluginsDir, "node_modules", canonicalName, "package.json");
|
||||||
const pkgContent = await import("node:fs/promises");
|
const pkgRaw = await readFile(pkgJsonPath, "utf-8");
|
||||||
const pkgRaw = await pkgContent.readFile(pkgJsonPath, "utf-8");
|
|
||||||
const pkg = JSON.parse(pkgRaw);
|
const pkg = JSON.parse(pkgRaw);
|
||||||
const v = pkg.version;
|
const v = pkg.version;
|
||||||
installedVersion =
|
installedVersion =
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ function writeStore(records: AdapterPluginRecord[]): void {
|
|||||||
// Atomic write: write to a temp file in the same directory then rename.
|
// 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
|
// rename() is atomic on POSIX when source and target are on the same
|
||||||
// filesystem, preventing partial/corrupted reads from concurrent processes.
|
// 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.writeFileSync(tmpPath, JSON.stringify(records, null, 2), "utf-8");
|
||||||
fs.renameSync(tmpPath, ADAPTER_PLUGINS_STORE_PATH);
|
fs.renameSync(tmpPath, ADAPTER_PLUGINS_STORE_PATH);
|
||||||
storeCache = records;
|
storeCache = records;
|
||||||
|
|||||||
Reference in New Issue
Block a user