Files
memind/mindspace-seo-discovery-service.test.mjs
T
john f281f15788
Memind CI / Test, build, and release guards (pull_request) Failing after 3m21s
feat(seo): 固化 m.tkmind.cn 百度验证、推送与 sitemap 去重
让 Portal 首页稳定注入站长验证 meta,并提供 sitemap 批量推送脚本与 LaunchAgent 安装入口;sitemap/llms 对同页优先保留 /u/ canonical URL。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-16 16:28:46 +08:00

81 lines
2.4 KiB
JavaScript

import assert from 'node:assert/strict';
import test from 'node:test';
import {
dedupeDiscoveryEntriesByPage,
mergeDiscoveryEntries,
renderLlmsTxt,
renderRobotsTxt,
renderSitemapXml,
} from './mindspace-seo-discovery-service.mjs';
test('renderSitemapXml emits only provided urls', () => {
const xml = renderSitemapXml(
[{ publicUrl: '/u/john/pages/demo', updatedAt: Date.parse('2026-08-01T00:00:00.000Z') }],
{ origin: 'https://m.tkmind.cn' },
);
assert.match(xml, /<loc>https:\/\/m\.tkmind\.cn\/u\/john\/pages\/demo<\/loc>/);
});
test('renderRobotsTxt references sitemap when enabled', () => {
const body = renderRobotsTxt({
origin: 'https://m.tkmind.cn',
sitemapEnabled: true,
llmsTxtEnabled: true,
});
assert.match(body, /Sitemap: https:\/\/m\.tkmind\.cn\/sitemap\.xml/);
assert.match(body, /llms\.txt/);
});
test('dedupeDiscoveryEntriesByPage prefers /u/ urls for the same page', () => {
const merged = dedupeDiscoveryEntriesByPage([
{
pageId: 'page-1',
publicUrl: '/MindSpace/user/public/demo.html',
accessMode: 'public',
status: 'online',
},
{
pageId: 'page-1',
publicUrl: '/u/john/pages/demo',
accessMode: 'public',
status: 'online',
},
]);
assert.equal(merged.length, 1);
assert.equal(merged[0].publicUrl, '/u/john/pages/demo');
});
test('dedupeDiscoveryEntriesByPage drops archived duplicates', () => {
const merged = dedupeDiscoveryEntriesByPage([
{
pageId: 'page-2',
publicUrl: '/MindSpace/user/public/_archived-demo.html',
accessMode: 'public',
status: 'online',
},
{
pageId: 'page-2',
publicUrl: '/u/john/pages/demo',
accessMode: 'public',
status: 'online',
},
]);
assert.equal(merged.length, 1);
assert.equal(merged[0].publicUrl, '/u/john/pages/demo');
});
test('mergeDiscoveryEntries appends platform static pages', () => {
const merged = mergeDiscoveryEntries([
{ publicUrl: '/u/john/pages/demo', accessMode: 'public', status: 'online' },
]);
assert.ok(merged.some((entry) => String(entry.publicUrl ?? '').includes('/learn/')));
});
test('renderLlmsTxt lists markdown links', () => {
const body = renderLlmsTxt(
[{ publicUrl: '/u/john/pages/demo', summary: '仙居玩水' }],
{ origin: 'https://m.tkmind.cn' },
);
assert.match(body, /\[仙居玩水\]\(https:\/\/m\.tkmind\.cn\/u\/john\/pages\/demo\)/);
});