Skip to content

fix(ui): LongBridge 超时/未知失败缺少处置建议,横幅却提示「需要安装」 #312

Description

@wxrbyte

问题与复现

现象:当 LongBridge CLI 调用超时(或返回未归类的错误)时,应用顶部的 LongBridge 横幅把问题描述成「需要安装 / 需要登录」,并给出与事实矛盾的处置建议 Install LongBridge CLI and run longbridge auth login.——可 CLI 其实已经装好、也可能已经登录,只是这次调用没在超时时间内返回。

完整链路:

  1. packages/longbridge-tools/src/status.ts:4-10 定义 LongBridgeStatusValue 共 6 个取值:'available' | 'not_installed' | 'not_authed' | 'rate_limited' | 'timeout' | 'unknown'。executor.ts:43-44 把超时映射成 LONGBRIDGE_TIMEOUT,status.ts:33-35 再映射成 status: 'timeout';status.ts:36 把其余错误(含 LONGBRIDGE_PARSE_FAILURE / LONGBRIDGE_UNKNOWN)映射成 'unknown'。
  2. apps/electron/src/main/kernelHost.ts:2586-2597(修复前)只处理其中 3 个,其余全部落到 default: return undefined:
function getLongBridgeStatusAction(status: string) {
  switch (status) {
    case 'not_installed':
      return 'Install the LongBridge CLI (longbridge --help) and authenticate with longbridge auth login.';
    case 'not_authed':
      return 'Run longbridge auth login to authenticate the LongBridge CLI.';
    case 'rate_limited':
      return 'LongBridge is rate-limited; market data requests are paused. Try again later.';
    default:
      return undefined;   // ← 'timeout' / 'unknown' 也落在这里
  }
}
  1. kernelHost.ts:645-647 只在 available 时短路,其余状态都会调用上面的映射,于是 timeout / unknown 拿到 action: undefined。
  2. UI packages/ui/src/components/layout/AppShell.tsx:67-73(修复前)把 undefined 兜底成「去安装」,标题也只有两分支:
if (!error && (!status || status.available)) return null;   // 只有 available 不显示
const message = error ?? status?.message ?? 'LongBridge CLI status is unavailable.';
const action = status?.action ?? 'Install LongBridge CLI and run longbridge auth login.';  // ← undefined 兜底成"去安装"
const title = status?.status === 'rate_limited' ? 'LongBridge paused: ' : 'LongBridge setup needed: ';

具体反例:

输入 { installed: true, authed: true, available: false, status: 'timeout', error: { code: 'LONGBRIDGE_TIMEOUT', message: 'LongBridge CLI timed out.' } }

输出项 实际(修复前) 预期
action undefined → UI 兜底显示 Install LongBridge CLI and run longbridge auth login. 提示超时 / 重试,而不是让人去装 CLI
横幅标题前缀 LongBridge setup needed: LongBridge paused: (超时是暂时不可用,不是配置问题)

status: 'unknown' 时 action 同样为 undefined,UI 同样兜底成安装引导。

预期与修复方向

  • getLongBridgeStatusAction() 补齐 'timeout' 与 'unknown' 分支:让 6 个取值中除 'available'(由调用方短路、本就不需要动作)之外都有明确处置建议。
  • UI 标题的「paused」判定并入 'timeout'——超时与限流同属「暂时不可用」;'unknown' 保留 setup needed(原因未知,确实可能是环境问题)。

复现证据

  • 环境:Windows 10、Bun 1.4.2(744846f84);基线 main 3a17eca6(2026-10-03T16:16:35Z)
  • 聚焦测试 cd apps/electron && bun test src/main/kernelHost.test.ts(新增 3 个用例):
    • 修复前 → 12 pass / 2 fail(两条新用例报 Expected: "string" / Received: "undefined")
    • 修复后 → 14 pass / 0 fail
  • 类型检查 bun run typecheck → @finagent/core / i18n / shared / ui / electron 全部 exit 0
  • 全量 cd apps/electron && bun test → 32 pass / 1 fail。唯一失败是 research-prompts.test.ts 的 synthesis prompt embeds SECURITY RULES before the data bundle,与本改动无关且属既有问题:它单独运行是 4 pass / 0 fail,把本 PR 的 3 个文件还原成 main 版本后全量仍为 29 pass / 1 fail(同一条失败),且 research-prompts.ts / research-prompts.test.ts 与上游 main 逐字节一致——是既有的跨文件测试隔离问题。
  • 未运行的测试:test:e2e / test:e2e:visible / test:package-smoke(Windows 上跑不起完整 e2e)。
  • 说明:上游 .github/workflows/pr.yml 当前为 disabled_manually,新 PR 不会产生 check run;以上均为等价本地命令结果。

查重与冲突

范围

  • 3 个文件:
    1. apps/electron/src/main/kernelHost.ts——新增 'timeout' / 'unknown' 两个 action 分支;
    2. apps/electron/src/main/kernelHost.test.ts——新增 3 个用例(available 无动作、timeout 走重试而非安装、unknown 有自己的动作);
    3. packages/ui/src/components/layout/AppShell.tsx——标题 paused 判定并入 timeout(该组件无单测基建,改动是单行条件扩展)。
  • 不修改已支持状态的既有文案,不改动 IPC 契约与状态码。

Activity

  1. wxrbyte commented on Oct 8, 2026

    @wxrbyte
    ContributorAuthor

    /claim

  2. added
    claimedClaimed by a contributor and currently in progress
    on Oct 8, 2026
  3. github-actions commented on Oct 8, 2026

    @github-actions

    @wxrbyte 已认领该 Issue,并已自动设为 Assignee。提交 PR 时请在描述中写 Closes #312。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

claimedClaimed by a contributor and currently in progress

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions