fix(wechat): sync MindSpace pages after MP generation and redirect on 401
Memind CI / Test, build, and release guards (push) Failing after 3m31s

WeChat page delivery now triggers syncUserGeneratedPages so write_file HTML
gets page records; public share widget redirects unauthenticated owners to
WeChat OAuth instead of only showing an error.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
john
2026-09-11 19:58:25 +08:00
parent 2c3c1f7a52
commit 0e7e4829db
6 changed files with 191 additions and 8 deletions
@@ -51,6 +51,7 @@ export async function bootstrapPortalIntegrationServices({
apiSecret,
mindSpacePages,
mindSpacePageLiveEdit,
syncUserGeneratedPages = null,
logger = console,
healthChannelStore = null,
healthObservationStore = null,
@@ -212,6 +213,35 @@ export async function bootstrapPortalIntegrationServices({
sessionId,
artifacts = [],
}) => {
const relativePaths = [
...new Set(
artifacts
.map((artifact) =>
String(
artifact?.relativePath ??
artifact?.relative_path ??
'',
).trim(),
)
.filter(Boolean),
),
];
if (
typeof syncUserGeneratedPages === 'function' &&
userId
) {
void syncUserGeneratedPages(userId, {
sessionId,
sinceMs: Date.now() - 10 * 60 * 1000,
onlyRelativePaths:
relativePaths.length > 0 ? relativePaths : null,
}).catch((error) => {
logger.warn?.(
'[WeChat MP] page sync after generation failed:',
error instanceof Error ? error.message : error,
);
});
}
for (const artifact of artifacts) {
const pageOwner =
(await userAuth
@@ -129,6 +129,10 @@ function createSetup(overrides = {}) {
apiSecret: 'secret',
mindSpacePages: { id: 'pages' },
mindSpacePageLiveEdit: { id: 'live-edit' },
syncUserGeneratedPages(userId, options) {
calls.push(['sync-user-pages', userId, options]);
return Promise.resolve({ created: 1, updated: 0, skipped: 0 });
},
logger: {
log(...args) {
calls.push(['log', ...args]);
@@ -407,6 +411,13 @@ test('preserves generated-page analytics projection', async () => {
.length,
1,
);
const syncCall = setup.calls.find(
([name]) => name === 'sync-user-pages',
);
assert.ok(syncCall);
assert.equal(syncCall[1], 'user-1');
assert.equal(syncCall[2].sessionId, 'session-1');
assert.deepEqual(syncCall[2].onlyRelativePaths, ['public/page.html']);
const analyticsCall = setup.calls.find(
([name]) => name === 'analytics',
);