Skip to content

fix(config): Dashboard 链接跟随 listen host 而非误报 LAN IP - #667

Merged
deepcoldy merged 3 commits into
deepcoldy:masterfrom
tgao-bd:fix/dashboard-url-follow-listen-host
Jul 30, 2026
Merged

deepcoldy merged 3 commits into
deepcoldy:masterfrom
tgao-bd:fix/dashboard-url-follow-listen-host

Conversation

@tgao-bd

@tgao-bd tgao-bd commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

问题:~/.botmux/.env 里 BOTMUX_DASHBOARD_HOST=127.0.0.1 时,restart 后打印/DM 的 Dashboard 链接仍是 getLocalIp() 探测出的 LAN IP,指向一个根本没在监听的地址。

根因:getDashboardExternalHost() 的回退链只有
BOTMUX_DASHBOARD_EXTERNAL_HOST ?? WEB_EXTERNAL_HOST ?? getLocalIp(), 从不参考实际监听地址 BOTMUX_DASHBOARD_HOST。

修复:未显式配置对外 host 时,优先广告具体的 listen host(127.0.0.1 / LAN IP 等可达地址原样使用);仅当 bind 为通配 0.0.0.0/:: 这种非可达地址时才回退 LAN IP 自动探测。顺带把 dashboard.ts 里重复的 isWildcardBindHost 收敛到 config.ts。

影响面:只动 config.ts 的 dashboard externalHost 解析 + dashboard.ts 去重导入; web.externalHost(web 终端)不受影响,仍走各自逻辑。所有经由
config.dashboard.externalHost 的出口(restart 提示、restart-report DM、v3 卡片、 federation、plugin service)一并受益。

测试:pnpm build 绿;新增 web-external-host.test.ts 3 例(具体 bind 广告自身 / 通配 bind 回退 LAN IP / 显式 external host 优先);dashboard-url、terminal-url、 federation-spoke-api 回归全绿(73 passed)。

问题:~/.botmux/.env 里 BOTMUX_DASHBOARD_HOST=127.0.0.1 时,restart 后打印/DM
的 Dashboard 链接仍是 getLocalIp() 探测出的 LAN IP,指向一个根本没在监听的地址。

根因:getDashboardExternalHost() 的回退链只有
BOTMUX_DASHBOARD_EXTERNAL_HOST ?? WEB_EXTERNAL_HOST ?? getLocalIp(),
从不参考实际监听地址 BOTMUX_DASHBOARD_HOST。

修复:未显式配置对外 host 时,优先广告具体的 listen host(127.0.0.1 / LAN IP
等可达地址原样使用);仅当 bind 为通配 0.0.0.0/:: 这种非可达地址时才回退 LAN IP
自动探测。顺带把 dashboard.ts 里重复的 isWildcardBindHost 收敛到 config.ts。

影响面:只动 config.ts 的 dashboard externalHost 解析 + dashboard.ts 去重导入;
web.externalHost(web 终端)不受影响,仍走各自逻辑。所有经由
config.dashboard.externalHost 的出口(restart 提示、restart-report DM、v3 卡片、
federation、plugin service)一并受益。

测试:pnpm build 绿;新增 web-external-host.test.ts 3 例(具体 bind 广告自身 /
通配 bind 回退 LAN IP / 显式 external host 优先);dashboard-url、terminal-url、
federation-spoke-api 回归全绿(73 passed)。
@tgao-bd
tgao-bd requested a review from deepcoldy as a code owner July 29, 2026 21:36
PR deepcoldy#667 review 后续(Shen Han + 内部 traex 复核):新增 formatUrlHost() 统一
处理 host→URL,IPv6 literal(含 ':')包成 [::1] 再拼进 URL,否则
http://::1:7891/ 是非法 URL(new URL() 抛)。IPv4/域名/已括号原样。

收口所有 host 进 URL 的出口:buildDashboardUrls、v3 卡片×5、federation×3、
web 终端 terminal-url×2 + sessions-card×1(后者是同根同源的孪生 bug:
WEB_EXTERNAL_HOST=::1 同样会生成非法终端链接)。getter 仍返回纯 host,
仅 URL 层加括号,分层不变。

