fix: restore page links after delayed materialization

This commit is contained in:
john
2026-07-24 17:58:52 +08:00
parent 550969bed2
commit 1d291fd528
3 changed files with 25 additions and 0 deletions
+15
View File
@@ -219,6 +219,21 @@ test('sanitizePublicHtmlLinksInText finds pages in the workspace beside H5_USERS
}
});
test('sanitizePublicHtmlLinksInText restores a previously suppressed link after the page appears', () => {
const owner = `test-user-${Date.now()}-restored-link`;
const htmlPath = path.join(process.cwd(), 'MindSpace', owner, 'public', 'poem.html');
try {
fs.mkdirSync(path.dirname(htmlPath), { recursive: true });
fs.writeFileSync(htmlPath, '<!doctype html><title>Poem</title>');
const text = '页面链接:\n(页面生成未完成,已阻止显示失效链接:poem.html。)';
const next = sanitizePublicHtmlLinksInText(text, { id: owner, username: 'john' });
assert.match(next, new RegExp(`\\[poem\\.html\\]\\([^)]*/MindSpace/${owner}/public/poem\\.html\\)`));
assert.doesNotMatch(next, /页面生成未完成/);
} finally {
fs.rmSync(path.join(process.cwd(), 'MindSpace', owner), { recursive: true, force: true });
}
});
test('sanitizePublicHtmlLinksInText canonicalizes wrong MindSpace public hosts', () => {
const owner = `test-user-${Date.now()}-canonical-host`;
const previousBase = process.env.H5_PUBLIC_BASE_URL;