fix(agentctl): accept the Windows executable suffix in the ACP probe allow-list (#2422)

This commit is contained in:
João Manso
2026-08-08 19:33:19 +01:00
committed by GitHub
parent 7133b132f6
commit ff94d3d5ab
2 changed files with 62 additions and 1 deletions
@@ -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:
@@ -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) {