refactor(plugins): make runtime registry lazy

This commit is contained in:
Vincent Koc 2026-03-24 11:04:03 -07:00
parent e16f0cf908
commit 6451beddb2
2 changed files with 10 additions and 4 deletions

View File

@ -1,6 +1,7 @@
import { afterEach, describe, expect, it } from "vitest";
import { createEmptyPluginRegistry } from "./registry.js";
import {
getActivePluginRegistry,
pinActivePluginHttpRouteRegistry,
releasePinnedPluginHttpRouteRegistry,
resetPluginRuntimeStateForTest,
@ -14,6 +15,12 @@ describe("plugin runtime route registry", () => {
resetPluginRuntimeStateForTest();
});
it("stays empty until a caller explicitly installs or requires a registry", () => {
resetPluginRuntimeStateForTest();
expect(getActivePluginRegistry()).toBeNull();
});
it("keeps the pinned route registry when the active plugin registry changes", () => {
const startupRegistry = createEmptyPluginRegistry();
const laterRegistry = createEmptyPluginRegistry();

View File

@ -17,7 +17,7 @@ const state: RegistryState = (() => {
};
if (!globalState[REGISTRY_STATE]) {
globalState[REGISTRY_STATE] = {
registry: createEmptyPluginRegistry(),
registry: null,
httpRouteRegistry: null,
httpRouteRegistryPinned: false,
key: null,
@ -100,9 +100,8 @@ export function getActivePluginRegistryVersion(): number {
}
export function resetPluginRuntimeStateForTest(): void {
const emptyRegistry = createEmptyPluginRegistry();
state.registry = emptyRegistry;
state.httpRouteRegistry = emptyRegistry;
state.registry = null;
state.httpRouteRegistry = null;
state.httpRouteRegistryPinned = false;
state.key = null;
state.version += 1;