mirror of
https://github.com/moltbot/moltbot.git
synced 2026-04-21 05:32:53 +00:00
test: harden runtime schema activation regression
This commit is contained in:
@@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user