fix(wechat): complement page link delivery when reply references public html
Memind CI / Test, build, and release guards (push) Failing after 7s
Memind CI / Test, build, and release guards (push) Failing after 7s
Intent routing and reply content now both trigger HTML delivery: public links, public/*.html paths, or html writes in the agent reply enable artifact recovery, link attachment, and fail-closed when the claimed page is missing. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -23,6 +23,9 @@ import {
|
||||
shouldRotateUnlinkedWechatRoute,
|
||||
shouldRetryHtmlGenerationReply,
|
||||
shouldForceNewWechatAgentSession,
|
||||
hasAnyPublicHtmlLinkInReply,
|
||||
replyImpliesPublicHtmlDelivery,
|
||||
shouldFailClosedOnMissingPublicHtmlDelivery,
|
||||
splitWechatText,
|
||||
verifyWechatMpSignature,
|
||||
verifyWechatMpUrlChallenge,
|
||||
@@ -728,6 +731,105 @@ test('shouldRetryHtmlGenerationReply allows normal H5 agent text without fake pa
|
||||
);
|
||||
});
|
||||
|
||||
test('replyImpliesPublicHtmlDelivery detects public links in assistant messages for chat.general', () => {
|
||||
const reply = {
|
||||
text: '以下是专题报告摘要。',
|
||||
messages: [
|
||||
{
|
||||
role: 'assistant',
|
||||
content: [
|
||||
{
|
||||
type: 'text',
|
||||
text: '完整报告:https://m.tkmind.cn/MindSpace/user-1/public/ai-out-of-control-report.html',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
assert.equal(replyImpliesPublicHtmlDelivery(reply), true);
|
||||
assert.equal(hasAnyPublicHtmlLinkInReply(reply), true);
|
||||
});
|
||||
|
||||
test('shouldRetryHtmlGenerationReply fails closed for chat.general when reply claims missing public html', () => {
|
||||
const intent = { agentText: '帮我深度搜索一下AI失控话题' };
|
||||
const reply = {
|
||||
text: '报告已生成。',
|
||||
messages: [
|
||||
{
|
||||
role: 'assistant',
|
||||
content: [
|
||||
{
|
||||
type: 'text',
|
||||
text: '查看页面:https://m.tkmind.cn/MindSpace/user-1/public/ai-out-of-control-report.html',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
assert.equal(
|
||||
shouldRetryHtmlGenerationReply({
|
||||
reply,
|
||||
intent,
|
||||
confirmedArtifacts: [],
|
||||
hasValidLinkInReply: false,
|
||||
}),
|
||||
true,
|
||||
);
|
||||
assert.equal(
|
||||
shouldFailClosedOnMissingPublicHtmlDelivery({
|
||||
reply,
|
||||
confirmedArtifacts: [],
|
||||
hasValidLinkInReply: false,
|
||||
}),
|
||||
true,
|
||||
);
|
||||
});
|
||||
|
||||
test('replyImpliesPublicHtmlDelivery attaches delivery when confirmed artifact exists', async (t) => {
|
||||
const workspaceRoot = fs.mkdtempSync('/tmp/wechat-mp-reply-implied-');
|
||||
t.after(() => {
|
||||
fs.rmSync(workspaceRoot, { recursive: true, force: true });
|
||||
});
|
||||
const htmlPath = `${workspaceRoot}/public/ai-out-of-control-report.html`;
|
||||
fs.mkdirSync(path.dirname(htmlPath), { recursive: true });
|
||||
fs.writeFileSync(htmlPath, '<!doctype html><title>AI Out Of Control</title><body>report</body>');
|
||||
const reply = {
|
||||
text: '以下是 AI 失控专题摘要。',
|
||||
messages: [
|
||||
{
|
||||
role: 'assistant',
|
||||
content: [
|
||||
{
|
||||
type: 'text',
|
||||
text: '完整报告见 public/ai-out-of-control-report.html',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
assert.equal(replyImpliesPublicHtmlDelivery(reply), true);
|
||||
const prepared = prepareWechatHtmlDeliveryAtWorkspace({
|
||||
reply,
|
||||
publishDir: workspaceRoot,
|
||||
buildCanonicalUrl: (relativePath) =>
|
||||
`https://m.tkmind.cn/MindSpace/user-1/${relativePath}`,
|
||||
allowRecentArtifacts: true,
|
||||
});
|
||||
assert.equal(prepared.confirmedArtifacts.length, 1);
|
||||
assert.equal(
|
||||
shouldFailClosedOnMissingPublicHtmlDelivery({
|
||||
reply,
|
||||
confirmedArtifacts: prepared.confirmedArtifacts,
|
||||
hasValidLinkInReply: false,
|
||||
}),
|
||||
false,
|
||||
);
|
||||
const text = await maybeAttachPublishedHtmlLink(reply, {
|
||||
artifacts: prepared.confirmedArtifacts,
|
||||
});
|
||||
assert.match(text, /https:\/\/m\.tkmind\.cn\/MindSpace\/user-1\/public\/ai-out-of-control-report\.html/);
|
||||
});
|
||||
|
||||
test('wechat mp service rejects blocked publish claims that did not use the H5 page skill', async () => {
|
||||
const wechatCalls = [];
|
||||
const service = createBoundWechatService({
|
||||
|
||||
Reference in New Issue
Block a user