fix: normalize alternate tkmind publish links

This commit is contained in:
john
2026-06-28 15:38:31 +08:00
parent f31775b0c7
commit 82ac5fc744
2 changed files with 47 additions and 0 deletions
+5
View File
@@ -435,7 +435,12 @@ function rewritePublishedHtmlLinks(text, artifacts = []) {
`https?:\\/\\/[^\\s)]+\\/(?:MindSpace\\/[^\\s/]+\\/)?public\\/${escapeRegExp(filename)}\\b`,
'g',
);
const wrongTkmindHtmlLinkPattern = new RegExp(
`https?:\\/\\/(?:[^\\s./]+\\.)*tkmind\\.cn\\/[^\n\\s)]*${escapeRegExp(filename)}\\b`,
'gi',
);
next = next.replace(wrongPublicLinkPattern, canonicalUrl);
next = next.replace(wrongTkmindHtmlLinkPattern, canonicalUrl);
next = next.replace(PUBLIC_HTML_LINK_PATTERN, (match) => {
if (match === canonicalUrl) return match;
const matchedFilename = String(match).split('/').pop();
+42
View File
@@ -336,6 +336,48 @@ test('maybeAttachPublishedHtmlLink rewrites wrong public html links to the canon
);
});
test('maybeAttachPublishedHtmlLink rewrites tkmind domain variants to the canonical published url', async () => {
const workspaceRoot = fs.mkdtempSync('/tmp/wechat-mp-rewrite-domain-');
const htmlPath = `${workspaceRoot}/public/codex-prod-check-v6.html`;
fs.mkdirSync(`${workspaceRoot}/public`, { recursive: true });
fs.writeFileSync(htmlPath, '<!doctype html><title>Prod Check</title>');
const text = await maybeAttachPublishedHtmlLink(
{
text: '唯一可访问链接:https://mindspace.tkmind.cn/a70ff537-8908-486e-9b6c-042e07cc25db/codex-prod-check-v6.html',
messages: [
{
role: 'assistant',
content: [
{
type: 'toolRequest',
toolCall: {
value: {
name: 'sandbox-fs__write_file',
arguments: {
path: 'public/codex-prod-check-v6.html',
content: '<!doctype html><title>Prod Check</title>',
},
},
},
},
],
},
],
},
{
workingDir: workspaceRoot,
publicBaseUrl: 'https://m.tkmind.cn',
},
);
assert.doesNotMatch(text, /https:\/\/mindspace\.tkmind\.cn\/.+\/codex-prod-check-v6\.html/);
assert.match(
text,
/https:\/\/m\.tkmind\.cn\/MindSpace\/.+\/public\/codex-prod-check-v6\.html/,
);
});
test('wechat mp service splits long agent replies into multiple customer messages', async () => {
const token = 'token';
const timestamp = '1710000000';