mirror of
https://github.com/moltbot/moltbot.git
synced 2026-04-12 17:35:58 +00:00
92 lines
2.7 KiB
TypeScript
92 lines
2.7 KiB
TypeScript
import path from "node:path";
|
|
import { describe, expect, it } from "vitest";
|
|
import { withPathResolutionEnv } from "../test-utils/env.js";
|
|
import { formatPluginSourceForTable, resolvePluginSourceRoots } from "./source-display.js";
|
|
|
|
function createPluginSourceRoots() {
|
|
const stockRoot = path.resolve(
|
|
path.sep,
|
|
"opt",
|
|
"homebrew",
|
|
"lib",
|
|
"node_modules",
|
|
"openclaw",
|
|
"extensions",
|
|
);
|
|
const globalRoot = path.resolve(path.sep, "Users", "x", ".openclaw", "extensions");
|
|
const workspaceRoot = path.resolve(path.sep, "Users", "x", "ws", ".openclaw", "extensions");
|
|
return {
|
|
stock: stockRoot,
|
|
global: globalRoot,
|
|
workspace: workspaceRoot,
|
|
};
|
|
}
|
|
|
|
describe("formatPluginSourceForTable", () => {
|
|
it.each([
|
|
{
|
|
name: "bundled plugin sources under the stock root",
|
|
origin: "bundled" as const,
|
|
sourceKey: "stock" as const,
|
|
dirName: "demo-stock",
|
|
fileName: "index.ts",
|
|
expectedValue: "stock:demo-stock/index.ts",
|
|
expectedRootKey: "stock" as const,
|
|
},
|
|
{
|
|
name: "workspace plugin sources under the workspace root",
|
|
origin: "workspace" as const,
|
|
sourceKey: "workspace" as const,
|
|
dirName: "demo-workspace",
|
|
fileName: "index.ts",
|
|
expectedValue: "workspace:demo-workspace/index.ts",
|
|
expectedRootKey: "workspace" as const,
|
|
},
|
|
{
|
|
name: "global plugin sources under the global root",
|
|
origin: "global" as const,
|
|
sourceKey: "global" as const,
|
|
dirName: "demo-global",
|
|
fileName: "index.js",
|
|
expectedValue: "global:demo-global/index.js",
|
|
expectedRootKey: "global" as const,
|
|
},
|
|
])(
|
|
"shortens $name",
|
|
({ origin, sourceKey, dirName, fileName, expectedValue, expectedRootKey }) => {
|
|
const roots = createPluginSourceRoots();
|
|
const out = formatPluginSourceForTable(
|
|
{
|
|
origin,
|
|
source: path.join(roots[sourceKey], dirName, fileName),
|
|
},
|
|
roots,
|
|
);
|
|
expect(out.value).toBe(expectedValue);
|
|
expect(out.rootKey).toBe(expectedRootKey);
|
|
},
|
|
);
|
|
|
|
it("resolves source roots from an explicit env override", () => {
|
|
const homeDir = path.resolve(path.sep, "tmp", "openclaw-home");
|
|
const roots = withPathResolutionEnv(
|
|
homeDir,
|
|
{
|
|
OPENCLAW_BUNDLED_PLUGINS_DIR: "~/bundled",
|
|
OPENCLAW_STATE_DIR: "~/state",
|
|
},
|
|
(env) =>
|
|
resolvePluginSourceRoots({
|
|
env,
|
|
workspaceDir: "~/ws",
|
|
}),
|
|
);
|
|
|
|
expect(roots).toEqual({
|
|
stock: path.join(homeDir, "bundled"),
|
|
global: path.join(homeDir, "state", "extensions"),
|
|
workspace: path.join(homeDir, "ws", ".openclaw", "extensions"),
|
|
});
|
|
});
|
|
});
|