Fix commenter-targeted outreach attribution

This commit is contained in:
jjbrunton committed 2026-08-14 12:45:16 +01:00
1 parent b5304e24e3
commit f77157d303
19 files changed
+328 -49

No files matched your search

+43 -9
View File
@@ -656,15 +656,49 @@ describe('OpenRouterClient', () => {
expect(prompt).toContain('different opening words');
});
it('states that a comment-target recipient is not the person depicted', async () => {
mockCreate.mockResolvedValueOnce({ choices: [{ message: { content: 'That comment caught my attention.' } }] });
await client.generateMessage(
'Analysis', 'Title', 'Commenter', [], undefined, null, null, undefined, [],
'<<<UNTRUSTED PUBLIC COMMENT>>>\nI want that too\n<<<END COMMENT>>>',
);
const prompt = mockCreate.mock.calls[0][0].messages[0].content as string;
expect(prompt).toContain('The recipient commented on somebody else\'s post');
expect(prompt).toContain('Do not imply that the image depicts the recipient');
it('uses a separate commenter contract instead of the image-author prompt', async () => {
mockCreate.mockResolvedValueOnce({ choices: [{ message: { content: 'I saw your comment about wanting that done to you.' } }] });
await client.generateCommentTargetedMessage({
recipient: 'Commenter',
comment: 'I want that too',
sourcePostTitle: 'Source title',
sourceImageAnalysis: 'The source subject is kneeling',
toneGuidance: 'Be direct about her body.',
});
const systemPrompt = mockCreate.mock.calls[0][0].messages[0].content as string;
const userPrompt = mockCreate.mock.calls[0][0].messages[1].content as string;
expect(systemPrompt).toContain('The RECIPIENT is the commenter');
expect(systemPrompt).toContain('The SOURCE POST SUBJECT is a different person');
expect(userPrompt).toContain('I want that too');
expect(`${systemPrompt}\n${userPrompt}`).not.toContain('Write a message for Commenter about');
});
it('regenerates a draft that treats the commenter as the person pictured', async () => {
mockCreate
.mockResolvedValueOnce({ choices: [{ message: { content: 'Your body looks incredible, send me another photo.' } }] })
.mockResolvedValueOnce({ choices: [{ message: { content: 'I saw your comment about wanting to be pinned down. That idea suits you.' } }] });
await expect(client.generateCommentTargetedMessage({
recipient: 'Commenter',
comment: "I wish that was me being pinned down",
sourcePostTitle: 'Source title',
sourceImageAnalysis: 'The source subject is kneeling',
})).resolves.toContain('saw your comment');
expect(mockCreate).toHaveBeenCalledTimes(2);
expect(mockCreate.mock.calls[1][0].messages[1].content).toContain('REWRITE REQUIRED');
});
it('fails closed when regenerated drafts still misattribute the source image', async () => {
mockCreate.mockResolvedValue({ choices: [{ message: { content: 'You look amazing in that photo and your body is perfect.' } }] });
await expect(client.generateCommentTargetedMessage({
recipient: 'Commenter',
comment: 'I want that too',
sourcePostTitle: 'Source title',
sourceImageAnalysis: 'The source subject is kneeling',
})).rejects.toThrow('Comment-targeted opener rejected');
expect(mockCreate).toHaveBeenCalledTimes(2);
});
it('substitutes {rating} placeholder when score provided', async () => {