mirror of
https://github.com/NanmiCoder/cc-haha
synced 2026-07-16 13:03:31 +08:00
WeChat development turns were reaching the local CLI, but the adapter treated iLink business failures as successful sends and only emitted a short-lived typing indicator. The adapter now validates sendmessage/sendtyping ret codes, retries text replies without stale context tokens, keeps typing alive during long-running tool work, and surfaces queue failures back to the chat. Constraint: WeChat uses separate sendmessage and sendtyping APIs with business-level ret codes inside HTTP 200 responses. Rejected: Only fixing the typing indicator | the transcript showed the agent completed the task, so the reply delivery path also needed hardening. Confidence: high Scope-risk: narrow Directive: Do not treat WeChat HTTP 200 responses as successful until the iLink ret/errcode body has been checked. Tested: bun test adapters/wechat/__tests__/protocol.test.ts adapters/wechat/__tests__/typing.test.ts Tested: cd adapters && bunx tsc --noEmit Tested: bun run check:adapters Tested: real bound WeChat getconfig, typing, text send, cancel typing smoke Not-tested: Full inbound WeChat user-message loop without a fresh user-triggered message
39 lines
1.3 KiB
TypeScript
39 lines
1.3 KiB
TypeScript
import { describe, expect, it } from 'bun:test'
|
|
import { WechatTypingController } from '../typing.js'
|
|
|
|
describe('WechatTypingController', () => {
|
|
it('sends typing immediately and keeps it alive until stopped', async () => {
|
|
const calls: Array<[string, string]> = []
|
|
const controller = new WechatTypingController(async (chatId, status) => {
|
|
calls.push([chatId, status])
|
|
}, 10)
|
|
|
|
controller.start('chat-1')
|
|
await Bun.sleep(25)
|
|
controller.stop('chat-1')
|
|
controller.destroy()
|
|
|
|
expect(calls[0]).toEqual(['chat-1', 'typing'])
|
|
expect(calls.filter(([, status]) => status === 'typing').length).toBeGreaterThanOrEqual(2)
|
|
expect(calls.at(-1)).toEqual(['chat-1', 'cancel'])
|
|
})
|
|
|
|
it('does not create duplicate keepalive timers for the same chat', async () => {
|
|
const calls: Array<[string, string]> = []
|
|
const controller = new WechatTypingController(async (chatId, status) => {
|
|
calls.push([chatId, status])
|
|
}, 10)
|
|
|
|
controller.start('chat-1')
|
|
controller.start('chat-1')
|
|
await Bun.sleep(25)
|
|
controller.stop('chat-1')
|
|
controller.destroy()
|
|
|
|
const typingCalls = calls.filter(([, status]) => status === 'typing')
|
|
expect(typingCalls.length).toBeGreaterThanOrEqual(3)
|
|
expect(typingCalls.length).toBeLessThanOrEqual(5)
|
|
expect(calls.at(-1)).toEqual(['chat-1', 'cancel'])
|
|
})
|
|
})
|