From 680c0f77cb35e322c772cd5b7c237249bc86d91e Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Wed, 8 Apr 2026 08:49:26 +0100 Subject: [PATCH] perf(config): trim web search config helper imports --- src/config/plugin-web-search-config.test.ts | 44 +++++++++++++++++++++ src/config/plugin-web-search-config.ts | 6 ++- 2 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 src/config/plugin-web-search-config.test.ts diff --git a/src/config/plugin-web-search-config.test.ts b/src/config/plugin-web-search-config.test.ts new file mode 100644 index 00000000000..fd2c83bddc4 --- /dev/null +++ b/src/config/plugin-web-search-config.test.ts @@ -0,0 +1,44 @@ +import { describe, expect, it } from "vitest"; +import { resolvePluginWebSearchConfig } from "./plugin-web-search-config.js"; + +describe("resolvePluginWebSearchConfig", () => { + it("returns the nested plugin webSearch object when present", () => { + expect( + resolvePluginWebSearchConfig( + { + plugins: { + entries: { + brave: { + config: { + webSearch: { + apiKey: "brave-key", + }, + }, + }, + }, + }, + }, + "brave", + ), + ).toEqual({ + apiKey: "brave-key", + }); + }); + + it("ignores non-record plugin config values", () => { + expect( + resolvePluginWebSearchConfig( + { + plugins: { + entries: { + brave: { + config: "nope", + }, + }, + }, + }, + "brave", + ), + ).toBeUndefined(); + }); +}); diff --git a/src/config/plugin-web-search-config.ts b/src/config/plugin-web-search-config.ts index 089d59a1320..85cf76211d5 100644 --- a/src/config/plugin-web-search-config.ts +++ b/src/config/plugin-web-search-config.ts @@ -1,5 +1,3 @@ -import { isRecord } from "../utils.js"; - type PluginWebSearchConfigCarrier = { plugins?: { entries?: Record< @@ -11,6 +9,10 @@ type PluginWebSearchConfigCarrier = { }; }; +function isRecord(value: unknown): value is Record { + return typeof value === "object" && value !== null && !Array.isArray(value); +} + export function resolvePluginWebSearchConfig( config: PluginWebSearchConfigCarrier | undefined, pluginId: string,