47 lines
1.1 KiB
Go
47 lines
1.1 KiB
Go
package memory
|
|
|
|
import (
|
|
"context"
|
|
"io"
|
|
"log/slog"
|
|
"testing"
|
|
|
|
"git.yeij.top/AskaEth/Cyrene_v2/internal/db"
|
|
)
|
|
|
|
// testLogger returns a logger that writes nowhere, keeping test output clean.
|
|
func testLogger() *slog.Logger {
|
|
return slog.New(slog.NewTextHandler(io.Discard, nil))
|
|
}
|
|
|
|
// newTestStore opens an isolated in-memory SQLite DB and builds a Store over it.
|
|
// Each call owns a private DB, so parallel tests are isolated by construction.
|
|
func newTestStore(t *testing.T) *Store {
|
|
t.Helper()
|
|
ctx := context.Background()
|
|
d, err := db.Open(ctx, ":memory:", testLogger())
|
|
if err != nil {
|
|
t.Fatalf("open in-memory db: %v", err)
|
|
}
|
|
t.Cleanup(func() { _ = d.Close() })
|
|
|
|
s, err := NewStore(ctx, d, testLogger())
|
|
if err != nil {
|
|
t.Fatalf("NewStore: %v", err)
|
|
}
|
|
return s
|
|
}
|
|
|
|
// baseItem is a minimal valid memory item for tests.
|
|
func baseItem() MemoryItem {
|
|
return MemoryItem{
|
|
PersonaID: "persona.a",
|
|
RoleID: "role.1",
|
|
Scope: ScopePersona,
|
|
Kind: KindRelationship,
|
|
Content: "她喜欢喝冰美式",
|
|
Tags: []string{"habit", "coffee"},
|
|
Confidence: 0.9,
|
|
}
|
|
}
|