test: harden runtime schema activation regression

This commit is contained in:
Altay
2026-04-09 09:42:05 +01:00
parent a7b322c38a
commit dd1ed1d519

View File

@@ -1,4 +1,12 @@
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
import { createEmptyPluginRegistry } from "../plugins/registry-empty.js";
import {
getActivePluginRegistry,
getActivePluginRegistryKey,
getActivePluginRegistryVersion,
resetPluginRuntimeStateForTest,
setActivePluginRegistry,
} from "../plugins/runtime.js";
import type { ConfigFileSnapshot, OpenClawConfig } from "./types.js";
const mockLoadConfig = vi.hoisted(() => vi.fn<() => OpenClawConfig>());
@@ -144,6 +152,10 @@ beforeAll(async () => {
await import("./runtime-schema.js"));
});
afterEach(() => {
resetPluginRuntimeStateForTest();
});
describe("readBestEffortRuntimeConfigSchema", () => {
beforeEach(() => {
vi.clearAllMocks();
@@ -212,13 +224,16 @@ describe("loadGatewayRuntimeConfigSchema", () => {
expect(channelProps?.matrix).toBeTruthy();
});
it('calls loadPluginManifestRegistry with cache:false on every invocation (regression guard for #54816)', async () => {
it("does not activate or replace the active plugin registry across repeated schema loads (regression guard for #54816)", () => {
// Each MCP connection triggers a config.schema / config.get gateway request which calls
// loadGatewayRuntimeConfigSchema. The original bug caused a fresh full plugin registry to
// be activated on every call, re-running registerFull for all channel plugins including
// Feishu. Verify that repeated calls always pass cache:false so the manifest registry
// path is used and no activation state accumulates between calls.
const { loadGatewayRuntimeConfigSchema } = await import('./runtime-schema.js');
// Feishu. Verify that repeated calls keep using manifest metadata without replacing the
// already-active runtime registry or mutating its activation version.
const activeRegistry = createEmptyPluginRegistry();
setActivePluginRegistry(activeRegistry, "startup-registry");
const versionBefore = getActivePluginRegistryVersion();
loadGatewayRuntimeConfigSchema();
loadGatewayRuntimeConfigSchema();
loadGatewayRuntimeConfigSchema();
@@ -227,5 +242,8 @@ describe("loadGatewayRuntimeConfigSchema", () => {
for (const call of mockLoadPluginManifestRegistry.mock.calls) {
expect(call[0]).toMatchObject({ cache: false });
}
expect(getActivePluginRegistry()).toBe(activeRegistry);
expect(getActivePluginRegistryKey()).toBe("startup-registry");
expect(getActivePluginRegistryVersion()).toBe(versionBefore);
});
});