Files
CHORUS/pkg/slurp/temporal/test_helpers.go

133 lines
4.0 KiB
Go

package temporal
import (
"context"
"fmt"
"time"
slurpContext "chorus/pkg/slurp/context"
"chorus/pkg/slurp/storage"
"chorus/pkg/ucxl"
)
// mockStorage provides an in-memory implementation of the storage interfaces used by temporal tests.
type mockStorage struct {
data map[string]interface{}
}
func newMockStorage() *mockStorage {
return &mockStorage{
data: make(map[string]interface{}),
}
}
func (ms *mockStorage) StoreContext(ctx context.Context, node *slurpContext.ContextNode, roles []string) error {
ms.data[node.UCXLAddress.String()] = node
return nil
}
func (ms *mockStorage) RetrieveContext(ctx context.Context, address ucxl.Address, role string) (*slurpContext.ContextNode, error) {
if data, exists := ms.data[address.String()]; exists {
return data.(*slurpContext.ContextNode), nil
}
return nil, storage.ErrNotFound
}
func (ms *mockStorage) UpdateContext(ctx context.Context, node *slurpContext.ContextNode, roles []string) error {
ms.data[node.UCXLAddress.String()] = node
return nil
}
func (ms *mockStorage) DeleteContext(ctx context.Context, address ucxl.Address) error {
delete(ms.data, address.String())
return nil
}
func (ms *mockStorage) ExistsContext(ctx context.Context, address ucxl.Address) (bool, error) {
_, exists := ms.data[address.String()]
return exists, nil
}
func (ms *mockStorage) ListContexts(ctx context.Context, criteria *storage.ListCriteria) ([]*slurpContext.ContextNode, error) {
results := make([]*slurpContext.ContextNode, 0)
for _, data := range ms.data {
if node, ok := data.(*slurpContext.ContextNode); ok {
results = append(results, node)
}
}
return results, nil
}
func (ms *mockStorage) SearchContexts(ctx context.Context, query *storage.SearchQuery) (*storage.SearchResults, error) {
return &storage.SearchResults{}, nil
}
func (ms *mockStorage) BatchStore(ctx context.Context, batch *storage.BatchStoreRequest) (*storage.BatchStoreResult, error) {
return &storage.BatchStoreResult{}, nil
}
func (ms *mockStorage) BatchRetrieve(ctx context.Context, batch *storage.BatchRetrieveRequest) (*storage.BatchRetrieveResult, error) {
return &storage.BatchRetrieveResult{}, nil
}
func (ms *mockStorage) GetStorageStats(ctx context.Context) (*storage.StorageStatistics, error) {
return &storage.StorageStatistics{}, nil
}
func (ms *mockStorage) Sync(ctx context.Context) error {
return nil
}
func (ms *mockStorage) Backup(ctx context.Context, destination string) error {
return nil
}
func (ms *mockStorage) Restore(ctx context.Context, source string) error {
return nil
}
// createTestAddress constructs a deterministic UCXL address for test scenarios.
func createTestAddress(path string) ucxl.Address {
return ucxl.Address{
Agent: "test-agent",
Role: "tester",
Project: "test-project",
Task: "unit-test",
TemporalSegment: ucxl.TemporalSegment{
Type: ucxl.TemporalLatest,
},
Path: path,
Raw: fmt.Sprintf("ucxl://test-agent:tester@test-project:unit-test/*^/%s", path),
}
}
// createTestContext prepares a lightweight context node for graph operations.
func createTestContext(path string, technologies []string) *slurpContext.ContextNode {
return &slurpContext.ContextNode{
Path: path,
UCXLAddress: createTestAddress(path),
Summary: fmt.Sprintf("Test context for %s", path),
Purpose: fmt.Sprintf("Test purpose for %s", path),
Technologies: technologies,
Tags: []string{"test"},
Insights: []string{"test insight"},
GeneratedAt: time.Now(),
RAGConfidence: 0.8,
}
}
// createTestDecision fabricates decision metadata to drive evolution in tests.
func createTestDecision(id, maker, rationale string, scope ImpactScope) *DecisionMetadata {
return &DecisionMetadata{
ID: id,
Maker: maker,
Rationale: rationale,
Scope: scope,
ConfidenceLevel: 0.8,
ExternalRefs: []string{},
CreatedAt: time.Now(),
ImplementationStatus: "complete",
Metadata: make(map[string]interface{}),
}
}