Dixie is capped (max_inflight 2, queue_depth 8, queue_wait 20s) and never queued on llama-server. Streaming chat, thinking off, 45s fallback to clean. Digest and chunk-embedding caches are content-addressed SQLite (Honcho context is not cached). Recover uses the guarded Fetcher. guardian-star is refused in code.
88 lines
2.0 KiB
Go
88 lines
2.0 KiB
Go
package dcache
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestHitMissAndNormalise(t *testing.T) {
|
|
d, err := Open(filepath.Join(t.TempDir(), "c.db"), 1<<20, nil)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer d.Close()
|
|
k1 := DigestKey("abc", "What Share?", "m", PromptVersion)
|
|
k2 := DigestKey("abc", "what share?", "m", PromptVersion)
|
|
if k1 != k2 {
|
|
t.Fatal("normalise")
|
|
}
|
|
if _, ok := d.GetDigest(k1); ok {
|
|
t.Fatal("miss")
|
|
}
|
|
d.PutDigest(k1, "forty two", 1)
|
|
h, ok := d.GetDigest(k2)
|
|
if !ok || h.Text != "forty two" {
|
|
t.Fatalf("%v %v", ok, h)
|
|
}
|
|
k3 := DigestKey("abd", "what share?", "m", PromptVersion)
|
|
if _, ok := d.GetDigest(k3); ok {
|
|
t.Fatal("changed content must miss")
|
|
}
|
|
}
|
|
|
|
func TestPromptVersionInvalidates(t *testing.T) {
|
|
k1 := DigestKey("h", "q", "m", "1")
|
|
k2 := DigestKey("h", "q", "m", "2")
|
|
if k1 == k2 {
|
|
t.Fatal("version")
|
|
}
|
|
}
|
|
|
|
func TestNoContextTable(t *testing.T) {
|
|
d, err := Open(filepath.Join(t.TempDir(), "c.db"), 1<<20, nil)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer d.Close()
|
|
var n int
|
|
_ = d.sql.QueryRow(`SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name='context'`).Scan(&n)
|
|
if n != 0 {
|
|
t.Fatal("must not store context")
|
|
}
|
|
}
|
|
|
|
func TestEvictUnderCap(t *testing.T) {
|
|
d, err := Open(filepath.Join(t.TempDir(), "c.db"), 200, nil)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer d.Close()
|
|
for i := 0; i < 20; i++ {
|
|
d.PutDigest(DigestKey("h", string(rune('a'+i)), "m", "1"), "xxxxxxxxxxxxxxxxxxxx", 1)
|
|
}
|
|
if d.Size() > 400 {
|
|
t.Fatalf("size %d", d.Size())
|
|
}
|
|
if d.Evictions == 0 {
|
|
t.Fatal("want evictions")
|
|
}
|
|
}
|
|
|
|
func TestCorruptDBBypass(t *testing.T) {
|
|
p := filepath.Join(t.TempDir(), "c.db")
|
|
if err := os.WriteFile(p, []byte("not a database"), 0o600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
d, err := Open(p, 1<<20, nil)
|
|
if err == nil {
|
|
_ = d.Close()
|
|
// Open may succeed then query fails — GetDigest must miss not panic
|
|
if _, ok := d.GetDigest("x"); ok {
|
|
t.Fatal("corrupt hit")
|
|
}
|
|
return
|
|
}
|
|
// open failed: caller warns and bypasses
|
|
}
|