Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[pull] main from coder:main #261

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 9 commits into from
Jun 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 0 additions & 12 deletions agent/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ func TestAgent_Stats_SSH(t *testing.T) {
t.Parallel()

for _, port := range sshPorts {
port := port
t.Run(fmt.Sprintf("(:%d)", port), func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -342,7 +341,6 @@ func TestAgent_SessionExec(t *testing.T) {
t.Parallel()

for _, port := range sshPorts {
port := port
t.Run(fmt.Sprintf("(:%d)", port), func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -468,7 +466,6 @@ func TestAgent_SessionTTYShell(t *testing.T) {
}

for _, port := range sshPorts {
port := port
t.Run(fmt.Sprintf("(%d)", port), func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -611,7 +608,6 @@ func TestAgent_Session_TTY_MOTD(t *testing.T) {
}

for _, test := range tests {
test := test
t.Run(test.name, func(t *testing.T) {
t.Parallel()
session := setupSSHSession(t, test.manifest, test.banner, func(fs afero.Fs) {
Expand Down Expand Up @@ -688,16 +684,13 @@ func TestAgent_Session_TTY_MOTD_Update(t *testing.T) {

//nolint:paralleltest // These tests need to swap the banner func.
for _, port := range sshPorts {
port := port

sshClient, err := conn.SSHClientOnPort(ctx, port)
require.NoError(t, err)
t.Cleanup(func() {
_ = sshClient.Close()
})

for i, test := range tests {
test := test
t.Run(fmt.Sprintf("(:%d)/%d", port, i), func(t *testing.T) {
// Set new banner func and wait for the agent to call it to update the
// banner.
Expand Down Expand Up @@ -1210,7 +1203,6 @@ func TestAgent_CoderEnvVars(t *testing.T) {
t.Parallel()

for _, key := range []string{"CODER", "CODER_WORKSPACE_NAME", "CODER_WORKSPACE_OWNER_NAME", "CODER_WORKSPACE_AGENT_NAME"} {
key := key
t.Run(key, func(t *testing.T) {
t.Parallel()

Expand All @@ -1233,7 +1225,6 @@ func TestAgent_SSHConnectionEnvVars(t *testing.T) {
// For some reason this test produces a TTY locally and a non-TTY in CI
// so we don't test for the absence of SSH_TTY.
for _, key := range []string{"SSH_CONNECTION", "SSH_CLIENT"} {
key := key
t.Run(key, func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -1276,7 +1267,6 @@ func TestAgent_SSHConnectionLoginVars(t *testing.T) {
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.key, func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -1796,7 +1786,6 @@ func TestAgent_ReconnectingPTY(t *testing.T) {
t.Setenv("LANG", "C")

for _, backendType := range backends {
backendType := backendType
t.Run(backendType, func(t *testing.T) {
if backendType == "Screen" {
if runtime.GOOS != "linux" {
Expand Down Expand Up @@ -2496,7 +2485,6 @@ func TestAgent_Dial(t *testing.T) {
}

for _, c := range cases {
c := c
t.Run(c.name, func(t *testing.T) {
t.Parallel()

Expand Down
31 changes: 7 additions & 24 deletions agent/agentcontainers/api.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package agentcontainers

import (
"bytes"
"context"
"errors"
"fmt"
"io"
"net/http"
"os"
"path"
Expand Down Expand Up @@ -1114,27 +1112,6 @@ func (api *API) maybeInjectSubAgentIntoContainerLocked(ctx context.Context, dc c
if proc.agent.ID == uuid.Nil || maybeRecreateSubAgent {
subAgentConfig.Architecture = arch

// Detect workspace folder by executing `pwd` in the container.
// NOTE(mafredri): This is a quick and dirty way to detect the
// workspace folder inside the container. In the future we will
// rely more on `devcontainer read-configuration`.
var pwdBuf bytes.Buffer
err = api.dccli.Exec(ctx, dc.WorkspaceFolder, dc.ConfigPath, "pwd", []string{},
WithExecOutput(&pwdBuf, io.Discard),
WithExecContainerID(container.ID),
)
if err != nil {
return xerrors.Errorf("check workspace folder in container: %w", err)
}
directory := strings.TrimSpace(pwdBuf.String())
if directory == "" {
logger.Warn(ctx, "detected workspace folder is empty, using default workspace folder",
slog.F("default_workspace_folder", DevcontainerDefaultContainerWorkspaceFolder),
)
directory = DevcontainerDefaultContainerWorkspaceFolder
}
subAgentConfig.Directory = directory

displayAppsMap := map[codersdk.DisplayApp]bool{
// NOTE(DanielleMaywood):
// We use the same defaults here as set in terraform-provider-coder.
Expand All @@ -1146,7 +1123,10 @@ func (api *API) maybeInjectSubAgentIntoContainerLocked(ctx context.Context, dc c
codersdk.DisplayAppPortForward: true,
}

var appsWithPossibleDuplicates []SubAgentApp
var (
appsWithPossibleDuplicates []SubAgentApp
workspaceFolder = DevcontainerDefaultContainerWorkspaceFolder
)

if err := func() error {
var (
Expand All @@ -1167,6 +1147,8 @@ func (api *API) maybeInjectSubAgentIntoContainerLocked(ctx context.Context, dc c
return err
}

workspaceFolder = config.Workspace.WorkspaceFolder

// NOTE(DanielleMaywood):
// We only want to take an agent name specified in the root customization layer.
// This restricts the ability for a feature to specify the agent name. We may revisit
Expand Down Expand Up @@ -1241,6 +1223,7 @@ func (api *API) maybeInjectSubAgentIntoContainerLocked(ctx context.Context, dc c

subAgentConfig.DisplayApps = displayApps
subAgentConfig.Apps = apps
subAgentConfig.Directory = workspaceFolder
}

deleteSubAgent := proc.agent.ID != uuid.Nil && maybeRecreateSubAgent && !proc.agent.EqualConfig(subAgentConfig)
Expand Down
35 changes: 8 additions & 27 deletions agent/agentcontainers/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1262,6 +1262,11 @@ func TestAPI(t *testing.T) {
deleteErrC: make(chan error, 1),
}
fakeDCCLI = &fakeDevcontainerCLI{
readConfig: agentcontainers.DevcontainerConfig{
Workspace: agentcontainers.DevcontainerWorkspace{
WorkspaceFolder: "/workspaces/coder",
},
},
execErrC: make(chan func(cmd string, args ...string) error, 1),
readConfigErrC: make(chan func(envs []string) error, 1),
}
Expand All @@ -1273,8 +1278,8 @@ func TestAPI(t *testing.T) {
Running: true,
CreatedAt: time.Now(),
Labels: map[string]string{
agentcontainers.DevcontainerLocalFolderLabel: "/workspaces",
agentcontainers.DevcontainerConfigFileLabel: "/workspace/.devcontainer/devcontainer.json",
agentcontainers.DevcontainerLocalFolderLabel: "/home/coder/coder",
agentcontainers.DevcontainerConfigFileLabel: "/home/coder/coder/.devcontainer/devcontainer.json",
},
}
)
Expand Down Expand Up @@ -1320,11 +1325,6 @@ func TestAPI(t *testing.T) {

// Allow initial agent creation and injection to succeed.
testutil.RequireSend(ctx, t, fakeSAC.createErrC, nil)
testutil.RequireSend(ctx, t, fakeDCCLI.execErrC, func(cmd string, args ...string) error {
assert.Equal(t, "pwd", cmd)
assert.Empty(t, args)
return nil
}) // Exec pwd.
testutil.RequireSend(ctx, t, fakeDCCLI.readConfigErrC, func(envs []string) error {
assert.Contains(t, envs, "CODER_WORKSPACE_AGENT_NAME=test-container")
assert.Contains(t, envs, "CODER_WORKSPACE_NAME=test-workspace")
Expand All @@ -1350,7 +1350,7 @@ func TestAPI(t *testing.T) {
// Verify agent was created.
require.Len(t, fakeSAC.created, 1)
assert.Equal(t, "test-container", fakeSAC.created[0].Name)
assert.Equal(t, "/workspaces", fakeSAC.created[0].Directory)
assert.Equal(t, "/workspaces/coder", fakeSAC.created[0].Directory)
assert.Len(t, fakeSAC.deleted, 0)

t.Log("Agent injected successfully, now testing reinjection into the same container...")
Expand Down Expand Up @@ -1467,11 +1467,6 @@ func TestAPI(t *testing.T) {
testutil.RequireSend(ctx, t, fakeSAC.deleteErrC, nil)
// Expect the agent to be recreated.
testutil.RequireSend(ctx, t, fakeSAC.createErrC, nil)
testutil.RequireSend(ctx, t, fakeDCCLI.execErrC, func(cmd string, args ...string) error {
assert.Equal(t, "pwd", cmd)
assert.Empty(t, args)
return nil
}) // Exec pwd.
testutil.RequireSend(ctx, t, fakeDCCLI.readConfigErrC, func(envs []string) error {
assert.Contains(t, envs, "CODER_WORKSPACE_AGENT_NAME=test-container")
assert.Contains(t, envs, "CODER_WORKSPACE_NAME=test-workspace")
Expand Down Expand Up @@ -1814,7 +1809,6 @@ func TestAPI(t *testing.T) {
},
},
},
execErrC: make(chan func(cmd string, args ...string) error, 1),
}

testContainer = codersdk.WorkspaceAgentContainer{
Expand Down Expand Up @@ -1861,15 +1855,9 @@ func TestAPI(t *testing.T) {

// Close before api.Close() defer to avoid deadlock after test.
defer close(fSAC.createErrC)
defer close(fDCCLI.execErrC)

// Given: We allow agent creation and injection to succeed.
testutil.RequireSend(ctx, t, fSAC.createErrC, nil)
testutil.RequireSend(ctx, t, fDCCLI.execErrC, func(cmd string, args ...string) error {
assert.Equal(t, "pwd", cmd)
assert.Empty(t, args)
return nil
})

// Wait until the ticker has been registered.
tickerTrap.MustWait(ctx).MustRelease(ctx)
Expand Down Expand Up @@ -1913,7 +1901,6 @@ func TestAPI(t *testing.T) {
},
},
readConfigErrC: make(chan func(envs []string) error, 2),
execErrC: make(chan func(cmd string, args ...string) error, 1),
}

testContainer = codersdk.WorkspaceAgentContainer{
Expand Down Expand Up @@ -1960,16 +1947,10 @@ func TestAPI(t *testing.T) {

// Close before api.Close() defer to avoid deadlock after test.
defer close(fSAC.createErrC)
defer close(fDCCLI.execErrC)
defer close(fDCCLI.readConfigErrC)

// Given: We allow agent creation and injection to succeed.
testutil.RequireSend(ctx, t, fSAC.createErrC, nil)
testutil.RequireSend(ctx, t, fDCCLI.execErrC, func(cmd string, args ...string) error {
assert.Equal(t, "pwd", cmd)
assert.Empty(t, args)
return nil
})
testutil.RequireSend(ctx, t, fDCCLI.readConfigErrC, func(env []string) error {
// We expect the wrong workspace agent name passed in first.
assert.Contains(t, env, "CODER_WORKSPACE_AGENT_NAME=test-container")
Expand Down
4 changes: 0 additions & 4 deletions agent/agentcontainers/containers_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ func TestWrapDockerExec(t *testing.T) {
},
}
for _, tt := range tests {
tt := tt // appease the linter even though this isn't needed anymore
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
actualCmd, actualArgs := wrapDockerExec("my-container", tt.containerUser, tt.cmdArgs[0], tt.cmdArgs[1:]...)
Expand All @@ -54,7 +53,6 @@ func TestWrapDockerExec(t *testing.T) {
func TestConvertDockerPort(t *testing.T) {
t.Parallel()

//nolint:paralleltest // variable recapture no longer required
for _, tc := range []struct {
name string
in string
Expand Down Expand Up @@ -101,7 +99,6 @@ func TestConvertDockerPort(t *testing.T) {
expectError: "invalid port",
},
} {
//nolint: paralleltest // variable recapture no longer required
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
actualPort, actualNetwork, actualErr := convertDockerPort(tc.in)
Expand Down Expand Up @@ -151,7 +148,6 @@ func TestConvertDockerVolume(t *testing.T) {
expectError: "invalid volume",
},
} {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
})
Expand Down
5 changes: 5 additions & 0 deletions agent/agentcontainers/devcontainercli.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
type DevcontainerConfig struct {
MergedConfiguration DevcontainerMergedConfiguration `json:"mergedConfiguration"`
Configuration DevcontainerConfiguration `json:"configuration"`
Workspace DevcontainerWorkspace `json:"workspace"`
}

type DevcontainerMergedConfiguration struct {
Expand All @@ -46,6 +47,10 @@ type CoderCustomization struct {
Name string `json:"name,omitempty"`
}

type DevcontainerWorkspace struct {
WorkspaceFolder string `json:"workspaceFolder"`
}

// DevcontainerCLI is an interface for the devcontainer CLI.
type DevcontainerCLI interface {
Up(ctx context.Context, workspaceFolder, configPath string, opts ...DevcontainerCLIUpOptions) (id string, err error)
Expand Down
1 change: 0 additions & 1 deletion agent/agentssh/x11_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,6 @@ func Test_addXauthEntry(t *testing.T) {
require.NoError(t, err)

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

Expand Down
1 change: 0 additions & 1 deletion agent/proto/compare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ func TestLabelsEqual(t *testing.T) {
eq: false,
},
} {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
require.Equal(t, tc.eq, proto.LabelsEqual(tc.a, tc.b))
Expand Down
2 changes: 0 additions & 2 deletions agent/proto/resourcesmonitor/queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ func TestResourceMonitorQueue(t *testing.T) {
}

for _, tt := range tests {
tt := tt

t.Run(tt.name, func(t *testing.T) {
t.Parallel()
queue := resourcesmonitor.NewQueue(20)
Expand Down
1 change: 0 additions & 1 deletion agent/proto/resourcesmonitor/resources_monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ func TestPushResourcesMonitoringWithConfig(t *testing.T) {
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

Expand Down
1 change: 0 additions & 1 deletion apiversion/apiversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ func TestAPIVersionValidate(t *testing.T) {
expectedError: "no longer supported",
},
} {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()

Expand Down
1 change: 0 additions & 1 deletion buildinfo/buildinfo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ func TestBuildInfo(t *testing.T) {
}

for _, c := range cases {
c := c
t.Run(c.name, func(t *testing.T) {
t.Parallel()
require.Equal(t, c.expectMatch, buildinfo.VersionsMatch(c.v1, c.v2),
Expand Down
1 change: 0 additions & 1 deletion cli/agent_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ func Test_extractPort(t *testing.T) {
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
got, err := extractPort(tt.urlString)
Expand Down
1 change: 0 additions & 1 deletion cli/autoupdate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ func TestAutoUpdate(t *testing.T) {
}

for _, c := range cases {
c := c
t.Run(c.Name, func(t *testing.T) {
t.Parallel()
client := coderdtest.New(t, nil)
Expand Down
1 change: 0 additions & 1 deletion cli/clitest/golden.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ ExtractCommandPathsLoop:
}

for _, tt := range cases {
tt := tt
t.Run(tt.Name, func(t *testing.T) {
t.Parallel()
ctx := testutil.Context(t, testutil.WaitLong)
Expand Down
Loading
Loading