Skip to content

Commit a5278c9

Browse files
feat(agent/agentcontainers): support agent name in customization
This PR supports specifying a name that will be used for the devcontainer agent in the customizations section of the devcontainer.json configuration file.
1 parent 118bf98 commit a5278c9

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

agent/agentcontainers/api.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,6 +1146,7 @@ func (api *API) maybeInjectSubAgentIntoContainerLocked(ctx context.Context, dc c
11461146
}
11471147

11481148
var appsWithPossibleDuplicates []SubAgentApp
1149+
var possibleAgentName string
11491150

11501151
if config, err := api.dccli.ReadConfig(ctx, dc.WorkspaceFolder, dc.ConfigPath,
11511152
[]string{
@@ -1173,6 +1174,14 @@ func (api *API) maybeInjectSubAgentIntoContainerLocked(ctx context.Context, dc c
11731174

11741175
appsWithPossibleDuplicates = append(appsWithPossibleDuplicates, customization.Apps...)
11751176
}
1177+
1178+
// NOTE(DanielleMaywood):
1179+
// We only want to take an agent name specified in the very last customization layer.
1180+
// This restricts the ability for a feature to specify the agent name. We may revisit
1181+
// this in the future, but for now we want to restrict this behavior.
1182+
if len(coderCustomization) > 0 {
1183+
possibleAgentName = coderCustomization[len(coderCustomization)-1].Name
1184+
}
11761185
}
11771186

11781187
displayApps := make([]codersdk.DisplayApp, 0, len(displayAppsMap))
@@ -1204,6 +1213,10 @@ func (api *API) maybeInjectSubAgentIntoContainerLocked(ctx context.Context, dc c
12041213

12051214
subAgentConfig.DisplayApps = displayApps
12061215
subAgentConfig.Apps = apps
1216+
1217+
if possibleAgentName != "" {
1218+
subAgentConfig.Name = possibleAgentName
1219+
}
12071220
}
12081221

12091222
deleteSubAgent := proc.agent.ID != uuid.Nil && maybeRecreateSubAgent && !proc.agent.EqualConfig(subAgentConfig)

agent/agentcontainers/api_test.go

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1739,6 +1739,32 @@ func TestAPI(t *testing.T) {
17391739
assert.Equal(t, int32(2), subAgent.Apps[1].Order)
17401740
},
17411741
},
1742+
{
1743+
name: "Name",
1744+
customization: []agentcontainers.CoderCustomization{
1745+
{
1746+
Name: "not-this-name",
1747+
},
1748+
{
1749+
Name: "custom-name",
1750+
},
1751+
},
1752+
afterCreate: func(t *testing.T, subAgent agentcontainers.SubAgent) {
1753+
require.Equal(t, "custom-name", subAgent.Name)
1754+
},
1755+
},
1756+
{
1757+
name: "NameIsOnlyUsedWhenInLastLayer",
1758+
customization: []agentcontainers.CoderCustomization{
1759+
{
1760+
Name: "custom-name",
1761+
},
1762+
{},
1763+
},
1764+
afterCreate: func(t *testing.T, subAgent agentcontainers.SubAgent) {
1765+
require.NotEqual(t, "custom-name", subAgent.Name)
1766+
},
1767+
},
17421768
}
17431769

17441770
for _, tt := range tests {
@@ -1825,7 +1851,6 @@ func TestAPI(t *testing.T) {
18251851

18261852
// Then: We expected it to succeed
18271853
require.Len(t, fSAC.created, 1)
1828-
assert.Equal(t, testContainer.FriendlyName, fSAC.created[0].Name)
18291854

18301855
if tt.afterCreate != nil {
18311856
tt.afterCreate(t, fSAC.created[0])

agent/agentcontainers/devcontainercli.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ type DevcontainerCustomizations struct {
3434
type CoderCustomization struct {
3535
DisplayApps map[codersdk.DisplayApp]bool `json:"displayApps,omitempty"`
3636
Apps []SubAgentApp `json:"apps,omitempty"`
37+
Name string `json:"name,omitempty"`
3738
}
3839

3940
// DevcontainerCLI is an interface for the devcontainer CLI.

0 commit comments

Comments
 (0)