/ internal / agent / resultshape_test.go
resultshape_test.go
 1  package agent
 2  
 3  import (
 4  	"strings"
 5  	"testing"
 6  )
 7  
 8  func TestShapeContextResult_DefaultPassthrough(t *testing.T) {
 9  	content := "plain tool output"
10  	shaped := shapeContextResult("mock_tool", content, nil)
11  	if shaped.Text != content {
12  		t.Fatalf("expected default profile passthrough, got %q", shaped.Text)
13  	}
14  	if shaped.Signature != "" {
15  		t.Fatalf("expected no signature for default profile, got %q", shaped.Signature)
16  	}
17  }
18  
19  func TestShapeTreeResult_SummarizesLargeTree(t *testing.T) {
20  	content := strings.Repeat("button ref=e1234 label=Open\n", 150)
21  	shaped := shapeTreeResult(content, nil)
22  
23  	if !strings.Contains(shaped.Text, "[tree snapshot summary;") {
24  		t.Fatalf("expected tree summary header, got %q", shaped.Text)
25  	}
26  	if strings.Contains(shaped.Text, "ref=e1234") {
27  		t.Fatal("expected volatile ref IDs to be normalized out of the shaped result")
28  	}
29  	if !strings.Contains(shaped.Text, "ref=*") {
30  		t.Fatal("expected shaped tree excerpt to retain normalized ref markers")
31  	}
32  	if shaped.Signature == "" {
33  		t.Fatal("expected tree signature")
34  	}
35  }
36  
37  func TestShapeTreeResult_CollapsesUnchangedReads(t *testing.T) {
38  	content := strings.Repeat("button ref=e1234 label=Open\n", 150)
39  	first := shapeTreeResult(content, nil)
40  	second := shapeTreeResult(content, &first)
41  
42  	if !strings.Contains(second.Text, "unchanged since last read") {
43  		t.Fatalf("expected unchanged collapse, got %q", second.Text)
44  	}
45  	if second.Signature != first.Signature {
46  		t.Fatalf("expected matching signatures, got %q vs %q", second.Signature, first.Signature)
47  	}
48  }