From ff94d3d5ab3c190940538d095c4787738a0ad95f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Manso?= Date: Sat, 8 Aug 2026 19:33:19 +0100 Subject: [PATCH] fix(agentctl): accept the Windows executable suffix in the ACP probe allow-list (#2422) --- .../agentctl/server/utility/acp_executor.go | 23 ++++++++++- .../server/utility/acp_executor_test.go | 40 +++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/apps/backend/internal/agentctl/server/utility/acp_executor.go b/apps/backend/internal/agentctl/server/utility/acp_executor.go index 6e3a9878d7..6dd9f77c3d 100644 --- a/apps/backend/internal/agentctl/server/utility/acp_executor.go +++ b/apps/backend/internal/agentctl/server/utility/acp_executor.go @@ -11,6 +11,7 @@ import ( "os/exec" "path/filepath" "regexp" + "runtime" "sort" "strings" "sync" @@ -1161,8 +1162,28 @@ var allowedProbeCommands = map[string]string{ // resolveProbeCommand validates and returns a hard-coded executable name for // the given command. Returns the empty string if the command is not allowed. +// +// An agent launched from an absolute path arrives here carrying the executable +// suffix Windows requires — "mock-agent.exe" — which never matches the bare +// allow-list key, so its probe is refused before it can spawn. +// +// Only ".exe" is trimmed, and only on Windows. That is the suffix the Go build +// emits, so it is the only one an allow-listed binary can arrive with; trimming +// whatever filepath.Ext returns would instead let "mock-agent.cmd" or +// "mock-agent.txt" reach an allow-listed entry. Unix executables carry no such +// convention at all, and trimming there would let "opencode.sh" pass as +// "opencode". func resolveProbeCommand(name string) string { - return allowedProbeCommands[filepath.Base(name)] + base := filepath.Base(name) + if resolved, ok := allowedProbeCommands[base]; ok { + return resolved + } + if runtime.GOOS == "windows" { + if ext := filepath.Ext(base); strings.EqualFold(ext, ".exe") { + return allowedProbeCommands[strings.TrimSuffix(base, ext)] + } + } + return "" } // stderrTailLimit bounds how much of a spawned agent's stderr reaches the log: diff --git a/apps/backend/internal/agentctl/server/utility/acp_executor_test.go b/apps/backend/internal/agentctl/server/utility/acp_executor_test.go index 715f847646..0775b01fed 100644 --- a/apps/backend/internal/agentctl/server/utility/acp_executor_test.go +++ b/apps/backend/internal/agentctl/server/utility/acp_executor_test.go @@ -6,6 +6,7 @@ import ( "errors" "maps" "path/filepath" + "runtime" "slices" "strings" "testing" @@ -213,6 +214,45 @@ func TestResolveProbeCommand_RejectsUnknown(t *testing.T) { } } +// The mock agent is the one allow-listed command launched from an absolute +// path, so on Windows it reaches this lookup as "mock-agent.exe". The coverage +// above builds Unix-style paths, whose base name never carries an executable +// suffix, which is why the gap passed on every runner including Windows. +func TestResolveProbeCommand_ExecutableSuffix(t *testing.T) { + t.Parallel() + + const name = "mock-agent" + dir := t.TempDir() + + for _, tc := range []struct { + file string + wantWindows string + }{ + {file: name + ".exe", wantWindows: name}, + {file: name + ".EXE", wantWindows: name}, + {file: name + ".cmd", wantWindows: ""}, + {file: name + ".txt", wantWindows: ""}, + {file: name + ".exe.txt", wantWindows: ""}, + } { + t.Run(tc.file, func(t *testing.T) { + t.Parallel() + + path := filepath.Join(dir, tc.file) + got := resolveProbeCommand(path) + + // Only Windows trims, and only ".exe" — any other suffix, and any + // suffix at all on Unix, leaves the name unmatched. + want := "" + if runtime.GOOS == "windows" { + want = tc.wantWindows + } + if got != want { + t.Fatalf("resolveProbeCommand(%q) = %q, want %q", path, got, want) + } + }) + } +} + // TestIsOpenCodeACPCommand verifies that the fallback only applies to // OpenCode's ACP transport command. func TestIsOpenCodeACPCommand(t *testing.T) {