mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-19 04:14:47 +00:00
test: tighten web provider runtime assertions
This commit is contained in:
@@ -47,6 +47,17 @@ vi.mock("./runtime/load-context.js", () => ({
|
||||
let resolvePluginWebProviders: typeof import("./web-provider-runtime-shared.js").resolvePluginWebProviders;
|
||||
let resolveRuntimeWebProviders: typeof import("./web-provider-runtime-shared.js").resolveRuntimeWebProviders;
|
||||
|
||||
function requireRecord(value: unknown): Record<string, unknown> {
|
||||
expect(value).toBeTruthy();
|
||||
expect(typeof value).toBe("object");
|
||||
expect(Array.isArray(value)).toBe(false);
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
|
||||
function mockArg(mock: ReturnType<typeof vi.fn>, callIndex = 0): Record<string, unknown> {
|
||||
return requireRecord(mock.mock.calls[callIndex]?.[0]);
|
||||
}
|
||||
|
||||
describe("web-provider-runtime-shared", () => {
|
||||
beforeAll(async () => {
|
||||
({ resolvePluginWebProviders, resolveRuntimeWebProviders } =
|
||||
@@ -97,16 +108,8 @@ describe("web-provider-runtime-shared", () => {
|
||||
},
|
||||
);
|
||||
|
||||
expect(mocks.getLoadedRuntimePluginRegistry).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
requiredPluginIds: [],
|
||||
}),
|
||||
);
|
||||
expect(mapRegistryProviders).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
onlyPluginIds: [],
|
||||
}),
|
||||
);
|
||||
expect(mockArg(mocks.getLoadedRuntimePluginRegistry).requiredPluginIds).toEqual([]);
|
||||
expect(mockArg(mapRegistryProviders).onlyPluginIds).toEqual([]);
|
||||
});
|
||||
|
||||
it("preserves explicit empty scopes in direct runtime web provider resolution", () => {
|
||||
@@ -129,16 +132,8 @@ describe("web-provider-runtime-shared", () => {
|
||||
},
|
||||
);
|
||||
|
||||
expect(mocks.getLoadedRuntimePluginRegistry).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
requiredPluginIds: [],
|
||||
}),
|
||||
);
|
||||
expect(mapRegistryProviders).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
onlyPluginIds: [],
|
||||
}),
|
||||
);
|
||||
expect(mockArg(mocks.getLoadedRuntimePluginRegistry).requiredPluginIds).toEqual([]);
|
||||
expect(mockArg(mapRegistryProviders).onlyPluginIds).toEqual([]);
|
||||
});
|
||||
|
||||
it("preserves explicit scopes when config is omitted in direct runtime resolution", () => {
|
||||
@@ -160,16 +155,8 @@ describe("web-provider-runtime-shared", () => {
|
||||
},
|
||||
);
|
||||
|
||||
expect(mocks.getLoadedRuntimePluginRegistry).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
requiredPluginIds: ["alpha"],
|
||||
}),
|
||||
);
|
||||
expect(mapRegistryProviders).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
onlyPluginIds: ["alpha"],
|
||||
}),
|
||||
);
|
||||
expect(mockArg(mocks.getLoadedRuntimePluginRegistry).requiredPluginIds).toEqual(["alpha"]);
|
||||
expect(mockArg(mapRegistryProviders).onlyPluginIds).toEqual(["alpha"]);
|
||||
});
|
||||
|
||||
it("reuses the active registry after deriving web provider candidates from resolved config", () => {
|
||||
@@ -263,11 +250,7 @@ describe("web-provider-runtime-shared", () => {
|
||||
);
|
||||
|
||||
expect(providers).toEqual(["provider"]);
|
||||
expect(mocks.getLoadedRuntimePluginRegistry).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
requiredPluginIds: ["brave"],
|
||||
}),
|
||||
);
|
||||
expect(mockArg(mocks.getLoadedRuntimePluginRegistry).requiredPluginIds).toEqual(["brave"]);
|
||||
expect(mocks.loadOpenClawPlugins).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
@@ -293,11 +276,7 @@ describe("web-provider-runtime-shared", () => {
|
||||
},
|
||||
);
|
||||
|
||||
expect(mocks.getLoadedRuntimePluginRegistry).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
requiredPluginIds: ["brave"],
|
||||
}),
|
||||
);
|
||||
expect(mockArg(mocks.getLoadedRuntimePluginRegistry).requiredPluginIds).toEqual(["brave"]);
|
||||
expect(mocks.loadOpenClawPlugins).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
@@ -324,12 +303,8 @@ describe("web-provider-runtime-shared", () => {
|
||||
);
|
||||
|
||||
expect(providers).toEqual(["provider"]);
|
||||
expect(mocks.loadOpenClawPlugins).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
cache: true,
|
||||
onlyPluginIds: ["brave"],
|
||||
}),
|
||||
);
|
||||
expect(mockArg(mocks.loadOpenClawPlugins).cache).toBe(true);
|
||||
expect(mockArg(mocks.loadOpenClawPlugins).onlyPluginIds).toEqual(["brave"]);
|
||||
});
|
||||
|
||||
it("falls back to a scoped provider load when the active runtime registry has no web providers", () => {
|
||||
@@ -469,11 +444,7 @@ describe("web-provider-runtime-shared", () => {
|
||||
},
|
||||
);
|
||||
|
||||
expect(mocks.loadOpenClawPlugins).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
cache: false,
|
||||
onlyPluginIds: ["brave"],
|
||||
}),
|
||||
);
|
||||
expect(mockArg(mocks.loadOpenClawPlugins).cache).toBe(false);
|
||||
expect(mockArg(mocks.loadOpenClawPlugins).onlyPluginIds).toEqual(["brave"]);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user