From eb8d760dd9de78ef0eafd45fe97aa062d807f0cc Mon Sep 17 00:00:00 2001 From: john Date: Sat, 4 Jul 2026 14:01:39 +0800 Subject: [PATCH] test(wechat): align page fixtures with share preview requirements Mock HTML in wechat-mp tests now includes mindspace-cover metadata so page link delivery assertions match production guard behavior. Co-authored-by: Cursor --- wechat-mp.test.mjs | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/wechat-mp.test.mjs b/wechat-mp.test.mjs index 852d113..58c44a7 100644 --- a/wechat-mp.test.mjs +++ b/wechat-mp.test.mjs @@ -61,6 +61,14 @@ function inboundXml({ ].join(''); } +function previewReadyPageHtml({ title = 'Page', subtitle = '测试页面' } = {}) { + return `${title}
${'x'.repeat(600)}
`; +} + +function jsonEscapedPreviewReadyPageHtml(options = {}) { + return previewReadyPageHtml(options).replace(/\\/g, '\\\\').replace(/"/g, '\\"'); +} + function createBoundWechatService({ token = 'token', wechatFetch, @@ -504,7 +512,7 @@ test('maybeAttachPublishedHtmlLink can attach a verified existing public html li const workspaceRoot = fs.mkdtempSync('/tmp/wechat-mp-existing-public-'); const htmlPath = `${workspaceRoot}/public/thailand-guide.html`; fs.mkdirSync(`${workspaceRoot}/public`, { recursive: true }); - fs.writeFileSync(htmlPath, 'Thailand'); + fs.writeFileSync(htmlPath, previewReadyPageHtml({ title: 'Thailand', subtitle: '泰国旅行攻略' })); const text = await maybeAttachPublishedHtmlLink( { @@ -2008,7 +2016,7 @@ test('wechat mp service recreates poisoned dedicated session after bare completi } if (pathname === `/sessions/${sessionId}/reply`) { if (sessionId === 'session-2') { - fs.writeFileSync(htmlPath, 'Hello'); + fs.writeFileSync(htmlPath, previewReadyPageHtml({ title: 'Hello', subtitle: 'Hello 页面' })); } return new Response('{}', { status: 200, headers: { 'Content-Type': 'application/json' } }); } @@ -2025,7 +2033,7 @@ test('wechat mp service recreates poisoned dedicated session after bare completi return new Response( [ 'data: {"type":"Message","request_id":"req-poisoned-retry","message":{"id":"assistant-skill","role":"assistant","metadata":{"userVisible":true},"content":[{"type":"toolRequest","toolCall":{"value":{"name":"load_skill","arguments":{"name":"static-page-publish"}}}}]}}\n\n', - `data: {"type":"Message","request_id":"req-poisoned-retry","message":{"id":"assistant-tool","role":"assistant","metadata":{"userVisible":true},"content":[{"type":"toolRequest","toolCall":{"value":{"name":"developer","arguments":{"action":"write","path":"${htmlPath.replace(/\\/g, '\\\\')}","content":"Hello"}}}}]}}\n\n`, + `data: {"type":"Message","request_id":"req-poisoned-retry","message":{"id":"assistant-tool","role":"assistant","metadata":{"userVisible":true},"content":[{"type":"toolRequest","toolCall":{"value":{"name":"developer","arguments":{"action":"write","path":"${htmlPath.replace(/\\/g, '\\\\')}","content":"${jsonEscapedPreviewReadyPageHtml({ title: 'Hello', subtitle: 'Hello 页面' })}"}}}}]}}\n\n`, 'data: {"type":"Message","request_id":"req-poisoned-retry","message":{"id":"assistant-2","role":"assistant","metadata":{"userVisible":true},"content":[{"type":"text","text":"已完成"}]}}\n\n', 'data: {"type":"Finish","request_id":"req-poisoned-retry","token_state":{"inputTokens":2,"outputTokens":2}}\n\n', ].join(''), @@ -2187,7 +2195,7 @@ test('wechat mp service forwards html link when write_file created a real page w if (pathname === `/sessions/${sessionId}/reply`) { if (sessionId === 'session-2') { fs.mkdirSync(path.dirname(htmlPath), { recursive: true }); - fs.writeFileSync(htmlPath, 'Hello'); + fs.writeFileSync(htmlPath, previewReadyPageHtml({ title: 'Hello', subtitle: 'Hello 页面' })); } return new Response('{}', { status: 200, headers: { 'Content-Type': 'application/json' } }); } @@ -2195,7 +2203,7 @@ test('wechat mp service forwards html link when write_file created a real page w if (sessionId === 'session-1') { return new Response( [ - 'data: {"type":"Message","request_id":"req-skill-miss","message":{"id":"assistant-tool","role":"assistant","metadata":{"userVisible":true},"content":[{"type":"toolRequest","toolCall":{"value":{"name":"sandbox-fs__write_file","arguments":{"path":"public/hello-world.html","content":"Hello"}}}}]}}\n\n', + `data: {"type":"Message","request_id":"req-skill-miss","message":{"id":"assistant-tool","role":"assistant","metadata":{"userVisible":true},"content":[{"type":"toolRequest","toolCall":{"value":{"name":"sandbox-fs__write_file","arguments":{"path":"public/hello-world.html","content":"${jsonEscapedPreviewReadyPageHtml({ title: 'Hello World', subtitle: 'Hello World 页面' })}"}}}}]}}\n\n`, 'data: {"type":"Message","request_id":"req-skill-miss","message":{"id":"assistant-1","role":"assistant","metadata":{"userVisible":true},"content":[{"type":"text","text":"页面已生成:https://m.tkmind.cn/MindSpace/john/public/hello-world.html"}]}}\n\n', 'data: {"type":"Finish","request_id":"req-skill-miss","token_state":{"inputTokens":1,"outputTokens":1}}\n\n', ].join(''), @@ -2205,7 +2213,7 @@ test('wechat mp service forwards html link when write_file created a real page w return new Response( [ 'data: {"type":"Message","request_id":"req-skill-retry","message":{"id":"assistant-skill","role":"assistant","metadata":{"userVisible":true},"content":[{"type":"toolRequest","toolCall":{"value":{"name":"load_skill","arguments":{"name":"static-page-publish"}}}}]}}\n\n', - 'data: {"type":"Message","request_id":"req-skill-retry","message":{"id":"assistant-tool","role":"assistant","metadata":{"userVisible":true},"content":[{"type":"toolRequest","toolCall":{"value":{"name":"sandbox-fs__write_file","arguments":{"path":"public/hello-world.html","content":"Hello"}}}}]}}\n\n', + `data: {"type":"Message","request_id":"req-skill-retry","message":{"id":"assistant-tool","role":"assistant","metadata":{"userVisible":true},"content":[{"type":"toolRequest","toolCall":{"value":{"name":"sandbox-fs__write_file","arguments":{"path":"public/hello-world.html","content":"${jsonEscapedPreviewReadyPageHtml({ title: 'Hello World', subtitle: 'Hello World 页面' })}"}}}}]}}\n\n`, 'data: {"type":"Message","request_id":"req-skill-retry","message":{"id":"assistant-2","role":"assistant","metadata":{"userVisible":true},"content":[{"type":"text","text":"[Hello World](https://m.tkmind.cn/MindSpace/user-1/public/hello-world.html)"}]}}\n\n', 'data: {"type":"Finish","request_id":"req-skill-retry","token_state":{"inputTokens":2,"outputTokens":2}}\n\n', ].join(''), @@ -2265,7 +2273,7 @@ test('wechat mp service trusts an existing requested public html file when the a const workspaceRoot = fs.mkdtempSync('/tmp/wechat-mp-existing-requested-'); const htmlPath = path.join(workspaceRoot, 'public', 'thailand-guide.html'); fs.mkdirSync(path.dirname(htmlPath), { recursive: true }); - fs.writeFileSync(htmlPath, 'Thailand'); + fs.writeFileSync(htmlPath, previewReadyPageHtml({ title: 'Thailand', subtitle: '泰国旅行攻略' })); const service = createWechatMpService({ config: { @@ -2425,7 +2433,7 @@ test('wechat mp service attaches the newly generated page link even when no html } if (pathname === `/sessions/${sessionId}/reply`) { fs.mkdirSync(path.dirname(htmlPath), { recursive: true }); - fs.writeFileSync(htmlPath, 'Summer'); + fs.writeFileSync(htmlPath, previewReadyPageHtml({ title: 'Summer', subtitle: '夏日主题页面' })); return new Response('{}', { status: 200, headers: { 'Content-Type': 'application/json' } }); } if (pathname === '/agent/harness_remember' || pathname === '/agent/harness_bootstrap') {