Skip to content

Commit

Permalink
Fetch staged entries from Brave Search before opt-in to Leo (uplift t…
Browse files Browse the repository at this point in the history
…o 1.73.x) (#26468)

Merge pull request #26424 from brave/fix_opt_in_case

Fetch staged entries from Brave Search before opt-in to Leo
  • Loading branch information
yrliou authored Nov 11, 2024
1 parent 68175ae commit 9b43ec8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 20 deletions.
5 changes: 2 additions & 3 deletions components/ai_chat/core/browser/conversation_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1031,8 +1031,7 @@ void ConversationHandler::MaybeFetchOrClearContentStagedConversation() {
}

const bool can_check_for_staged_conversation =
ai_chat_service_->HasUserOptedIn() && IsContentAssociationPossible() &&
should_send_page_contents_;
IsContentAssociationPossible() && should_send_page_contents_;
if (!can_check_for_staged_conversation) {
// Clear any staged conversation entries since user might have unassociated
// content with this conversation
Expand All @@ -1055,7 +1054,7 @@ void ConversationHandler::OnGetStagedEntriesFromContent(
const std::optional<std::vector<SearchQuerySummary>>& entries) {
// Check if all requirements are still met.
if (is_request_in_progress_ || !entries || !IsContentAssociationPossible() ||
!should_send_page_contents_ || !ai_chat_service_->HasUserOptedIn()) {
!should_send_page_contents_) {
return;
}

Expand Down
21 changes: 5 additions & 16 deletions components/ai_chat/core/browser/conversation_handler_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1089,13 +1089,6 @@ TEST_F(ConversationHandlerUnitTest,
conversation_handler_->OnGetStagedEntriesFromContent(entries);
task_environment_.RunUntilIdle();
EXPECT_EQ(conversation_handler_->GetConversationHistory().size(), 0u);

// No staged entries if user opt-out.
conversation_handler_->SetShouldSendPageContents(true);
EmulateUserOptedOut();
conversation_handler_->OnGetStagedEntriesFromContent(entries);
task_environment_.RunUntilIdle();
EXPECT_EQ(conversation_handler_->GetConversationHistory().size(), 0u);
}

TEST_F(ConversationHandlerUnitTest, OnGetStagedEntriesFromContent) {
Expand Down Expand Up @@ -1131,19 +1124,15 @@ TEST_F(ConversationHandlerUnitTest, OnGetStagedEntriesFromContent) {
EXPECT_EQ(history[5]->text, "summary2");
}

TEST_F(ConversationHandlerUnitTest_OptedOut,
TEST_F(ConversationHandlerUnitTest,
MaybeFetchOrClearSearchQuerySummary_NotOptedIn) {
// Content will have staged entries, but we want to make sure that
// ConversationHandler won't ask for them when not opted-in yet.
// Staged entries could be retrieved before user opts in.
SetAssociatedContentStagedEntries(/*empty=*/false);
EXPECT_CALL(*associated_content_, GetStagedEntriesFromContent).Times(0);
// Modifying whether page contents should be sent should trigger content
// staging.
EXPECT_CALL(*associated_content_, GetStagedEntriesFromContent).Times(1);
// Don't get a false positive because no client is automatically connected.
// Connecting a client will trigger content staging.
NiceMock<MockConversationHandlerClient> client(conversation_handler_.get());
EXPECT_TRUE(conversation_handler_->IsAnyClientConnected());
conversation_handler_->SetShouldSendPageContents(false);
conversation_handler_->SetShouldSendPageContents(true);
conversation_handler_->GetAssociatedContentInfo(base::BindLambdaForTesting(
[&](mojom::SiteInfoPtr site_info, bool should_send_page_contents) {
EXPECT_TRUE(should_send_page_contents);
Expand All @@ -1152,7 +1141,7 @@ TEST_F(ConversationHandlerUnitTest_OptedOut,
task_environment_.RunUntilIdle();
testing::Mock::VerifyAndClearExpectations(conversation_handler_.get());

EXPECT_TRUE(conversation_handler_->GetConversationHistory().empty());
EXPECT_FALSE(conversation_handler_->GetConversationHistory().empty());
}

TEST_F(ConversationHandlerUnitTest,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ function Main() {
<div className={styles.promptContainer}>
<LongConversationInfo />
</div>}
{!aiChatContext.hasAcceptedAgreement && <WelcomeGuide />}
{!aiChatContext.hasAcceptedAgreement && !conversationContext.conversationHistory.length && <WelcomeGuide />}
</div>
</div>
<div className={styles.input}>
Expand Down

0 comments on commit 9b43ec8

Please sign in to comment.