feat(wechat): MindSpace public draft push with 143 host defaults
Add public-page WeChat draft button, publication standard conversion for poem/prose/generic pages, and quick push APIs. Default Studio release SSH targets to john@180.159.29.143 with 105 edge upstream via 10.10.0.2. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,103 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import {
|
||||
getQuickWechatDraftFromPublicHtmlStatus,
|
||||
quickWechatDraftFromPublicHtml,
|
||||
} from './mindspace-chat-wechat-draft.mjs';
|
||||
|
||||
const SAMPLE_HTML = `<!DOCTYPE html><html><head><title>测试页面</title></head><body><h1>标题</h1><p>正文</p></body></html>`;
|
||||
|
||||
test('getQuickWechatDraftFromPublicHtmlStatus reports validation and config state', async () => {
|
||||
const result = await getQuickWechatDraftFromPublicHtmlStatus({
|
||||
user: { id: 'user-1' },
|
||||
relativePath: 'public/demo.html',
|
||||
mindSpacePages: {
|
||||
async findPageByRelativePath(userId, relativePath) {
|
||||
assert.equal(userId, 'user-1');
|
||||
assert.equal(relativePath, 'public/demo.html');
|
||||
return { id: 'page-1', title: '测试页面', summary: '摘要' };
|
||||
},
|
||||
},
|
||||
mindSpacePublications: {
|
||||
async getCurrent(userId, pageId) {
|
||||
assert.equal(userId, 'user-1');
|
||||
assert.equal(pageId, 'page-1');
|
||||
return { publicUrl: 'https://m.tkmind.cn/u/demo/pages/demo.html' };
|
||||
},
|
||||
},
|
||||
readWorkspaceHtml: async ({ userId, relativePath }) => {
|
||||
assert.equal(userId, 'user-1');
|
||||
assert.equal(relativePath, 'public/demo.html');
|
||||
return { html: SAMPLE_HTML };
|
||||
},
|
||||
getWechatMpConfig: () => ({
|
||||
async getConfig() {
|
||||
return { configured: true };
|
||||
},
|
||||
}),
|
||||
getWechatPageDraft: () => ({
|
||||
async listRuns() {
|
||||
return [];
|
||||
},
|
||||
}),
|
||||
});
|
||||
|
||||
assert.equal(result.pageId, 'page-1');
|
||||
assert.equal(result.configured, true);
|
||||
assert.equal(result.canPush, true);
|
||||
assert.equal(result.validation.profile, 'generic');
|
||||
});
|
||||
|
||||
test('quickWechatDraftFromPublicHtml validates before push', async () => {
|
||||
await assert.rejects(
|
||||
() => quickWechatDraftFromPublicHtml({
|
||||
user: { id: 'user-1' },
|
||||
relativePath: 'public/empty.html',
|
||||
mindSpacePages: {
|
||||
async findPageByRelativePath() {
|
||||
return { id: 'page-1', title: '', summary: '' };
|
||||
},
|
||||
},
|
||||
mindSpacePublications: {
|
||||
async getCurrent() {
|
||||
return { publicUrl: 'https://example.com/empty.html' };
|
||||
},
|
||||
},
|
||||
readWorkspaceHtml: async () => ({ html: '' }),
|
||||
getWechatPageDraft: () => ({
|
||||
async pushPageDraft() {
|
||||
throw new Error('should not push invalid page');
|
||||
},
|
||||
}),
|
||||
}),
|
||||
(error) => error.code === 'wechat_draft_validation_failed',
|
||||
);
|
||||
});
|
||||
|
||||
test('quickWechatDraftFromPublicHtml delegates to draft service', async () => {
|
||||
const calls = [];
|
||||
const result = await quickWechatDraftFromPublicHtml({
|
||||
user: { id: 'user-1' },
|
||||
relativePath: 'public/demo.html',
|
||||
mindSpacePages: {
|
||||
async findPageByRelativePath() {
|
||||
return { id: 'page-1', title: '测试页面', summary: '摘要' };
|
||||
},
|
||||
},
|
||||
mindSpacePublications: {
|
||||
async getCurrent() {
|
||||
return { publicUrl: 'https://example.com/demo.html' };
|
||||
},
|
||||
},
|
||||
readWorkspaceHtml: async () => ({ html: SAMPLE_HTML }),
|
||||
getWechatPageDraft: () => ({
|
||||
async pushPageDraft(userId, pageId, options) {
|
||||
calls.push([userId, pageId, options]);
|
||||
return { ok: true, draftMediaId: 'draft-1' };
|
||||
},
|
||||
}),
|
||||
});
|
||||
|
||||
assert.deepEqual(calls, [['user-1', 'page-1', { triggeredBy: 'user-1', skipValidation: true }]]);
|
||||
assert.equal(result.draftMediaId, 'draft-1');
|
||||
});
|
||||
Reference in New Issue
Block a user