Files
memind/wechat-draft-publication-standard.test.mjs
T
john d8eaef3fbd feat(wechat): MindSpace public draft push with 143 host defaults
Add public-page WeChat draft button, publication standard conversion for poem/prose/generic pages, and quick push APIs. Default Studio release SSH targets to john@180.159.29.143 with 105 edge upstream via 10.10.0.2.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-11 12:32:13 +08:00

71 lines
2.9 KiB
JavaScript

import assert from 'node:assert/strict';
import fs from 'node:fs';
import path from 'node:path';
import test from 'node:test';
import { applyWechatDraftArticleLayout } from './wechat-draft-article-layout.mjs';
import {
buildMindSpacePageWechatDraftArticleForPush,
resolveWechatDraftThumbPath,
} from './mindspace-wechat-page-draft.mjs';
import {
verifyWechatDraftCoverResolution,
verifyWechatDraftPublicationContent,
WECHAT_DRAFT_PUBLICATION_STANDARD,
WECHAT_DRAFT_PUBLICATION_STANDARD_VERSION,
} from './wechat-draft-publication-standard.mjs';
const userId = '1c99b83b-0454-474f-a5d2-129d34506a32';
const AUGUST_HTML = fs.readFileSync(
`MindSpace/${userId}/public/august-afternoon.html`,
'utf8',
);
const PUBLIC_URL = `http://127.0.0.1:8081/MindSpace/${userId}/public/august-afternoon.html`;
test('standard version is pinned', () => {
assert.equal(WECHAT_DRAFT_PUBLICATION_STANDARD.version, WECHAT_DRAFT_PUBLICATION_STANDARD_VERSION);
assert.equal(WECHAT_DRAFT_PUBLICATION_STANDARD.cover.priority[0], 'hero-raster');
});
test('verifyWechatDraftPublicationContent rejects legacy large read button', () => {
const bad = applyWechatDraftArticleLayout('<p>正文</p>', {
publicUrl: PUBLIC_URL,
qrcodeImageUrl: 'https://mmbiz.qpic.cn/qrcode.png',
}).replace('阅读原文', '点击阅读原文');
const result = verifyWechatDraftPublicationContent(bad, { publicUrl: PUBLIC_URL });
assert.equal(result.ok, false);
assert.ok(result.issues.some((item) => /大按钮/.test(item)));
});
test('august-afternoon cover resolves to hero raster', () => {
const resolved = resolveWechatDraftThumbPath(AUGUST_HTML, {
h5Root: process.cwd(),
userId,
workspaceRelativePath: 'public/august-afternoon.html',
publishDir: path.join(process.cwd(), 'MindSpace', userId),
});
assert.equal(resolved.source, 'hero');
assert.match(resolved.path ?? '', /\.webp$/);
const coverCheck = verifyWechatDraftCoverResolution(resolved);
assert.equal(coverCheck.ok, true);
});
test('august-afternoon article layout matches publication standard', async () => {
const article = await buildMindSpacePageWechatDraftArticleForPush({
html: AUGUST_HTML,
publicUrl: PUBLIC_URL,
pageTitle: '八月午后 · 一首短诗',
pageSummary: '一首关于八月午后的短诗',
publishDir: path.join(process.cwd(), 'MindSpace', userId),
htmlRelativePath: 'public/august-afternoon.html',
memindLibRoot: process.cwd(),
});
const check = verifyWechatDraftPublicationContent(article.content, { publicUrl: PUBLIC_URL });
assert.equal(check.ok, true, check.issues.join('; '));
assert.match(article.content, /蝉声把正午拉得很长/);
const readIdx = article.content.indexOf('阅读原文');
const followIdx = article.content.indexOf('欢迎关注 TKMind 智趣');
const heroIdx = article.content.indexOf('<img');
assert.ok(heroIdx < readIdx, 'hero 应在阅读原文之前');
assert.ok(readIdx < followIdx, '阅读原文应在关注区之前');
});