@@ -116,8 +116,10 @@ def test_to_create_input_minimal():
116116 assert len (settings ) == 1
117117 cfg_dict = json .loads (settings [0 ]["config" ])
118118 assert cfg_dict ["path" ] == "/invoke"
119- assert cfg_dict ["agents" ] == []
120- assert cfg_dict ["metadata" ] == {"agentRuntimeName" : "alpha" }
119+ assert cfg_dict ["headers" ] == {}
120+ forwarded = cfg_dict ["body" ]["forwardedProps" ]
121+ assert forwarded ["agents" ] == []
122+ assert forwarded ["metadata" ] == {"agentRuntimeName" : "alpha" }
121123
122124
123125def test_to_create_input_full ():
@@ -136,14 +138,17 @@ def test_to_create_input_full():
136138 )
137139 pc_dict = inp .model_dump ()["protocolConfiguration" ]
138140 settings_cfg = json .loads (pc_dict ["protocolSettings" ][0 ]["config" ])
139- assert settings_cfg ["prompt" ] == "hello"
140- assert settings_cfg ["agents" ] == ["a1" ]
141- assert settings_cfg ["tools" ] == ["t1" , "t2" ]
142- assert settings_cfg ["skills" ] == ["s1" ]
143- assert settings_cfg ["sandboxes" ] == ["sb1" ]
144- assert settings_cfg ["workspaces" ] == ["ws1" ]
145- assert settings_cfg ["modelServiceName" ] == "foo"
146- assert settings_cfg ["modelName" ] == "bar"
141+ assert settings_cfg ["path" ] == "/invoke"
142+ assert settings_cfg ["headers" ] == {}
143+ forwarded = settings_cfg ["body" ]["forwardedProps" ]
144+ assert forwarded ["prompt" ] == "hello"
145+ assert forwarded ["agents" ] == ["a1" ]
146+ assert forwarded ["tools" ] == ["t1" , "t2" ]
147+ assert forwarded ["skills" ] == ["s1" ]
148+ assert forwarded ["sandboxes" ] == ["sb1" ]
149+ assert forwarded ["workspaces" ] == ["ws1" ]
150+ assert forwarded ["modelServiceName" ] == "foo"
151+ assert forwarded ["modelName" ] == "bar"
147152
148153
149154def test_to_create_input_tags_fixed ():
@@ -158,7 +163,9 @@ def test_to_create_input_metadata_only_agent_runtime_name():
158163 settings_cfg = json .loads (
159164 inp .protocol_configuration .protocol_settings [0 ]["config" ]
160165 )
161- assert settings_cfg ["metadata" ] == {"agentRuntimeName" : "d" }
166+ assert settings_cfg ["body" ]["forwardedProps" ]["metadata" ] == {
167+ "agentRuntimeName" : "d"
168+ }
162169
163170
164171def test_to_create_input_uses_pre_environment_endpoint ():
@@ -194,15 +201,21 @@ def _make_rt(**kwargs):
194201
195202def test_from_agent_runtime ():
196203 config_json = json .dumps ({
197- "prompt" : "hi" ,
198- "agents" : ["a" ],
199- "tools" : ["t" ],
200- "skills" : [],
201- "sandboxes" : [],
202- "workspaces" : [],
203- "modelServiceName" : "svc" ,
204- "modelName" : "mod" ,
205- "metadata" : {"agentRuntimeName" : "foo" },
204+ "path" : "/invoke" ,
205+ "headers" : {},
206+ "body" : {
207+ "forwardedProps" : {
208+ "prompt" : "hi" ,
209+ "agents" : ["a" ],
210+ "tools" : ["t" ],
211+ "skills" : [],
212+ "sandboxes" : [],
213+ "workspaces" : [],
214+ "modelServiceName" : "svc" ,
215+ "modelName" : "mod" ,
216+ "metadata" : {"agentRuntimeName" : "foo" },
217+ }
218+ },
206219 })
207220 pc = {
208221 "type" : SUPER_AGENT_PROTOCOL_TYPE ,
@@ -227,6 +240,89 @@ def test_from_agent_runtime():
227240 )
228241
229242
243+ def test_from_agent_runtime_legacy_flat_config ():
244+ """旧结构兼容: config 是扁平 dict, 业务字段直接在根 (历史 AgentRuntime)."""
245+ config_json = json .dumps ({
246+ "prompt" : "legacy" ,
247+ "agents" : ["la" ],
248+ "tools" : ["lt" ],
249+ "skills" : [],
250+ "sandboxes" : [],
251+ "workspaces" : [],
252+ "modelServiceName" : "legacy-svc" ,
253+ "modelName" : "legacy-mod" ,
254+ "metadata" : {"agentRuntimeName" : "legacy" },
255+ })
256+ pc = {
257+ "type" : SUPER_AGENT_PROTOCOL_TYPE ,
258+ "protocolSettings" : [{
259+ "type" : SUPER_AGENT_PROTOCOL_TYPE ,
260+ "config" : config_json ,
261+ "name" : "legacy" ,
262+ "path" : "/invoke" ,
263+ }],
264+ "externalEndpoint" : "https://x.com/super-agents/__SUPER_AGENT__" ,
265+ }
266+ rt = _make_rt (agent_runtime_name = "legacy" , protocol_configuration = pc )
267+ agent = from_agent_runtime (rt )
268+ assert agent .prompt == "legacy"
269+ assert agent .agents == ["la" ]
270+ assert agent .model_service_name == "legacy-svc"
271+
272+
273+ def test_parse_super_agent_config_dict_config_new_structure ():
274+ """config 已经是 dict (非字符串) 时也能拍平."""
275+ pc = {
276+ "type" : SUPER_AGENT_PROTOCOL_TYPE ,
277+ "protocolSettings" : [{
278+ "type" : SUPER_AGENT_PROTOCOL_TYPE ,
279+ "config" : {
280+ "path" : "/invoke" ,
281+ "headers" : {},
282+ "body" : {
283+ "forwardedProps" : {
284+ "prompt" : "p" ,
285+ "agents" : [],
286+ }
287+ },
288+ },
289+ }],
290+ }
291+ business = parse_super_agent_config (_make_rt (protocol_configuration = pc ))
292+ assert business ["prompt" ] == "p"
293+ assert business ["agents" ] == []
294+
295+
296+ def test_parse_super_agent_config_dict_config_legacy_flat ():
297+ """config 是 dict + 旧扁平结构时走 fallback, 原样返回."""
298+ pc = {
299+ "type" : SUPER_AGENT_PROTOCOL_TYPE ,
300+ "protocolSettings" : [{
301+ "type" : SUPER_AGENT_PROTOCOL_TYPE ,
302+ "config" : {"prompt" : "legacy-dict" , "agents" : ["la" ]},
303+ }],
304+ }
305+ business = parse_super_agent_config (_make_rt (protocol_configuration = pc ))
306+ assert business == {"prompt" : "legacy-dict" , "agents" : ["la" ]}
307+
308+
309+ def test_flatten_protocol_config_non_dict_returns_empty ():
310+ """非 dict 输入 (防御分支) 返回空 dict."""
311+ from agentrun .super_agent .api .control import _flatten_protocol_config
312+
313+ assert _flatten_protocol_config (None ) == {}
314+ assert _flatten_protocol_config ("not-a-dict" ) == {}
315+ assert _flatten_protocol_config ([1 , 2 , 3 ]) == {}
316+
317+
318+ def test_flatten_protocol_config_body_without_forwarded_props ():
319+ """body 存在但缺 forwardedProps → fallback 到整个 cfg (旧结构)."""
320+ from agentrun .super_agent .api .control import _flatten_protocol_config
321+
322+ cfg = {"body" : {"other" : "x" }, "prompt" : "flat" }
323+ assert _flatten_protocol_config (cfg ) == cfg
324+
325+
230326def test_is_super_agent_true ():
231327 pc = {
232328 "type" : SUPER_AGENT_PROTOCOL_TYPE ,
@@ -280,10 +376,11 @@ def test_to_update_input_full_protocol_replace():
280376 assert inp .description == "new"
281377 settings = inp .protocol_configuration .protocol_settings
282378 assert len (settings ) == 1
283- assert (
284- json .loads (settings [0 ]["config" ])["metadata" ]["agentRuntimeName" ]
285- == "alpha"
286- )
379+ cfg_json = json .loads (settings [0 ]["config" ])
380+ forwarded = cfg_json ["body" ]["forwardedProps" ]
381+ assert forwarded ["metadata" ]["agentRuntimeName" ] == "alpha"
382+ assert forwarded ["prompt" ] == "p"
383+ assert forwarded ["tools" ] == ["t" ]
287384
288385
289386# ─── Dara ListAgentRuntimesRequest tags 补丁 ──────────────────
0 commit comments