mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-04 08:20:24 +00:00
refactor: dedupe gateway config and infra flows
This commit is contained in:
@@ -555,6 +555,18 @@ describe("installPluginFromArchive", () => {
|
||||
});
|
||||
|
||||
describe("installPluginFromDir", () => {
|
||||
function expectInstalledAsMemoryCognee(
|
||||
result: Awaited<ReturnType<typeof installPluginFromDir>>,
|
||||
extensionsDir: string,
|
||||
) {
|
||||
expect(result.ok).toBe(true);
|
||||
if (!result.ok) {
|
||||
return;
|
||||
}
|
||||
expect(result.pluginId).toBe("memory-cognee");
|
||||
expect(result.targetDir).toBe(path.join(extensionsDir, "memory-cognee"));
|
||||
}
|
||||
|
||||
it("uses --ignore-scripts for dependency install", async () => {
|
||||
const { pluginDir, extensionsDir } = setupInstallPluginFromDirFixture();
|
||||
|
||||
@@ -617,12 +629,7 @@ describe("installPluginFromDir", () => {
|
||||
logger: { info: (msg: string) => infoMessages.push(msg), warn: () => {} },
|
||||
});
|
||||
|
||||
expect(res.ok).toBe(true);
|
||||
if (!res.ok) {
|
||||
return;
|
||||
}
|
||||
expect(res.pluginId).toBe("memory-cognee");
|
||||
expect(res.targetDir).toBe(path.join(extensionsDir, "memory-cognee"));
|
||||
expectInstalledAsMemoryCognee(res, extensionsDir);
|
||||
expect(
|
||||
infoMessages.some((msg) =>
|
||||
msg.includes(
|
||||
@@ -644,12 +651,7 @@ describe("installPluginFromDir", () => {
|
||||
logger: { info: () => {}, warn: () => {} },
|
||||
});
|
||||
|
||||
expect(res.ok).toBe(true);
|
||||
if (!res.ok) {
|
||||
return;
|
||||
}
|
||||
expect(res.pluginId).toBe("memory-cognee");
|
||||
expect(res.targetDir).toBe(path.join(extensionsDir, "memory-cognee"));
|
||||
expectInstalledAsMemoryCognee(res, extensionsDir);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -147,6 +147,42 @@ function buildFileInstallResult(pluginId: string, targetFile: string): InstallPl
|
||||
};
|
||||
}
|
||||
|
||||
type PackageInstallCommonParams = {
|
||||
extensionsDir?: string;
|
||||
timeoutMs?: number;
|
||||
logger?: PluginInstallLogger;
|
||||
mode?: "install" | "update";
|
||||
dryRun?: boolean;
|
||||
expectedPluginId?: string;
|
||||
};
|
||||
|
||||
type FileInstallCommonParams = Pick<
|
||||
PackageInstallCommonParams,
|
||||
"extensionsDir" | "logger" | "mode" | "dryRun"
|
||||
>;
|
||||
|
||||
function pickPackageInstallCommonParams(
|
||||
params: PackageInstallCommonParams,
|
||||
): PackageInstallCommonParams {
|
||||
return {
|
||||
extensionsDir: params.extensionsDir,
|
||||
timeoutMs: params.timeoutMs,
|
||||
logger: params.logger,
|
||||
mode: params.mode,
|
||||
dryRun: params.dryRun,
|
||||
expectedPluginId: params.expectedPluginId,
|
||||
};
|
||||
}
|
||||
|
||||
function pickFileInstallCommonParams(params: FileInstallCommonParams): FileInstallCommonParams {
|
||||
return {
|
||||
extensionsDir: params.extensionsDir,
|
||||
logger: params.logger,
|
||||
mode: params.mode,
|
||||
dryRun: params.dryRun,
|
||||
};
|
||||
}
|
||||
|
||||
export function resolvePluginInstallDir(pluginId: string, extensionsDir?: string): string {
|
||||
const extensionsBase = extensionsDir
|
||||
? resolveUserPath(extensionsDir)
|
||||
@@ -166,15 +202,11 @@ export function resolvePluginInstallDir(pluginId: string, extensionsDir?: string
|
||||
return targetDirResult.path;
|
||||
}
|
||||
|
||||
async function installPluginFromPackageDir(params: {
|
||||
packageDir: string;
|
||||
extensionsDir?: string;
|
||||
timeoutMs?: number;
|
||||
logger?: PluginInstallLogger;
|
||||
mode?: "install" | "update";
|
||||
dryRun?: boolean;
|
||||
expectedPluginId?: string;
|
||||
}): Promise<InstallPluginResult> {
|
||||
async function installPluginFromPackageDir(
|
||||
params: {
|
||||
packageDir: string;
|
||||
} & PackageInstallCommonParams,
|
||||
): Promise<InstallPluginResult> {
|
||||
const { logger, timeoutMs, mode, dryRun } = resolveTimedInstallModeOptions(params, defaultLogger);
|
||||
|
||||
const manifestPath = path.join(params.packageDir, "package.json");
|
||||
@@ -344,15 +376,11 @@ async function installPluginFromPackageDir(params: {
|
||||
};
|
||||
}
|
||||
|
||||
export async function installPluginFromArchive(params: {
|
||||
archivePath: string;
|
||||
extensionsDir?: string;
|
||||
timeoutMs?: number;
|
||||
logger?: PluginInstallLogger;
|
||||
mode?: "install" | "update";
|
||||
dryRun?: boolean;
|
||||
expectedPluginId?: string;
|
||||
}): Promise<InstallPluginResult> {
|
||||
export async function installPluginFromArchive(
|
||||
params: {
|
||||
archivePath: string;
|
||||
} & PackageInstallCommonParams,
|
||||
): Promise<InstallPluginResult> {
|
||||
const logger = params.logger ?? defaultLogger;
|
||||
const timeoutMs = params.timeoutMs ?? 120_000;
|
||||
const mode = params.mode ?? "install";
|
||||
@@ -370,25 +398,23 @@ export async function installPluginFromArchive(params: {
|
||||
onExtracted: async (packageDir) =>
|
||||
await installPluginFromPackageDir({
|
||||
packageDir,
|
||||
extensionsDir: params.extensionsDir,
|
||||
timeoutMs,
|
||||
logger,
|
||||
mode,
|
||||
dryRun: params.dryRun,
|
||||
expectedPluginId: params.expectedPluginId,
|
||||
...pickPackageInstallCommonParams({
|
||||
extensionsDir: params.extensionsDir,
|
||||
timeoutMs,
|
||||
logger,
|
||||
mode,
|
||||
dryRun: params.dryRun,
|
||||
expectedPluginId: params.expectedPluginId,
|
||||
}),
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
export async function installPluginFromDir(params: {
|
||||
dirPath: string;
|
||||
extensionsDir?: string;
|
||||
timeoutMs?: number;
|
||||
logger?: PluginInstallLogger;
|
||||
mode?: "install" | "update";
|
||||
dryRun?: boolean;
|
||||
expectedPluginId?: string;
|
||||
}): Promise<InstallPluginResult> {
|
||||
export async function installPluginFromDir(
|
||||
params: {
|
||||
dirPath: string;
|
||||
} & PackageInstallCommonParams,
|
||||
): Promise<InstallPluginResult> {
|
||||
const dirPath = resolveUserPath(params.dirPath);
|
||||
if (!(await fileExists(dirPath))) {
|
||||
return { ok: false, error: `directory not found: ${dirPath}` };
|
||||
@@ -400,12 +426,7 @@ export async function installPluginFromDir(params: {
|
||||
|
||||
return await installPluginFromPackageDir({
|
||||
packageDir: dirPath,
|
||||
extensionsDir: params.extensionsDir,
|
||||
timeoutMs: params.timeoutMs,
|
||||
logger: params.logger,
|
||||
mode: params.mode,
|
||||
dryRun: params.dryRun,
|
||||
expectedPluginId: params.expectedPluginId,
|
||||
...pickPackageInstallCommonParams(params),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -517,30 +538,22 @@ export async function installPluginFromNpmSpec(params: {
|
||||
return finalized;
|
||||
}
|
||||
|
||||
export async function installPluginFromPath(params: {
|
||||
path: string;
|
||||
extensionsDir?: string;
|
||||
timeoutMs?: number;
|
||||
logger?: PluginInstallLogger;
|
||||
mode?: "install" | "update";
|
||||
dryRun?: boolean;
|
||||
expectedPluginId?: string;
|
||||
}): Promise<InstallPluginResult> {
|
||||
export async function installPluginFromPath(
|
||||
params: {
|
||||
path: string;
|
||||
} & PackageInstallCommonParams,
|
||||
): Promise<InstallPluginResult> {
|
||||
const pathResult = await resolveExistingInstallPath(params.path);
|
||||
if (!pathResult.ok) {
|
||||
return pathResult;
|
||||
}
|
||||
const { resolvedPath: resolved, stat } = pathResult;
|
||||
const packageInstallOptions = pickPackageInstallCommonParams(params);
|
||||
|
||||
if (stat.isDirectory()) {
|
||||
return await installPluginFromDir({
|
||||
dirPath: resolved,
|
||||
extensionsDir: params.extensionsDir,
|
||||
timeoutMs: params.timeoutMs,
|
||||
logger: params.logger,
|
||||
mode: params.mode,
|
||||
dryRun: params.dryRun,
|
||||
expectedPluginId: params.expectedPluginId,
|
||||
...packageInstallOptions,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -548,20 +561,12 @@ export async function installPluginFromPath(params: {
|
||||
if (archiveKind) {
|
||||
return await installPluginFromArchive({
|
||||
archivePath: resolved,
|
||||
extensionsDir: params.extensionsDir,
|
||||
timeoutMs: params.timeoutMs,
|
||||
logger: params.logger,
|
||||
mode: params.mode,
|
||||
dryRun: params.dryRun,
|
||||
expectedPluginId: params.expectedPluginId,
|
||||
...packageInstallOptions,
|
||||
});
|
||||
}
|
||||
|
||||
return await installPluginFromFile({
|
||||
filePath: resolved,
|
||||
extensionsDir: params.extensionsDir,
|
||||
logger: params.logger,
|
||||
mode: params.mode,
|
||||
dryRun: params.dryRun,
|
||||
...pickFileInstallCommonParams(params),
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user