Files
memind/mindspace-workspace-page-deliver-page-data.test.mjs
john fb055c6721 fix(page-data): bind Page Data pages structurally on deliver, not by intent
Finish/sync now auto-registers datasets and binds any HTML using page-data-client.js
before publication, so user confirmation cannot publish unbound collect pages.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-13 00:18:49 +08:00

75 lines
2.4 KiB
JavaScript

import assert from 'node:assert/strict';
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import test from 'node:test';
import { createWorkspacePageDeliverService } from './mindspace-workspace-page-deliver.mjs';
const PAGE_DATA_HTML = `<!doctype html><html><body>
<script src="/assets/page-data-client.js"></script>
<script>MindSpacePageData.createClient({ apiBase: '/api' }).insertRow('survey', { q1: 'a' });</script>
</body></html>`;
test('ensureWorkspaceHtmlPublications skips page-data html and delegates to pageDataEnsure', async () => {
const h5Root = fs.mkdtempSync(path.join(os.tmpdir(), 'deliver-h5-'));
const userId = 'user-1';
const publishDir = path.join(h5Root, 'MindSpace', userId);
fs.mkdirSync(path.join(publishDir, 'public'), { recursive: true });
fs.writeFileSync(path.join(publishDir, 'public', 'survey.html'), PAGE_DATA_HTML, 'utf8');
const published = [];
const bound = [];
const service = createWorkspacePageDeliverService({
pool: {
async query() {
return [[{
page_id: 'page-1',
title: '问卷',
current_version_id: 'ver-1',
workspace_relative_path: 'public/survey.html',
source_snapshot_json: JSON.stringify({
auto_synced: true,
relative_path: 'public/survey.html',
content_mode: 'static_html',
}),
}]];
},
},
pageService: {
async getPage() {
return { id: 'page-1', title: '问卷', currentVersionId: 'ver-1' };
},
findPageByRelativePath: async () => null,
},
publicationService: {
async getCurrent() {
return null;
},
async publish(userIdArg, pageId, input) {
published.push({ userId: userIdArg, pageId, input });
return { id: 'pub-1' };
},
},
pageSyncService: {
async syncUserGeneratedPages() {
return { created: 0, updated: 0, skipped: 0 };
},
},
pageDataEnsure: {
async ensurePageDataHtmlPagesBound() {
bound.push(true);
return { bound: [{ relativePath: 'public/survey.html' }], skipped: [], errors: [] };
},
},
h5Root,
storageRoot: null,
});
const result = await service.syncAndDeliver(userId);
assert.equal(bound.length, 1);
assert.equal(result.publish.published, 0);
assert.equal(result.publish.skipped, 1);
assert.equal(published.length, 0);
fs.rmSync(h5Root, { recursive: true, force: true });
});