Skip to content

Conversation

@Dishant1804
Copy link
Collaborator

Proposed change

  • added question detector to nestbot mentions

Checklist

  • I've read and followed the contributing guidelines.
  • I've run make check-test locally; all checks and tests passed.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 22, 2025

Summary by CodeRabbit

  • New Features

    • Enhanced Slack AI handler with intelligent question detection to prioritize OWASP-related queries.
    • Added default response mechanism for out-of-scope questions to streamline response handling.
  • Tests

    • Expanded test coverage for question detection logic and response routing scenarios.

Walkthrough

The changes add OWASP-related question detection to the AI query processor by introducing a pre-check that returns a default response for non-OWASP questions, short-circuiting agent execution. Corresponding test coverage is added for both OWASP and non-OWASP query scenarios.

Changes

Cohort / File(s) Summary
AI Query Processing Enhancement
backend/apps/slack/common/handlers/ai.py
Imported QuestionDetector, added pre-check in process_ai_query to return default OWASP-focused response for non-OWASP questions, and short-circuit agent execution accordingly.
Test Suite Updates
backend/tests/apps/slack/common/handlers/ai_test.py
Exported get_default_response function, updated imports, and added test scenarios covering non-OWASP queries, QuestionDetector dependency injection, and verification that non-OWASP queries bypass agent execution.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

The changes follow a straightforward pre-check pattern with localized, cohesive modifications across two files. The new logic is relatively simple (question type validation), and test additions are consistent repetitions of similar scenarios.

Possibly related PRs

Suggested reviewers

  • kasya
  • arkid15r

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title Check ✅ Passed The pull request title "Added question detector to nestbot mentions" directly references a real and significant aspect of the changeset. The raw summary confirms that a QuestionDetector import was added and integrated into the process_ai_query function, which aligns precisely with what the title describes. While the title does not capture all implementation details (such as the filtering of OWASP-related questions or the default response behavior), it accurately and specifically identifies the primary code addition and is clear enough for a teammate reviewing the history to understand that a question detection capability was added to the AI query handling.
Description Check ✅ Passed The pull request description states "added question detector to nestbot mentions" which directly corresponds to the changes documented in the raw summary. The description is related to the changeset in a meaningful way, referencing the exact same feature addition. Although the description is brief and lacks extensive detail about the filtering logic or default response behavior, the evaluation criteria explicitly states that level of detail is not important for passing this lenient check, only that the description be related in some way to the changeset.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sonarqubecloud
Copy link

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
backend/apps/slack/common/handlers/ai.py (1)

66-73: Consider a more helpful default response message.

The current message is terse and may not provide sufficient guidance to users who are unfamiliar with OWASP or unsure what constitutes an OWASP-related question.

Consider enriching the message:

 def get_default_response() -> str:
     """Get default response for non-OWASP questions.
 
     Returns:
         str: A default response for non-OWASP questions.
 
     """
-    return "Please ask questions related to OWASP."
+    return (
+        "I can only answer questions related to OWASP (Open Web Application Security Project). "
+        "Please ask about OWASP projects, security standards, vulnerabilities, or best practices."
+    )
backend/tests/apps/slack/common/handlers/ai_test.py (1)

137-151: Add assertion to verify AgenticRAGAgent is not invoked.

The test correctly verifies the default response is returned for non-OWASP questions, but should also confirm that the expensive agent execution is short-circuited.

Apply this diff to add the verification:

+    @patch("apps.slack.common.handlers.ai.AgenticRAGAgent")
     @patch("apps.slack.common.handlers.ai.QuestionDetector")
-    def test_process_ai_query_non_owasp_question(self, mock_question_detector_class):
+    def test_process_ai_query_non_owasp_question(
+        self, mock_question_detector_class, mock_agent_class
+    ):
         """Test AI query processing when question is not OWASP-related."""
         query = "What is the weather today?"
 
         mock_question_detector = Mock()
         mock_question_detector.is_owasp_question.return_value = False
         mock_question_detector_class.return_value = mock_question_detector
 
         result = process_ai_query(query)
 
         mock_question_detector_class.assert_called_once()
         mock_question_detector.is_owasp_question.assert_called_once_with(text=query)
+        mock_agent_class.assert_not_called()
         assert result == get_default_response()
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8c8930a and 9a05d01.

📒 Files selected for processing (2)
  • backend/apps/slack/common/handlers/ai.py (3 hunks)
  • backend/tests/apps/slack/common/handlers/ai_test.py (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
backend/tests/apps/slack/common/handlers/ai_test.py (3)
backend/apps/slack/common/handlers/ai.py (4)
  • get_blocks (14-29)
  • get_default_response (66-73)
  • get_error_blocks (51-63)
  • process_ai_query (32-48)
backend/apps/slack/common/question_detector.py (1)
  • is_owasp_question (42-69)
backend/apps/ai/agent/agent.py (1)
  • run (27-52)
backend/apps/slack/common/handlers/ai.py (2)
backend/apps/slack/common/question_detector.py (2)
  • QuestionDetector (20-155)
  • is_owasp_question (42-69)
backend/apps/slack/models/message.py (1)
  • text (83-85)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Run frontend unit tests
  • GitHub Check: Run backend tests
  • GitHub Check: Run frontend e2e tests
  • GitHub Check: CodeQL (javascript-typescript)
🔇 Additional comments (3)
backend/apps/slack/common/handlers/ai.py (1)

9-9: LGTM!

The import is correctly added for the new question detection functionality.

backend/tests/apps/slack/common/handlers/ai_test.py (2)

7-12: LGTM!

The import correctly adds get_default_response which is needed for the new test assertions.


70-136: LGTM!

The existing tests are correctly updated to mock QuestionDetector with is_owasp_question returning True, ensuring these tests continue to focus on the agent execution path while properly integrating the new question detection dependency.

@arkid15r arkid15r merged commit 29e3487 into OWASP:feature/nestbot-ai-assistant Nov 2, 2025
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants