Skip to content

Commit e307781

Browse files
committed
test(plugins): observe active registry reuse at the boundary tools.ts crosses
Four `resolvePluginTools` tests failed on `main`: the compatible-registry mock was never called. #133518 moved `resolveCompatibleRuntimePluginRegistry` out of `loader-runtime-registry.ts` into `active-runtime-registry.ts` so active-registry reads stop pulling in the loader eagerly. `tools.ts` calls `getLoadedRuntimePluginRegistry`, which now reaches that function intra-module, so the file's `vi.mock("./loader.js")` seam stopped observing it. Behavior was never affected: the tool names resolve and no cold load happens, because the real implementation moved verbatim. Only the observation point was stale, so count the call at the boundary `tools.ts` actually crosses and keep delegating to the real implementation. Verified against d3e058c^ (87/87 pass) and d3e058c (4 fail), and the probe that proves the old `./loader.js` seam now takes zero calls in this file.
1 parent 0f091ea commit e307781

1 file changed

Lines changed: 22 additions & 4 deletions

File tree

‎src/plugins/tools.optional.test.ts‎

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ type MockRegistryToolEntry = {
2222

2323
const loadOpenClawPluginsMock = vi.fn();
2424
const resolveCompatibleRuntimePluginRegistryMock = vi.fn();
25+
const getLoadedRuntimePluginRegistryMock = vi.fn();
2526
const applyPluginAutoEnableMock = vi.fn();
2627
const loadContextMocks = vi.hoisted(() => ({
2728
actualResolve: undefined as
@@ -40,6 +41,22 @@ vi.mock("./loader.js", () => ({
4041
resolveCompatibleRuntimePluginRegistryMock(params),
4142
}));
4243

44+
// resolveCompatibleRuntimePluginRegistry now lives in this module, so the
45+
// ./loader.js seam no longer observes the intra-module call that tool resolution
46+
// triggers. Count the boundary tools.ts actually crosses, keeping real behavior.
47+
vi.mock("./active-runtime-registry.js", async (importOriginal) => {
48+
const actual = await importOriginal<typeof import("./active-runtime-registry.js")>();
49+
return {
50+
...actual,
51+
getLoadedRuntimePluginRegistry: (
52+
params?: Parameters<typeof actual.getLoadedRuntimePluginRegistry>[0],
53+
) => {
54+
getLoadedRuntimePluginRegistryMock(params);
55+
return actual.getLoadedRuntimePluginRegistry(params);
56+
},
57+
};
58+
});
59+
4360
vi.mock("../config/plugin-auto-enable.js", () => ({
4461
applyPluginAutoEnable: (params: unknown) => applyPluginAutoEnableMock(params),
4562
}));
@@ -555,6 +572,7 @@ describe("resolvePluginTools optional tools", () => {
555572

556573
beforeEach(() => {
557574
loadOpenClawPluginsMock.mockReset();
575+
getLoadedRuntimePluginRegistryMock.mockReset();
558576
resolveCompatibleRuntimePluginRegistryMock.mockReset();
559577
resolveCompatibleRuntimePluginRegistryMock.mockImplementation(() =>
560578
getActivePluginRegistry?.(),
@@ -3093,7 +3111,7 @@ describe("resolvePluginTools optional tools", () => {
30933111
);
30943112

30953113
expectResolvedToolNames(tools, ["optional_tool"]);
3096-
expect(resolveCompatibleRuntimePluginRegistryMock).toHaveBeenCalledOnce();
3114+
expect(getLoadedRuntimePluginRegistryMock).toHaveBeenCalledOnce();
30973115
expect(loadOpenClawPluginsMock).not.toHaveBeenCalled();
30983116
});
30993117

@@ -3133,7 +3151,7 @@ describe("resolvePluginTools optional tools", () => {
31333151

31343152
expectResolvedToolNames(tools, ["optional_tool"]);
31353153
expect(heavyFactory).not.toHaveBeenCalled();
3136-
expect(resolveCompatibleRuntimePluginRegistryMock).toHaveBeenCalledOnce();
3154+
expect(getLoadedRuntimePluginRegistryMock).toHaveBeenCalledOnce();
31373155
expect(loadOpenClawPluginsMock).not.toHaveBeenCalled();
31383156
});
31393157

@@ -3193,7 +3211,7 @@ describe("resolvePluginTools optional tools", () => {
31933211

31943212
expectResolvedToolNames(tools, ["memory_search", "memory_get"]);
31953213
expect(memorySearchFactory).toHaveBeenCalledTimes(1);
3196-
expect(resolveCompatibleRuntimePluginRegistryMock).toHaveBeenCalledOnce();
3214+
expect(getLoadedRuntimePluginRegistryMock).toHaveBeenCalledOnce();
31973215
expect(loadOpenClawPluginsMock).not.toHaveBeenCalled();
31983216
});
31993217

@@ -3309,7 +3327,7 @@ describe("resolvePluginTools optional tools", () => {
33093327
toolAllowlist: ["*", "tavily"],
33103328
allowGatewaySubagentBinding: true,
33113329
});
3312-
expect(resolveCompatibleRuntimePluginRegistryMock).toHaveBeenCalledOnce();
3330+
expect(getLoadedRuntimePluginRegistryMock).toHaveBeenCalledOnce();
33133331
const loaderParams = mockCallParams(loadOpenClawPluginsMock) as {
33143332
onlyPluginIds?: string[];
33153333
toolDiscovery?: unknown;

0 commit comments

Comments
 (0)