feat: add phase 3 readonly models
This commit is contained in:
71
internal/projects/store_test.go
Normal file
71
internal/projects/store_test.go
Normal file
@@ -0,0 +1,71 @@
|
||||
package projects
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestStoreListsProjectsFromConfig(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
existing := filepath.Join(root, "workspace-a")
|
||||
missing := filepath.Join(root, "workspace-b")
|
||||
if err := os.MkdirAll(existing, 0o755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
config := `[projects."` + existing + `"]
|
||||
trust_level = "trusted"
|
||||
display_name = "Alpha"
|
||||
|
||||
[projects."` + missing + `"]
|
||||
trust_level = "untrusted"
|
||||
`
|
||||
if err := os.WriteFile(filepath.Join(root, "config.toml"), []byte(config), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
items, err := Store{CodexHome: root}.List()
|
||||
if err != nil {
|
||||
t.Fatalf("List returned error: %v", err)
|
||||
}
|
||||
if len(items) != 2 {
|
||||
t.Fatalf("len(items) = %d, want 2: %#v", len(items), items)
|
||||
}
|
||||
if items[0].Path != existing || items[0].DisplayName != "Alpha" || items[0].TrustLevel != "trusted" || !items[0].DirectoryExists {
|
||||
t.Fatalf("unexpected first project: %#v", items[0])
|
||||
}
|
||||
if items[1].Path != missing || items[1].DisplayName != filepath.Base(missing) || items[1].TrustLevel != "untrusted" || items[1].DirectoryExists {
|
||||
t.Fatalf("unexpected second project: %#v", items[1])
|
||||
}
|
||||
}
|
||||
|
||||
func TestStoreListsProjectsInStablePathOrder(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
config := `[projects."/tmp/zeta"]
|
||||
trust_level = "trusted"
|
||||
|
||||
[projects."/tmp/alpha"]
|
||||
trust_level = "trusted"
|
||||
`
|
||||
if err := os.WriteFile(filepath.Join(root, "config.toml"), []byte(config), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
items, err := Store{CodexHome: root}.List()
|
||||
if err != nil {
|
||||
t.Fatalf("List returned error: %v", err)
|
||||
}
|
||||
if got, want := []string{items[0].Path, items[1].Path}, []string{"/tmp/alpha", "/tmp/zeta"}; got[0] != want[0] || got[1] != want[1] {
|
||||
t.Fatalf("paths = %#v, want %#v", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStoreMissingConfigReturnsEmptyListWithLowConfidenceSource(t *testing.T) {
|
||||
items, err := Store{CodexHome: t.TempDir()}.List()
|
||||
if err != nil {
|
||||
t.Fatalf("List returned error: %v", err)
|
||||
}
|
||||
if len(items) != 0 {
|
||||
t.Fatalf("len(items) = %d, want 0", len(items))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user