Skip to content

fix: restrict observability logging suggestion to Python only#222

Open
chundawat-h wants to merge 2 commits into
imDarshanGK:mainfrom
chundawat-h:bug/fix-Observability/Logging-suggestion-leaks
Open

fix: restrict observability logging suggestion to Python only#222
chundawat-h wants to merge 2 commits into
imDarshanGK:mainfrom
chundawat-h:bug/fix-Observability/Logging-suggestion-leaks

Conversation

@chundawat-h
Copy link
Copy Markdown
Contributor

Description

This PR resolves a cross-language suggestion leakage bug where the Python-specific print/observability rule (SUGGESTION 7: Logging) was running for all programming languages. This caused the analyzer to suggest Python-specific code snippets (like import logging and logger.info()) in reports for other languages like Java and C++.

Related Issue

Fixes #156

Key changes:

  • Restricted the logging/observability print check in backend/app/services/code_assistant.py to only run when language == "Python".
  • Added a robust unit test case test_suggestions_observability_print_only_python() in backend/tests/test_endpoints.py to assert that Observability suggestions are not generated for Java but function correctly for Python.

Type of Change

  • Bug fix
  • New feature
  • Documentation update
  • Refactor

Testing

  • I ran backend tests ($env:RATE_LIMIT_PER_MINUTE=100; python -m pytest -v passes with all 40 tests green)
  • I tested frontend behavior manually (verified locally that Java print statements no longer show Python logging suggestions)

Checklist

  • I have read CONTRIBUTING.md
  • My branch is up to date with main
  • I have run pytest -v and all tests pass
  • I have not introduced duplicate issues or features
  • My PR title follows the format: feat/fix/docs/test: short description
  • I have added tests for new features (Level 2 and 3 issues)
  • No hardcoded secrets or API keys in my code
  • This PR is linked to a GSSoC 2026 issue

Test evidence

$env:RATE_LIMIT_PER_MINUTE=100; python -m pytest -v
====================================== test session starts ======================================
platform win32 -- Python 3.13.3, pytest-9.0.3, pluggy-1.6.0 -- C:\Python313\python.exe
cachedir: .pytest_cache
rootdir: D:\deta\Desktop\OpenSourceProjects\New folder\AI-dev-assistant\backend
plugins: anyio-4.13.0, asyncio-1.3.0
asyncio: mode=Mode.STRICT, debug=False, asyncio_default_fixture_loop_scope=None, asyncio_default_test_loop_scope=function
collected 52 items

tests/test_endpoints.py::test_root PASSED [ 1%]
tests/test_endpoints.py::test_health PASSED [ 3%]
tests/test_endpoints.py::test_rate_limit_headers_on_success_response PASSED [ 5%]
tests/test_endpoints.py::test_rate_limit_returns_429_with_retry_after_header PASSED [ 7%]
tests/test_endpoints.py::test_explanation_python PASSED [ 9%]
tests/test_endpoints.py::test_explanation_no_language_hint PASSED [ 11%]
tests/test_endpoints.py::test_explanation_rust PASSED [ 13%]
tests/test_endpoints.py::test_explanation_detects_rust_without_hint PASSED [ 15%]
tests/test_endpoints.py::test_explanation_accepts_rust_hint_alias PASSED [ 17%]
tests/test_endpoints.py::test_explanation_empty_code PASSED [ 19%]
tests/test_endpoints.py::test_explanation_too_long PASSED [ 21%]
tests/test_endpoints.py::test_explanation_typescript PASSED [ 23%]
tests/test_endpoints.py::test_explanation_java PASSED [ 25%]
tests/test_endpoints.py::test_explanation_cpp PASSED [ 26%]
tests/test_endpoints.py::test_explanation_cyclomatic_fields_present PASSED [ 28%]
tests/test_endpoints.py::test_explanation_cyclomatic_simple PASSED [ 30%]
tests/test_endpoints.py::test_explanation_cyclomatic_moderate PASSED [ 32%]
tests/test_endpoints.py::test_explanation_cyclomatic_high PASSED [ 34%]
tests/test_endpoints.py::test_explanation_cyclomatic_very_high PASSED [ 36%]
tests/test_endpoints.py::test_debug_detects_zero_division PASSED [ 38%]
tests/test_endpoints.py::test_debug_detects_hardcoded_secret PASSED [ 40%]
tests/test_endpoints.py::test_debug_detects_bare_except PASSED [ 42%]
tests/test_endpoints.py::test_debug_detects_eval PASSED [ 44%]
tests/test_endpoints.py::test_debug_clean_code PASSED [ 46%]
tests/test_endpoints.py::test_debug_javascript PASSED [ 48%]
tests/test_endpoints.py::test_debug_java PASSED [ 50%]
tests/test_endpoints.py::test_debug_cpp PASSED [ 51%]
tests/test_endpoints.py::test_explanation_php PASSED [ 53%]
tests/test_endpoints.py::test_explanation_detects_php_without_hint PASSED [ 55%]
tests/test_endpoints.py::test_debug_php PASSED [ 57%]
tests/test_endpoints.py::test_debug_php_buggy_patterns PASSED [ 59%]
tests/test_endpoints.py::test_debug_rust PASSED [ 61%]
tests/test_endpoints.py::test_debug_rust_buggy_patterns PASSED [ 63%]
tests/test_endpoints.py::test_debug_kotlin PASSED [ 65%]
tests/test_endpoints.py::test_debug_issue_has_required_fields PASSED [ 67%]
tests/test_endpoints.py::test_js_ts_security_patterns PASSED [ 69%]
tests/test_endpoints.py::test_suggestions_returns_score PASSED [ 71%]
tests/test_endpoints.py::test_suggestions_perfect_score PASSED [ 73%]
tests/test_endpoints.py::test_suggestions_observability_print_only_python PASSED [ 75%]
tests/test_endpoints.py::test_full_analyze PASSED [ 76%]
tests/test_endpoints.py::test_full_analyze_all_languages PASSED [ 78%]
tests/test_endpoints.py::test_missing_code_field PASSED [ 80%]
tests/test_endpoints.py::test_unicode_code PASSED [ 82%]
tests/test_endpoints.py::test_single_line_code PASSED [ 84%]
tests/test_ping.py::test_ping PASSED [ 86%]
tests/test_python_ast_analyzer.py::test_detects_missing_bracket_syntax_error PASSED [ 88%]
tests/test_python_ast_analyzer.py::test_detects_invalid_indentation_syntax_error PASSED [ 90%]
tests/test_python_ast_analyzer.py::test_detects_division_by_zero_expression PASSED [ 92%]
tests/test_python_ast_analyzer.py::test_detects_division_by_zero_inside_function_call PASSED [ 94%]
tests/test_python_ast_analyzer.py::test_detects_out_of_range_list_index PASSED [ 96%]
tests/test_python_ast_analyzer.py::test_detects_out_of_range_string_index PASSED [ 98%]
tests/test_python_ast_analyzer.py::test_detects_string_integer_concatenation PASSED [100%]

====================================== 52 passed in 1.56s =======================================

Updated the test count in README to reflect the current number of tests.
@chundawat-h chundawat-h requested a review from imDarshanGK as a code owner May 21, 2026 12:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Python Observability/Logging suggestion leaks into Java/C++ analyses

1 participant