MCPcopy Index your code
hub / github.com/coder/coder / TestResolvePath

Function TestResolvePath

agent/agentcontextconfig/resolve_test.go:23–77  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

21}
22
23func TestResolvePath(t *testing.T) { //nolint:tparallel // subtests using t.Setenv cannot be parallel
24 t.Run("EmptyInput", func(t *testing.T) {
25 t.Parallel()
26 require.Equal(t, "", agentcontextconfig.ResolvePath("", platformAbsPath("base")))
27 })
28
29 t.Run("WhitespaceOnly", func(t *testing.T) {
30 t.Parallel()
31 require.Equal(t, "", agentcontextconfig.ResolvePath(" ", platformAbsPath("base")))
32 })
33
34 // Tests that use t.Setenv cannot be parallel.
35 t.Run("TildeAlone", func(t *testing.T) {
36 fakeHome := t.TempDir()
37 t.Setenv("HOME", fakeHome)
38 t.Setenv("USERPROFILE", fakeHome)
39 got := agentcontextconfig.ResolvePath("~", platformAbsPath("base"))
40 require.Equal(t, fakeHome, got)
41 })
42
43 t.Run("TildeSlashPath", func(t *testing.T) {
44 fakeHome := t.TempDir()
45 t.Setenv("HOME", fakeHome)
46 t.Setenv("USERPROFILE", fakeHome)
47 got := agentcontextconfig.ResolvePath("~/docs/readme", platformAbsPath("base"))
48 require.Equal(t, filepath.Join(fakeHome, "docs", "readme"), got)
49 })
50
51 t.Run("AbsolutePath", func(t *testing.T) {
52 t.Parallel()
53 p := platformAbsPath("etc", "coder")
54 got := agentcontextconfig.ResolvePath(p, platformAbsPath("base"))
55 require.Equal(t, p, got)
56 })
57
58 t.Run("RelativePath", func(t *testing.T) {
59 t.Parallel()
60 base := platformAbsPath("work")
61 got := agentcontextconfig.ResolvePath("foo/bar", base)
62 require.Equal(t, filepath.Join(base, "foo", "bar"), got)
63 })
64
65 t.Run("RelativePathWithWhitespace", func(t *testing.T) {
66 t.Parallel()
67 base := platformAbsPath("work")
68 got := agentcontextconfig.ResolvePath(" foo/bar ", base)
69 require.Equal(t, filepath.Join(base, "foo", "bar"), got)
70 })
71
72 t.Run("RelativePathWithEmptyBaseDir", func(t *testing.T) {
73 t.Parallel()
74 got := agentcontextconfig.ResolvePath(".agents/skills", "")
75 require.Equal(t, "", got)
76 })
77}
78
79func TestResolvePath_HomeUnset(t *testing.T) {
80 // Cannot be parallel — modifies HOME env var.

Callers

nothing calls this directly

Calls 6

ResolvePathFunction · 0.92
SetenvMethod · 0.80
platformAbsPathFunction · 0.70
RunMethod · 0.65
TempDirMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected