Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

test(mcps): cover the page-end step-back for split surrogate pairs

Zhao Dengfengc9b3d475f544
diff --git a/packages/lizi-mcps/src/browser/browserMcpServer.test.ts b/packages/lizi-mcps/src/browser/browserMcpServer.test.ts
index c6e0bfbb28..72d348dffb 100644
--- a/packages/lizi-mcps/src/browser/browserMcpServer.test.ts
+++ b/packages/lizi-mcps/src/browser/browserMcpServer.test.ts
@@ -341,17 +341,21 @@ describe('browser experience cache', () => {
const loneSurrogate = /[\ud800-\udbff](?![\udc00-\udfff])|(?<![\ud800-\udbff])[\udc00-\udfff]/;
try {
const id = (await invoke(h, { action: 'act', targetId: 'tab', request: { kind: 'evaluate', fn: '() => []' } })).fullResult.id;
- // 奇数页长让边界落在代理对中间;每一页都必须是合法 Unicode,拼接后逐字节还原。
+ // 首个 emoji 从奇数位开始,12_000 的页尾正好切在代理对中间:页尾须退回一位。
+ const emoji = JSON.stringify(original).indexOf('😀');
+ expect((12_000 - emoji) % 2).toBe(1);
+ const first = await invoke(h, { action: 'readResult', resultId: id, offset: 0, maxChars: 12_000 });
+ expect(first.nextOffset).toBe(11_999);
+ // 每一页都必须是合法 Unicode,拼接后逐字节还原。
let offset: number | null = 0;
let text = '';
while (offset !== null) {
- const chunk = await invoke(h, { action: 'readResult', resultId: id, offset, maxChars: 12_001 });
+ const chunk = await invoke(h, { action: 'readResult', resultId: id, offset, maxChars: 12_000 });
expect(chunk.text).not.toMatch(loneSurrogate);
text += chunk.text; offset = chunk.nextOffset;
}
expect(JSON.parse(text)).toEqual(original);
// maxChars=1 落在代理对上时整对返回并前进,不会卡在原地。
- const emoji = JSON.stringify(original).indexOf('😀');
expect(await invoke(h, { action: 'readResult', resultId: id, offset: emoji, maxChars: 1 }))
.toMatchObject({ text: '😀', nextOffset: emoji + 2 });
} finally { await h.cleanup(); }