From c149de7750cf9b8139b14c302db4c2f238755b61 Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Sat, 25 Apr 2026 19:45:54 -0700 Subject: [PATCH] fix(plugins): resolve runtime metadata fallbacks cold --- .../manifest-command-aliases.runtime.ts | 22 ++++++++++---- src/plugins/synthetic-auth.runtime.test.ts | 30 ++++++++++++++----- src/plugins/synthetic-auth.runtime.ts | 11 ++++--- 3 files changed, 46 insertions(+), 17 deletions(-) diff --git a/src/plugins/manifest-command-aliases.runtime.ts b/src/plugins/manifest-command-aliases.runtime.ts index a06ca9e8639..23f975fb092 100644 --- a/src/plugins/manifest-command-aliases.runtime.ts +++ b/src/plugins/manifest-command-aliases.runtime.ts @@ -4,7 +4,8 @@ import { type PluginManifestCommandAliasRegistry, type PluginManifestCommandAliasRecord, } from "./manifest-command-aliases.js"; -import { loadPluginManifestRegistry } from "./manifest-registry.js"; +import { loadPluginManifestRegistryForInstalledIndex } from "./manifest-registry-installed.js"; +import { loadPluginRegistrySnapshot } from "./plugin-registry.js"; export function resolveManifestCommandAliasOwner(params: { command: string | undefined; @@ -15,11 +16,20 @@ export function resolveManifestCommandAliasOwner(params: { }): PluginManifestCommandAliasRecord | undefined { const registry = params.registry ?? - loadPluginManifestRegistry({ - config: params.config, - workspaceDir: params.workspaceDir, - env: params.env, - }); + (() => { + const index = loadPluginRegistrySnapshot({ + config: params.config, + workspaceDir: params.workspaceDir, + env: params.env, + }); + return loadPluginManifestRegistryForInstalledIndex({ + index, + config: params.config, + workspaceDir: params.workspaceDir, + env: params.env, + includeDisabled: true, + }); + })(); return resolveManifestCommandAliasOwnerInRegistry({ command: params.command, registry, diff --git a/src/plugins/synthetic-auth.runtime.test.ts b/src/plugins/synthetic-auth.runtime.test.ts index cd3bf8a16f1..f55f24bc6e5 100644 --- a/src/plugins/synthetic-auth.runtime.test.ts +++ b/src/plugins/synthetic-auth.runtime.test.ts @@ -1,14 +1,22 @@ import { beforeEach, describe, expect, it, vi } from "vitest"; const getPluginRegistryState = vi.hoisted(() => vi.fn()); -const loadPluginManifestRegistry = vi.hoisted(() => vi.fn()); +const pluginRegistryMocks = vi.hoisted(() => ({ + loadPluginManifestRegistryForInstalledIndex: vi.fn(), + loadPluginRegistrySnapshot: vi.fn(() => ({ plugins: [] })), +})); vi.mock("./runtime-state.js", () => ({ getPluginRegistryState, })); -vi.mock("./manifest-registry.js", () => ({ - loadPluginManifestRegistry, +vi.mock("./manifest-registry-installed.js", () => ({ + loadPluginManifestRegistryForInstalledIndex: + pluginRegistryMocks.loadPluginManifestRegistryForInstalledIndex, +})); + +vi.mock("./plugin-registry.js", () => ({ + loadPluginRegistrySnapshot: pluginRegistryMocks.loadPluginRegistrySnapshot, })); import { resolveRuntimeSyntheticAuthProviderRefs } from "./synthetic-auth.runtime.js"; @@ -16,11 +24,14 @@ import { resolveRuntimeSyntheticAuthProviderRefs } from "./synthetic-auth.runtim describe("synthetic auth runtime refs", () => { beforeEach(() => { getPluginRegistryState.mockReset(); - loadPluginManifestRegistry.mockReset().mockReturnValue({ plugins: [] }); + pluginRegistryMocks.loadPluginManifestRegistryForInstalledIndex + .mockReset() + .mockReturnValue({ plugins: [] }); + pluginRegistryMocks.loadPluginRegistrySnapshot.mockReset().mockReturnValue({ plugins: [] }); }); it("uses manifest-owned synthetic auth refs before the runtime registry exists", () => { - loadPluginManifestRegistry.mockReturnValue({ + pluginRegistryMocks.loadPluginManifestRegistryForInstalledIndex.mockReturnValue({ plugins: [ { syntheticAuthRefs: [" local-provider ", "local-provider", "local-cli"] }, { syntheticAuthRefs: ["remote-provider"] }, @@ -33,7 +44,11 @@ describe("synthetic auth runtime refs", () => { "local-cli", "remote-provider", ]); - expect(loadPluginManifestRegistry).toHaveBeenCalledWith({ cache: true }); + expect(pluginRegistryMocks.loadPluginRegistrySnapshot).toHaveBeenCalledWith({ cache: true }); + expect(pluginRegistryMocks.loadPluginManifestRegistryForInstalledIndex).toHaveBeenCalledWith({ + index: expect.anything(), + includeDisabled: true, + }); }); it("prefers the active runtime registry when plugins are already loaded", () => { @@ -64,6 +79,7 @@ describe("synthetic auth runtime refs", () => { }); expect(resolveRuntimeSyntheticAuthProviderRefs()).toEqual(["runtime-provider", "runtime-cli"]); - expect(loadPluginManifestRegistry).not.toHaveBeenCalled(); + expect(pluginRegistryMocks.loadPluginManifestRegistryForInstalledIndex).not.toHaveBeenCalled(); + expect(pluginRegistryMocks.loadPluginRegistrySnapshot).not.toHaveBeenCalled(); }); }); diff --git a/src/plugins/synthetic-auth.runtime.ts b/src/plugins/synthetic-auth.runtime.ts index cbc563e8c98..f1265489cca 100644 --- a/src/plugins/synthetic-auth.runtime.ts +++ b/src/plugins/synthetic-auth.runtime.ts @@ -1,5 +1,6 @@ import { normalizeProviderId } from "../agents/provider-id.js"; -import { loadPluginManifestRegistry } from "./manifest-registry.js"; +import { loadPluginManifestRegistryForInstalledIndex } from "./manifest-registry-installed.js"; +import { loadPluginRegistrySnapshot } from "./plugin-registry.js"; import { getPluginRegistryState } from "./runtime-state.js"; function uniqueProviderRefs(values: readonly string[]): string[] { @@ -18,10 +19,12 @@ function uniqueProviderRefs(values: readonly string[]): string[] { } function resolveManifestSyntheticAuthProviderRefs(): string[] { + const index = loadPluginRegistrySnapshot({ cache: true }); return uniqueProviderRefs( - loadPluginManifestRegistry({ cache: true }).plugins.flatMap( - (plugin) => plugin.syntheticAuthRefs ?? [], - ), + loadPluginManifestRegistryForInstalledIndex({ + index, + includeDisabled: true, + }).plugins.flatMap((plugin) => plugin.syntheticAuthRefs ?? []), ); }