feat: harden workspace file APIs
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5
parent
c1b8982e3b
commit
04b309d3fc
@@ -0,0 +1,51 @@
|
||||
package workspace
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestLocalManagerListReturnsSortedWorkspaces(t *testing.T) {
|
||||
mgr := NewLocalManager(t.TempDir())
|
||||
if _, err := mgr.Create("beta"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := mgr.Create("alpha"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
got, err := mgr.List()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(got) != 2 {
|
||||
t.Fatalf("len = %d, want 2", len(got))
|
||||
}
|
||||
if got[0].ID != "alpha" || got[1].ID != "beta" {
|
||||
t.Fatalf("ids = %q, %q; want alpha, beta", got[0].ID, got[1].ID)
|
||||
}
|
||||
if got[0].Root == "" || got[1].Root == "" {
|
||||
t.Fatal("manager list should keep internal roots for service use")
|
||||
}
|
||||
}
|
||||
|
||||
func TestLocalManagerListSkipsUnsafeDirectoryNames(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
if err := os.Mkdir(filepath.Join(root, "valid"), 0755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// Contains space, which is invalid per ValidID regex
|
||||
if err := os.Mkdir(filepath.Join(root, "bad name"), 0755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
mgr := NewLocalManager(root)
|
||||
got, err := mgr.List()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(got) != 1 || got[0].ID != "valid" {
|
||||
t.Fatalf("got %#v, want only valid", got)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user