惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园_首页
H
Help Net Security
量子位
The Cloudflare Blog
博客园 - Franky
博客园 - 聂微东
博客园 - 司徒正美
Last Week in AI
Last Week in AI
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Apple Machine Learning Research
Apple Machine Learning Research
宝玉的分享
宝玉的分享
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
有赞技术团队
有赞技术团队
罗磊的独立博客
GbyAI
GbyAI
雷峰网
雷峰网
T
The Blog of Author Tim Ferriss
Martin Fowler
Martin Fowler
S
SegmentFault 最新的问题
美团技术团队
阮一峰的网络日志
阮一峰的网络日志
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
U
Unit 42
MongoDB | Blog
MongoDB | Blog

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 test: merge chat context notice checks · openclaw/openclaw@5c2f4af feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248
test: slim provider registry mocks · openclaw/openclaw@2e...
steipete · 2026-04-17 · via Recent Commits to openclaw:main
11

import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";

2-

import { createEmptyPluginRegistry } from "../plugins/registry.js";

2+

import type { ImageGenerationProviderPlugin } from "../plugins/types.js";

334-

const { resolveRuntimePluginRegistryMock } = vi.hoisted(() => ({

5-

resolveRuntimePluginRegistryMock: vi.fn<

6-

(params?: unknown) => ReturnType<typeof createEmptyPluginRegistry> | undefined

7-

>(() => undefined),

4+

const { resolvePluginCapabilityProvidersMock } = vi.hoisted(() => ({

5+

resolvePluginCapabilityProvidersMock: vi.fn<() => ImageGenerationProviderPlugin[]>(() => []),

86

}));

9710-

vi.mock("../plugins/loader.js", () => ({

11-

resolveRuntimePluginRegistry: resolveRuntimePluginRegistryMock,

8+

vi.mock("../plugins/capability-provider-runtime.js", () => ({

9+

resolvePluginCapabilityProviders: resolvePluginCapabilityProvidersMock,

1210

}));

13111412

let getImageGenerationProvider: typeof import("./provider-registry.js").getImageGenerationProvider;

1513

let listImageGenerationProviders: typeof import("./provider-registry.js").listImageGenerationProviders;

161415+

function createProvider(

16+

params: Pick<ImageGenerationProviderPlugin, "id"> & Partial<ImageGenerationProviderPlugin>,

17+

): ImageGenerationProviderPlugin {

18+

return {

19+

label: params.id,

20+

capabilities: {

21+

generate: {},

22+

edit: { enabled: false },

23+

},

24+

generateImage: async () => ({

25+

images: [{ buffer: Buffer.from("image"), mimeType: "image/png" }],

26+

}),

27+

...params,

28+

};

29+

}

30+1731

describe("image-generation provider registry", () => {

1832

beforeAll(async () => {

1933

({ getImageGenerationProvider, listImageGenerationProviders } =

2034

await import("./provider-registry.js"));

2135

});

22362337

beforeEach(() => {

24-

resolveRuntimePluginRegistryMock.mockReset();

25-

resolveRuntimePluginRegistryMock.mockReturnValue(undefined);

38+

resolvePluginCapabilityProvidersMock.mockReset();

39+

resolvePluginCapabilityProvidersMock.mockReturnValue([]);

2640

});

274128-

it("does not load plugins when listing without config", () => {

42+

it("delegates provider resolution to the capability provider boundary", () => {

2943

expect(listImageGenerationProviders()).toEqual([]);

30-

expect(resolveRuntimePluginRegistryMock).toHaveBeenCalledWith();

44+

expect(resolvePluginCapabilityProvidersMock).toHaveBeenCalledWith({

45+

key: "imageGenerationProviders",

46+

cfg: undefined,

47+

});

3148

});

32493350

it("uses active plugin providers without loading from disk", () => {

34-

const registry = createEmptyPluginRegistry();

35-

registry.imageGenerationProviders.push({

36-

pluginId: "custom-image",

37-

pluginName: "Custom Image",

38-

source: "test",

39-

provider: {

40-

id: "custom-image",

41-

label: "Custom Image",

42-

capabilities: {

43-

generate: {},

44-

edit: { enabled: false },

45-

},

46-

generateImage: async () => ({

47-

images: [{ buffer: Buffer.from("image"), mimeType: "image/png" }],

48-

}),

49-

},

50-

});

51-

resolveRuntimePluginRegistryMock.mockReturnValue(registry);

51+

resolvePluginCapabilityProvidersMock.mockReturnValue([createProvider({ id: "custom-image" })]);

52525353

const provider = getImageGenerationProvider("custom-image");

54545555

expect(provider?.id).toBe("custom-image");

56-

expect(resolveRuntimePluginRegistryMock).toHaveBeenCalledWith();

56+

expect(resolvePluginCapabilityProvidersMock).toHaveBeenCalledWith({

57+

key: "imageGenerationProviders",

58+

cfg: undefined,

59+

});

5760

});

58615962

it("ignores prototype-like provider ids and aliases", () => {

60-

const registry = createEmptyPluginRegistry();

61-

registry.imageGenerationProviders.push(

62-

{

63-

pluginId: "blocked-image",

64-

pluginName: "Blocked Image",

65-

source: "test",

66-

provider: {

67-

id: "__proto__",

68-

aliases: ["constructor", "prototype"],

69-

capabilities: {

70-

generate: {},

71-

edit: { enabled: false },

72-

},

73-

generateImage: async () => ({

74-

images: [{ buffer: Buffer.from("image"), mimeType: "image/png" }],

75-

}),

76-

},

77-

},

78-

{

79-

pluginId: "safe-image",

80-

pluginName: "Safe Image",

81-

source: "test",

82-

provider: {

83-

id: "safe-image",

84-

aliases: ["safe-alias", "constructor"],

85-

capabilities: {

86-

generate: {},

87-

edit: { enabled: false },

88-

},

89-

generateImage: async () => ({

90-

images: [{ buffer: Buffer.from("image"), mimeType: "image/png" }],

91-

}),

92-

},

93-

},

94-

);

95-

resolveRuntimePluginRegistryMock.mockReturnValue(registry);

63+

resolvePluginCapabilityProvidersMock.mockReturnValue([

64+

createProvider({ id: "__proto__", aliases: ["constructor", "prototype"] }),

65+

createProvider({ id: "safe-image", aliases: ["safe-alias", "constructor"] }),

66+

]);

96679768

expect(listImageGenerationProviders().map((provider) => provider.id)).toEqual(["safe-image"]);

9869

expect(getImageGenerationProvider("__proto__")).toBeUndefined();