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"]); + }); + }); });