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

+47
View File
@@ -98,6 +98,53 @@ describe('CandidateQueueRepository', () => {
expect(queue.countActive()).toBe(2);
});
it('requeues only unedited commenter preparations from the legacy opener contract', () => {
const legacyComment = {
...post('comment-legacy', 'alice', 300),
targetComment: {
body: 'I wish that was me', permalink: '/r/test/comment-legacy/c1',
sourcePostId: 'source', sourcePostAuthor: 'source-author',
expressedGender: 'unknown' as const, confidence: 0.93,
},
};
const currentComment = {
...post('comment-current', 'bob', 200),
targetComment: {
body: 'I want that too', permalink: '/r/test/comment-current/c2',
sourcePostId: 'source', sourcePostAuthor: 'source-author',
expressedGender: 'unknown' as const, confidence: 0.91,
},
};
const editedComment = {
...post('comment-edited', 'dana', 150),
targetComment: {
body: 'I would love that', permalink: '/r/test/comment-edited/c3',
sourcePostId: 'source', sourcePostAuthor: 'source-author',
expressedGender: 'unknown' as const, confidence: 0.9,
},
};
queue.enqueue([legacyComment, currentComment, editedComment, post('post-author', 'carol', 100)], 'image', 1, 1_000);
for (let index = 0; index < 4; index += 1) {
const worker = `worker-${index}`;
const candidate = queue.claimForScreening(worker, 100, 1_010)!;
const contract = candidate.postId === 'comment-current'
? 'comment-author-v2'
: candidate.postId === 'post-author' ? 'post-author-v1' : undefined;
queue.markReady(candidate.postId, worker, {
...prepared(candidate.post), openerContract: contract,
operatorEdited: candidate.postId === 'comment-edited',
}, 1_011);
}
expect(queue.requeueLegacyCommentPreparations(1_020)).toBe(1);
expect(queue.listActive()).toEqual(expect.arrayContaining([
expect.objectContaining({ postId: 'comment-legacy', status: 'discovered', prepared: null }),
expect.objectContaining({ postId: 'comment-current', status: 'ready' }),
expect.objectContaining({ postId: 'comment-edited', status: 'ready' }),
expect.objectContaining({ postId: 'post-author', status: 'ready' }),
]));
});
it('admits, screens, and sends the newest posts before older higher-priority posts', () => {
queue.enqueue([
post('old-high-priority', 'alice', 100),