顺带精简 config.ts 注释、web-external-host.test 收敛到 loadConfig helper。

测试:pnpm build 绿;dashboard-url/web-external-host/terminal-url/sessions-card/
federation-spoke-api 共 164 tests 通过(新增 formatUrlHost 单元 + ::1 端到端 +
出口 URL 可解析不变式)。
@deepcoldy

Copy link
Copy Markdown
Owner

Claude 首次 review(head fe759fa7)

核心修复逻辑正确:getDashboardExternalHost() 未配置对外 host 时优先广告具体 listen host、仅通配 bind 才回退 LAN IP;formatUrlHost() 给裸 IPv6 literal 加方括号。pnpm build 绿,merge-tree vs master 退出码 0 无冲突。两处建议修复后再合:

🔴 P2 — 本 PR 新增的测试在本机(platform-bound)失败

test/web-external-host.test.ts:83 returns a concrete IPv6 bind raw 断言 buildDashboardUrl(...) === 'http://[::1]:7891/',但本机(远程访问开 + 已绑定中心平台)实际返回 https://m-....botmux.bytedance.net/ → FAIL。

根因:这条用例没有 mock platform/binding.js / global-config.js,而它的孪生用例 test/dashboard-url.test.ts 的 IPv6 case 两者都 mock 了、稳定通过。所以本用例是非 hermetic 的——只在「远程访问关」的机器上绿,任何 platform-bound 部署(含 daemon 机)都会红。PR body 写「164 tests 通过」应是在未绑定平台的机器上跑的。

建议:本用例 mock 掉 platform/remote-access 依赖(照抄 dashboard-url.test.ts 的 vi.mock),或去掉 buildDashboardUrl 断言只留 config.dashboard.externalHost === '::1'(IPv6 加括号已由 dashboard-url.test.ts 覆盖)。

🟡 P2 — commit 2「收口所有 host 进 URL 出口」漏了 plugin service 两处

commit 1 body 明确把 "plugin service" 列为受益出口,但 src/core/plugins/service-manager.ts 两处读 config.dashboard.externalHost 未过 formatUrlHost(均已 node 实测复现):

  • L249 `http://${config.dashboard.externalHost}:${port}/` → IPv6 ::1 拼出 http://::1:8080/,new URL() 抛错的非法 URL(这里是展示字符串不重解析,症状=坏链非崩溃)。
  • L236 url.hostname = config.dashboard.externalHost → WHATWG .hostname setter 对裸 IPv6(::1)静默拒绝,loopback host 不会被改写成对外 host,等于没生效——正是本 PR 想修的「链接指向错 host」同类 bug。

实际触发面窄(需装了 plugin service + IPv6 bind),但既然 commit message 声明「所有出口」+ 明列 plugin service,建议一并 formatUrlHost 收口保持一致(L236 传给 setter 的值也需先 formatUrlHost 括起来才不会被静默丢)。


逻辑主路径无误、无安全问题。以上两点修复后我认为可合。已 @ codex 做独立复审;未经申晗确认不合码。

PR deepcoldy#667 review 后续(Claude 首审 + Codex 复审共识):

1. commit 2 声称「收口所有 host→URL 出口」漏了 plugin service 两处
   (service-manager.ts)——commit 1 body 自列 plugin service 为受益出口:
   · serviceUrls 默认 openUrl `http://${externalHost}:${port}/` 遇 IPv6
     externalHost(如 ::1)拼出非法 URL `http://::1:8080/`(new URL() 抛)。
   · rewriteLoopbackServiceUrl 的 `url.hostname = externalHost` 对裸 ::1
     被 WHATWG setter 静默拒绝 → loopback rewrite 失效(正是本 PR 想修的
     「链接指向错 host」同类 bug)。
   修:新增 urlReadyDashboardHost() 统一走 formatUrlHost,openUrl / setter /
   传给插件 urls() 的 host 三处都用 URL-ready(IPv6 已括号)形式。Codex 复审
   补充的 L246 契约点一并收口:urls() ctx 的 host 现在是 URL-ready,插件按常规
   插值即得合法 IPv6 URL;runtime.ts 的类型注释同步声明该契约。

