From 34dac65d2aaf9483358397b8a3469e4fb5ddf12b Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sun, 8 Jun 2025 08:33:44 +0100 Subject: [PATCH] fix: Handle empty string item_type parameter in list tool MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes issue where item_type: '' was not properly defaulting to the correct operation. Empty strings and whitespace-only strings now fall back to the proper default logic: - If app is provided: defaults to 'application_windows' - If no app: defaults to 'running_applications' 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- src/tools/list.ts | 4 ++-- tests/unit/tools/list.test.ts | 36 +++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/tools/list.ts b/src/tools/list.ts index eb26422..a8dcbe5 100644 --- a/src/tools/list.ts +++ b/src/tools/list.ts @@ -192,7 +192,7 @@ export async function listToolHandler( } // Process the response based on item type - const effective_item_type = input.item_type || (input.app ? "application_windows" : "running_applications"); + const effective_item_type = (input.item_type && input.item_type.trim() !== "") ? input.item_type : (input.app ? "application_windows" : "running_applications"); if (effective_item_type === "running_applications") { return handleApplicationsList( @@ -387,7 +387,7 @@ async function handleServerStatus( export function buildSwiftCliArgs(input: ListToolInput): string[] { const args = ["list"]; - const itemType = input.item_type || (input.app ? "application_windows" : "running_applications"); + const itemType = (input.item_type && input.item_type.trim() !== "") ? input.item_type : (input.app ? "application_windows" : "running_applications"); if (itemType === "running_applications") { args.push("apps"); diff --git a/tests/unit/tools/list.test.ts b/tests/unit/tools/list.test.ts index 3dfadef..3fa1711 100644 --- a/tests/unit/tools/list.test.ts +++ b/tests/unit/tools/list.test.ts @@ -983,4 +983,40 @@ describe("List Tool", () => { expect(() => listToolSchema.parse(input)).toThrow(); }); }); + + describe("buildSwiftCliArgs empty string handling", () => { + it("should treat empty string item_type as undefined and default correctly", () => { + // Test case where item_type is empty string (should default to running_applications) + const inputWithEmptyString: ListToolInput = { + item_type: "", + include_window_details: [], + }; + + const args = buildSwiftCliArgs(inputWithEmptyString); + expect(args).toEqual(["list", "apps"]); + }); + + it("should treat empty string item_type with app as application_windows", () => { + // Test case where item_type is empty string but app is provided + const inputWithEmptyStringAndApp: ListToolInput = { + item_type: "", + app: "Safari", + include_window_details: [], + }; + + const args = buildSwiftCliArgs(inputWithEmptyStringAndApp); + expect(args).toEqual(["list", "windows", "--app", "Safari"]); + }); + + it("should treat whitespace-only item_type as undefined", () => { + // Test case where item_type is just whitespace + const inputWithWhitespace: ListToolInput = { + item_type: " ", + include_window_details: [], + }; + + const args = buildSwiftCliArgs(inputWithWhitespace); + expect(args).toEqual(["list", "apps"]); + }); + }); });