From 50df6f0d3eb00d29d3051c10eeebd0b25d3f043d Mon Sep 17 00:00:00 2001 From: YeonGyu-Kim Date: Sat, 11 Apr 2026 23:36:35 +0900 Subject: [PATCH] test(claude-code-plugin-loader): cover plugin path nullish resolution Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus --- .../plugin-path-resolver.test.ts | 55 +++++++++++++++++++ .../plugin-path-resolver.ts | 2 +- 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 src/features/claude-code-plugin-loader/plugin-path-resolver.test.ts diff --git a/src/features/claude-code-plugin-loader/plugin-path-resolver.test.ts b/src/features/claude-code-plugin-loader/plugin-path-resolver.test.ts new file mode 100644 index 000000000..3461b1f01 --- /dev/null +++ b/src/features/claude-code-plugin-loader/plugin-path-resolver.test.ts @@ -0,0 +1,55 @@ +import { describe, expect, test } from "bun:test" + +import { resolvePluginPath, resolvePluginPaths } from "./plugin-path-resolver" + +describe("resolvePluginPath", () => { + test("#given a plugin root placeholder #when resolving the path #then it replaces the placeholder", () => { + // given + const path = "${CLAUDE_PLUGIN_ROOT}/dist/index.js" + + // when + const result = resolvePluginPath(path, "/tmp/plugin-root") + + // then + expect(result).toBe("/tmp/plugin-root/dist/index.js") + }) +}) + +describe("resolvePluginPaths", () => { + test("#given a nested object #when resolving paths #then it rewrites every nested string path", () => { + // given + const value = { + command: "node", + args: ["${CLAUDE_PLUGIN_ROOT}/server.js"], + nested: { + config: "${CLAUDE_PLUGIN_ROOT}/config.json", + }, + } + + // when + const result = resolvePluginPaths(value, "/tmp/plugin-root") + + // then + expect(result).toEqual({ + command: "node", + args: ["/tmp/plugin-root/server.js"], + nested: { + config: "/tmp/plugin-root/config.json", + }, + }) + }) + + test("#given nullish input #when resolving paths #then it returns the same nullish value", () => { + // given + const nullValue = null + const undefinedValue = undefined + + // when + const nullResult = resolvePluginPaths(nullValue, "/tmp/plugin-root") + const undefinedResult = resolvePluginPaths(undefinedValue, "/tmp/plugin-root") + + // then + expect(nullResult).toBeNull() + expect(undefinedResult).toBeUndefined() + }) +}) diff --git a/src/features/claude-code-plugin-loader/plugin-path-resolver.ts b/src/features/claude-code-plugin-loader/plugin-path-resolver.ts index c8806aa58..0027d8fe9 100644 --- a/src/features/claude-code-plugin-loader/plugin-path-resolver.ts +++ b/src/features/claude-code-plugin-loader/plugin-path-resolver.ts @@ -5,7 +5,7 @@ export function resolvePluginPath(path: string, pluginRoot: string): string { } export function resolvePluginPaths(obj: T, pluginRoot: string): T { - if (obj === null || obj === undefined) return obj + if (obj == null) return obj if (typeof obj === "string") { return resolvePluginPath(obj, pluginRoot) as T }