diff --git a/mindspace-wechat-page-draft.test.mjs b/mindspace-wechat-page-draft.test.mjs index f2bab1f..2e62c2c 100644 --- a/mindspace-wechat-page-draft.test.mjs +++ b/mindspace-wechat-page-draft.test.mjs @@ -230,26 +230,43 @@ test('convertGenericPageHtmlToWechatArticle leaves length clipping to layout', ( }); test('resolveWechatDraftThumbPath prefers hero image over thumbnail sidecar', () => { - const userId = '1c99b83b-0454-474f-a5d2-129d34506a32'; - const html = fs.readFileSync(`MindSpace/${userId}/public/august-afternoon.html`, 'utf8'); + const userId = 'test-user-hero-pref'; + const root = fs.mkdtempSync(path.join(os.tmpdir(), 'wechat-thumb-hero-')); + const publishDir = path.join(root, 'MindSpace', userId); + const publicDir = path.join(publishDir, 'public'); + fs.mkdirSync(publicDir, { recursive: true }); + const heroPath = path.join(publicDir, 'images', 'hero-ca5a45b835d8.webp'); + fs.mkdirSync(path.dirname(heroPath), { recursive: true }); + fs.writeFileSync(heroPath, Buffer.from('webp')); + fs.writeFileSync(path.join(publicDir, 'august-afternoon.thumbnail.png'), Buffer.from('png')); + const html = `八月午后 + +

标题

`; + fs.writeFileSync(path.join(publicDir, 'august-afternoon.html'), html, 'utf8'); const resolved = resolveWechatDraftThumbPath(html, { - h5Root: process.cwd(), + h5Root: root, userId, workspaceRelativePath: 'public/august-afternoon.html', - publishDir: path.join(process.cwd(), 'MindSpace', userId), + publishDir, }); assert.equal(resolved.source, 'hero'); assert.match(resolved.path ?? '', /hero-ca5a45b835d8\.webp$/); }); test('resolveWechatDraftThumbPath falls back to raster sidecar when hero missing', () => { - const userId = '1c99b83b-0454-474f-a5d2-129d34506a32'; + const userId = 'test-user-sidecar-fallback'; + const root = fs.mkdtempSync(path.join(os.tmpdir(), 'wechat-thumb-sidecar-')); + const publishDir = path.join(root, 'MindSpace', userId); + const publicDir = path.join(publishDir, 'public'); + fs.mkdirSync(publicDir, { recursive: true }); + fs.writeFileSync(path.join(publicDir, 'august-afternoon.thumbnail.png'), Buffer.from('png')); const html = `无 hero

标题

`; + fs.writeFileSync(path.join(publicDir, 'august-afternoon.html'), html, 'utf8'); const resolved = resolveWechatDraftThumbPath(html, { - h5Root: process.cwd(), + h5Root: root, userId, workspaceRelativePath: 'public/august-afternoon.html', - publishDir: path.join(process.cwd(), 'MindSpace', userId), + publishDir, }); assert.equal(resolved.source, 'thumbnail-sidecar'); assert.match(resolved.path ?? '', /august-afternoon\.thumbnail\.png$/);