Skip to content

Commit 8997950

Browse files
committed
fix(codersdk/toolsdk): re-fetch agent ID in GetWorkspaceAgentLogs test
Prior sub-tests call CreateWorkspaceBuild through the API, which triggers SoftDeletePriorWorkspaceAgents and soft-deletes the agent from build #1. Re-fetch the workspace to get the current (non-deleted) agent ID instead of using the stale one captured at setup time.
1 parent 757a00c commit 8997950

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

codersdk/toolsdk/toolsdk_test.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,10 +741,21 @@ func TestTools(t *testing.T) {
741741
})
742742

743743
t.Run("GetWorkspaceAgentLogs", func(t *testing.T) {
744+
ctx := testutil.Context(t, testutil.WaitShort)
744745
tb, err := toolsdk.NewDeps(memberClient)
745746
require.NoError(t, err)
747+
748+
// Re-fetch the workspace to get the current agent ID. Prior
749+
// sub-tests may have created new builds which soft-delete
750+
// agents from earlier builds (SoftDeletePriorWorkspaceAgents).
751+
latestWS, err := client.Workspace(ctx, r.Workspace.ID)
752+
require.NoError(t, err)
753+
require.NotEmpty(t, latestWS.LatestBuild.Resources)
754+
require.NotEmpty(t, latestWS.LatestBuild.Resources[0].Agents)
755+
currentAgentID := latestWS.LatestBuild.Resources[0].Agents[0].ID
756+
746757
logs, err := testTool(t, toolsdk.GetWorkspaceAgentLogs, tb, toolsdk.GetWorkspaceAgentLogsArgs{
747-
WorkspaceAgentID: agentID.String(),
758+
WorkspaceAgentID: currentAgentID.String(),
748759
})
749760

750761
require.NoError(t, err)

0 commit comments

Comments
 (0)