forked from lovyou-ai/agent
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathspec_test.go
More file actions
133 lines (124 loc) · 3.97 KB
/
Copy pathspec_test.go
File metadata and controls
133 lines (124 loc) · 3.97 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
package agent
import (
"strings"
"testing"
"time"
egagent "github.com/transpara-ai/eventgraph/go/pkg/agent"
"github.com/transpara-ai/eventgraph/go/pkg/event"
"github.com/transpara-ai/eventgraph/go/pkg/types"
)
type specEmitCase struct {
name string
wantType string
emit func(a *Agent) error
}
func specEmitCases() []specEmitCase {
now := time.Unix(1700000000, 0).UTC()
return []specEmitCase{
{
name: "EmitSpecIngested",
wantType: "hive.spec.ingested",
emit: func(a *Agent) error {
return a.EmitSpecIngested(event.SpecIngestedContent{
SpecRef: "spec_test_1",
SourceOpID: types.MustEventID("01900000-0000-7000-8000-000000000003"),
IngestedAt: now,
})
},
},
{
name: "EmitSpecCompleted",
wantType: "hive.spec.completed",
emit: func(a *Agent) error {
return a.EmitSpecCompleted(event.SpecCompletedContent{
SpecRef: "spec_test_1",
Outcome: "success",
CompletedAt: now,
})
},
},
{
name: "EmitRefineryIntakeReceived",
wantType: "refinery.intake.received",
emit: func(a *Agent) error {
return a.EmitRefineryIntakeReceived(event.RefineryIntakeReceivedContent{IntakeRef: "site-node-1", SpaceID: "space-1", Title: "Spec", Actor: "Tester", ActorID: "u1", ArtifactCount: 1, ReceivedAt: now})
},
},
{
name: "EmitRefineryArtifactAttached",
wantType: "refinery.artifact.attached",
emit: func(a *Agent) error {
return a.EmitRefineryArtifactAttached(event.RefineryArtifactAttachedContent{IntakeRef: "site-node-1", ArtifactRef: "doc-1", Filename: "spec.md", Hash: "sha256:abc", AttachedAt: now})
},
},
{
name: "EmitRefineryIntakeClassified",
wantType: "refinery.intake.classified",
emit: func(a *Agent) error {
return a.EmitRefineryIntakeClassified(event.RefineryIntakeClassifiedContent{IntakeRef: "site-node-1", ClassifierKind: "spec", RecommendedState: "spec.draft", PersistedState: "intake.raw", ArtifactCount: 1, ClassifiedAt: now})
},
},
{
name: "EmitRefineryStateTransitioned",
wantType: "refinery.state.transitioned",
emit: func(a *Agent) error {
return a.EmitRefineryStateTransitioned(event.RefineryStateTransitionedContent{IntakeRef: "site-node-1", FromState: "", ToState: "intake.raw", Reason: "all submissions start as raw intake", TransitionedAt: now})
},
},
}
}
func TestSpecEmittersHappyPath(t *testing.T) {
for _, tc := range specEmitCases() {
t.Run(tc.name, func(t *testing.T) {
a := newTestAgent(t, tc.name+"_happy")
if err := tc.emit(a); err != nil {
t.Fatalf("%s: unexpected error: %v", tc.name, err)
}
last := a.LastEvent()
if last.IsZero() {
t.Fatalf("%s: LastEvent is zero after emit", tc.name)
}
ev, err := a.Graph().Store().Get(last)
if err != nil {
t.Fatalf("%s: Get(%s): %v", tc.name, last.Value(), err)
}
if got := ev.Type().Value(); got != tc.wantType {
t.Fatalf("%s: emitted event type = %q, want %q", tc.name, got, tc.wantType)
}
})
}
}
func TestSpecEmittersRetired(t *testing.T) {
for _, tc := range specEmitCases() {
t.Run(tc.name, func(t *testing.T) {
a := newTestAgent(t, tc.name+"_retired")
a.mu.Lock()
a.state = egagent.StateRetired
a.mu.Unlock()
err := tc.emit(a)
if err == nil {
t.Fatalf("%s: expected error on retired agent, got nil", tc.name)
}
if !strings.Contains(err.Error(), "agent is retired") {
t.Fatalf("%s: error = %q, want it to contain %q", tc.name, err.Error(), "agent is retired")
}
})
}
}
func TestSpecEmittersSuspended(t *testing.T) {
for _, tc := range specEmitCases() {
t.Run(tc.name, func(t *testing.T) {
a := newTestAgent(t, tc.name+"_suspended")
a.mu.Lock()
a.state = egagent.StateSuspended
a.mu.Unlock()
err := tc.emit(a)
if err == nil {
t.Fatalf("%s: expected error on suspended agent, got nil", tc.name)
}
if !strings.Contains(err.Error(), "agent is suspended") {
t.Fatalf("%s: error = %q, want it to contain %q", tc.name, err.Error(), "agent is suspended")
}
})
}
}