From 4f7c2a3edcd158aa0397084838fe434b6e471ea0 Mon Sep 17 00:00:00 2001 From: Alejandro Florez Date: Wed, 30 Sep 2026 07:37:14 -0500 Subject: [PATCH 1/3] test(cli): reject extra send-key operands Signed-off-by: Alejandro Florez --- .../CLIExplicitSurfaceRoutingTests.swift | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/cmuxCLITests/CLIExplicitSurfaceRoutingTests.swift b/cmuxCLITests/CLIExplicitSurfaceRoutingTests.swift index dda1fbd188f1..ac6fa5bae265 100644 --- a/cmuxCLITests/CLIExplicitSurfaceRoutingTests.swift +++ b/cmuxCLITests/CLIExplicitSurfaceRoutingTests.swift @@ -43,6 +43,34 @@ struct CLIExplicitSurfaceRoutingTests { ) } + @Test func sendKeyCommandsRejectExtraArgumentsWithoutSocketRequest() throws { + let cases: [[String]] = [ + ["send-key", "--surface", Self.targetSurfaceRef, "ctrl+c", "enter"], + ["send-key-panel", "--panel", Self.targetSurfaceRef, "ctrl+c", "enter"], + ] + + for (index, arguments) in cases.enumerated() { + let execution = try runMockCommand( + arguments: arguments, + socketName: "key-arity-\(index)" + ) { line in + Self.malformedRequestResponse(raw: line) + } + + let requests = try execution.state.requestObjects() + #expect(requests.isEmpty, Comment(rawValue: String(describing: requests))) + #expect(!execution.result.timedOut, Comment(rawValue: execution.result.stderr)) + #expect( + execution.result.status != 0, + Comment(rawValue: execution.result.stderr + execution.result.stdout) + ) + #expect( + execution.result.stderr.contains("unexpected arguments"), + Comment(rawValue: execution.result.stderr) + ) + } + } + @Test func numericSurfaceHandleStillInheritsCallerWorkspaceForIndexResolution() throws { let socketPath = Self.makeSocketPath("numeric") let listenerFD = try Self.bindUnixSocket(at: socketPath) From 32d5c5a441ba2c1daabb1fda997887b237bebb25 Mon Sep 17 00:00:00 2001 From: Alejandro Florez Date: Wed, 30 Sep 2026 07:39:08 -0500 Subject: [PATCH 2/3] fix(cli): reject extra send-key operands Signed-off-by: Alejandro Florez --- CLI/cmux.swift | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CLI/cmux.swift b/CLI/cmux.swift index 10073fc6cc7d..46968ff15516 100644 --- a/CLI/cmux.swift +++ b/CLI/cmux.swift @@ -7662,6 +7662,10 @@ struct CMUXCLI { let surfaceArg = sfArg ?? (wsArg == nil && windowRaw == nil ? ProcessInfo.processInfo.environment["CMUX_SURFACE_ID"] : nil) let keyArgs = rem2.first == "--" ? Array(rem2.dropFirst()) : rem2 guard let key = keyArgs.first else { throw CLIError(message: "send-key requires a key") } + if keyArgs.count > 1 { + let trailing = keyArgs.dropFirst().joined(separator: " ") + throw CLIError(message: "send-key: unexpected arguments: \(trailing)") + } var params: [String: Any] = ["key": key] let winId = try normalizeWindowHandle(windowRaw, client: client) if let winId { params["window_id"] = winId } @@ -7706,6 +7710,10 @@ struct CMUXCLI { let skpArgs = rem2.first == "--" ? Array(rem2.dropFirst()) : rem2 let key = skpArgs.first ?? "" guard !key.isEmpty else { throw CLIError(message: "send-key-panel requires a key") } + if skpArgs.count > 1 { + let trailing = skpArgs.dropFirst().joined(separator: " ") + throw CLIError(message: "send-key-panel: unexpected arguments: \(trailing)") + } var params: [String: Any] = ["key": key] let winId = try normalizeWindowHandle(windowRaw, client: client) if let winId { params["window_id"] = winId } From 59566ffb632858e22827e89a1add205bc209340d Mon Sep 17 00:00:00 2001 From: Alejandro Florez Date: Wed, 30 Sep 2026 08:15:11 -0500 Subject: [PATCH 3/3] fix(cli): localize unexpected send-key arguments Signed-off-by: Alejandro Florez --- CLI/cmux.swift | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/CLI/cmux.swift b/CLI/cmux.swift index 46968ff15516..4441706781b4 100644 --- a/CLI/cmux.swift +++ b/CLI/cmux.swift @@ -7664,7 +7664,14 @@ struct CMUXCLI { guard let key = keyArgs.first else { throw CLIError(message: "send-key requires a key") } if keyArgs.count > 1 { let trailing = keyArgs.dropFirst().joined(separator: " ") - throw CLIError(message: "send-key: unexpected arguments: \(trailing)") + throw CLIError(message: String( + format: String( + localized: "cli.readSelection.error.unexpectedArguments", + defaultValue: "%@: unexpected arguments: %@" + ), + "send-key", + trailing + )) } var params: [String: Any] = ["key": key] let winId = try normalizeWindowHandle(windowRaw, client: client) @@ -7712,7 +7719,14 @@ struct CMUXCLI { guard !key.isEmpty else { throw CLIError(message: "send-key-panel requires a key") } if skpArgs.count > 1 { let trailing = skpArgs.dropFirst().joined(separator: " ") - throw CLIError(message: "send-key-panel: unexpected arguments: \(trailing)") + throw CLIError(message: String( + format: String( + localized: "cli.readSelection.error.unexpectedArguments", + defaultValue: "%@: unexpected arguments: %@" + ), + "send-key-panel", + trailing + )) } var params: [String: Any] = ["key": key] let winId = try normalizeWindowHandle(windowRaw, client: client)