diff --git a/__tests__/workers/cdc/primary.ts b/__tests__/workers/cdc/primary.ts index bad9e2dc52..60eb75475d 100644 --- a/__tests__/workers/cdc/primary.ts +++ b/__tests__/workers/cdc/primary.ts @@ -1781,6 +1781,61 @@ describe('post', () => { expect(notifyContentRequested).toHaveBeenCalledTimes(0); }); + it('should re-request enrichment when a scheduled freeform post becomes visible', async () => { + const before = { + ...base, + type: PostType.Freeform, + content: '1'.repeat(FREEFORM_POST_MINIMUM_CONTENT_LENGTH), + visible: false, + }; + const after = { + ...before, + visible: true, + }; + + await expectSuccessfulBackground( + worker, + mockChangeMessage({ + after, + before, + op: 'u', + table: 'post', + }), + ); + + expect(notifyFreeformContentRequested).toHaveBeenCalledTimes(1); + expect( + jest.mocked(notifyFreeformContentRequested).mock.calls[0][1].payload + .after, + ).toEqual(after); + }); + + it('should not re-request enrichment when a freeform post that becomes visible is too short', async () => { + const before = { + ...base, + type: PostType.Freeform, + title: '', + content: '', + visible: false, + }; + const after = { + ...before, + visible: true, + }; + + await expectSuccessfulBackground( + worker, + mockChangeMessage({ + after, + before, + op: 'u', + table: 'post', + }), + ); + + expect(notifyFreeformContentRequested).toHaveBeenCalledTimes(0); + }); + it('should notify when yggdrasil id is available on creation', async () => { const after = { ...base, diff --git a/src/workers/cdc/primary.ts b/src/workers/cdc/primary.ts index f562db75b2..3ef97e068b 100644 --- a/src/workers/cdc/primary.ts +++ b/src/workers/cdc/primary.ts @@ -1198,6 +1198,17 @@ const onPostChange = async ( data.payload.after!, data.payload.before!, ); + if (data.payload.after!.type === PostType.Freeform) { + // A scheduled freeform post just went live. Its tags/contentQuality were + // captured once when it was scheduled and are never refreshed at publish, + // so a post enriched during a broken window (e.g. empty tags) goes live + // broken. Re-request enrichment — same content-requested emit as creation — + // so yggdrasil re-enriches against current models before it's shown. + const freeform = data as ChangeMessage; + if (isFreeformPostLongEnough(freeform)) { + await notifyFreeformContentRequested(logger, freeform); + } + } if ( data.payload.after!.type === PostType.Freeform && data.payload.after!.authorId