fix(completion): offer unique hostnames without instance prefix

bash (and zsh without a matcher) only accept candidates that start with
the typed text, so "fsn1-bx1<Tab>" found nothing when every candidate
was qualified as "prod/…". Hostnames that exist in only one instance
are now offered bare; names present in several instances stay
qualified. Connecting to a bare name still checks every instance for
ambiguity, so the connection behavior is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Sebastian UnterschützandClaude Opus 5.5 committed 2026-10-28 11:44:54 +01:00
1 parent 6243514def
commit 091f5cc518
5 files changed
+80 -4

No files matched your search

+31
View File
@@ -8,6 +8,7 @@ import (
"os"
"os/exec"
"path/filepath"
"reflect"
"strings"
"testing"
"time"
@@ -206,3 +207,33 @@ func TestRefreshCachesIndependentDevicesAndVMs(t *testing.T) {
}
}
}
func TestHostCompletionsMatchTypedText(t *testing.T) {
entries := []cache.Entry{
{Name: "prod/fsn1-bx1.example.com"},
{Name: "prod/fsn1-bx2.example.com"},
{Name: "stg/fsn1-bx2.example.com"},
{Name: "stg/hel1-tb1.example.com"},
{Name: "prod/HEL1-TB2"},
}
for _, tc := range []struct {
input string
want []string
}{
// Unique names are bare; names in both instances stay qualified.
{"fsn1", []string{"fsn1-bx1.example.com", "prod/fsn1-bx2.example.com", "stg/fsn1-bx2.example.com"}},
{"hel1", []string{"HEL1-TB2", "hel1-tb1.example.com"}},
{"prod/", []string{"prod/HEL1-TB2", "prod/fsn1-bx1.example.com", "prod/fsn1-bx2.example.com"}},
{"stg/fsn", []string{"stg/fsn1-bx2.example.com"}},
// An instance name typed without the slash completes qualified targets.
{"st", []string{"stg/fsn1-bx2.example.com", "stg/hel1-tb1.example.com"}},
} {
if got := hostCompletions(entries, tc.input); !reflect.DeepEqual(got, tc.want) {
t.Errorf("%q: got %v, want %v", tc.input, got, tc.want)
}
}
// Single-instance caches are unchanged.
if got := hostCompletions([]cache.Entry{{Name: "web01"}, {Name: "db01"}}, "w"); !reflect.DeepEqual(got, []string{"web01"}) {
t.Errorf("single instance: %v", got)
}
}