Repository navigation
fix(cnb): pin login to CNB_HOST so it ignores the current dir git remote - #530
Merged
Merged
Conversation
The cnb CLI infers its platform URL from the first git remote of the
current directory when --host is not given. Running `cnb login` inside a
repo whose remote points at a non-CNB host (e.g. an internal git server)
therefore sends the OAuth2 device-auth request there and fails with 401,
while the same command succeeds in a directory with no such remote.
Pass --host ${CNB_HOST} explicitly. CNB_HOST (TEAMAI_CNB_HOST, default
cnb.cool) is already the single source of truth for every other CNB
operation (clone / create-repo / PR), so anchoring login to it keeps the
provider's auth consistent and self-hosted-friendly.
5 of 9 tasks
Walternater
pushed a commit
to Walternater/teamai-cli
that referenced
this pull request
Nov 2, 2026
…ote (Tencent#530) The cnb CLI infers its platform URL from the first git remote of the current directory when --host is not given. Running `cnb login` inside a repo whose remote points at a non-CNB host (e.g. an internal git server) therefore sends the OAuth2 device-auth request there and fails with 401, while the same command succeeds in a directory with no such remote. Pass --host ${CNB_HOST} explicitly. CNB_HOST (TEAMAI_CNB_HOST, default cnb.cool) is already the single source of truth for every other CNB operation (clone / create-repo / PR), so anchoring login to it keeps the provider's auth consistent and self-hosted-friendly.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What & why
cnb login(@cnbcool/cnb-cli)在未显式指定--host时,会从当前目录第一个 git remote 推断平台地址(resolvePlatformUrl→getGitRemoteHosts()跑git remote -v)。优先级为:--host> git remote >CNB_API_ENDPOINT> 默认cnb.cool。因此在一个 remote 指向非 CNB 平台(如内网 git 服务器)的仓库里跑
cnb login,device-auth 请求会被打到那个 host 并返回 401;而在没有该 remote 的目录里同一命令却成功——表现为「同一命令换个目录就登录失败」。teamai 的
cnbLogin()此前调cnb login未传--host,在这种仓库里首次teamai init(provider=cnb、且未登录过)会踩同样的坑。本 provider 其他所有操作(clone / create-repo / PR)都已以CNB_HOST为唯一真相源,唯独 login 例外。What changed
src/providers/cnb/cnb-cli.ts:cnbLogin()改为cnb login --host ${CNB_HOST}(CNB_HOST=TEAMAI_CNB_HOST??cnb.cool),与 provider 其他操作同源;自托管实例自动带上其域名。src/__tests__/cnb-login-host.test.ts:断言默认与TEAMAI_CNB_HOST两种情况下的 argv。docs/providers.md:手动cnb login示例改为带--host cnb.cool,并说明原因与 teamai 自动带 host 的行为。CI 路径(
CNB_TOKEN)根本不触发 login,不受影响。Test plan / report
环境:macOS,真实
@cnbcool/cnb-cliv1.15.20,在 remote 指向git.woa.com(非 CNB)的仓库目录内。npx tsc --noEmit— passnpx vitest run— 221 files / 3040 tests passednpm run build— pass(dist 内含login", "--host", CNB_HOST)真实 CLI 复现 + 修复验证(
cnb ... --debug,密钥已打码):--host(推断 git remote)https://git.woa.comstatus=401→登录失败: status=401 body=(复现报错)--host cnb.cool(修复)https://cnb.coolstatus=200,进入 token 轮询(authorization_pending,正常等待浏览器授权)验证 teamai 实际发出的 argv(用记录参数的假
cnbshim 驱动真实cnbLogin()):login --host cnb.coolTEAMAI_CNB_HOST=cnb.internal.example.com:login --host cnb.internal.example.com