55 "testing"
66
77 "github.com/stretchr/testify/assert"
8+
9+ "github.com/docker/docker-agent/pkg/paths"
810)
911
1012func TestShQuote (t * testing.T ) {
@@ -20,16 +22,46 @@ func TestAgentCommand(t *testing.T) {
2022
2123 // First run: creates the worktree from the base.
2224 cmd := agentCommand ("coder" , "sess1" , "/tmp/a.sock" , "board-abc" , "origin/main" , "do the thing" )
23- assert .Contains (t , cmd , " run 'coder' --yolo --session 'sess1' --listen 'unix:///tmp/a.sock'" )
25+ assert .Contains (t , cmd , " run 'coder' --yolo " )
26+ assert .Contains (t , cmd , " --session 'sess1' --listen 'unix:///tmp/a.sock'" )
2427 assert .Contains (t , cmd , "--worktree='board-abc' --worktree-base 'origin/main'" )
2528 assert .True (t , strings .HasSuffix (cmd , " 'do the thing'" ))
2629
30+ // The board's config, data, and cache dirs are forwarded so the agent
31+ // resolves the same aliases and creates its worktree where the board
32+ // watches, even when the board runs with directory overrides (e.g. in a
33+ // sandbox whose $HOME differs from the mounted host directories).
34+ assert .Contains (t , cmd , " --config-dir " + shQuote (paths .GetConfigDir ())+ " " )
35+ assert .Contains (t , cmd , " --data-dir " + shQuote (paths .GetDataDir ())+ " " )
36+ assert .Contains (t , cmd , " --cache-dir " + shQuote (paths .GetCacheDir ())+ " " )
37+
2738 // Resume: no worktree flags, no prompt.
2839 cmd = agentCommand ("coder" , "sess1" , "/tmp/a.sock" , "" , "" , "" )
2940 assert .NotContains (t , cmd , "--worktree" )
3041 assert .True (t , strings .HasSuffix (cmd , "--listen 'unix:///tmp/a.sock'" ))
3142}
3243
44+ // TestAgentCommandForwardsDirOverrides covers the scenario the forwarding
45+ // exists for: the board running with directory overrides. Not parallel: it
46+ // mutates the process-global overrides, and restores them before returning
47+ // — during the serial phase, before parallel tests resume.
48+ func TestAgentCommandForwardsDirOverrides (t * testing.T ) {
49+ configDir , dataDir , cacheDir := t .TempDir (), t .TempDir (), t .TempDir ()
50+ paths .SetConfigDir (configDir )
51+ paths .SetDataDir (dataDir )
52+ paths .SetCacheDir (cacheDir )
53+ t .Cleanup (func () {
54+ paths .SetConfigDir ("" )
55+ paths .SetDataDir ("" )
56+ paths .SetCacheDir ("" )
57+ })
58+
59+ cmd := agentCommand ("coder" , "sess1" , "/tmp/a.sock" , "" , "" , "" )
60+ assert .Contains (t , cmd , " --config-dir " + shQuote (configDir )+ " " )
61+ assert .Contains (t , cmd , " --data-dir " + shQuote (dataDir )+ " " )
62+ assert .Contains (t , cmd , " --cache-dir " + shQuote (cacheDir )+ " " )
63+ }
64+
3365func TestTmuxFormatEscape (t * testing.T ) {
3466 t .Parallel ()
3567
0 commit comments