import assert from 'node:assert/strict'; import test from 'node:test'; import { extractFaqFromHeadings, parseMindspaceGeoMeta, resolveGeoFaq, resolveGeoKeywords, } from './mindspace-geo-meta.mjs'; test('parseMindspaceGeoMeta reads author faq and keywords', () => { const html = ``; const meta = parseMindspaceGeoMeta(html); assert.equal(meta.summary, '攻略'); assert.deepEqual(meta.keywords, ['旅游']); assert.equal(meta.faq.length, 1); }); test('parseMindspaceGeoMeta reads legacy single-quoted json with apostrophes in faq', () => { const html = ``; const meta = parseMindspaceGeoMeta(html); assert.equal(meta.summary, '业绩回顾'); assert.equal(meta.faq[0].a, '单客户费比上限18%,超标须特批'); }); test('extractFaqFromHeadings builds faq from h2 and paragraph', () => { const html = `

最佳季节

春秋两季气候最舒适,适合徒步与摄影。

交通方式

可乘坐高铁到仙居站,再转乘景区巴士。

`; const faq = extractFaqFromHeadings(html); assert.equal(faq.length, 2); assert.equal(faq[0].q, '最佳季节'); assert.match(faq[0].a, /春秋/); }); test('resolveGeoFaq prefers author faq over extracted headings', () => { const html = `

自动问题

自动答案内容足够长以通过校验。

`; const faq = resolveGeoFaq(html); assert.equal(faq[0].q, '作者问题'); }); test('resolveGeoKeywords falls back to cover tag and h2 headings', () => { const html = `仙居玩水攻略

装备清单

`; const keywords = resolveGeoKeywords(html); assert.ok(keywords.includes('旅行')); assert.ok(keywords.includes('装备清单')); });