Skip to content

Commit fa35616

Browse files
authored
feat: brief should not have empty sections (#3254)
1 parent 569c018 commit fa35616

2 files changed

Lines changed: 80 additions & 9 deletions

File tree

__tests__/workers/brief/userGenerateBrief.ts

Lines changed: 73 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ describe('userGenerateBrief worker', () => {
408408
items: [
409409
{
410410
title: 'OpenAI gets a DoD contract, Microsoft gets salty',
411-
body: 'OpenAI landed a $200 million contract with the US Department of Defense for AI tools, marking its first direct federal government partnership. This move, reported by The Verge and TechCrunch, signals a shift from OpenAI’s previous stance on military use. It also puts them in direct competition with Microsoft, their main investor, who previously handled government AI contracts through Azure. The tension is real, with OpenAI reportedly considering an antitrust complaint against Microsoft to loosen their grip.',
411+
body: `OpenAI landed a $200 million contract with the US Department of Defense for AI tools, marking its first direct federal government partnership. This move, reported by The Verge and TechCrunch, signals a shift from OpenAI’s previous stance on military use. It also puts them in direct competition with Microsoft, their main investor, who previously handled government AI contracts through Azure. The tension is real, with OpenAI reportedly considering an antitrust complaint against Microsoft to loosen their grip.`,
412412
},
413413
],
414414
},
@@ -455,7 +455,7 @@ describe('userGenerateBrief worker', () => {
455455
items: [
456456
{
457457
title: 'OpenAI gets a DoD contract, Microsoft gets salty',
458-
body: 'OpenAI landed a $200 million contract with the US Department of Defense for AI tools, marking its first direct federal government partnership. This move, reported by The Verge and TechCrunch, signals a shift from OpenAIs previous stance on military use. It also puts them in direct competition with Microsoft, their main investor, who previously handled government AI contracts through Azure. The tension is real, with OpenAI reportedly considering an antitrust complaint against Microsoft to loosen their grip.',
458+
body: "OpenAI landed a $200 million contract with the US Department of Defense for AI tools, marking its first direct federal government partnership. This move, reported by The Verge and TechCrunch, signals a shift from OpenAI's previous stance on military use. It also puts them in direct competition with Microsoft, their main investor, who previously handled government AI contracts through Azure. The tension is real, with OpenAI reportedly considering an antitrust complaint against Microsoft to loosen their grip.",
459459
},
460460
],
461461
},
@@ -482,7 +482,7 @@ describe('userGenerateBrief worker', () => {
482482
items: [
483483
{
484484
title: 'OpenAI gets a DoD contract, Microsoft gets salty',
485-
body: 'OpenAI landed a $200 million contract with the US Department of Defense for AI tools, marking its first direct federal government partnership. This move, reported by The Verge and TechCrunch, signals a shift from OpenAIs previous stance on military use. It also puts them in direct competition with Microsoft, their main investor, who previously handled government AI contracts through Azure. The tension is real, with OpenAI reportedly considering an antitrust complaint against Microsoft to loosen their grip.',
485+
body: "OpenAI landed a $200 million contract with the US Department of Defense for AI tools, marking its first direct federal government partnership. This move, reported by The Verge and TechCrunch, signals a shift from OpenAI's previous stance on military use. It also puts them in direct competition with Microsoft, their main investor, who previously handled government AI contracts through Azure. The tension is real, with OpenAI reportedly considering an antitrust complaint against Microsoft to loosen their grip.",
486486
},
487487
],
488488
},
@@ -533,7 +533,7 @@ describe('userGenerateBrief worker', () => {
533533
items: [
534534
{
535535
title: 'OpenAI gets a DoD contract, Microsoft gets salty',
536-
body: 'OpenAI landed a $200 million contract with the US Department of Defense for AI tools, marking its first direct federal government partnership. This move, reported by The Verge and TechCrunch, signals a shift from OpenAIs previous stance on military use. It also puts them in direct competition with Microsoft, their main investor, who previously handled government AI contracts through Azure. The tension is real, with OpenAI reportedly considering an antitrust complaint against Microsoft to loosen their grip.',
536+
body: "OpenAI landed a $200 million contract with the US Department of Defense for AI tools, marking its first direct federal government partnership. This move, reported by The Verge and TechCrunch, signals a shift from OpenAI's previous stance on military use. It also puts them in direct competition with Microsoft, their main investor, who previously handled government AI contracts through Azure. The tension is real, with OpenAI reportedly considering an antitrust complaint against Microsoft to loosen their grip.",
537537
postIds: [],
538538
},
539539
],
@@ -551,4 +551,73 @@ describe('userGenerateBrief worker', () => {
551551

552552
expect(triggerTypedEvent).toHaveBeenCalledTimes(1);
553553
});
554+
555+
it('should not include sections with empty items in generated brief', async () => {
556+
const postId = await generateShortId();
557+
558+
const post = con.getRepository(BriefPost).create({
559+
id: postId,
560+
shortId: postId,
561+
authorId: 'ugbw-1',
562+
private: true,
563+
visible: false,
564+
});
565+
566+
await con.getRepository(BriefPost).save(post);
567+
568+
nock('http://api')
569+
.post('/api/user/briefing')
570+
.reply(200, {
571+
sections: [
572+
{
573+
title: 'Must know',
574+
items: [
575+
{
576+
title: 'OpenAI gets a DoD contract, Microsoft gets salty',
577+
body: 'OpenAI landed a $200 million contract with the US Department of Defense for AI tools, marking its first direct federal government partnership.',
578+
},
579+
],
580+
},
581+
{
582+
title: 'Empty section',
583+
items: [],
584+
},
585+
{
586+
title: 'Good to know',
587+
items: [
588+
{
589+
title: 'AI agents are still pretty dumb',
590+
body: "Salesforce's benchmark found AI agents only 58% successful on single tasks.",
591+
},
592+
],
593+
},
594+
],
595+
});
596+
597+
await expectSuccessfulTypedBackground(worker, {
598+
payload: new UserBriefingRequest({
599+
userId: 'ugbw-1',
600+
frequency: BriefingType.Daily,
601+
modelName: BriefingModel.Default,
602+
}),
603+
postId,
604+
});
605+
606+
const briefPost = await con.getRepository(BriefPost).findOne({
607+
where: {
608+
id: postId,
609+
},
610+
});
611+
612+
expect(briefPost).toBeDefined();
613+
expect(briefPost!.visible).toBe(true);
614+
expect(briefPost!.content).toBe(`## Must know
615+
616+
- **OpenAI gets a DoD contract, Microsoft gets salty**: OpenAI landed a $200 million contract with the US Department of Defense for AI tools, marking its first direct federal government partnership.
617+
618+
## Good to know
619+
620+
- **AI agents are still pretty dumb**: Salesforce's benchmark found AI agents only 58% successful on single tasks.`);
621+
expect(briefPost!.content).not.toContain('Empty section');
622+
});
554623
});

src/workers/brief/userGenerateBrief.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@ const generateMarkdown = (data: Briefing): string => {
2020
let markdown = '';
2121

2222
for (const section of data.sections) {
23-
markdown += `## ${section.title}\n\n`;
23+
if (section.items.length) {
24+
markdown += `## ${section.title}\n\n`;
2425

25-
for (const item of section.items) {
26-
markdown += `- **${item.title}**: ${item.body}\n`;
27-
}
26+
for (const item of section.items) {
27+
markdown += `- **${item.title}**: ${item.body}\n`;
28+
}
2829

29-
markdown += '\n';
30+
markdown += '\n';
31+
}
3032
}
3133

3234
return markdown.trim();

0 commit comments

Comments
 (0)