Skip to content
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
11 changes: 9 additions & 2 deletions server-go/modules/config/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -1096,10 +1096,17 @@ func (s *Store) WorkspaceAdd(change WorkspaceMutation) error {
return errors.New("workspace already exists")
}
if len(paths) >= maxWorkspaces {
// Make room by dropping server-local workspaces whose directory is gone.
// Only a shared workspace (no provider) lives on this filesystem: a
// detached or mirror workspace's path is the client's, so it never
// exists here, and judging it by a stat here dropped every one of them
// whenever the registry filled.
keptPaths, keptProviders, keptRemotes, keptHeads := []string{}, []string{}, []string{}, []string{}
for i, registered := range paths {
if _, statErr := os.Stat(registered); errors.Is(statErr, os.ErrNotExist) {
continue
if providers[i] == "" {
if _, statErr := os.Stat(registered); errors.Is(statErr, os.ErrNotExist) {
continue
}
}
keptPaths = append(keptPaths, registered)
keptProviders = append(keptProviders, providers[i])
Expand Down
43 changes: 43 additions & 0 deletions server-go/modules/config/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package config

import (
"encoding/json"
"fmt"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -743,3 +744,45 @@ func TestMalformedReloadKeepsLastGoodSnapshotAndRejectsMutations(t *testing.T) {
t.Fatalf("recovered snapshot: value=%#v err=%v", value, err)
}
}

// A full registry makes room only from server-local workspaces that are gone.
// A detached workspace's path is the client's and never exists on the server,
// so pruning it by a local stat dropped every detached workspace at once.
func TestAFullRegistryKeepsClientWorkspaces(t *testing.T) {
dir := t.TempDir()
store, err := NewStore(filepath.Join(dir, "aimee.yaml"))
if err != nil {
t.Fatal(err)
}
for i := 0; i < maxWorkspaces-1; i++ {
change := WorkspaceMutation{Path: fmt.Sprintf("/client/repo-%d", i), Provider: "detached"}
if err := store.WorkspaceAdd(change); err != nil {
t.Fatal(err)
}
}
gone := filepath.Join(dir, "gone")
if err := store.WorkspaceAdd(WorkspaceMutation{Path: gone}); err != nil {
t.Fatal(err)
}
// Full: the next add may drop the vanished server-local one, and only it.
if err := store.WorkspaceAdd(WorkspaceMutation{Path: "/client/new", Provider: "detached"}); err != nil {
t.Fatal(err)
}
values, _, err := store.Snapshot()
if err != nil {
t.Fatal(err)
}
paths, _ := values["workspaces"].([]any)
if len(paths) != maxWorkspaces {
t.Fatalf("%d workspaces after the add, want %d", len(paths), maxWorkspaces)
}
for _, path := range paths {
if path == gone {
t.Fatal("the vanished server-local workspace was kept")
}
}
// Full of client workspaces only: refuse rather than drop one.
if err := store.WorkspaceAdd(WorkspaceMutation{Path: "/client/one-more", Provider: "detached"}); err == nil {
t.Fatal("a registry full of client workspaces accepted another by dropping one")
}
}
Loading