-
Notifications
You must be signed in to change notification settings - Fork 2
fix(workspace): stop creating and sweep orphaned workspace dirs #496
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| package provider | ||
|
|
||
| import ( | ||
| "os" | ||
| "path/filepath" | ||
| "testing" | ||
|
|
||
| "github.com/devsy-org/devsy/pkg/config" | ||
| devcontainerconfig "github.com/devsy-org/devsy/pkg/devcontainer/config" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func setupTestHome(t *testing.T) { | ||
| t.Helper() | ||
| home := t.TempDir() | ||
| t.Setenv("HOME", home) | ||
| t.Setenv("USERPROFILE", home) | ||
| config.ResetPathManager() | ||
| t.Cleanup(config.ResetPathManager) | ||
| } | ||
|
|
||
| func TestSaveWorkspaceResult_RefusesWithoutConfig(t *testing.T) { | ||
| setupTestHome(t) | ||
|
|
||
| ws := &Workspace{ID: "ghost", Context: config.DefaultContext} | ||
| err := SaveWorkspaceResult(ws, &devcontainerconfig.Result{}) | ||
| require.Error(t, err) | ||
|
|
||
| // Must not leave an orphan dir behind. | ||
| dir, dirErr := GetWorkspaceDir(ws.Context, ws.ID) | ||
| require.NoError(t, dirErr) | ||
| require.NoDirExists(t, dir) | ||
| } | ||
|
|
||
| func TestSaveWorkspaceResult_WritesWhenConfigExists(t *testing.T) { | ||
| setupTestHome(t) | ||
|
|
||
| ws := &Workspace{ID: "real", Context: config.DefaultContext} | ||
| require.NoError(t, SaveWorkspaceConfig(ws)) | ||
| require.NoError(t, SaveWorkspaceResult(ws, &devcontainerconfig.Result{})) | ||
|
|
||
| dir, err := GetWorkspaceDir(ws.Context, ws.ID) | ||
| require.NoError(t, err) | ||
| _, err = os.Stat(filepath.Join(dir, WorkspaceResultFile)) | ||
| require.NoError(t, err) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| package workspace | ||
|
|
||
| import ( | ||
| "os" | ||
| "path/filepath" | ||
| "testing" | ||
|
|
||
| "github.com/devsy-org/devsy/pkg/provider" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestSweepOrphanWorkspaceDirs(t *testing.T) { | ||
| setupTestPathManager(t) | ||
|
|
||
| require.NoError(t, provider.SaveWorkspaceConfig( | ||
| &provider.Workspace{ID: "healthy", Context: testDefaultContext}, | ||
| )) | ||
|
|
||
| workspacesDir, err := provider.GetWorkspacesDir(testDefaultContext) | ||
| require.NoError(t, err) | ||
|
|
||
| // Orphan dir with only auxiliary state, plus a dotfile that must survive. | ||
| orphanDir := filepath.Join(workspacesDir, "orphan") | ||
| require.NoError(t, os.MkdirAll(filepath.Join(orphanDir, "logs"), 0o750)) | ||
| require.NoError(t, os.WriteFile( | ||
| filepath.Join(orphanDir, provider.WorkspaceResultFile), []byte("{}"), 0o600, | ||
| )) | ||
| dotDir := filepath.Join(workspacesDir, ".keep") | ||
| require.NoError(t, os.MkdirAll(dotDir, 0o750)) | ||
|
|
||
| SweepOrphanWorkspaceDirs(testDefaultContext) | ||
|
|
||
| healthyDir := filepath.Join(workspacesDir, "healthy") | ||
| require.DirExists(t, healthyDir) | ||
| require.NoDirExists(t, orphanDir) | ||
| require.DirExists(t, dotDir) | ||
| } | ||
|
|
||
| func TestSweepOrphanWorkspaceDirs_MissingDirIsNoop(t *testing.T) { | ||
| setupTestPathManager(t) | ||
|
|
||
| // No workspaces dir created yet — sweep must not panic or error. | ||
| SweepOrphanWorkspaceDirs(testDefaultContext) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Run the orphan sweep on every successful delete path.
SweepOrphanWorkspaceDirsis only reached after thedeleteWorkspacebranch on Line 58. Successful deletes that return earlier—imported workspaces on Lines 46-47, and--forcefolder deletes returned from Line 41 viahandleDeleteLoadError/forceDeleteFolder—skip the sweep entirely, so existing config-less dirs still survive in those flows. Please move the sweep into a shared post-success return path or invoke it from the other successful branches too, and add a regression test for those branches.🤖 Prompt for AI Agents