Merged
fix(client-cli): only skip the login URL prompt for scripted --token logins #407
fix(client-cli): only skip the login URL prompt for scripted --token logins #407
Merged
Yiyang ShaoAdd on 4 days ago
Yiyang ShaoCollaborators
4 days ago

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 --token work 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):

  • Without --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 with token must start with 'a2x_pat_'.
  • When stdin is closed, sys.stdin is None and sys.stdin.isatty() raises AttributeError.
  • A stdin that reports a TTY but has no input (Windows < NUL) still ends in EOFError.

Changes in AgentRegistry/client/a2x_registry_client/cli.py:

  • Skip the URL prompt only when --token is given and stdin is not interactive; without --token the prompt keeps reading stdin.
  • Treat a missing sys.stdin as non-interactive.
  • Fall back to the default URL, with the existing stderr note, when the prompt hits EOF.

Verification

  • Added 3 tests to 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.
  • The 3 new tests fail against the current develop cli.py and pass with this change.
likedislike
Pull Request has been successfully merged by openJiuwen-bot.
(Thank you for Yiyang Shao's contribution.)
atomgit-bot
atomgit-bot
4 days ago Comments:

变更摘要

本 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 提示内容。
likedislike
Incorrect?
atomgit-bot
atomgit-bot
4 days ago Comments:

代码审查

类型 数量
🔴 阻塞 0
🟡 建议 1

💬 仅评论

likedislike
Incorrect?
OopenJiuwen-botCollaborators
4 days ago Added label: sig/sig-agent-protocol
atomgit-bot
atomgit-bot
4 days ago Comments:

AtomGit AI 助手使用指南

在 PR 评论中使用命令即可触发。支持在普通评论和代码行评论中使用。

功能 命令 说明
代码审查 /ai review 检查代码质量、潜在问题、安全风险
PR 摘要 /ai summary 生成 PR 变更内容的结构化摘要
代码解释 /ai explain 解释代码变更的逻辑和意图
自由提问 @atomgit-bot <问题> 询问关于本 PR 的任何问题
帮助 /ai help 显示此帮助信息

免责声明

AI 助手可能存在误判,请结合自身判断。可以对评论点 👍 或 👎 帮助我们改进。

likedislike
Incorrect?
openJiuwen-botCollaborators
4 days ago Comments:

欢迎来到 openJiuwen 社区

Hey @YiyangShao , 感谢你对社区的贡献.

机器人使用手册

有关指令的使用,可以点击 此处 查看详情。开发人员可以在每个PR或Issue下方评论特定指令来触发机器人任务。

联系指引

有疑问可以联系 SIG: sig-agent-protocol ,
维护者是: @YiyangShao, @xinyu-jiuwen ,
审核者是: @gcw_hx9prznZ, @mingo007 .

likedislike
OopenJiuwen-botCollaborators
4 days ago Added label: openJiuwen-cla/yes
openJiuwen-botCollaborators
4 days ago Comments:

CLA 签署成功

YiyangShao, 感谢您的代码贡献。 所有的代码贡献者都已完成了 CLA 签署。 👍

likedislike
Oopenjiuwen-syncCollaborators
4 days ago Modify description of pull request
openJiuwen-botCollaborators
4 days ago Comments:

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

likedislike
OopenJiuwen-botCollaborators
4 days ago Added label: ci-running
atomgit-bot
atomgit-bot4 days agoStart code review1
AgentRegistry/client/a2x_registry_client/cli.py
@@ -64,0 +61,4 @@
61+ return input(f"Registry URL [{DEFAULT_BASE_URL}]: ").strip() or DEFAULT_BASE_URL
62+ except EOFError:
63+ # A TTY check is not proof of input: Windows reports `< NUL` as a TTY.
64+ return _fallback_base_url()
atomgit-bot
atomgit-bot4 days agoComments:

🟡 Medium Priority

变更行:cli.py:57-64 新增 interactive = sys.stdin is not None and sys.stdin.isatty(),但该空值保护只用于 --token 分支(第 58-59 行);无 --token 时仍然直接执行第 61 行的 input(...),而 except 只捕获 EOFError。

影响/失败模式:

  1. 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 分支。
  2. 若 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」的测试。

likedislike
Incorrect?
OopenJiuwen-botCollaborators
4 days ago Removed label: ci-running
openJiuwen-botCollaborators
4 days ago Comments:
任务名称 结果 日志操作
静态检查 ✅SUCCESS 点此跳转
防投毒检查 ✅SUCCESS 点此跳转
开源合规检查 ✅SUCCESS 点此跳转
禁用词扫描 ✅SUCCESS 点此跳转
A4P Java SDK UT ✅SUCCESS 点此跳转
likedislike
OopenJiuwen-botCollaborators
4 days ago Added label: ci-successful
ZzhengwCollaborators
3 days ago Resolved final issue
maoqiming
maoqimingCollaborators
3 days ago Comments:

/lgtm
/approve

likedislike
OopenJiuwen-botCollaborators
3 days ago Added label: approvedlgtm-mingo007
openJiuwen-botCollaborators
3 days ago Comments:

Review Code Feedback

  • The label lgtm-mingo007, approved was added to this pull request. It means that mingo007 reviewed the code changes. 👋
Tips
  • If this pull request is not merged while all conditions are met, comment /check-pr to try again. 😄
likedislike
OopenJiuwen-botCollaborators
3 days ago Merged pull request
OopenJiuwen-botCollaborators
3 days ago Removed label: ci-successful