8000 feat(coderd/agentapi): allow inserting apps for sub agents by DanielleMaywood · Pull Request #18129 · coder/coder · GitHub
[go: up one dir, main page]

Skip to content

feat(coderd/agentapi): allow inserting apps for sub agents #18129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Jun 5, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
fix: add validation error for duplicate slug names
  • Loading branch information
DanielleMaywood committed Jun 3, 2025
commit 5250e1ca7650232b4e656712dc1bb1a3c3d8d090
9 changes: 8 additions & 1 deletion coderd/agentapi/subagent.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ func (a *SubAgentAPI) CreateSubAgent(ctx context.Context, req *agentproto.Create
return nil, xerrors.Errorf("insert sub agent: %w", err)
}

appSlugs := make(map[string]struct{})
for i, app := range req.Apps {
slug := app.Slug
if slug == "" {
Expand All @@ -94,7 +95,13 @@ func (a *SubAgentAPI) CreateSubAgent(ctx context.Context, req *agentproto.Create
Detail: fmt.Sprintf("app slug %q does not match regex %q", slug, provisioner.AppSlugRegex),
}
}

if _, exists := appSlugs[slug]; exists {
return nil, codersdk.ValidationError{
Field: fmt.Sprintf("apps[%d].slug", i),
Detail: fmt.Sprintf("app slug %q is already in use", slug),
}
}
appSlugs[slug] = struct{}{}
health := database.WorkspaceAppHealthDisabled
if app.Healthcheck == nil {
app.Healthcheck = &agentproto.CreateSubAgentRequest_App_Healthcheck{}
Expand Down
42 changes: 42 additions & 0 deletions coderd/agentapi/subagent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,48 @@ func TestSubAgentAPI(t *testing.T) {
},
},
},
{
name: "DuplicateAppSlugs",
apps: []*proto.CreateSubAgentRequest_App{
{
Slug: "duplicate-app",
DisplayName: ptr.Ref("First App"),
},
{
Slug: "duplicate-app",
DisplayName: ptr.Ref("Second App"),
},
},
expectedError: &codersdk.ValidationError{
Field: "apps[1].slug",
Detail: "app slug \"duplicate-app\" is already in use",
},
},
{
name: "MultipleDuplicateAppSlugs",
apps: []*proto.CreateSubAgentRequest_App{
{
Slug: "valid-app",
DisplayName: ptr.Ref("Valid App"),
},
{
Slug: "duplicate-app",
DisplayName: ptr.Ref("First Duplicate"),
},
{
Slug: "duplicate-app",
DisplayName: ptr.Ref("Second Duplicate"),
},
{
Slug: "duplicate-app",
DisplayName: ptr.Ref("Third Duplicate"),
},
},
expectedError: &codersdk.ValidationError{
Field: "apps[2].slug",
Detail: "app slug \"duplicate-app\" is already in use",
},
},
}

for _, tt := range tests {
Expand Down
Loading
0