@@ -223,3 +223,91 @@ async fn management_rows_derive_missing_diagnostics_from_probe_reason() {
223223 Some ( "definitely-missing-cli" )
224224 ) ;
225225}
226+
227+ #[ tokio:: test]
228+ async fn management_rows_project_runtime_catalogs_from_agent_metadata ( ) {
229+ let db = init_database_memory ( ) . await . unwrap ( ) ;
230+ let repo: Arc < dyn IAgentMetadataRepository > = Arc :: new ( SqliteAgentMetadataRepository :: new ( db. pool ( ) . clone ( ) ) ) ;
231+
232+ repo. upsert ( & UpsertAgentMetadataParams {
233+ id : "agent-with-catalog" ,
234+ icon : None ,
235+ name : "Catalog Agent" ,
236+ name_i18n : None ,
237+ description : None ,
238+ description_i18n : None ,
239+ backend : Some ( "claude" . into ( ) ) ,
240+ agent_type : "acp" ,
241+ agent_source : "builtin" ,
242+ agent_source_info : None ,
243+ enabled : true ,
244+ command : None ,
245+ args : Some ( "[]" ) ,
246+ env : Some ( "[]" ) ,
247+ native_skills_dirs : None ,
248+ behavior_policy : None ,
249+ yolo_id : None ,
250+ agent_capabilities : None ,
251+ auth_methods : None ,
252+ config_options : Some (
253+ r#"{"config_options":[{"id":"model","type":"select","category":"model","options":[{"value":"claude-opus","label":"Claude Opus"}],"current_value":"claude-opus"}]}"# ,
254+ ) ,
255+ available_modes : Some (
256+ r#"{"current_mode_id":"plan","available_modes":[{"id":"plan","name":"Plan"}]}"# ,
257+ ) ,
258+ available_models : Some (
259+ r#"{"current_model_id":"claude-opus","current_model_label":"Claude Opus","available_models":[{"id":"claude-opus","label":"Claude Opus"}]}"# ,
260+ ) ,
261+ available_commands : None ,
262+ sort_order : 100 ,
263+ } )
264+ . await
265+ . unwrap ( ) ;
266+
267+ let registry = AgentRegistry :: new ( repo) ;
268+ registry. hydrate ( ) . await . unwrap ( ) ;
269+
270+ let row = registry
271+ . list_management_rows ( )
272+ . await
273+ . into_iter ( )
274+ . find ( |item| item. id == "agent-with-catalog" )
275+ . unwrap ( ) ;
276+ let row_json = serde_json:: to_value ( & row) . unwrap ( ) ;
277+
278+ assert_eq ! (
279+ row_json[ "available_models" ] [ "current_model_id" ] . as_str( ) ,
280+ Some ( "claude-opus" )
281+ ) ;
282+ assert_eq ! ( row_json[ "available_modes" ] [ "current_mode_id" ] . as_str( ) , Some ( "plan" ) ) ;
283+ assert_eq ! (
284+ row_json[ "config_options" ] [ "config_options" ] [ 0 ] [ "current_value" ] . as_str( ) ,
285+ Some ( "claude-opus" )
286+ ) ;
287+ }
288+
289+ #[ tokio:: test]
290+ async fn management_rows_include_aionrs_builtin_mode_catalog ( ) {
291+ let db = init_database_memory ( ) . await . unwrap ( ) ;
292+ let repo: Arc < dyn IAgentMetadataRepository > = Arc :: new ( SqliteAgentMetadataRepository :: new ( db. pool ( ) . clone ( ) ) ) ;
293+ let registry = AgentRegistry :: new ( repo) ;
294+ registry. hydrate ( ) . await . unwrap ( ) ;
295+
296+ let row = registry
297+ . list_management_rows ( )
298+ . await
299+ . into_iter ( )
300+ . find ( |item| item. agent_type == AgentType :: Aionrs )
301+ . unwrap ( ) ;
302+ let row_json = serde_json:: to_value ( & row) . unwrap ( ) ;
303+
304+ assert_eq ! ( row_json[ "available_modes" ] [ "current_mode_id" ] . as_str( ) , Some ( "default" ) ) ;
305+ assert_eq ! (
306+ row_json[ "available_modes" ] [ "available_modes" ] [ 1 ] [ "id" ] . as_str( ) ,
307+ Some ( "auto_edit" )
308+ ) ;
309+ assert_eq ! (
310+ row_json[ "config_options" ] [ "config_options" ] [ 0 ] [ "options" ] [ 2 ] [ "value" ] . as_str( ) ,
311+ Some ( "yolo" )
312+ ) ;
313+ }
0 commit comments