Module: MockServer::A2A

Defined in:
lib/mockserver/a2a.rb

Overview

Fluent builder for mocking an A2A (Agent-to-Agent) agent.

Mirrors the Java A2aMockBuilder (and its Node/Python siblings). It produces the same wire-level expectation JSON: a set of HTTP expectations that emulate an A2A agent serving an agent card and speaking JSON-RPC 2.0 over +POST +. The generated control-plane expectations are:

* agent-card +GET <agent_card_path>+ (default +/.well-known/agent.json+);
* JSON-RPC +tasks/send+, +tasks/get+, +tasks/cancel+;
* optional SSE streaming (+with_streaming+);
* optional push-notification config + delivery (+with_push_notifications+);
* optional per-message custom task handlers (+on_task_send+);
* optional advertised skills (+with_skill+).

Each JSON-RPC response is a Velocity template that echoes the incoming JSON-RPC id back via $!{request.jsonRpcRawId}.

Examples:

MockServer::A2A.a2a_mock('/a2a')
  .with_agent_name('WeatherAgent')
  .with_skill('weather')
    .with_name('Weather lookup')
    .with_tag('forecast')
  .and_then
  .on_task_send
    .matching_message('forecast')
    .responding_with('Sunny, 25C')
  .and_then
  .apply_to(client)

Defined Under Namespace

Classes: A2aMockBuilder, A2aSkillBuilder, A2aTaskHandlerBuilder, RawExpectation, SkillDef, TaskHandler, WebhookTarget

Class Method Summary collapse

Class Method Details

.a2a_mock(path = '/a2a') ⇒ A2aMockBuilder

Create a new A2A mock builder. path defaults to /a2a.

Returns:



525
526
527
# File 'lib/mockserver/a2a.rb', line 525

def self.a2a_mock(path = '/a2a')
  A2aMockBuilder.new(path)
end

.escape_json(value) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

JSON-escape a string the same way Jackson writeValueAsString does, then strip the surrounding quotes — yielding only the escaped inner content.



40
41
42
43
44
45
# File 'lib/mockserver/a2a.rb', line 40

def self.escape_json(value)
  return '' if value.nil?

  quoted = JSON.generate(value.to_s)
  quoted[1...-1]
end

.escape_velocity(value) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Escape Velocity metacharacters so literal $ / # survive rendering.



49
50
51
52
53
# File 'lib/mockserver/a2a.rb', line 49

def self.escape_velocity(value)
  return value if value.nil?

  value.to_s.gsub('$', '${esc.d}').gsub('#', '${esc.h}')
end

.velocity_json_rpc_response(result_json) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



56
57
58
59
60
# File 'lib/mockserver/a2a.rb', line 56

def self.velocity_json_rpc_response(result_json)
  '{"statusCode": 200, ' \
    '"headers": [{"name": "Content-Type", "values": ["application/json"]}], ' \
    '"body": {"jsonrpc": "2.0", "result": ' + result_json + ', "id": $!{request.jsonRpcRawId}}}'
end