From 209ef8da83019d274d2b3260ca2f18fbbf67ceaa Mon Sep 17 00:00:00 2001 From: "Claude (noether)" Date: Thu, 23 Jul 2026 11:20:19 +0200 Subject: [PATCH] =?UTF-8?q?sic=20v2=20client=20WP4:=20parseTarget=20?= =?UTF-8?q?=E2=80=94=20split=20host/hop1/hop2=20into=20host=20+=20ordered?= =?UTF-8?q?=20hops?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/sic/addr.go | 30 ++++++++++++++++++++++++++++++ cmd/sic/parsetarget_test.go | 27 +++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 cmd/sic/addr.go create mode 100644 cmd/sic/parsetarget_test.go diff --git a/cmd/sic/addr.go b/cmd/sic/addr.go new file mode 100644 index 0000000..0336be1 --- /dev/null +++ b/cmd/sic/addr.go @@ -0,0 +1,30 @@ +package main + +func parseTarget(s string) (host string, hops []string) { + for i := 0; i < len(s); i++ { + if s[i] == '/' { + host = s[:i] + hops = splitHops(s[i+1:]) + return + } + } + host = s + hops = nil + return +} + +func splitHops(s string) []string { + if s == "" { + return nil + } + var hops []string + start := 0 + for i := 0; i < len(s); i++ { + if s[i] == '/' { + hops = append(hops, s[start:i]) + start = i + 1 + } + } + hops = append(hops, s[start:]) + return hops +} diff --git a/cmd/sic/parsetarget_test.go b/cmd/sic/parsetarget_test.go new file mode 100644 index 0000000..6a55f88 --- /dev/null +++ b/cmd/sic/parsetarget_test.go @@ -0,0 +1,27 @@ +package main + +import ( + "reflect" + "testing" +) + +// WP4: parseTarget splits "host/hop1/hop2" into the ssh host + the ordered nested hops. A bare +// host (no '/') has no hops. Pure split; validation (empty host, hop count vs nest depth) is +// resolveVerbs' job, not this one. +func TestParseTarget(t *testing.T) { + cases := []struct { + in string + host string + hops []string + }{ + {"boltzmann", "boltzmann", nil}, + {"boltzmann/memory", "boltzmann", []string{"memory"}}, + {"boltzmann/memory/stash-stash-1", "boltzmann", []string{"memory", "stash-stash-1"}}, + } + for _, tc := range cases { + host, hops := parseTarget(tc.in) + if host != tc.host || !reflect.DeepEqual(hops, tc.hops) { + t.Fatalf("parseTarget(%q) = (%q, %#v), want (%q, %#v)", tc.in, host, hops, tc.host, tc.hops) + } + } +}