clawwork-ai/ClawWork

[Enhancement] Add unit tests for GatewayDispatcher error handling logic

Open

#227 创建于 2026年4月1日

在 GitHub 查看
 (1 评论) (0 反应) (0 负责人)TypeScript (63 fork)github user discovery
area/dxarea/gatewayenhancementhelp wanted

仓库指标

Star
 (519 star)
PR 合并指标
 (PR 指标待抓取)

描述

What problem are you trying to solve?

GatewayDispatcher contains critical error deduplication and lifecycle buffering logic (shouldDisplayError, isSameFailure, lifecycleErrorBuffer) that currently has zero test coverage. These are some of the most bug-prone code paths in the app — they handle error display, deduplication, and a 2-second buffering window — but any regression would go unnoticed.

Where

  • Source: packages/core/src/services/gateway-dispatcher.ts
  • Test directory: packages/core/ currently has no test/ directory — you will need to create one

What needs to be done

  1. Create packages/core/test/gateway-dispatcher.test.ts
  2. Extract shouldDisplayError and isSameFailure as pure testable functions (or test them through the dispatcher)
  3. Write tests covering:
    • isSameFailure: returns true for identical error codes/messages, false for different ones
    • shouldDisplayError: respects the lifecycle error buffer (errors within the 2s window after a lifecycle event are suppressed)
    • shouldDisplayError: does not suppress errors when chat.state is already error
    • The buffer timer: after 2s, buffered errors are released
  4. Use vi.useFakeTimers() for the buffer window tests
  5. Run pnpm check to verify

Why does this matter?

Error display logic is invisible when it works and catastrophic when it breaks — users either get spammed with duplicate errors or see no errors at all. Tests here prevent both failure modes.

Primary area

Task execution

贡献者指南