-
Notifications
You must be signed in to change notification settings - Fork 3k
fix(dingtalk): skip uppercase webhook reaction targets #5466
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,111 @@ | ||||||
| import { describe, expect, it, vi } from 'vitest'; | ||||||
|
|
||||||
| vi.mock('dingtalk-stream-sdk-nodejs', () => ({ | ||||||
| DWClient: class { | ||||||
| disconnect = vi.fn(); | ||||||
| getConfig = vi.fn(() => ({ access_token: 'token' })); | ||||||
| registerCallbackListener = vi.fn(); | ||||||
| send = vi.fn(); | ||||||
| connect = vi.fn(); | ||||||
| }, | ||||||
| TOPIC_ROBOT: 'robot', | ||||||
| EventAck: { SUCCESS: 'success' }, | ||||||
| })); | ||||||
|
|
||||||
| vi.mock('@qwen-code/channel-base', () => ({ | ||||||
| ChannelBase: class { | ||||||
| protected config: Record<string, unknown>; | ||||||
| protected name: string; | ||||||
|
|
||||||
| constructor( | ||||||
| name: string, | ||||||
| config: Record<string, unknown>, | ||||||
| _bridge: unknown, | ||||||
| ) { | ||||||
| this.name = name; | ||||||
| this.config = config; | ||||||
| } | ||||||
| }, | ||||||
| })); | ||||||
|
|
||||||
| const { DingtalkChannel } = await import('./DingtalkAdapter.js'); | ||||||
|
|
||||||
| function createChannel(): DingtalkChannel { | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Suggestion] TypeScript errors in test file:
Suggested change
— DeepSeek/deepseek-v4-pro via Qwen Code /review |
||||||
| return new DingtalkChannel( | ||||||
| 'test-dingtalk', | ||||||
| { | ||||||
| type: 'dingtalk', | ||||||
| clientId: 'client-id', | ||||||
| clientSecret: 'client-secret', | ||||||
| senderPolicy: 'open', | ||||||
| allowedUsers: [], | ||||||
| sessionScope: 'user', | ||||||
| cwd: '/tmp', | ||||||
| groupPolicy: 'open', | ||||||
| groups: {}, | ||||||
| }, | ||||||
| {} as never, | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Suggestion]
Suggested change
— DeepSeek/deepseek-v4-pro via Qwen Code /review |
||||||
| ); | ||||||
| } | ||||||
|
|
||||||
| function getPromptHook( | ||||||
| channel: DingtalkChannel, | ||||||
| hook: 'onPromptStart' | 'onPromptEnd', | ||||||
| ): (chatId: string, sessionId: string, messageId?: string) => void { | ||||||
| const fn = (channel as unknown as Record<string, unknown>)[hook] as ( | ||||||
| chatId: string, | ||||||
| sessionId: string, | ||||||
| messageId?: string, | ||||||
| ) => void; | ||||||
| return fn.bind(channel); | ||||||
| } | ||||||
|
|
||||||
| describe('DingtalkChannel prompt reactions', () => { | ||||||
| it('skips uppercase webhook URLs when starting a prompt', () => { | ||||||
| const channel = createChannel(); | ||||||
| const attachReaction = vi.fn().mockResolvedValue(undefined); | ||||||
| ( | ||||||
| channel as unknown as { attachReaction: typeof attachReaction } | ||||||
| ).attachReaction = attachReaction; | ||||||
|
|
||||||
| getPromptHook(channel, 'onPromptStart')( | ||||||
| 'HTTPS://oapi.dingtalk.com/robot/send?access_token=token', | ||||||
| 'session-1', | ||||||
| 'message-1', | ||||||
| ); | ||||||
|
|
||||||
| expect(attachReaction).not.toHaveBeenCalled(); | ||||||
| }); | ||||||
|
|
||||||
| it('still attaches reactions for conversation IDs', () => { | ||||||
| const channel = createChannel(); | ||||||
| const attachReaction = vi.fn().mockResolvedValue(undefined); | ||||||
| ( | ||||||
| channel as unknown as { attachReaction: typeof attachReaction } | ||||||
| ).attachReaction = attachReaction; | ||||||
|
|
||||||
| getPromptHook(channel, 'onPromptStart')( | ||||||
| 'cid-123', | ||||||
| 'session-1', | ||||||
| 'message-1', | ||||||
| ); | ||||||
|
|
||||||
| expect(attachReaction).toHaveBeenCalledWith('message-1', 'cid-123'); | ||||||
| }); | ||||||
|
|
||||||
| it('skips uppercase webhook URLs when ending a prompt', () => { | ||||||
| const channel = createChannel(); | ||||||
| const recallReaction = vi.fn().mockResolvedValue(undefined); | ||||||
| ( | ||||||
| channel as unknown as { recallReaction: typeof recallReaction } | ||||||
| ).recallReaction = recallReaction; | ||||||
|
|
||||||
| getPromptHook(channel, 'onPromptEnd')( | ||||||
| 'HTTPS://oapi.dingtalk.com/robot/send?access_token=token', | ||||||
| 'session-1', | ||||||
| 'message-1', | ||||||
| ); | ||||||
|
|
||||||
| expect(recallReaction).not.toHaveBeenCalled(); | ||||||
| }); | ||||||
| }); | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Suggestion]
"test:ci": "vitest run"is identical to"test"on the line above. No other channel package (qqbot, weixin, feishu, telegram) has a separatetest:ciscript. Unless a CI pipeline specifically invokestest:ciand expects it to differ fromtest, this adds no value and creates confusion about which to use.— DeepSeek/deepseek-v4-pro via Qwen Code /review