107 lines
		
	
	
		
			3.5 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			107 lines
		
	
	
		
			3.5 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| //go:build !slurp_full
 | |
| // +build !slurp_full
 | |
| 
 | |
| package temporal
 | |
| 
 | |
| import (
 | |
| 	"context"
 | |
| 	"fmt"
 | |
| 	"testing"
 | |
| )
 | |
| 
 | |
| func TestTemporalGraphStubBasicLifecycle(t *testing.T) {
 | |
| 	storage := newMockStorage()
 | |
| 	graph := NewTemporalGraph(storage)
 | |
| 	ctx := context.Background()
 | |
| 
 | |
| 	address := createTestAddress("stub/basic")
 | |
| 	contextNode := createTestContext("stub/basic", []string{"go"})
 | |
| 
 | |
| 	node, err := graph.CreateInitialContext(ctx, address, contextNode, "tester")
 | |
| 	if err != nil {
 | |
| 		t.Fatalf("expected initial context creation to succeed, got error: %v", err)
 | |
| 	}
 | |
| 
 | |
| 	if node == nil {
 | |
| 		t.Fatal("expected non-nil temporal node for initial context")
 | |
| 	}
 | |
| 
 | |
| 	decision := createTestDecision("stub-dec-001", "tester", "initial evolution", ImpactLocal)
 | |
| 	evolved, err := graph.EvolveContext(ctx, address, createTestContext("stub/basic", []string{"go", "feature"}), ReasonCodeChange, decision)
 | |
| 	if err != nil {
 | |
| 		t.Fatalf("expected context evolution to succeed, got error: %v", err)
 | |
| 	}
 | |
| 
 | |
| 	if evolved.Version != node.Version+1 {
 | |
| 		t.Fatalf("expected version to increment, got %d after %d", evolved.Version, node.Version)
 | |
| 	}
 | |
| 
 | |
| 	latest, err := graph.GetLatestVersion(ctx, address)
 | |
| 	if err != nil {
 | |
| 		t.Fatalf("expected latest version retrieval to succeed, got error: %v", err)
 | |
| 	}
 | |
| 
 | |
| 	if latest.Version != evolved.Version {
 | |
| 		t.Fatalf("expected latest version %d, got %d", evolved.Version, latest.Version)
 | |
| 	}
 | |
| }
 | |
| 
 | |
| func TestTemporalInfluenceAnalyzerStub(t *testing.T) {
 | |
| 	storage := newMockStorage()
 | |
| 	graph := NewTemporalGraph(storage).(*temporalGraphImpl)
 | |
| 	analyzer := NewInfluenceAnalyzer(graph)
 | |
| 	ctx := context.Background()
 | |
| 
 | |
| 	addrA := createTestAddress("stub/serviceA")
 | |
| 	addrB := createTestAddress("stub/serviceB")
 | |
| 
 | |
| 	if _, err := graph.CreateInitialContext(ctx, addrA, createTestContext("stub/serviceA", []string{"go"}), "tester"); err != nil {
 | |
| 		t.Fatalf("failed to create context A: %v", err)
 | |
| 	}
 | |
| 	if _, err := graph.CreateInitialContext(ctx, addrB, createTestContext("stub/serviceB", []string{"go"}), "tester"); err != nil {
 | |
| 		t.Fatalf("failed to create context B: %v", err)
 | |
| 	}
 | |
| 
 | |
| 	if err := graph.AddInfluenceRelationship(ctx, addrA, addrB); err != nil {
 | |
| 		t.Fatalf("expected influence relationship to succeed, got error: %v", err)
 | |
| 	}
 | |
| 
 | |
| 	analysis, err := analyzer.AnalyzeInfluenceNetwork(ctx)
 | |
| 	if err != nil {
 | |
| 		t.Fatalf("expected influence analysis to succeed, got error: %v", err)
 | |
| 	}
 | |
| 
 | |
| 	if analysis.TotalNodes == 0 {
 | |
| 		t.Fatal("expected influence analysis to report at least one node")
 | |
| 	}
 | |
| }
 | |
| 
 | |
| func TestTemporalDecisionNavigatorStub(t *testing.T) {
 | |
| 	storage := newMockStorage()
 | |
| 	graph := NewTemporalGraph(storage).(*temporalGraphImpl)
 | |
| 	navigator := NewDecisionNavigator(graph)
 | |
| 	ctx := context.Background()
 | |
| 
 | |
| 	address := createTestAddress("stub/navigator")
 | |
| 	if _, err := graph.CreateInitialContext(ctx, address, createTestContext("stub/navigator", []string{"go"}), "tester"); err != nil {
 | |
| 		t.Fatalf("failed to create initial context: %v", err)
 | |
| 	}
 | |
| 
 | |
| 	for i := 2; i <= 3; i++ {
 | |
| 		id := fmt.Sprintf("stub-hop-%03d", i)
 | |
| 		decision := createTestDecision(id, "tester", "hop", ImpactLocal)
 | |
| 		if _, err := graph.EvolveContext(ctx, address, createTestContext("stub/navigator", []string{"go", "v"}), ReasonCodeChange, decision); err != nil {
 | |
| 			t.Fatalf("failed to evolve context to version %d: %v", i, err)
 | |
| 		}
 | |
| 	}
 | |
| 
 | |
| 	timeline, err := navigator.GetDecisionTimeline(ctx, address, false, 0)
 | |
| 	if err != nil {
 | |
| 		t.Fatalf("expected timeline retrieval to succeed, got error: %v", err)
 | |
| 	}
 | |
| 
 | |
| 	if timeline == nil || timeline.TotalDecisions == 0 {
 | |
| 		t.Fatal("expected non-empty decision timeline")
 | |
| 	}
 | |
| }
 | 
