test: dedupe plugin utility config suites

This commit is contained in:
Peter Steinberger
2026-03-28 04:01:55 +00:00
parent c5b1582d48
commit 708ff9145e
10 changed files with 116 additions and 61 deletions

View File

@@ -3,24 +3,11 @@ 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,
};
}
const PLUGIN_SOURCE_ROOTS = {
stock: path.resolve(path.sep, "opt", "homebrew", "lib", "node_modules", "openclaw", "extensions"),
global: path.resolve(path.sep, "Users", "x", ".openclaw", "extensions"),
workspace: path.resolve(path.sep, "Users", "x", "ws", ".openclaw", "extensions"),
};
function expectFormattedSource(params: {
origin: "bundled" | "workspace" | "global";
@@ -30,13 +17,12 @@ function expectFormattedSource(params: {
expectedValue: string;
expectedRootKey: "stock" | "workspace" | "global";
}) {
const roots = createPluginSourceRoots();
const out = formatPluginSourceForTable(
{
origin: params.origin,
source: path.join(roots[params.sourceKey], params.dirName, params.fileName),
source: path.join(PLUGIN_SOURCE_ROOTS[params.sourceKey], params.dirName, params.fileName),
},
roots,
PLUGIN_SOURCE_ROOTS,
);
expect(out.value).toBe(params.expectedValue);
expect(out.rootKey).toBe(params.expectedRootKey);