mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 06:23:17 -10:00
Each toolchain is one image.ToolDef in image.SharedTools, which also holds its guest environment, its PATH folders and its version files. They leave base's devvm-tools.sh for /etc/devvm/toolchains.sh, which every launch writes, so base.sh changes and every image rebuilds once. The structure test's names rule fails on a toolchain's name as a literal outside internal/image, TestToolchainsComplete checks the toolchains page, and Contributing gains Adding a toolchain. Co-Authored-By: Claude Opus 5.5 <[email protected]>
87 lines
2.6 KiB
Go
87 lines
2.6 KiB
Go
package cli
|
|
|
|
import (
|
|
"slices"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/devvmhq/devvm/internal/image"
|
|
)
|
|
|
|
func TestJoined(t *testing.T) {
|
|
names := []string{"base", "docker", "nix", "foo", "fop"}
|
|
for _, tc := range []struct {
|
|
in string
|
|
want []string
|
|
}{
|
|
{"", names},
|
|
{"d", []string{"docker"}},
|
|
{"docker+", []string{"docker+base", "docker+nix", "docker+foo", "docker+fop"}},
|
|
{"docker+f", []string{"docker+foo", "docker+fop"}},
|
|
{"docker+foo+f", []string{"docker+foo+fop"}},
|
|
{"x", nil},
|
|
} {
|
|
if got := joined(tc.in, names); !slices.Equal(got, tc.want) {
|
|
t.Errorf("joined(%q) = %q, want %q", tc.in, got, tc.want)
|
|
}
|
|
}
|
|
}
|
|
|
|
// --tools, --agents and --layers complete a comma-separated list of their
|
|
// part's names, and none.
|
|
func TestCompleteParts(t *testing.T) {
|
|
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
|
|
t.Setenv("XDG_DATA_HOME", t.TempDir())
|
|
u, _, _ := testUI()
|
|
a := newApp(u)
|
|
others := slices.DeleteFunc(slices.Clone(image.Toolchains), func(n string) bool { return n == "node" })
|
|
for _, tc := range []struct {
|
|
flag, in string
|
|
want []string
|
|
}{
|
|
{"tools", "", append(slices.Clone(image.Toolchains), "none")},
|
|
{"tools", "node,", prefixed("node,", others, "")},
|
|
{"tools", "node,p", prefixed("node,", others, "p")},
|
|
{"agents", "c", prefixed("", image.Agents, "c")},
|
|
{"agents", "n", append(prefixed("", image.Agents, "n"), "none")},
|
|
{"layers", "", []string{"desktop", "docker", "nix", "none"}},
|
|
{"layers", "de", []string{"desktop"}},
|
|
} {
|
|
if got, _ := completeParts(a, tc.flag)(nil, nil, tc.in); !slices.Equal(got, tc.want) {
|
|
t.Errorf("--%s %q = %q, want %q", tc.flag, tc.in, got, tc.want)
|
|
}
|
|
}
|
|
}
|
|
|
|
// prefixed is before and each of names that starts with prefix, in their
|
|
// order: what a completion of a list offers.
|
|
func prefixed(before string, names []string, prefix string) []string {
|
|
var out []string
|
|
for _, n := range names {
|
|
if strings.HasPrefix(n, prefix) {
|
|
out = append(out, before+n)
|
|
}
|
|
}
|
|
return out
|
|
}
|
|
|
|
// devvm tools add and rm complete separate words: the shared tools not
|
|
// given yet.
|
|
func TestCompleteToolNames(t *testing.T) {
|
|
all := slices.Concat(image.Toolchains, image.Agents)
|
|
for _, tc := range []struct {
|
|
args []string
|
|
in string
|
|
want []string
|
|
}{
|
|
{nil, "c", prefixed("", all, "c")},
|
|
{[]string{"claude"}, "c", slices.DeleteFunc(prefixed("", all, "c"), func(n string) bool { return n == "claude" })},
|
|
{[]string{"node"}, "", slices.DeleteFunc(slices.Clone(all), func(n string) bool { return n == "node" })},
|
|
{nil, "node+", nil},
|
|
} {
|
|
if got, _ := completeToolNames(nil, tc.args, tc.in); !slices.Equal(got, tc.want) {
|
|
t.Errorf("completeToolNames(%q, %q) = %q, want %q", tc.args, tc.in, got, tc.want)
|
|
}
|
|
}
|
|
}
|