diff --git a/backend/app/ai.py b/backend/app/ai.py index 79cde69..e794f8c 100644 --- a/backend/app/ai.py +++ b/backend/app/ai.py @@ -117,7 +117,8 @@ def _answer_direct_fact_question(question: str, context: dict[str, Any]) -> str "in monthly dividend income to reach your target." ) - if "progress" in normalized and ("goal" in normalized or "target" in normalized): + asks_progress = "progress" in normalized or "tracking" in normalized + if asks_progress and ("goal" in normalized or "target" in normalized): return ( f"You are {context['progress_percent']:.2f}% of the way to your " f"{_format_currency(context['monthly_target'])}/month target." diff --git a/backend/tests/test_ai.py b/backend/tests/test_ai.py index ed64549..e3956ae 100644 --- a/backend/tests/test_ai.py +++ b/backend/tests/test_ai.py @@ -38,6 +38,27 @@ def test_answer_portfolio_question_answers_current_monthly_income_directly( self.assertEqual(answer, "Your current monthly dividend income is $10.20.") mock_post.assert_not_called() + @patch("app.ai._portfolio_context") + @patch("app.ai.requests.post") + def test_answer_portfolio_question_answers_goal_tracking_directly( + self, + mock_post, + mock_portfolio_context, + ) -> None: + mock_portfolio_context.return_value = { + "monthly_income": 10.2, + "annual_income": 122.4, + "monthly_target": 5000, + "progress_percent": 0.2, + "remaining_monthly_income": 4989.8, + "holdings": [{"ticker": "SCHD"}], + } + + answer = answer_portfolio_question("How am I tracking toward my goal?") + + self.assertEqual(answer, "You are 0.20% of the way to your $5,000.00/month target.") + mock_post.assert_not_called() + @patch("app.ai._portfolio_context") @patch("app.ai._get_openrouter_headers") @patch("app.ai.requests.post")