Repository navigation
fix(config): Dashboard 链接跟随 listen host 而非误报 LAN IP - #667
Conversation
问题:~/.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)。
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 可解析不变式)。
Claude 首次 review(head
|
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]>
已按双审共识代修并 push(
|
|
To use Codex here, create a Codex account and connect to github. |
✅ 已合并(申晗授权 admin-merge)merge commit 合前终检:head 仍 双审共识:首审 2 条 P2 + codex 复审 L246 契约点均已代修关闭;187/187 相关 suite + 全量 11218 passed 绿;build 绿。
|
|
🚀 Released in v3.8.0 |
问题:~/.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)。