test: isolate channel catalog fixtures

This commit is contained in:
Peter Steinberger
2026-04-28 19:06:38 +01:00
parent 84154bb09c
commit cd2e13be8a

View File

@@ -14,6 +14,22 @@ type CatalogEntryMeta = {
aliases?: string[];
};
function createCatalogFixtureEnv(overrides: NodeJS.ProcessEnv = {}): NodeJS.ProcessEnv {
return {
...process.env,
OPENCLAW_DISABLE_PLUGIN_DISCOVERY_CACHE: "1",
OPENCLAW_DISABLE_PLUGIN_MANIFEST_CACHE: "1",
...overrides,
};
}
function createCatalogFallbackOnlyEnv(): NodeJS.ProcessEnv {
return createCatalogFixtureEnv({
OPENCLAW_DISABLE_BUNDLED_PLUGINS: "1",
OPENCLAW_BUNDLED_PLUGINS_DIR: "/nonexistent/bundled/plugins",
});
}
export function describeChannelCatalogEntryContract(params: {
channelId: string;
npmSpec: string;
@@ -44,13 +60,13 @@ export function describeBundledMetadataOnlyChannelCatalogContract(params: {
}) {
describe(`${params.pluginId} bundled metadata-only channel catalog contract`, () => {
it("includes the bundled metadata-only channel entry when the runtime entrypoint is omitted", () => {
const packageRoot = fs.mkdtempSync(
const workspaceDir = fs.mkdtempSync(
path.join(resolvePreferredOpenClawTmpDir(), "openclaw-bundled-catalog-"),
);
const bundledDir = path.join(packageRoot, "dist", "extensions", params.pluginId);
const bundledDir = path.join(workspaceDir, ".openclaw", "extensions", params.pluginId);
fs.mkdirSync(bundledDir, { recursive: true });
fs.writeFileSync(
path.join(packageRoot, "package.json"),
path.join(workspaceDir, "package.json"),
JSON.stringify({ name: "openclaw" }),
"utf8",
);
@@ -77,10 +93,8 @@ export function describeBundledMetadataOnlyChannelCatalogContract(params: {
);
const entry = listChannelPluginCatalogEntries({
env: {
...process.env,
OPENCLAW_BUNDLED_PLUGINS_DIR: path.join(packageRoot, "dist", "extensions"),
},
workspaceDir,
env: createCatalogFixtureEnv({ OPENCLAW_DISABLE_BUNDLED_PLUGINS: "1" }),
}).find((item) => item.id === params.meta.id);
expect(entry?.install.npmSpec).toBe(params.npmSpec);
@@ -123,10 +137,7 @@ export function describeOfficialFallbackChannelCatalogContract(params: {
);
const entry = listChannelPluginCatalogEntries({
env: {
...process.env,
OPENCLAW_BUNDLED_PLUGINS_DIR: "/nonexistent/bundled/plugins",
},
env: createCatalogFallbackOnlyEnv(),
officialCatalogPaths: [catalogPath],
}).find((item) => item.id === params.channelId);
@@ -202,10 +213,7 @@ export function describeOfficialFallbackChannelCatalogContract(params: {
const entry = listChannelPluginCatalogEntries({
catalogPaths: [externalCatalogPath],
officialCatalogPaths: [officialCatalogPath],
env: {
...process.env,
OPENCLAW_BUNDLED_PLUGINS_DIR: path.join(dir, "dist", "extensions"),
},
env: createCatalogFallbackOnlyEnv(),
}).find((item) => item.id === params.channelId);
expect(entry?.install.npmSpec).toBe(params.externalNpmSpec);
@@ -240,10 +248,7 @@ export function describeOfficialFallbackChannelCatalogContract(params: {
const entry = listChannelPluginCatalogEntries({
catalogPaths: [catalogPath],
officialCatalogPaths: [],
env: {
...process.env,
OPENCLAW_BUNDLED_PLUGINS_DIR: "/nonexistent/bundled/plugins",
},
env: createCatalogFallbackOnlyEnv(),
}).find((item) => item.id === params.channelId);
expect(entry?.installSource?.npm).toMatchObject({