oclaw/openclaw/extensions/huggingface/index.test.ts
oliver dbbe3add6a 重构主控编排与运行时预热链路,统一工作区提示词/专家调度协议并补齐 wiki 记忆注入与写回闭环。
同时收敛启动与运维脚本默认行为(含 wiki worker)、更新 Admin 可观测性与相关测试,降低首轮时延并提高运行稳定性。

Made-with: Cursor
2026-04-26 08:34:33 +08:00

71 lines
1.8 KiB
TypeScript

import { describe, expect, it, vi } from "vitest";
import { createTestPluginApi } from "../../test/helpers/plugins/plugin-api.js";
const buildHuggingfaceProviderMock = vi.hoisted(() =>
vi.fn(async () => ({
baseUrl: "https://router.huggingface.co/v1",
api: "openai-completions",
models: [],
})),
);
vi.mock("./provider-catalog.js", () => ({
buildHuggingfaceProvider: buildHuggingfaceProviderMock,
}));
vi.mock("./onboard.js", () => ({
applyHuggingfaceConfig: vi.fn((cfg) => cfg),
HUGGINGFACE_DEFAULT_MODEL_REF: "huggingface/deepseek-ai/DeepSeek-R1",
}));
import plugin from "./index.js";
function registerProvider() {
return registerProviderWithPluginConfig({});
}
function registerProviderWithPluginConfig(pluginConfig: Record<string, unknown>) {
const registerProviderMock = vi.fn();
plugin.register(
createTestPluginApi({
id: "huggingface",
name: "Hugging Face",
source: "test",
config: {},
pluginConfig,
runtime: {} as never,
registerProvider: registerProviderMock,
}),
);
expect(registerProviderMock).toHaveBeenCalledTimes(1);
return registerProviderMock.mock.calls[0]?.[0];
}
describe("huggingface plugin", () => {
it("skips catalog discovery when plugin discovery is disabled", async () => {
const provider = registerProvider();
const result = await provider.catalog.run({
config: {
plugins: {
entries: {
huggingface: {
config: {
discovery: { enabled: false },
},
},
},
},
},
resolveProviderApiKey: () => ({
apiKey: "hf_test_token",
discoveryApiKey: "hf_test_token",
}),
} as never);
expect(result).toBeNull();
expect(buildHuggingfaceProviderMock).not.toHaveBeenCalled();
});
});