@@ -433,7 +433,72 @@ func TestOpenVSCodeDevContainer(t *testing.T) {
433433 agentcontainers .WithContainerLabelIncludeFilter ("coder.test" , t .Name ()),
434434 )
435435 })
436- coderdtest .NewWorkspaceAgentWaiter (t , client , workspace .ID ).AgentNames ([]string {parentAgentName , devcontainerName }).Wait ()
436+ resources := coderdtest .NewWorkspaceAgentWaiter (t , client , workspace .ID ).AgentNames ([]string {parentAgentName }).Wait ()
437+ parentAgent := coderdtest .RequireWorkspaceAgentByName (t , resources , parentAgentName )
438+ parentAgentID := parentAgent .ID
439+
440+ // Agent connection does not guarantee the parent agent's container API
441+ // has completed its first devcontainer update. Wait for that endpoint so
442+ // parallel open commands do not race the initial cache population.
443+ ctx := testutil .Context (t , testutil .WaitSuperLong )
444+ testutil .Eventually (ctx , t , func (ctx context.Context ) bool {
445+ resp , err := client .WorkspaceAgentListContainers (ctx , parentAgentID , nil )
446+ if err != nil {
447+ t .Logf ("list containers: %v" , err )
448+ return false
449+ }
450+ var devcontainerAgentID uuid.UUID
451+ for _ , dc := range resp .Devcontainers {
452+ if dc .ID != devcontainerID {
453+ continue
454+ }
455+ if dc .Status != codersdk .WorkspaceAgentDevcontainerStatusRunning {
456+ t .Logf ("devcontainer %s status %q" , devcontainerName , dc .Status )
457+ return false
458+ }
459+ if dc .Container == nil {
460+ t .Logf ("devcontainer %s missing container" , devcontainerName )
461+ return false
462+ }
463+ if dc .Container .ID != containerID {
464+ t .Logf ("devcontainer %s has container %s, want %s" , devcontainerName , dc .Container .ID , containerID )
465+ return false
466+ }
467+ if dc .Agent == nil {
468+ t .Logf ("devcontainer %s missing subagent" , devcontainerName )
469+ return false
470+ }
471+ if dc .Agent .Name != devcontainerName {
472+ t .Logf ("devcontainer %s has subagent %s, want %s" , devcontainerName , dc .Agent .Name , devcontainerName )
473+ return false
474+ }
475+ devcontainerAgentID = dc .Agent .ID
476+ }
477+ if devcontainerAgentID == uuid .Nil {
478+ t .Logf ("devcontainer %s not found" , devcontainerName )
479+ return false
480+ }
481+
482+ workspace , err := client .Workspace (ctx , workspace .ID )
483+ if err != nil {
484+ t .Logf ("get workspace: %v" , err )
485+ return false
486+ }
487+ for _ , resource := range workspace .LatestBuild .Resources {
488+ for _ , workspaceAgent := range resource .Agents {
489+ if workspaceAgent .ID != devcontainerAgentID {
490+ continue
491+ }
492+ if workspaceAgent .Status != codersdk .WorkspaceAgentConnected {
493+ t .Logf ("devcontainer subagent %s status %q" , devcontainerAgentID , workspaceAgent .Status )
494+ return false
495+ }
496+ return true
497+ }
498+ }
499+ t .Logf ("devcontainer subagent %s not found in workspace" , devcontainerAgentID )
500+ return false
501+ }, testutil .IntervalMedium , "devcontainer did not become ready" )
437502
438503 insideWorkspaceEnv := map [string ]string {
439504 "CODER" : "true" ,
0 commit comments