Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.agents/
26 changes: 26 additions & 0 deletions internal/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package internal
import (
"fmt"
"os/exec"
"path/filepath"
goruntime "runtime"
"strings"
"time"
Expand Down Expand Up @@ -68,6 +69,9 @@ func ParseConfig(args []string, environment []string, startDir string) (Config,
// Build volumes with defaults (runtime-aware)
volumes := buildVolumes(cfg.Volumes, rt)

// Resolve relative host paths in volumes to absolute paths
volumes = resolveVolumePaths(volumes, startDir)

return Config{
Runtime: rt,
ImageName: ImageName(cfg.Image),
Expand Down Expand Up @@ -119,6 +123,28 @@ func buildVolumes(configVolumes []string, rt string) []string {
}
}

// resolveVolumePaths resolves relative host paths in volume mount specs to absolute paths.
// Volume specs have the format [host-path:]container-path[:options].
// Host paths starting with "." are treated as relative and resolved against baseDir.
// Named volumes (no leading "/" or ".") and container-only specs are left unchanged.
func resolveVolumePaths(volumes []string, baseDir string) []string {
resolved := make([]string, len(volumes))
for i, volume := range volumes {
hostPath, rest, hasColon := strings.Cut(volume, ":")
if !hasColon || !strings.HasPrefix(hostPath, ".") {
resolved[i] = volume
continue
}
absPath, err := filepath.Abs(filepath.Join(baseDir, hostPath))
if err != nil {
resolved[i] = volume
continue
}
resolved[i] = absPath + ":" + rest
}
return resolved
}

// buildEnvironment constructs the environment variable list with runtime-aware defaults
func buildEnvironment(environment []string, configEnv map[string]string, rt string) []string {
lookup := make(map[string]string)
Expand Down
54 changes: 54 additions & 0 deletions internal/config_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package internal_test

import (
"path/filepath"
"testing"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -82,6 +83,59 @@ func TestConfig(t *testing.T) {
}, config.Volumes)
})

t.Run("with relative --volume host path", func(t *testing.T) {
dir := t.TempDir()
args := []string{
"--runtime", "apple",
"--volume", "./relative/path:/container/path",
"some-program",
}
env := []string{
"TERM=some-term",
}

config, err := internal.ParseConfig(args, env, dir)
require.NoError(t, err)
require.Equal(t, []string{
filepath.Join(dir, "relative/path") + ":/container/path",
}, config.Volumes)
})

t.Run("with relative --volume host path and options", func(t *testing.T) {
dir := t.TempDir()
args := []string{
"--runtime", "apple",
"--volume", "./data:/container/data:ro",
"some-program",
}
env := []string{
"TERM=some-term",
}

config, err := internal.ParseConfig(args, env, dir)
require.NoError(t, err)
require.Equal(t, []string{
filepath.Join(dir, "data") + ":/container/data:ro",
}, config.Volumes)
})

t.Run("with named volume is not resolved", func(t *testing.T) {
args := []string{
"--runtime", "apple",
"--volume", "myvolume:/container/path",
"some-program",
}
env := []string{
"TERM=some-term",
}

config, err := internal.ParseConfig(args, env, ".")
require.NoError(t, err)
require.Equal(t, []string{
"myvolume:/container/path",
}, config.Volumes)
})

t.Run("with multiple --volume flags", func(t *testing.T) {
args := []string{
"--runtime", "apple",
Expand Down
Loading