70 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			70 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| 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")
 | |
| }
 | 
