Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CLI/cmux.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)")
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
}
var params: [String: Any] = ["key": key]
let winId = try normalizeWindowHandle(windowRaw, client: client)
if let winId { params["window_id"] = winId }
Expand Down Expand Up @@ -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 }
Expand Down
28 changes: 28 additions & 0 deletions cmuxCLITests/CLIExplicitSurfaceRoutingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading