|
| 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