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
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
test: workspace apps are deleted
  • Loading branch information
DanielleMaywood committed Jun 3, 2025
commit 459219146bd800a91c2b154a51bc39284bc0b0bb
63 changes: 63 additions & 0 deletions coderd/agentapi/subagent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,69 @@ func TestSubAgentAPI(t *testing.T) {
_, err = db.GetWorkspaceAgentByID(dbauthz.AsSystemRestricted(ctx), childAgentOne.ID) //nolint:gocritic // this is a test.
require.NoError(t, err)
})

t.Run("DeletesWorkspaceApps", func(t *testing.T) {
t.Parallel()

// Skip test on in-memory database since CASCADE DELETE is not implemented
if !dbtestutil.WillUsePostgres() {
t.Skip("CASCADE DELETE behavior requires PostgreSQL")
}

log := testutil.Logger(t)
ctx := testutil.Context(t, testutil.WaitShort)
clock := quartz.NewMock(t)

db, org := newDatabaseWithOrg(t)
user, agent := newUserWithWorkspaceAgent(t, db, org)
api := newAgentAPI(t, log, db, clock, user, org, agent)

// Given: A sub agent with workspace apps
createResp, err := api.CreateSubAgent(ctx, &proto.CreateSubAgentRequest{
Name: "child-agent-with-apps",
Directory: "/workspaces/coder",
Architecture: "amd64",
OperatingSystem: "linux",
Apps: []*proto.CreateSubAgentRequest_App{
{
Slug: "code-server A1AA ",
DisplayName: ptr.Ref("VS Code"),
Icon: ptr.Ref("/icon/code.svg"),
Url: ptr.Ref("http://localhost:13337"),
},
{
Slug: "vim",
Command: ptr.Ref("vim"),
DisplayName: ptr.Ref("Vim"),
},
},
})
require.NoError(t, err)

subAgentID, err := uuid.FromBytes(createResp.Agent.Id)
require.NoError(t, err)

// Verify that the apps were created
apps, err := api.Database.GetWorkspaceAppsByAgentID(dbauthz.AsSystemRestricted(ctx), subAgentID) //nolint:gocritic // this is a test.
require.NoError(t, err)
require.Len(t, apps, 2)

// When: We delete the sub agent
_, err = api.DeleteSubAgent(ctx, &proto.DeleteSubAgentRequest{
Id: createResp.Agent.Id,
})
require.NoError(t, err)

// Then: The agent is deleted
_, err = api.Database.GetWorkspaceAgentByID(dbauthz.AsSystemRestricted(ctx), subAgentID) //nolint:gocritic // this is a test.
require.ErrorIs(t, err, sql.ErrNoRows)

// And: The apps are also deleted (due to CASCADE DELETE)
// Use raw database since authorization layer requires agent to exist
appsAfterDeletion, err := db.GetWorkspaceAppsByAgentID(ctx, subAgentID)
require.NoError(t, err)
require.Empty(t, appsAfterDeletion)
})
})

t.Run("ListSubAgents", func(t *testing.T) {
Expand Down
Loading
0