Skip to content

fix(agent): fix unexpanded devcontainer paths for agentcontainers #17736

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 4 commits into from
May 12, 2025
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
update test to depend on path expansion
  • Loading branch information
mafredri committed May 9, 2025
commit 97532832f986426ac59bb7e3049bd70aae76d341
16 changes: 10 additions & 6 deletions agent/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1998,8 +1998,8 @@ func TestAgent_ReconnectingPTYContainer(t *testing.T) {
// You can run it manually as follows:
//
// CODER_TEST_USE_DOCKER=1 go test -count=1 ./agent -run TestAgent_DevcontainerAutostart
// nolint: paralleltest // This test sets an environment variable.
func TestAgent_DevcontainerAutostart(t *testing.T) {
t.Parallel()
if os.Getenv("CODER_TEST_USE_DOCKER") != "1" {
t.Skip("Set CODER_TEST_USE_DOCKER=1 to run this test")
}
Expand All @@ -2012,9 +2012,12 @@ func TestAgent_DevcontainerAutostart(t *testing.T) {

// Prepare temporary devcontainer for test (mywork).
devcontainerID := uuid.New()
tempWorkspaceFolder := t.TempDir()
tempWorkspaceFolder = filepath.Join(tempWorkspaceFolder, "mywork")
tmpdir := t.TempDir()
t.Setenv("HOME", tmpdir)
tempWorkspaceFolder := filepath.Join(tmpdir, "mywork")
unexpandedWorkspaceFolder := filepath.Join("~", "mywork")
t.Logf("Workspace folder: %s", tempWorkspaceFolder)
t.Logf("Unexpanded workspace folder: %s", unexpandedWorkspaceFolder)
devcontainerPath := filepath.Join(tempWorkspaceFolder, ".devcontainer")
err = os.MkdirAll(devcontainerPath, 0o755)
require.NoError(t, err, "create devcontainer directory")
Expand All @@ -2031,9 +2034,10 @@ func TestAgent_DevcontainerAutostart(t *testing.T) {
// is expected to be prepared by the provisioner normally.
Devcontainers: []codersdk.WorkspaceAgentDevcontainer{
{
ID: devcontainerID,
Name: "test",
WorkspaceFolder: tempWorkspaceFolder,
ID: devcontainerID,
Name: "test",
// Use an unexpanded path to test the expansion.
WorkspaceFolder: unexpandedWorkspaceFolder,
},
},
Scripts: []codersdk.WorkspaceAgentScript{
Expand Down
Loading