fix preview sandbox and local analytics proxy

This commit is contained in:
john
2026-07-24 14:21:06 +08:00
parent dab6140f99
commit 54637beffb
4 changed files with 21 additions and 2 deletions
+18
View File
@@ -117,6 +117,24 @@ test('buildChatSavePreviewUrls use local api routes', () => {
);
});
test('chat page previews keep generated scripts sandboxed and proxy analytics through Portal', async () => {
const [pageSavePreview, chatSharePreview, viteConfig] = await Promise.all([
fs.readFile(new URL('./src/components/PageSavePreviewPanel.tsx', import.meta.url), 'utf8'),
fs.readFile(new URL('./src/components/ChatSharePreviewModal.tsx', import.meta.url), 'utf8'),
fs.readFile(new URL('./vite.config.ts', import.meta.url), 'utf8'),
]);
assert.match(pageSavePreview, /sandbox="allow-scripts allow-downloads"/);
assert.match(chatSharePreview, /sandbox="allow-scripts allow-popups allow-downloads"/);
for (const source of [pageSavePreview, chatSharePreview]) {
assert.doesNotMatch(
source,
/sandbox="[^"]*(?:allow-scripts[^"]*allow-same-origin|allow-same-origin[^"]*allow-scripts)[^"]*"/,
);
}
assert.match(viteConfig, /['"]\/analytics['"]\s*:\s*portalTarget/);
});
test('findPublishHtml resolves nested public html by basename', async () => {
const root = await fs.mkdtemp(path.join(os.tmpdir(), 'memind-chat-save-'));
const publishDir = path.join(root, 'MindSpace', USER_ID, 'public');