Pull Request has been successfully merged by openJiuwen-bot.
(Thank you for Yiyang Shao's contribution.)变更摘要
本 PR 修复 AgentRegistry/client/a2x_registry_client/cli.py 中 login 子命令的 Registry URL 选择逻辑。此前版本在 stdin 非 TTY 时无条件跳过 URL 提示,导致无 --token 时管道输入被误读、sys.stdin 为 None 时抛 AttributeError、以及声称是 TTY 但无输入时抛 EOFError 三类问题。改动将跳过提示的条件收窄为「同时给出 --token 且 stdin 非交互」,并新增统一回退函数 _fallback_base_url() 处理缺失 stdin 与 EOF 场景,同时在 test_cli_login_non_interactive.py 中补充三个对应回归测试。
主要改动
- 收窄跳过 URL 提示的条件:
_resolve_login_base_url由「stdin 非 TTY 即跳过」改为args.token and not interactive才走默认 URL,使不带--token时仍从 stdin 读取 URL,恢复管道依次输入 URL 与 token 的用法。 - 新增
_fallback_base_url()回退函数: 把「向sys.stderr输出note: no --base-url given; using ...并返回DEFAULT_BASE_URL」的逻辑抽出复用,供 stdin 非交互与 EOF 两条路径共用。 - 空值与 EOF 的安全处理: 以
sys.stdin is not None and sys.stdin.isatty()计算interactive,避免 stdin 关闭时的AttributeError;并在input()外层捕获EOFError,覆盖 Windows< NUL这类报 TTY 却无输入的情况。 - 新增三个回归测试: 在
test_cli_login_non_interactive.py中加入无--token管道输入 URL 与 token、sys.stdin为None、以及自定义_TtyEof触发 EOF 三个用例,分别校验base_url、api_key写入结果与 stderr 提示内容。


欢迎来到 openJiuwen 社区
Hey @YiyangShao , 感谢你对社区的贡献.
机器人使用手册
有关指令的使用,可以点击 此处 查看详情。开发人员可以在每个PR或Issue下方评论特定指令来触发机器人任务。
联系指引
有疑问可以联系 SIG: sig-agent-protocol ,
维护者是: @YiyangShao, @xinyu-jiuwen ,
审核者是: @gcw_hx9prznZ, @mingo007 .


The pipeline(pipeline number:407) is running. Please wait a moment...


🟡 Medium Priority
变更行:cli.py:57-64 新增 interactive = sys.stdin is not None and sys.stdin.isatty(),但该空值保护只用于 --token 分支(第 58-59 行);无 --token 时仍然直接执行第 61 行的 input(...),而 except 只捕获 EOFError。
影响/失败模式:
sys.stdin is None(Unix 下以0<&-或pythonw/嵌入环境启动时 CPython 会把sys.stdin置为None)时,input()不会抛EOFError,而是抛RuntimeError: input(): lost sys.stdin,未被捕获 →cmd_login冒出 traceback、以非零码退出,而不是回退到DEFAULT_BASE_URL或给出可读错误。这正是本 PR 描述中列为「已修复」的 gap 之一,实际只修了--token分支。- 若
sys.stdin是一个已close()的流(不是None),第 57 行isatty()会抛ValueError: I/O operation on closed file,同样逃出函数。
该路径没有测试覆盖(新增的 test_login_with_token_tolerates_a_closed_stdin 只测了带 --token 的情况),所以回归不会被发现。修复方向:把 sys.stdin is None 与非交互两种情况统一放在提示之前判断,或在 try 中同时捕获 (EOFError, RuntimeError, OSError, ValueError),非交互/无 stdin 且无 --token 时回退默认 URL(并可对 getpass 提示给出明确错误)。
建议:在提示前统一处理「stdio 不可用」:if sys.stdin is None or not interactive: return _fallback_base_url() 的语义应覆盖无 --token 情况,或把 try 的 except 扩展到 (EOFError, RuntimeError, ValueError, OSError),避免 sys.stdin is None 或已关闭流时抛未捕获异常。同时补一条「无 --token + sys.stdin is None」的测试。


/lgtm
/approve


Paired: GitHub #221 ↔ GitCode !407
What type of PR is this?
/kind bug
What this PR does / why we need it
Follow-up to #346. That PR made
login --tokenwork without a TTY, but it skipped the Registry URL prompt whenever stdin was not a TTY, which left three gaps (raised by WeiZheng96 in #346 and not covered by the merged version):--token, a caller that pipes the URL and the token in sequence used to work; after #346 the URL line is read as the token and login exits 2 withtoken must start with 'a2x_pat_'.sys.stdinisNoneandsys.stdin.isatty()raisesAttributeError.< NUL) still ends inEOFError.Changes in
AgentRegistry/client/a2x_registry_client/cli.py:--tokenis given and stdin is not interactive; without--tokenthe prompt keeps reading stdin.sys.stdinas non-interactive.Verification
test_cli_login_non_interactive.py: piped URL and token without--token, a closed stdin, and EOF on a TTY stdin.pytest AgentRegistry/client/tests: 48 passed, 1 skipped.developcli.pyand pass with this change.