Skip to content

fix(cmd): preserve user-supplied base-url in ucloud init#146

Merged
Ali1213 merged 1 commit into
masterfrom
claude/sharp-lalande-41ee53
Jul 22, 2026
Merged

fix(cmd): preserve user-supplied base-url in ucloud init#146
Ali1213 merged 1 commit into
masterfrom
claude/sharp-lalande-41ee53

Conversation

@Episkey-G

Copy link
Copy Markdown
Collaborator

缺陷

ucloud init 交互中用户输入的自定义 base-url 无法落盘。NewCmdInit 在持久化前无条件执行 platform.ConfigIns.BaseURL = platform.DefaultBaseURL,把用户输入覆盖回主站默认值:

  • 用户输入的域名只在远程校验期(fetchRegionWithConfig)生效;
  • 落盘的是 DefaultBaseURL
  • 末尾的确认行打印的也是被覆盖后的值,用户无从察觉。

专属云客户(需指向 https://api.ucloud-global.com/ 等非主站网关)走 ucloud init 拿不到可用 profile,只能改用 ucloud config update --base-url ... 绕过。

修复

删除那行无条件覆盖即可。ConfigBaseURL() 已保证 BaseURL 非空——用户直接回车时 ConfigIns 仍保持包级默认值 DefaultBaseURL,故删除后默认路径行为不变。

同一段的 Timeout/MaxRetryTimes/Active 保持原样重置:这三项在 init 流程中本就没有用户输入环节,属于合理的初始化,只有 BaseURL 在 prompt 处有用户输入,故只改它。

测试

新增 TestInitPersistsUserSuppliedBaseURL:驱动真实的 NewCmdInit().Run()(stdin 喂入公钥/私钥/自定义 base-url/日志选项,配合假网关),重新读盘断言落盘的 base-url 与用户输入一致,同时校验 timeout/max-retry/active 仍为各自默认值(避免过度约束)。已验证把缺陷行放回后该用例变红、且仅 base-url 断言失败。

验证

  • /opt/homebrew/bin/go build ./... 通过
  • go vet ./cmd/... 无输出
  • go test ./... 全部包 ok,既有 init/config 用例无回归

init unconditionally reset ConfigIns.BaseURL to DefaultBaseURL right
before persisting, discarding the custom base-url entered at the prompt.
The value only took effect during remote validation and the confirmation
line echoed the overwritten default, so users could not tell their input
was dropped. Dedicated-cloud customers pointing at a non-primary gateway
had to work around it via `ucloud config update --base-url`.

Remove the overwrite; ConfigBaseURL() already leaves BaseURL populated
(the package-level default when the user just presses Enter). Timeout,
MaxRetryTimes and Active still reset to their defaults since init has no
prompt for them.

Add TestInitPersistsUserSuppliedBaseURL, which drives the real
NewCmdInit().Run() against a fake gateway and asserts the reloaded
profile keeps the entered base-url.
@github-actions

Copy link
Copy Markdown

🔴 平台 PR 默认硬拦,需管理员 Approve 放行(或由管理员提交)。判定:改动触及平台/受保护路径(cmd/configure.go, cmd/configure_test.go)

@Ali1213
Ali1213 merged commit 9f3fec5 into master Jul 22, 2026
12 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants