fix: harden agent and WeChat run completion
This commit is contained in:
@@ -22,6 +22,7 @@ import {
|
||||
verifyWechatMpSignature,
|
||||
verifyWechatMpUrlChallenge,
|
||||
decryptWechatMpPayload,
|
||||
executeSessionReply,
|
||||
WECHAT_CUSTOMER_TEXT_MAX_BYTES,
|
||||
} from './wechat-mp.mjs';
|
||||
import { createChatIntentRouter } from './chat-intent-router.mjs';
|
||||
@@ -69,6 +70,33 @@ function previewReadyPageHtml({ title = 'Page', subtitle = '测试页面', cover
|
||||
return `<!doctype html><html><head><meta name="description" content="${subtitle}"><meta name="mindspace-cover" content='{"tag":"页面","accent":"#3366cc","accent2":"#112233","subtitle":"${subtitle}"${coverField}}'><title>${title}</title></head><body><main>${'x'.repeat(600)}</main><p data-mindspace-page-tag="platform-brand">TKMind · 智趣</p></body></html>`;
|
||||
}
|
||||
|
||||
test('executeSessionReply converts a hanging event stream into a bounded timeout', async () => {
|
||||
let cancelled = false;
|
||||
const body = new ReadableStream({
|
||||
start(controller) {
|
||||
controller.enqueue(new TextEncoder().encode(': connected\n\n'));
|
||||
},
|
||||
cancel() {
|
||||
cancelled = true;
|
||||
},
|
||||
});
|
||||
await assert.rejects(
|
||||
executeSessionReply(
|
||||
async (_pathname, init) => {
|
||||
assert.equal(init.method, 'GET');
|
||||
return { ok: true, body };
|
||||
},
|
||||
'session-timeout',
|
||||
'request-timeout',
|
||||
'hello',
|
||||
{},
|
||||
{ timeoutMs: 20, submitReply: async () => {} },
|
||||
),
|
||||
(error) => error?.code === 'WECHAT_AGENT_REPLY_TIMEOUT',
|
||||
);
|
||||
assert.equal(cancelled, true);
|
||||
});
|
||||
|
||||
function jsonEscapedPreviewReadyPageHtml(options = {}) {
|
||||
return previewReadyPageHtml(options).replace(/\\/g, '\\\\').replace(/"/g, '\\"');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user