Module: A2A::TestHelpers

Defined in:
lib/a2a/test_helpers.rb

Class Method Summary collapse

Class Method Details

.stub_agentObject

Returns a stub agent that handles all A2A operations with minimal valid responses. Useful for integration tests that need a working server without real business logic.



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
# File 'lib/a2a/test_helpers.rb', line 13

def self.stub_agent
  Agent.new do
    on "SendMessage" do
      respond_with -> (env) {
        A2A::Schema["Send Message Response"].new({})
      }
    end

    on "SendStreamingMessage" do
      respond_with -> (env) {
        A2A::Schema["Stream Response"].new({})
      }
    end

    on "GetTask" do
      respond_with -> (env) {
        A2A::Schema["Task"].new(
          "id"        => "test-id",
          "contextId" => "ctx-1",
          "status"    => { "state" => "TASK_STATE_COMPLETED", "timestamp" => "2025-01-01T00:00:00Z" }
        )
      }
    end

    on "ListTasks" do
      respond_with -> (env) {
        A2A::Schema["List Tasks Response"].new({})
      }
    end

    on "CancelTask" do
      respond_with -> (env) {
        A2A::Schema["Task"].new(
          "id"        => "test-id",
          "contextId" => "ctx-1",
          "status"    => { "state" => "TASK_STATE_CANCELED", "timestamp" => "2025-01-01T00:00:00Z" }
        )
      }
    end

    on "SubscribeToTask" do
      respond_with -> (env) {
        A2A::Schema["Stream Response"].new({})
      }
    end

    on "CreateTaskPushNotificationConfig" do
      respond_with -> (env) {
        A2A::Schema["Task Push Notification Config"].new("url" => "http://example.com")
      }
    end

    on "GetTaskPushNotificationConfig" do
      respond_with -> (env) {
        A2A::Schema["Task Push Notification Config"].new("url" => "http://example.com")
      }
    end

    on "ListTaskPushNotificationConfigs" do
      respond_with -> (env) {
        A2A::Schema["List Task Push Notification Configs Response"].new({})
      }
    end

    on "GetExtendedAgentCard" do
      respond_with -> (env) {
        A2A::Schema["Agent Card"].new("name" => "Test", "version" => "1.0")
      }
    end

    on "DeleteTaskPushNotificationConfig" do
      respond_with -> (env) { nil }
    end
  end
end