fix(brand): require TKMind platform marker on wechat page delivery

Backfill missing platform-brand footer at serve time and block service-
account links when the HTML file omits data-mindspace-page-tag.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
john
2026-07-04 14:15:42 +08:00
parent cd81c4b2bb
commit b5a88d9746
8 changed files with 79 additions and 14 deletions
+27 -8
View File
@@ -16,6 +16,7 @@ import { buildGreetingText, resolveSyncReply } from './handlers/sync-replies.mjs
import { buildWechatAgentPrompt } from './prompts/chat-general.mjs';
import {
hasMindspaceCoverMeta,
hasPlatformBrandMarker,
hasShareDescription,
verifyArtifactSharePreview,
verifySharePreviewMeta,
@@ -120,26 +121,31 @@ test('verifyPageArtifactContent rejects small stub files', () => {
assert.equal(filterSendableHtmlArtifacts([artifact]).length, 0);
});
function writePreviewReadyHtml(file, { withCover = true } = {}) {
function writePreviewReadyHtml(file, { withCover = true, withBrand = true } = {}) {
const coverMeta = withCover
? '<meta name="mindspace-cover" content=\'{"tag":"旅行","accent":"#ff6b35","accent2":"#24243e","subtitle":"测试页面"}\'>'
: '';
const brandMeta = withBrand
? '<p data-mindspace-page-tag="platform-brand">TKMind · 智趣</p>'
: '';
fs.writeFileSync(
file,
`<!doctype html><html><head>
<meta name="description" content="一句话摘要">
${coverMeta}
</head><body><main>${'x'.repeat(600)}</main></body></html>`,
</head><body><main>${'x'.repeat(600)}</main>${brandMeta}</body></html>`,
'utf8',
);
}
test('verifySharePreviewMeta requires mindspace-cover and description', () => {
const withBoth = '<meta name="description" content="摘要"><meta name="mindspace-cover" content=\'{"tag":"旅行"}\'>';
assert.equal(verifySharePreviewMeta(withBoth).ok, true);
test('verifySharePreviewMeta requires mindspace-cover, description, and platform brand', () => {
const withAll =
'<meta name="description" content="摘要"><meta name="mindspace-cover" content=\'{"tag":"旅行"}\'><p data-mindspace-page-tag="platform-brand">TKMind · 智趣</p>';
assert.equal(verifySharePreviewMeta(withAll).ok, true);
assert.equal(verifySharePreviewMeta('<meta name="description" content="摘要">').ok, false);
assert.equal(hasMindspaceCoverMeta(withBoth), true);
assert.equal(hasShareDescription(withBoth), true);
assert.equal(hasMindspaceCoverMeta(withAll), true);
assert.equal(hasShareDescription(withAll), true);
assert.equal(hasPlatformBrandMarker(withAll), true);
});
test('resolvePageGenerateOutcome fails when html lacks share preview meta', () => {
@@ -151,10 +157,23 @@ test('resolvePageGenerateOutcome fails when html lacks share preview meta', () =
confirmedArtifacts: [{ localPath: file, relativePath: 'public/page.html' }],
});
assert.equal(outcome.action, 'fail');
assert.equal(outcome.reason, 'missing_share_preview');
assert.equal(outcome.reason, 'missing_mindspace_cover');
assert.match(outcome.failureText, /预览元数据/);
});
test('resolvePageGenerateOutcome fails when html lacks platform brand marker', () => {
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'wechat-brand-'));
const file = path.join(dir, 'page.html');
writePreviewReadyHtml(file, { withBrand: false });
const outcome = resolvePageGenerateOutcome({
reply: { text: '页面已生成' },
confirmedArtifacts: [{ localPath: file, relativePath: 'public/page.html' }],
});
assert.equal(outcome.action, 'fail');
assert.equal(outcome.reason, 'missing_platform_brand');
assert.match(outcome.failureText, /平台品牌/);
});
test('resolvePageGenerateOutcome sends when share preview meta is present', () => {
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'wechat-preview-ok-'));
const file = path.join(dir, 'page.html');