| 1 | package agent |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "encoding/json" |
| 6 | "testing" |
| 7 | |
| 8 | "reasonix/internal/event" |
| 9 | "reasonix/internal/tool" |
| 10 | ) |
| 11 | |
| 12 | type typedNilAgentSink struct{} |
| 13 | |
| 14 | func (*typedNilAgentSink) Emit(event.Event) {} |
| 15 | |
| 16 | type typedNilGate struct{} |
| 17 | |
| 18 | func (*typedNilGate) Check(context.Context, string, json.RawMessage, bool) (bool, string, error) { |
| 19 | return true, "", nil |
| 20 | } |
| 21 | |
| 22 | type typedNilHooks struct{} |
| 23 | |
| 24 | func (*typedNilHooks) PreToolUse(context.Context, string, json.RawMessage) (bool, string) { |
| 25 | return false, "" |
| 26 | } |
| 27 | func (*typedNilHooks) PostToolUse(context.Context, string, json.RawMessage, string) {} |
| 28 | func (*typedNilHooks) PostToolUseFailure(context.Context, string, json.RawMessage, string, error) {} |
| 29 | func (*typedNilHooks) PostLLMCall(context.Context, string, int) string { return "" } |
| 30 | func (*typedNilHooks) HasPostLLMCall() bool { return false } |
| 31 | func (*typedNilHooks) SubagentStop(context.Context, string) {} |
| 32 | func (*typedNilHooks) PreCompact(context.Context, string) string { return "" } |
| 33 | |
| 34 | func TestNewNormalizesTypedNilInterfaces(t *testing.T) { |
| 35 | var sink *typedNilAgentSink |
| 36 | var gate *typedNilGate |
| 37 | var hooks *typedNilHooks |
| 38 | |
| 39 | a := New(nil, tool.NewRegistry(), NewSession(""), Options{Gate: gate, Hooks: hooks}, sink) |
| 40 | a.sink.Emit(event.Event{Kind: event.Text, Text: "typed nil sink should not panic"}) |
| 41 | if a.gate != nil { |
| 42 | t.Fatal("typed nil gate should be normalized to nil") |
| 43 | } |
| 44 | if a.hooks != nil { |
| 45 | t.Fatal("typed nil hooks should be normalized to nil") |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | func TestSetGateNormalizesTypedNil(t *testing.T) { |
| 50 | var gate *typedNilGate |
| 51 | a := New(nil, tool.NewRegistry(), NewSession(""), Options{}, event.Discard) |
| 52 | |
| 53 | a.SetGate(gate) |
| 54 | if a.gate != nil { |
| 55 | t.Fatal("typed nil gate should be normalized to nil") |
| 56 | } |
| 57 | } |
| 58 |