Add commenter targeting mode

This commit is contained in:
Jamie Brunton committed 2026-08-14 08:51:27 +01:00
1 parent 0dfdda61fd
commit e9a4c965ee
23 files changed
+374 -10

No files matched your search

+78
View File
@@ -675,4 +675,82 @@ describe('MonitorService', () => {
expect(result[0].id).toBe('t3_m');
});
});
describe('comment-author targeting', () => {
it('turns a high-confidence targeted reaction into a commenter candidate with source media intact', async () => {
const source: RedditPost = {
id: 'post1', name: 't3_post1', subreddit: 'scene', author: 'poster', title: 'A scene',
url: 'https://example.com/scene.jpg', permalink: '/r/scene/comments/post1/a_scene/', thumbnail: '',
is_self: false, created_utc: 100, over_18: true, spoiler: false,
};
const redditApi = createMockRedditApi([source]);
redditApi.getBrowsingComments = vi.fn().mockResolvedValue([
{
fullname: 't1_match', kind: 'comment', subreddit: 'scene', author: 'reactor',
permalink: '/r/scene/comments/post1/a_scene/match/', createdAt: 101_000, score: 2,
text: "I'd love that to be done to me", nsfw: true, parentPostId: 'post1',
distinguished: null, removed: false,
},
{
fullname: 't1_praise', kind: 'comment', subreddit: 'scene', author: 'fan',
permalink: '/r/scene/comments/post1/a_scene/praise/', createdAt: 102_000, score: 1,
text: 'Great post, thanks for sharing', nsfw: true, parentPostId: 'post1',
distinguished: null, removed: false,
},
]);
const screener = {
screenCommentReactions: vi.fn().mockResolvedValue([
{ id: 't1_match', qualifies: true, expressedGender: 'female', confidence: 0.94, evidence: 'personal desire' },
{ id: 't1_praise', qualifies: false, expressedGender: 'unknown', confidence: 0.98, evidence: 'generic praise' },
]),
};
const config = getTestConfig({ reddit: {
subreddits: [{ name: 'scene', type: 'image', targetingMode: 'comment-author' }],
targetGenders: ['female'],
} });
monitor = new MonitorService(
redditApi, createMockPostsRepo(), createMockMessagesRepo(), config, logger, 0, undefined, screener,
);
const candidates = await monitor.fetchCandidates(config.reddit.subreddits[0]);
expect(candidates).toHaveLength(1);
expect(candidates[0]).toMatchObject({
id: 't1_match', name: 't1_match', author: 'reactor', url: source.url,
permalink: '/r/scene/comments/post1/a_scene/match/',
targetComment: {
body: "I'd love that to be done to me", sourcePostId: 'post1',
sourcePostAuthor: 'poster', expressedGender: 'female', confidence: 0.94,
},
});
await monitor.fetchCandidates(config.reddit.subreddits[0]);
expect(screener.screenCommentReactions).toHaveBeenCalledTimes(1);
});
it('fails closed on low-confidence or non-qualifying reactions', async () => {
const source = {
id: 'post1', name: 't3_post1', subreddit: 'scene', author: 'poster', title: 'A scene',
url: 'https://example.com/scene.jpg', permalink: '/r/scene/comments/post1/', thumbnail: '',
is_self: false, created_utc: 100, over_18: true, spoiler: false,
} as RedditPost;
const redditApi = createMockRedditApi([source]);
redditApi.getBrowsingComments = vi.fn().mockResolvedValue([
{ fullname: 't1_low', author: 'a', text: 'I want this as well', removed: false, createdAt: 101_000, permalink: '/low' },
{ fullname: 't1_male', author: 'b', text: 'As a man I want this', removed: false, createdAt: 102_000, permalink: '/male' },
]);
const screener = { screenCommentReactions: vi.fn().mockResolvedValue([
{ id: 't1_low', qualifies: true, expressedGender: 'female', confidence: 0.79, evidence: '' },
{ id: 't1_male', qualifies: false, expressedGender: 'male', confidence: 0.99, evidence: '' },
]) };
const config = getTestConfig({ reddit: {
subreddits: [{ name: 'scene', type: 'image', targetingMode: 'comment-author' }],
targetGenders: ['female'],
} });
monitor = new MonitorService(
redditApi, createMockPostsRepo(), createMockMessagesRepo(), config, logger, 0, undefined, screener,
);
await expect(monitor.fetchCandidates(config.reddit.subreddits[0])).resolves.toEqual([]);
});
});
});