745e9b691d
Memind CI / Test, build, and release guards (pull_request) Successful in 3m35s
未点公开发布但已落盘到 public/ 的页面,在无在线非 public 发布阻挡时 合成 implicit public snapshot,注入 canonical/JSON-LD 并扫描进 sitemap。 Co-authored-by: Cursor <cursoragent@cursor.com>
100 lines
3.2 KiB
JavaScript
100 lines
3.2 KiB
JavaScript
import assert from 'node:assert/strict';
|
|
import test from 'node:test';
|
|
import {
|
|
buildImplicitWorkspacePublicPublication,
|
|
isPublicationIndexable,
|
|
isWorkspacePublicHtmlRelativePath,
|
|
resolveIndexPolicy,
|
|
} from './mindspace-index-policy.mjs';
|
|
|
|
const indexablePublication = {
|
|
status: 'online',
|
|
accessMode: 'public',
|
|
userConfirmedAt: Date.now() - 1000,
|
|
expiresAt: null,
|
|
publicUrl: '/u/john/pages/demo',
|
|
};
|
|
|
|
test('isPublicationIndexable accepts confirmed public online publications', () => {
|
|
assert.equal(isPublicationIndexable(indexablePublication), true);
|
|
});
|
|
|
|
test('isPublicationIndexable accepts public online pages without confirmation', () => {
|
|
assert.equal(
|
|
isPublicationIndexable({ ...indexablePublication, userConfirmedAt: null }),
|
|
true,
|
|
);
|
|
});
|
|
|
|
test('isPublicationIndexable rejects private access modes', () => {
|
|
for (const accessMode of ['password', 'private_link', 'login_required', 'owner_only']) {
|
|
assert.equal(
|
|
isPublicationIndexable({ ...indexablePublication, accessMode }),
|
|
false,
|
|
);
|
|
}
|
|
});
|
|
|
|
test('resolveIndexPolicy stays off when master switch disabled', () => {
|
|
const policy = resolveIndexPolicy({
|
|
seoGeoConfig: { enabled: false },
|
|
publication: indexablePublication,
|
|
});
|
|
assert.equal(policy.mode, 'off');
|
|
assert.equal(policy.injectNoindex, false);
|
|
});
|
|
|
|
test('resolveIndexPolicy noindexes non-public publications when enabled', () => {
|
|
const policy = resolveIndexPolicy({
|
|
seoGeoConfig: { enabled: true, seo: { enabled: true }, geo: { enabled: true } },
|
|
publication: { ...indexablePublication, accessMode: 'password' },
|
|
});
|
|
assert.equal(policy.mode, 'noindex');
|
|
assert.equal(policy.injectNoindex, true);
|
|
});
|
|
|
|
test('resolveIndexPolicy marks public online pages indexable', () => {
|
|
const policy = resolveIndexPolicy({
|
|
seoGeoConfig: {
|
|
enabled: true,
|
|
seo: { enabled: true, canonical: true },
|
|
geo: { enabled: true, jsonLd: true },
|
|
},
|
|
publication: indexablePublication,
|
|
});
|
|
assert.equal(policy.mode, 'indexable');
|
|
assert.equal(policy.seoEnabled, true);
|
|
assert.equal(policy.geoEnabled, true);
|
|
});
|
|
|
|
test('resolveIndexPolicy skips embed delivery', () => {
|
|
const policy = resolveIndexPolicy({
|
|
seoGeoConfig: { enabled: true },
|
|
publication: indexablePublication,
|
|
embed: true,
|
|
});
|
|
assert.equal(policy.mode, 'off');
|
|
});
|
|
|
|
test('isWorkspacePublicHtmlRelativePath accepts public html and rejects archived', () => {
|
|
assert.equal(isWorkspacePublicHtmlRelativePath('public/demo.html'), true);
|
|
assert.equal(isWorkspacePublicHtmlRelativePath('public/_archived-demo.html'), false);
|
|
assert.equal(isWorkspacePublicHtmlRelativePath('private/demo.html'), false);
|
|
});
|
|
|
|
test('buildImplicitWorkspacePublicPublication marks workspace public html indexable', () => {
|
|
const snapshot = buildImplicitWorkspacePublicPublication({
|
|
publicUrl: '/MindSpace/user/public/demo.html',
|
|
});
|
|
assert.equal(isPublicationIndexable(snapshot), true);
|
|
const policy = resolveIndexPolicy({
|
|
seoGeoConfig: {
|
|
enabled: true,
|
|
seo: { enabled: true, canonical: true },
|
|
geo: { enabled: true, jsonLd: true },
|
|
},
|
|
publication: snapshot,
|
|
});
|
|
assert.equal(policy.mode, 'indexable');
|
|
});
|