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('

正文

', { 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('