@@ -468,7 +468,7 @@ def test_parse_model_info_reads_subscription_block():
468468 }},
469469 }
470470 assert events .parse_model_info (payload ) == {
471- "account_id" : "acct" , "principal_id" : "prin" ,
471+ "account_id" : "acct" , "principal_id" : "prin" , "user_name" : "" ,
472472 "app_key" : "K" , "app_secret" : "S" , "base_url" : "https://gw.test/v2" ,
473473 }
474474
@@ -484,8 +484,8 @@ def test_parse_model_info_unprovisioned_account():
484484 """未开通:`subscription: null`(实测三账号全如此)→ 各字段空。"""
485485 info = events .parse_model_info ({"account_id" : "a" , "subscription" : None ,
486486 "model_info" : {}})
487- assert info == {"account_id" : "a" , "principal_id" : "" , "app_key " : "" ,
488- "app_secret" : "" , "base_url" : "" }
487+ assert info == {"account_id" : "a" , "principal_id" : "" , "user_name " : "" ,
488+ "app_key" : "" , " app_secret" : "" , "base_url" : "" }
489489
490490
491491def test_parse_model_info_tolerates_garbage ():
@@ -495,6 +495,29 @@ def test_parse_model_info_tolerates_garbage():
495495 {"subscription" : {"model_info" : {"model_auth_info" : "x" }}})["base_url" ] == ""
496496
497497
498+ def test_parse_model_info_reads_user_name_from_principal_urn ():
499+ """用户名只在 `principal_urn` 末尾,接口没有独立字段(2026-10-21 实测)。"""
500+ info = events .parse_model_info (
501+ {"principal_urn" : "iam::acct:user:robbsluo" })
502+ assert info ["user_name" ] == "robbsluo"
503+
504+
505+ def test_parse_model_info_prefers_explicit_user_name ():
506+ for key in ("user_name" , "userName" ):
507+ info = events .parse_model_info (
508+ {key : " carol " , "principal_urn" : "iam::acct:user:ignored" })
509+ assert info ["user_name" ] == "carol"
510+
511+
512+ def test_parse_model_info_urn_without_user_marker_is_blank ():
513+ """URM 形态变了也不能炸:认不出就留空,昵称退到账号 ID。"""
514+ assert events .parse_model_info ({"principal_urn" : "iam::acct" })["user_name" ] == ""
515+ assert events .parse_model_info (
516+ {"principal_urn" : 123 })["user_name" ] == ""
517+ assert events .parse_model_info (
518+ {"user_name" : " " })["user_name" ] == ""
519+
520+
498521# ------------------------------------------------------------------ 授权 URL
499522
500523def test_build_authorize_url_wraps_login_page ():
0 commit comments