diff --git a/wechat-mp.mjs b/wechat-mp.mjs index 8f36a0c..e648a85 100644 --- a/wechat-mp.mjs +++ b/wechat-mp.mjs @@ -919,7 +919,7 @@ export function shouldRetryHtmlGenerationReply({ if (isMissingRequiredPublishSkill(reply, intent) || isSuspiciousBareCompletionReply(reply, intent)) { return true; } - if (!usedStaticPagePublishSkill(reply?.messages ?? [])) return true; + if (!usedStaticPagePublishSkill(reply?.messages ?? [])) return false; return !hasAnyUrl(reply?.text); } @@ -1917,9 +1917,6 @@ export function createWechatMpService({ if (reply.tokenState) { await userAuth.billSessionUsage(user.userId, sessionId, reply.tokenState, requestId); } - if (looksLikeHtmlGenerationIntent(intent?.agentText) && verifiedArtifacts.length === 0 && confirmedArtifacts.length === 0) { - throw new Error(buildHtmlPublishFailureText()); - } const finalizedReply = await maybeAttachPublishedHtmlLink(reply, { workingDir, publicBaseUrl: config.publicBaseUrl, @@ -1989,9 +1986,6 @@ export function createWechatMpService({ if (reply.tokenState) { await userAuth.billSessionUsage(user.userId, sessionId, reply.tokenState, retryId); } - if (looksLikeHtmlGenerationIntent(intent?.agentText) && verifiedArtifacts.length === 0 && confirmedArtifacts.length === 0) { - throw new Error(buildHtmlPublishFailureText()); - } const finalizedReply = await maybeAttachPublishedHtmlLink(reply, { workingDir, publicBaseUrl: config.publicBaseUrl, diff --git a/wechat-mp.test.mjs b/wechat-mp.test.mjs index 06c1a9e..acad6d7 100644 --- a/wechat-mp.test.mjs +++ b/wechat-mp.test.mjs @@ -226,6 +226,32 @@ test('shouldRetryHtmlGenerationReply does not skip retry because unrelated recen ); }); +test('shouldRetryHtmlGenerationReply allows normal H5 agent text without fake page links', () => { + const intent = { agentText: '帮我生成页面吧' }; + const reply = { + text: '请告诉我要生成什么主题和内容,我再继续。', + messages: [ + { + content: [ + { + type: 'text', + text: '请告诉我要生成什么主题和内容,我再继续。', + }, + ], + }, + ], + }; + assert.equal( + shouldRetryHtmlGenerationReply({ + reply, + intent, + confirmedArtifacts: [], + hasValidLinkInReply: false, + }), + false, + ); +}); + test('wechat mp service rejects blocked publish claims that did not use the H5 page skill', async () => { const wechatCalls = []; const service = createBoundWechatService({ @@ -2228,7 +2254,7 @@ test('wechat mp service does not trust unrelated recent html artifacts when repl assert.match(payload.text.content, /没有按 H5 里的页面技能真正生成成功|页面生成未完成/); }); -test('wechat mp service refuses to fabricate a fallback page when html generation produced no file', async () => { +test('wechat mp service forwards H5 agent text when page generation produced no file or fake link', async () => { const token = 'token'; const timestamp = '1710000000'; const nonce = 'nonce'; @@ -2329,11 +2355,12 @@ test('wechat mp service refuses to fabricate a fallback page when html generatio assert.equal(fs.existsSync(htmlPath), false); const sendCall = wechatCalls.find(([url]) => String(url).includes('/cgi-bin/message/custom/send')); const payload = JSON.parse(sendCall[2]); - assert.match(payload.text.content, /没有按 H5 里的页面技能真正生成成功/); + assert.match(payload.text.content, /🌴 泰国简易攻略/); + assert.doesNotMatch(payload.text.content, /没有按 H5 里的页面技能真正生成成功/); assert.doesNotMatch(payload.text.content, /https:\/\/m\.tkmind\.cn\/MindSpace\/.+\/public\/thailand-guide\.html/); }); -test('wechat mp service retries poisoned publish claims and still refuses fallback output', async () => { +test('wechat mp service retries poisoned publish claims before forwarding H5 retry text', async () => { const token = 'token'; const timestamp = '1710000000'; const nonce = 'nonce'; @@ -2497,7 +2524,8 @@ test('wechat mp service retries poisoned publish claims and still refuses fallba const sendCall = wechatCalls.find(([url]) => String(url).includes('/cgi-bin/message/custom/send')); const payload = JSON.parse(sendCall[2]); assert.doesNotMatch(payload.text.content, /页面都已经成功发布了|主题页面已发布/); - assert.match(payload.text.content, /没有按 H5 里的页面技能真正生成成功/); + assert.match(payload.text.content, /🌴 夏日主题页面/); + assert.doesNotMatch(payload.text.content, /没有按 H5 里的页面技能真正生成成功/); assert.doesNotMatch(payload.text.content, /summer-breeze-journal\.html/); });