1package modes
2
3import (
4 "testing"
5 "time"
6
7 "github.com/bnema/zut/packages/core"
8)
9
10func TestEventToJSONActivityLifecycle(t *testing.T) {
11 request := EventToJSON(core.EvRequestStarted{
12 Provider: "anthropic",
13 Model: "claude-test",
14 Scope: core.RetryScopeProvider,
15 Attempt: 2,
16 MaxAttempts: 3,
17 })
18 if got, want := request["type"], "request_started"; got != want {
19 t.Fatalf("type = %q, want %q", got, want)
20 }
21 for key, want := range map[string]any{
22 "provider": "anthropic",
23 "model": "claude-test",
24 "scope": "provider",
25 "attempt": 2,
26 "max_attempts": 3,
27 } {
28 if got := request[key]; got != want {
29 t.Errorf("request[%q] = %#v, want %#v", key, got, want)
30 }
31 }
32
33 retry := EventToJSON(core.EvRetryScheduled{
34 Scope: core.RetryScopeAgent, Attempt: 2, MaxAttempts: 4, Delay: 1500 * time.Millisecond,
35 })
36 if got, want := retry["delay_ms"], int64(1500); got != want {
37 t.Fatalf("delay_ms = %#v, want %#v", got, want)
38 }
39 if _, exists := retry["delay"]; exists {
40 t.Fatal("retry event must not serialize a duration")
41 }
42
43 tool := EventToJSON(core.EvToolExecutionStarted{ID: "call-1", Name: "read"})
44 if got, want := tool["type"], "tool_execution_started"; got != want {
45 t.Fatalf("type = %q, want %q", got, want)
46 }
47 if tool["id"] != "call-1" || tool["name"] != "read" {
48 t.Fatalf("tool event = %#v", tool)
49 }
50}