Wire SLURP persistence and add restart coverage
This commit is contained in:
69
pkg/slurp/slurp_persistence_test.go
Normal file
69
pkg/slurp/slurp_persistence_test.go
Normal 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")
|
||||
}
|
||||
Reference in New Issue
Block a user