Skip to content

Commit ac56dfb

Browse files
committed
fixes for CI
1 parent d92fdc2 commit ac56dfb

File tree

4 files changed

+269
-4
lines changed

4 files changed

+269
-4
lines changed

.golangci.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ linters:
1111
- staticcheck
1212
- ineffassign
1313
- typecheck
14-
- unused
1514
- gosimple
1615
- gosec
1716
- misspell
@@ -23,9 +22,6 @@ linters:
2322
- gocyclo
2423
- gocognit
2524

26-
disable:
27-
- unused # False positives on some fields
28-
2925
linters-settings:
3026
gofmt:
3127
simplify: true

pkg/agent/agent_test.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package agent
2+
3+
import (
4+
"testing"
5+
)
6+
7+
func TestMessageType(t *testing.T) {
8+
msg := Message{
9+
AgentID: "test-agent",
10+
AgentName: "Test Agent",
11+
Content: "Test message",
12+
Timestamp: 1234567890,
13+
Role: "agent",
14+
}
15+
16+
if msg.AgentID != "test-agent" {
17+
t.Errorf("Expected AgentID to be 'test-agent', got %s", msg.AgentID)
18+
}
19+
20+
if msg.AgentName != "Test Agent" {
21+
t.Errorf("Expected AgentName to be 'Test Agent', got %s", msg.AgentName)
22+
}
23+
24+
if msg.Content != "Test message" {
25+
t.Errorf("Expected Content to be 'Test message', got %s", msg.Content)
26+
}
27+
28+
if msg.Role != "agent" {
29+
t.Errorf("Expected Role to be 'agent', got %s", msg.Role)
30+
}
31+
}
32+
33+
func TestResponseMetrics(t *testing.T) {
34+
metrics := &ResponseMetrics{
35+
InputTokens: 100,
36+
OutputTokens: 50,
37+
TotalTokens: 150,
38+
Model: "test-model",
39+
Cost: 0.001,
40+
}
41+
42+
if metrics.TotalTokens != 150 {
43+
t.Errorf("Expected TotalTokens to be 150, got %d", metrics.TotalTokens)
44+
}
45+
46+
if metrics.Cost != 0.001 {
47+
t.Errorf("Expected Cost to be 0.001, got %f", metrics.Cost)
48+
}
49+
}

pkg/config/config_test.go

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
package config
2+
3+
import (
4+
"strings"
5+
"testing"
6+
"time"
7+
8+
"github.com/kevinelliott/agentpipe/pkg/agent"
9+
)
10+
11+
func TestNewDefaultConfig(t *testing.T) {
12+
cfg := NewDefaultConfig()
13+
14+
if cfg.Version != "1.0" {
15+
t.Errorf("Expected Version to be '1.0', got %s", cfg.Version)
16+
}
17+
18+
if cfg.Orchestrator.Mode != "round-robin" {
19+
t.Errorf("Expected default mode to be 'round-robin', got %s", cfg.Orchestrator.Mode)
20+
}
21+
22+
if cfg.Orchestrator.MaxTurns != 10 {
23+
t.Errorf("Expected default MaxTurns to be 10, got %d", cfg.Orchestrator.MaxTurns)
24+
}
25+
26+
if cfg.Orchestrator.TurnTimeout != 30*time.Second {
27+
t.Errorf("Expected default TurnTimeout to be 30s, got %v", cfg.Orchestrator.TurnTimeout)
28+
}
29+
30+
if !cfg.Logging.Enabled {
31+
t.Error("Expected logging to be enabled by default")
32+
}
33+
34+
if !strings.Contains(cfg.Logging.ChatLogDir, ".agentpipe/chats") {
35+
t.Errorf("Expected ChatLogDir to contain '.agentpipe/chats', got %s", cfg.Logging.ChatLogDir)
36+
}
37+
}
38+
39+
func TestConfigValidate(t *testing.T) {
40+
tests := []struct {
41+
name string
42+
config *Config
43+
wantErr bool
44+
errMsg string
45+
}{
46+
{
47+
name: "empty agents",
48+
config: &Config{
49+
Agents: []agent.AgentConfig{},
50+
},
51+
wantErr: true,
52+
errMsg: "at least one agent must be configured",
53+
},
54+
{
55+
name: "duplicate agent IDs",
56+
config: &Config{
57+
Agents: []agent.AgentConfig{
58+
{ID: "agent1", Type: "claude", Name: "Agent 1"},
59+
{ID: "agent1", Type: "gemini", Name: "Agent 2"},
60+
},
61+
},
62+
wantErr: true,
63+
errMsg: "duplicate agent ID",
64+
},
65+
{
66+
name: "invalid mode",
67+
config: &Config{
68+
Agents: []agent.AgentConfig{
69+
{ID: "agent1", Type: "claude", Name: "Agent 1"},
70+
},
71+
Orchestrator: OrchestratorConfig{
72+
Mode: "invalid-mode",
73+
},
74+
},
75+
wantErr: true,
76+
errMsg: "invalid orchestrator mode",
77+
},
78+
{
79+
name: "valid config",
80+
config: &Config{
81+
Agents: []agent.AgentConfig{
82+
{ID: "agent1", Type: "claude", Name: "Agent 1"},
83+
{ID: "agent2", Type: "gemini", Name: "Agent 2"},
84+
},
85+
Orchestrator: OrchestratorConfig{
86+
Mode: "round-robin",
87+
MaxTurns: 10,
88+
},
89+
},
90+
wantErr: false,
91+
},
92+
}
93+
94+
for _, tt := range tests {
95+
t.Run(tt.name, func(t *testing.T) {
96+
err := tt.config.Validate()
97+
if (err != nil) != tt.wantErr {
98+
t.Errorf("Validate() error = %v, wantErr %v", err, tt.wantErr)
99+
}
100+
if err != nil && tt.errMsg != "" && !strings.Contains(err.Error(), tt.errMsg) {
101+
t.Errorf("Validate() error message = %v, want to contain %v", err.Error(), tt.errMsg)
102+
}
103+
})
104+
}
105+
}

pkg/utils/tokens_test.go

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
package utils
2+
3+
import (
4+
"testing"
5+
)
6+
7+
func TestEstimateTokens(t *testing.T) {
8+
tests := []struct {
9+
name string
10+
text string
11+
expected int
12+
delta int // allowed difference
13+
}{
14+
{
15+
name: "empty string",
16+
text: "",
17+
expected: 0,
18+
delta: 0,
19+
},
20+
{
21+
name: "single word",
22+
text: "hello",
23+
expected: 1,
24+
delta: 1,
25+
},
26+
{
27+
name: "short sentence",
28+
text: "The quick brown fox jumps over the lazy dog",
29+
expected: 9,
30+
delta: 3,
31+
},
32+
{
33+
name: "with punctuation",
34+
text: "Hello, world! How are you today?",
35+
expected: 8,
36+
delta: 2,
37+
},
38+
{
39+
name: "with numbers",
40+
text: "The year 2024 has 365 days",
41+
expected: 8,
42+
delta: 2,
43+
},
44+
}
45+
46+
for _, tt := range tests {
47+
t.Run(tt.name, func(t *testing.T) {
48+
got := EstimateTokens(tt.text)
49+
diff := got - tt.expected
50+
if diff < 0 {
51+
diff = -diff
52+
}
53+
if diff > tt.delta {
54+
t.Errorf("EstimateTokens() = %v, want %v ± %v", got, tt.expected, tt.delta)
55+
}
56+
})
57+
}
58+
}
59+
60+
func TestEstimateCost(t *testing.T) {
61+
tests := []struct {
62+
name string
63+
model string
64+
inputTokens int
65+
outputTokens int
66+
wantCost float64
67+
delta float64
68+
}{
69+
{
70+
name: "claude-3-opus",
71+
model: "claude-3-opus",
72+
inputTokens: 1000,
73+
outputTokens: 500,
74+
wantCost: 0.0525, // Current implementation returns this
75+
delta: 0.0001,
76+
},
77+
{
78+
name: "gpt-4",
79+
model: "gpt-4",
80+
inputTokens: 1000,
81+
outputTokens: 500,
82+
wantCost: 0.06, // Current implementation returns this
83+
delta: 0.0001,
84+
},
85+
{
86+
name: "unknown model",
87+
model: "unknown",
88+
inputTokens: 1000,
89+
outputTokens: 500,
90+
wantCost: 0, // unknown model returns 0
91+
delta: 0.0000001,
92+
},
93+
{
94+
name: "zero tokens",
95+
model: "claude-3-opus",
96+
inputTokens: 0,
97+
outputTokens: 0,
98+
wantCost: 0,
99+
delta: 0,
100+
},
101+
}
102+
103+
for _, tt := range tests {
104+
t.Run(tt.name, func(t *testing.T) {
105+
got := EstimateCost(tt.model, tt.inputTokens, tt.outputTokens)
106+
diff := got - tt.wantCost
107+
if diff < 0 {
108+
diff = -diff
109+
}
110+
if diff > tt.delta {
111+
t.Errorf("EstimateCost() = %v, want %v ± %v", got, tt.wantCost, tt.delta)
112+
}
113+
})
114+
}
115+
}

0 commit comments

Comments
 (0)