2. test/web-external-host.test.ts 新增的 IPv6 用例非 hermetic:它 import
   buildDashboardUrl() 后读到真实的 isRemoteAccessEnabled()+platformMachineBaseUrl()
   状态(本 suite 只 mock node:os/ensure-tmux),platform-bound 机器上返回平台
   URL 而非 http://[::1]:7891/ → FAIL。IPv6 括号已在 dashboard-url.test.ts
   hermetic 覆盖,故删掉这句跨层断言,只留 config 层 `externalHost === '::1'`。

测试:新增 test/plugin-service-url-host.test.ts 6 例覆盖 Codex 要求的三类
(默认 openUrl / 插件自定义 urls() / loopback rewrite,含 IPv6+IPv4),mutation
双向验证有牙;plugin-service 三 suite + PR 声明 5 suite + 新增 = 187 tests 全绿;
pnpm build 绿。

Co-Authored-By: Riff <[email protected]>
@deepcoldy

Copy link
Copy Markdown
Owner

已按双审共识代修并 push(fe759fa7 → c91bafc4)

作者开了 maintainer-can-modify,Claude 直接在 fork 分支上修了两点(Codex 复审已独立复现两条 P2):

① plugin service 两处 IPv6 收口(P2 #2 + Codex L246 契约点)

src/core/plugins/service-manager.ts 新增 urlReadyDashboardHost() 统一过 formatUrlHost,三处都用 URL-ready(IPv6 已加 [])形式:

  • 默认 openUrl http://${host}:${port}/:IPv6 不再拼出非法 http://::1:8080/。
  • rewriteLoopbackServiceUrl 的 url.hostname = host:裸 ::1 会被 WHATWG setter 静默拒绝,现传括号形式 → loopback rewrite 生效。
  • 传给插件 urls({ host }) 的 host(Codex 指出的 L246 契约):现在是 URL-ready,插件常规插值即得合法 IPv6 URL;runtime.ts 类型注释同步声明契约。

② 测试去非 hermetic(P2 #1)

test/web-external-host.test.ts 的 IPv6 用例删掉跨层 buildDashboardUrl 断言(它读真实 remote-access/platform-binding 状态,platform-bound 机上必红);IPv6 括号已由 dashboard-url.test.ts hermetic 覆盖,此处只留 config 层 externalHost === '::1'。

验证

  • 新增 test/plugin-service-url-host.test.ts 6 例,覆盖 Codex 要求的三类(默认 openUrl / 插件自定义 urls() / loopback rewrite,IPv6+IPv4);mutation 双向验证有牙(还原任一 fix 对应用例即红)。
  • plugin-service 三 suite + PR 声明 5 suite + 新增 = 187 tests 全绿;pnpm build 绿;merge-tree --write-tree origin/master HEAD 退出码 0 无冲突。

@codex 请对 fe759fa7..c91bafc4 做 delta 复审。未经申晗确认不合码。

@chatgpt-codex-connector

Copy link
Copy Markdown

To use Codex here, create a Codex account and connect to github.

@deepcoldy
deepcoldy merged commit 446c607 into deepcoldy:master Jul 30, 2026
@deepcoldy

Copy link
Copy Markdown
Owner

✅ 已合并(申晗授权 admin-merge)

merge commit 446c6071(merge 模式非 squash,保留 tgao-bd 2 + Claude 1 共 3 commit 归属)。

合前终检:head 仍 c91bafc4 无中途分叉;master 未动(d048978b);merge-tree --write-tree origin/master c91bafc4 退出码 0 无冲突;OPEN/MERGEABLE(BLOCKED 仅 review-required 门槛,admin bypass)。

双审共识:首审 2 条 P2 + codex 复审 L246 契约点均已代修关闭;187/187 相关 suite + 全量 11218 passed 绿;build 绿。

⚠️ 仅到 master——未发版、未 live。上线需 pnpm switch:here && pnpm daemon:restart(会影响全 fleet),待申晗另行决定。

@github-actions

github-actions Bot commented Aug 2, 2026

Copy link
Copy Markdown

🚀 Released in v3.8.0

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