Wire SLURP persistence and add restart coverage

This commit is contained in:
anthonyrawlins
2025-09-27 15:26:25 +10:00
parent 17673c38a6
commit 0b670a535d
5 changed files with 1061 additions and 369 deletions

View File

@@ -0,0 +1,69 @@
package slurp
import (
"context"
"testing"
"time"
"chorus/pkg/config"
slurpContext "chorus/pkg/slurp/context"
"chorus/pkg/ucxl"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
// TestSLURPPersistenceLoadsContexts verifies LevelDB fallback (Roadmap: SEC-SLURP 1.1).
func TestSLURPPersistenceLoadsContexts(t *testing.T) {
configDir := t.TempDir()
cfg := &config.Config{
Slurp: config.SlurpConfig{Enabled: true},
UCXL: config.UCXLConfig{
Storage: config.StorageConfig{Directory: configDir},
},
}
primary, err := NewSLURP(cfg, nil, nil, nil)
require.NoError(t, err)
require.NoError(t, primary.Initialize(context.Background()))
t.Cleanup(func() {
_ = primary.Close()
})
address, err := ucxl.Parse("ucxl://agent:resolver@chorus:task/current/docs/example.go")
require.NoError(t, err)
node := &slurpContext.ContextNode{
Path: "docs/example.go",
UCXLAddress: *address,
Summary: "Persistent context summary",
Purpose: "Verify persistence pipeline",
Technologies: []string{"Go"},
Tags: []string{"persistence", "slurp"},
GeneratedAt: time.Now().UTC(),
RAGConfidence: 0.92,
}
_, err = primary.UpsertContext(context.Background(), node)
require.NoError(t, err)
require.NoError(t, primary.Close())
restore, err := NewSLURP(cfg, nil, nil, nil)
require.NoError(t, err)
require.NoError(t, restore.Initialize(context.Background()))
t.Cleanup(func() {
_ = restore.Close()
})
// Clear in-memory caches to force disk hydration path.
restore.contextsMu.Lock()
restore.contextStore = make(map[string]*slurpContext.ContextNode)
restore.resolvedCache = make(map[string]*slurpContext.ResolvedContext)
restore.contextsMu.Unlock()
resolved, err := restore.Resolve(context.Background(), address.String())
require.NoError(t, err)
require.NotNil(t, resolved)
assert.Equal(t, node.Summary, resolved.Summary)
assert.Equal(t, node.Purpose, resolved.Purpose)
assert.Contains(t, resolved.Technologies, "Go")
}