@dsh-overdrive/gateway 0.1.9 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -58,4 +58,43 @@ describe('PendingButtons', () => {
58
58
  expect(pb.match('chat-2', '1')).toEqual({ id: 'b', label: '拒绝' });
59
59
  expect(pb.match('chat-1', '1')).toEqual({ id: 'a', label: '同意' });
60
60
  });
61
+
62
+ it('文字审批关键词:批准/同意/yes → approve 按钮', () => {
63
+ const pb = new PendingButtons();
64
+ pb.set('chat-1', [
65
+ { id: 'approve:r1', label: '✅ 同意' },
66
+ { id: 'reject:r1', label: '🚫 拒绝' },
67
+ ]);
68
+ expect(pb.match('chat-1', '批准')).toEqual({ id: 'approve:r1', label: '✅ 同意' });
69
+ pb.set('chat-1', [
70
+ { id: 'approve:r2', label: '✅ 同意' },
71
+ { id: 'reject:r2', label: '🚫 拒绝' },
72
+ ]);
73
+ expect(pb.match('chat-1', 'yes')).toEqual({ id: 'approve:r2', label: '✅ 同意' });
74
+ pb.set('chat-1', [
75
+ { id: 'approve:r3', label: '✅ 同意' },
76
+ { id: 'reject:r3', label: '🚫 拒绝' },
77
+ ]);
78
+ expect(pb.match('chat-1', '同意 好的')).toEqual({ id: 'approve:r3', label: '✅ 同意' });
79
+ });
80
+
81
+ it('文字审批关键词:拒绝/no → reject 按钮', () => {
82
+ const pb = new PendingButtons();
83
+ pb.set('chat-1', [
84
+ { id: 'approve:r1', label: '✅ 同意' },
85
+ { id: 'reject:r1', label: '🚫 拒绝' },
86
+ ]);
87
+ expect(pb.match('chat-1', '拒绝')).toEqual({ id: 'reject:r1', label: '🚫 拒绝' });
88
+ expect(pb.match('chat-1', 'no')).toBeUndefined(); // 已消费
89
+ });
90
+
91
+ it('关键词审批与数字互斥、无关文本不命中', () => {
92
+ const pb = new PendingButtons();
93
+ pb.set('chat-1', [
94
+ { id: 'approve:r1', label: '✅ 同意' },
95
+ { id: 'reject:r1', label: '🚫 拒绝' },
96
+ ]);
97
+ expect(pb.match('chat-1', '拒绝批准')).toBeUndefined(); // 复合词不命中关键词
98
+ expect(pb.match('chat-1', '2')).toEqual({ id: 'reject:r1', label: '🚫 拒绝' }); // 数字仍可用
99
+ });
61
100
  });
@@ -0,0 +1,20 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { chunkLongText } from '../src/text.js';
3
+
4
+ describe('chunkLongText', () => {
5
+ it('短文本不分片', () => {
6
+ expect(chunkLongText('hello')).toEqual(['hello']);
7
+ });
8
+ it('超长文本按句号断行并带序号', () => {
9
+ const text = ('这是一段很长的内容。'.repeat(200));
10
+ const chunks = chunkLongText(text, 100);
11
+ expect(chunks.length).toBeGreaterThan(1);
12
+ expect(chunks[0]).toMatch(/(\d+\/\d+)$/);
13
+ expect(chunks.every((c) => c.length <= 130)).toBe(true);
14
+ });
15
+ it('无标点长文本按硬上限截断', () => {
16
+ const chunks = chunkLongText('x'.repeat(500), 200);
17
+ expect(chunks.length).toBe(3);
18
+ expect(chunks[0].length).toBeLessThanOrEqual(210);
19
+ });
20
+ });