Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions __tests__/workers/cdc/primary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ObjectType>({
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<ObjectType>({
after,
before,
op: 'u',
table: 'post',
}),
);

expect(notifyFreeformContentRequested).toHaveBeenCalledTimes(0);
});

it('should notify when yggdrasil id is available on creation', async () => {
const after = {
...base,
Expand Down
11 changes: 11 additions & 0 deletions src/workers/cdc/primary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<FreeformPost>;
if (isFreeformPostLongEnough(freeform)) {
await notifyFreeformContentRequested(logger, freeform);
}
}
if (
data.payload.after!.type === PostType.Freeform &&
data.payload.after!.authorId
Expand Down
Loading