Skip to content

Commit d8c86bb

Browse files
committed
set working dir properly
Signed-off-by: Christopher Petito <chrisjpetito@gmail.com>
1 parent 80eb2e4 commit d8c86bb

2 files changed

Lines changed: 51 additions & 0 deletions

File tree

cmd/root/run.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ func (f *runExecFlags) runtimeOpts(loadResult *teamloader.LoadResult, runConfig
337337
opts := []runtime.Opt{
338338
runtime.WithSessionStore(sessStore),
339339
runtime.WithCurrentAgent(agentName),
340+
runtime.WithWorkingDir(runConfig.WorkingDir),
340341
runtime.WithTracer(otel.Tracer(AppName)),
341342
runtime.WithModelSwitcherConfig(modelSwitcherCfg),
342343
}

cmd/root/run_runtime_opts_test.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package root
2+
3+
import (
4+
"context"
5+
"reflect"
6+
"testing"
7+
8+
"github.com/stretchr/testify/assert"
9+
"github.com/stretchr/testify/require"
10+
11+
"github.com/docker/docker-agent/pkg/agent"
12+
"github.com/docker/docker-agent/pkg/chat"
13+
"github.com/docker/docker-agent/pkg/config"
14+
"github.com/docker/docker-agent/pkg/model/provider/base"
15+
"github.com/docker/docker-agent/pkg/modelsdev"
16+
"github.com/docker/docker-agent/pkg/runtime"
17+
"github.com/docker/docker-agent/pkg/session"
18+
"github.com/docker/docker-agent/pkg/team"
19+
"github.com/docker/docker-agent/pkg/teamloader"
20+
"github.com/docker/docker-agent/pkg/tools"
21+
)
22+
23+
type rootTestProvider struct{}
24+
25+
func (rootTestProvider) ID() modelsdev.ID { return modelsdev.ParseIDOrZero("test/model") }
26+
27+
func (rootTestProvider) CreateChatCompletionStream(context.Context, []chat.Message, []tools.Tool) (chat.MessageStream, error) {
28+
return nil, nil
29+
}
30+
31+
func (rootTestProvider) BaseConfig() base.Config { return base.Config{} }
32+
func (rootTestProvider) MaxTokens() int { return 0 }
33+
34+
func TestRuntimeOptsPassesRunConfigWorkingDirToRuntime(t *testing.T) {
35+
t.Parallel()
36+
37+
workingDir := t.TempDir()
38+
agt := agent.New("root", "instructions", agent.WithModel(rootTestProvider{}), agent.WithAddEnvironmentInfo(true))
39+
loaded := &teamloader.LoadResult{Team: team.New(team.WithAgents(agt))}
40+
runConfig := &config.RuntimeConfig{Config: config.Config{WorkingDir: workingDir}}
41+
42+
rt, err := runtime.New(loaded.Team, (&runExecFlags{}).runtimeOpts(loaded, runConfig, session.NewInMemorySessionStore(), "root")...)
43+
require.NoError(t, err)
44+
45+
localRt, ok := rt.(*runtime.LocalRuntime)
46+
require.True(t, ok)
47+
got := reflect.ValueOf(localRt).Elem().FieldByName("workingDir").String()
48+
49+
assert.Equal(t, workingDir, got)
50+
}

0 commit comments

Comments
 (0)