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 <cursoragent@cursor.com>
This commit is contained in:
+16
-8
@@ -61,6 +61,14 @@ function inboundXml({
|
||||
].join('');
|
||||
}
|
||||
|
||||
function previewReadyPageHtml({ title = 'Page', subtitle = '测试页面' } = {}) {
|
||||
return `<!doctype html><html><head><meta name="description" content="${subtitle}"><meta name="mindspace-cover" content='{"tag":"页面","accent":"#3366cc","accent2":"#112233","subtitle":"${subtitle}"}'><title>${title}</title></head><body><main>${'x'.repeat(600)}</main></body></html>`;
|
||||
}
|
||||
|
||||
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, '<!doctype html><title>Thailand</title>');
|
||||
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, '<!doctype html><title>Hello</title>');
|
||||
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":"<!doctype html><title>Hello</title>"}}}}]}}\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, '<!doctype html><title>Hello</title>');
|
||||
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":"<!doctype html><title>Hello</title>"}}}}]}}\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":"<!doctype html><title>Hello</title>"}}}}]}}\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, '<!doctype html><title>Thailand</title>');
|
||||
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, '<!doctype html><title>Summer</title>');
|
||||
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') {
|
||||
|
||||
Reference in New Issue
Block a user