Both stores treat a missing file as an empty document, so a memory directory that does not exist looked exactly like a memory with nothing in it yet. archied logged "memory manager started" and ran with no memory at all; the failure would have surfaced at the agent's first write, as a tool error mid-conversation, long after startup said it was fine. Found live: a config copied from carina kept work_dir=/var/lib/archie /work, a container path with no counterpart on the host. New now establishes the directory and reports a path it cannot use, so the existing error path exits at startup where an operator can see it. Refs archie-core-rml
82 lines
2.0 KiB
Go
82 lines
2.0 KiB
Go
package builtin
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
// A missing memory directory is indistinguishable from an empty memory: both
|
|
// stores treat ENOENT as "no content yet". That makes a misconfigured Dir
|
|
// invisible until the agent's first memory write fails mid-conversation, long
|
|
// after startup reported success. New must settle the question up front.
|
|
func TestNewEstablishesDir(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
dir func(t *testing.T) string
|
|
wantErr bool
|
|
}{
|
|
{
|
|
name: "existing directory",
|
|
dir: func(t *testing.T) string { return t.TempDir() },
|
|
},
|
|
{
|
|
name: "missing directory is created",
|
|
dir: func(t *testing.T) string {
|
|
return filepath.Join(t.TempDir(), "nested", "memory")
|
|
},
|
|
},
|
|
{
|
|
name: "unwritable parent is reported",
|
|
dir: func(t *testing.T) string {
|
|
parent := filepath.Join(t.TempDir(), "ro")
|
|
if err := os.Mkdir(parent, 0o500); err != nil {
|
|
t.Fatalf("mkdir: %v", err)
|
|
}
|
|
return filepath.Join(parent, "memory")
|
|
},
|
|
wantErr: true,
|
|
},
|
|
{
|
|
name: "path occupied by a file is reported",
|
|
dir: func(t *testing.T) string {
|
|
p := filepath.Join(t.TempDir(), "memory")
|
|
if err := os.WriteFile(p, []byte("not a dir"), 0o600); err != nil {
|
|
t.Fatalf("write: %v", err)
|
|
}
|
|
return p
|
|
},
|
|
wantErr: true,
|
|
},
|
|
}
|
|
|
|
for _, tc := range tests {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
// Running as root defeats permission-based cases.
|
|
if tc.wantErr && os.Geteuid() == 0 {
|
|
t.Skip("running as root: permission cases are not meaningful")
|
|
}
|
|
dir := tc.dir(t)
|
|
|
|
_, err := New(Config{Dir: dir})
|
|
if tc.wantErr {
|
|
if err == nil {
|
|
t.Fatalf("New(%q) = nil error, want a failure the operator can act on", dir)
|
|
}
|
|
return
|
|
}
|
|
if err != nil {
|
|
t.Fatalf("New(%q): %v", dir, err)
|
|
}
|
|
|
|
info, statErr := os.Stat(dir)
|
|
if statErr != nil {
|
|
t.Fatalf("New returned success but %q does not exist: %v", dir, statErr)
|
|
}
|
|
if !info.IsDir() {
|
|
t.Fatalf("%q is not a directory", dir)
|
|
}
|
|
})
|
|
}
|
|
}
|