mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 13:11:22 +00:00
refactor(agent): dedupe harness and command workflows
This commit is contained in:
@@ -10,6 +10,42 @@ import {
|
||||
uninstallPlugin,
|
||||
} from "./uninstall.js";
|
||||
|
||||
async function createInstalledNpmPluginFixture(params: {
|
||||
baseDir: string;
|
||||
pluginId?: string;
|
||||
}): Promise<{
|
||||
pluginId: string;
|
||||
extensionsDir: string;
|
||||
pluginDir: string;
|
||||
config: OpenClawConfig;
|
||||
}> {
|
||||
const pluginId = params.pluginId ?? "my-plugin";
|
||||
const extensionsDir = path.join(params.baseDir, "extensions");
|
||||
const pluginDir = resolvePluginInstallDir(pluginId, extensionsDir);
|
||||
await fs.mkdir(pluginDir, { recursive: true });
|
||||
await fs.writeFile(path.join(pluginDir, "index.js"), "// plugin");
|
||||
|
||||
return {
|
||||
pluginId,
|
||||
extensionsDir,
|
||||
pluginDir,
|
||||
config: {
|
||||
plugins: {
|
||||
entries: {
|
||||
[pluginId]: { enabled: true },
|
||||
},
|
||||
installs: {
|
||||
[pluginId]: {
|
||||
source: "npm",
|
||||
spec: `${pluginId}@1.0.0`,
|
||||
installPath: pluginDir,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
describe("removePluginFromConfig", () => {
|
||||
it("removes plugin from entries", () => {
|
||||
const config: OpenClawConfig = {
|
||||
@@ -286,26 +322,9 @@ describe("uninstallPlugin", () => {
|
||||
});
|
||||
|
||||
it("deletes directory when deleteFiles is true", async () => {
|
||||
const pluginId = "my-plugin";
|
||||
const extensionsDir = path.join(tempDir, "extensions");
|
||||
const pluginDir = resolvePluginInstallDir(pluginId, extensionsDir);
|
||||
await fs.mkdir(pluginDir, { recursive: true });
|
||||
await fs.writeFile(path.join(pluginDir, "index.js"), "// plugin");
|
||||
|
||||
const config: OpenClawConfig = {
|
||||
plugins: {
|
||||
entries: {
|
||||
[pluginId]: { enabled: true },
|
||||
},
|
||||
installs: {
|
||||
[pluginId]: {
|
||||
source: "npm",
|
||||
spec: `${pluginId}@1.0.0`,
|
||||
installPath: pluginDir,
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
const { pluginId, extensionsDir, pluginDir, config } = await createInstalledNpmPluginFixture({
|
||||
baseDir: tempDir,
|
||||
});
|
||||
|
||||
try {
|
||||
const result = await uninstallPlugin({
|
||||
@@ -428,26 +447,9 @@ describe("uninstallPlugin", () => {
|
||||
});
|
||||
|
||||
it("returns a warning when directory deletion fails unexpectedly", async () => {
|
||||
const pluginId = "my-plugin";
|
||||
const extensionsDir = path.join(tempDir, "extensions");
|
||||
const pluginDir = resolvePluginInstallDir(pluginId, extensionsDir);
|
||||
await fs.mkdir(pluginDir, { recursive: true });
|
||||
await fs.writeFile(path.join(pluginDir, "index.js"), "// plugin");
|
||||
|
||||
const config: OpenClawConfig = {
|
||||
plugins: {
|
||||
entries: {
|
||||
[pluginId]: { enabled: true },
|
||||
},
|
||||
installs: {
|
||||
[pluginId]: {
|
||||
source: "npm",
|
||||
spec: `${pluginId}@1.0.0`,
|
||||
installPath: pluginDir,
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
const { pluginId, extensionsDir, config } = await createInstalledNpmPluginFixture({
|
||||
baseDir: tempDir,
|
||||
});
|
||||
|
||||
const rmSpy = vi.spyOn(fs, "rm").mockRejectedValueOnce(new Error("permission denied"));
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user