mirror of
https://github.com/hansjone/dsh-im-ops.git
synced 2026-10-11 06:33:17 +08:00
Merge pull request #48 from luochen211/fix/weixin-long-reply-chunking
fix: chunk long WeChat replies for iLink
This commit is contained in:
commit
36cbbe48e7
10 changed files with 219 additions and 174 deletions
|
|
@ -63,6 +63,8 @@ test('Weixin production has no per-bot result-file Gate', async (t) => {
|
|||
|
||||
assert.equal(Object.hasOwn(runtimes[0], 'outboundArtifactsEnabled'), false);
|
||||
assert.equal(Object.hasOwn(runtimes[1], 'outboundArtifactsEnabled'), false);
|
||||
assert.equal(runtimes[0].maxMessageChars, 1_800);
|
||||
assert.equal(runtimes[1].maxMessageChars, 1_800);
|
||||
await production.close();
|
||||
|
||||
const productionWithDefault = await createProductionController(ctx, { dataDir }, internals);
|
||||
|
|
@ -72,5 +74,6 @@ test('Weixin production has no per-bot result-file Gate', async (t) => {
|
|||
token: 'host-only',
|
||||
});
|
||||
assert.equal(Object.hasOwn(runtimes[2], 'outboundArtifactsEnabled'), false);
|
||||
assert.equal(runtimes[2].maxMessageChars, 1_800);
|
||||
await productionWithDefault.close();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -150,6 +150,38 @@ test('Weixin bridge hands a native file source to the current Harness turn', asy
|
|||
assert.deepEqual(sent, ['文件已收到']);
|
||||
});
|
||||
|
||||
test('Weixin splits long replies below the iLink text limit', async () => {
|
||||
const fixture = stateFixture();
|
||||
fixture.sessions.set('p2p:owner-user', 'session-long-reply');
|
||||
const chunks = [];
|
||||
const answer = '答案'.repeat(1_000);
|
||||
const bridge = new WeixinHarnessBridge({
|
||||
api: {
|
||||
sendText: async ({ text }) => {
|
||||
chunks.push(text);
|
||||
return { messageId: `weixin-long-${chunks.length}` };
|
||||
},
|
||||
},
|
||||
baseUrl: 'https://ilinkai.weixin.qq.com',
|
||||
token: 'token',
|
||||
ownerUserId: 'owner-user',
|
||||
harness: {
|
||||
sessionExists: async () => true,
|
||||
ask: async () => answer,
|
||||
},
|
||||
state: fixture.state,
|
||||
});
|
||||
|
||||
const receipt = await bridge.accept(message('weixin-long-reply', '生成一段长回答'));
|
||||
|
||||
assert.ok(chunks.length > 1);
|
||||
assert.ok(chunks.every((chunk) => chunk.length <= 1_800));
|
||||
assert.equal(chunks.join(''), answer);
|
||||
assert.equal(receipt.providerMessageIds.length, chunks.length);
|
||||
assert.equal(bridge.status.messagesReplied, 1);
|
||||
assert.equal(bridge.status.lastMessageError, null);
|
||||
});
|
||||
|
||||
test('Weixin starts a native-file download before an earlier queued turn finishes', async () => {
|
||||
const fixture = stateFixture();
|
||||
fixture.sessions.set('p2p:owner-user', 'session-prefetch-file');
|
||||
|
|
|
|||
|
|
@ -85,6 +85,7 @@ test('runtime verifies the token, consumes getUpdates, replies, persists cursor,
|
|||
const calls = [];
|
||||
let pollCount = 0;
|
||||
let askSignal;
|
||||
const answer = '答'.repeat(2_000);
|
||||
const stateData = { cursor: '', seen: new Set(), session: null };
|
||||
const api = {
|
||||
notifyStart: async (request) => calls.push(['start', request.token]),
|
||||
|
|
@ -133,7 +134,7 @@ test('runtime verifies the token, consumes getUpdates, replies, persists cursor,
|
|||
createSession: async () => 'session-1',
|
||||
ask: async (_sessionId, _text, options) => {
|
||||
askSignal = options.signal;
|
||||
return '回答';
|
||||
return answer;
|
||||
},
|
||||
},
|
||||
state,
|
||||
|
|
@ -145,10 +146,14 @@ test('runtime verifies the token, consumes getUpdates, replies, persists cursor,
|
|||
await flush();
|
||||
await flush();
|
||||
assert.equal(stateData.cursor, 'cursor-next');
|
||||
assert.deepEqual(calls.slice(0, 2), [
|
||||
['start', 'bot-token'],
|
||||
['send', '回答', 'context-7'],
|
||||
assert.equal(calls[0][0], 'start');
|
||||
assert.deepEqual(calls.slice(1, 3).map((call) => call[1].length), [1_800, 200]);
|
||||
assert.equal(calls.slice(1, 3).map((call) => call[1]).join(''), answer);
|
||||
assert.deepEqual(calls.slice(1, 3).map((call) => call[2]), [
|
||||
'context-7',
|
||||
'context-7',
|
||||
]);
|
||||
assert.equal(runtime.status.messagesReplied, 1);
|
||||
assert.equal(askSignal.aborted, false);
|
||||
await runtime.stop();
|
||||
assert.equal(askSignal.aborted, true);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue