Skip to content

fix(remote-agent): normalize websocket test url#1937

Merged
piorpua merged 1 commit intoiOfficeAI:mainfrom
cdxiaodong:fix/1822-remote-agent-url-guard
Mar 30, 2026
Merged

fix(remote-agent): normalize websocket test url#1937
piorpua merged 1 commit intoiOfficeAI:mainfrom
cdxiaodong:fix/1822-remote-agent-url-guard

Conversation

@cdxiaodong
Copy link
Copy Markdown
Member

Summary

  • normalize remote agent test URLs to add a ws:// prefix when the user omits the protocol
  • remove the temporal dead zone around the websocket instance and safely handle synchronous constructor failures
  • add regression tests for protocol-less URLs and constructor errors

Test plan

  • bun run lint
  • bun run format
  • bunx tsc --noEmit
  • bun run test

Fixes #1822

@sentry
Copy link
Copy Markdown

sentry bot commented Mar 30, 2026

Codecov Report

❌ Patch coverage is 73.68421% with 5 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/process/bridge/remoteAgentBridge.ts 73.68% 3 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

@piorpua piorpua added the bot:reviewing Review in progress (mutex) label Mar 30, 2026
@piorpua
Copy link
Copy Markdown
Contributor

piorpua commented Mar 30, 2026

Code Review:fix(remote-agent): normalize websocket test url (#1937)

变更概述

本 PR 修复了 remoteAgentBridge.tstestConnection 的两个问题:一是为用户省略协议前缀的 URL 自动补全 ws://;二是通过重构 finish() 闭包和将 WebSocket 构造器包入 try-catch,防止构造期间的同步异常导致 Promise 永远悬挂。两个改动均附有对应的回归测试。


方案评估

结论:✅ 方案合理

normalizeWebSocketUrl 为轻量的纯函数,逻辑清晰。settled 标志 + finish() 闭包是防止 Promise 多次 resolve 的惯用方式,正确地在构造失败时也清除了 timeout(通过闭包捕获)。原始代码中 ws 先被 timeout 回调引用、后才赋值的顺序问题也得到了修复。方案没有引入不必要的复杂度,与项目现有架构一致。


问题清单

🔵 LOW — 测试覆盖率略低(patch 73.68%)

文件src/process/bridge/remoteAgentBridge.ts

Codecov 报告 patch 覆盖率为 73.68%,有 3 个未覆盖行和 2 个部分覆盖行。结合代码来看,以下两条路径缺少测试用例:

  1. testConnection 的超时路径finish({ success: false, error: 'Connection timed out (10s)' }) 的 10 秒 timeout 没有对应测试。
  2. finish 的幂等守卫if (settled) return 分支(即 finish 被多次调用时的短路逻辑)没有测试覆盖。

codecov/patch 在本项目配置为 informational: true,不阻塞合并,但补充上述用例可进一步提升健壮性。参考方式:

it('returns timeout error when websocket does not open within 10s', async () => {
  vi.useFakeTimers();
  const handler = providerMap.get('testConnection')!;
  // 不让 mock 触发 open,只推进计时器
  const resultPromise = handler({ url: 'wss://slow-host', authType: 'none' });
  await vi.advanceTimersByTimeAsync(11_000);
  const result = await resultPromise;
  expect(result).toEqual({ success: false, error: 'Connection timed out (10s)' });
  vi.useRealTimers();
});

汇总

# 严重级别 文件 问题
1 🔵 LOW src/process/bridge/remoteAgentBridge.ts 超时路径与 settled 守卫缺少测试

结论

批准合并 — 无阻塞性问题,代码逻辑正确,测试覆盖了核心新增路径,仅有一条 LOW 级测试建议。


本报告由本地 pr-review skill 生成,包含完整项目上下文,无截断限制。

@piorpua
Copy link
Copy Markdown
Contributor

piorpua commented Mar 30, 2026

✅ 已自动 review,无阻塞性问题,正在触发自动合并。

@piorpua piorpua merged commit 9dbc2df into iOfficeAI:main Mar 30, 2026
14 checks passed
@piorpua piorpua added bot:done Auto-merged by bot and removed bot:reviewing Review in progress (mutex) labels Mar 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:done Auto-merged by bot

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(remoteAgent): testConnection crashes on URLs without protocol prefix

2 participants