-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathengine_test.go
More file actions
144 lines (130 loc) · 4.23 KB
/
Copy pathengine_test.go
File metadata and controls
144 lines (130 loc) · 4.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package omnidevx
import (
"context"
"errors"
"path/filepath"
"strings"
"testing"
"time"
core "github.com/plexusone/omnidevx-core"
)
type fakeCollector struct {
source core.Source
events []core.Event
err error
}
func (f *fakeCollector) Source() core.Source { return f.source }
func (f *fakeCollector) Collect(_ context.Context, req core.CollectRequest) (*core.CollectionResult, error) {
if f.err != nil {
return nil, f.err
}
return &core.CollectionResult{
Source: f.source,
Subject: req.Subject,
Period: req.Period,
Events: f.events,
CollectedAt: time.Now().UTC(),
}, nil
}
var _ core.Collector = (*fakeCollector)(nil)
func TestEngineCollectAll(t *testing.T) {
a := &fakeCollector{
source: core.Source{Provider: "anthropic", Product: "claude-code"},
events: []core.Event{{ID: "a:1", Type: core.EventPromptSubmitted}},
}
b := &fakeCollector{
source: core.Source{Provider: "openai", Product: "codex-cli"},
events: []core.Event{{ID: "b:1", Type: core.EventToolCompleted}, {ID: "b:2", Type: core.EventTaskCompleted}},
}
results, err := New(a, b).Collect(context.Background(), core.CollectRequest{})
if err != nil {
t.Fatal(err)
}
if len(results) != 2 {
t.Fatalf("results: got %d, want 2", len(results))
}
events := Events(results)
if len(events) != 3 {
t.Errorf("flattened events: got %d, want 3", len(events))
}
}
func TestEngineIsolatesFailures(t *testing.T) {
sentinel := errors.New("store locked")
failing := &fakeCollector{
source: core.Source{Provider: "openai", Product: "codex-cli"},
err: sentinel,
}
working := &fakeCollector{
source: core.Source{Provider: "anthropic", Product: "claude-code"},
events: []core.Event{{ID: "a:1", Type: core.EventPromptSubmitted}},
}
results, err := New(failing, working).Collect(context.Background(), core.CollectRequest{})
if err == nil {
t.Fatal("expected joined error, got nil")
}
if !errors.Is(err, sentinel) {
t.Errorf("error should wrap the sentinel: %v", err)
}
if !strings.Contains(err.Error(), "openai/codex-cli") {
t.Errorf("error should name the failing source: %v", err)
}
if len(results) != 1 {
t.Fatalf("surviving results: got %d, want 1", len(results))
}
if results[0].Source.Product != "claude-code" {
t.Errorf("surviving result: got %s", results[0].Source.Product)
}
}
func TestEngineAddAndCollectors(t *testing.T) {
a := &fakeCollector{source: core.Source{Provider: "x", Product: "a"}}
b := &fakeCollector{source: core.Source{Provider: "x", Product: "b"}}
e := New(a).Add(b)
if got := len(e.Collectors()); got != 2 {
t.Errorf("collectors: got %d, want 2", got)
}
}
func TestEngineCanceledContext(t *testing.T) {
a := &fakeCollector{source: core.Source{Provider: "x", Product: "a"}}
ctx, cancel := context.WithCancel(context.Background())
cancel()
if _, err := New(a).Collect(ctx, core.CollectRequest{}); !errors.Is(err, context.Canceled) {
t.Errorf("expected context.Canceled, got %v", err)
}
}
// TestProviderConstructors proves the re-exported constructors compose real
// providers into the engine against empty stores.
func TestProviderConstructors(t *testing.T) {
claude, err := NewClaudeCodeCollector(ClaudeCodeOptions{Dir: t.TempDir()})
if err != nil {
t.Fatal(err)
}
cdx, err := NewCodexCollector(CodexConfig{Dir: t.TempDir()})
if err != nil {
t.Fatal(err)
}
kiro, err := NewKiroCollector(KiroConfig{DBPath: filepath.Join(t.TempDir(), "missing.sqlite3"), SessionsDir: t.TempDir()})
if err != nil {
t.Fatal(err)
}
engine := New(claude, cdx, kiro)
// Claude's collector errors on a missing projects/ dir; Codex and Kiro
// tolerate empty stores. The engine must surface the former and keep the
// latter two.
results, err := engine.Collect(context.Background(), CollectRequest{})
if err == nil {
t.Fatal("expected error from claude collector on empty dir")
}
if !strings.Contains(err.Error(), "anthropic/claude-code") {
t.Errorf("error should name claude collector: %v", err)
}
if len(results) != 2 {
t.Fatalf("expected two surviving results, got %+v", results)
}
products := map[string]bool{}
for _, r := range results {
products[r.Source.Product] = true
}
if !products["codex-cli"] || !products["kiro-cli"] {
t.Fatalf("expected surviving codex and kiro results, got %+v", results)
}
}