Skip to content

PR 3: Python — Web App Job & Context tests#446

Merged
nitrobass24 merged 3 commits into
developfrom
test/web-app-job-context
May 1, 2026
Merged

PR 3: Python — Web App Job & Context tests#446
nitrobass24 merged 3 commits into
developfrom
test/web-app-job-context

Conversation

@nitrobass24
Copy link
Copy Markdown
Owner

@nitrobass24 nitrobass24 commented May 1, 2026

Summary

  • Adds unit tests for two previously untested modules
  • web_app_job (7 tests): WebAppJob.setup() creates server on configured port and starts thread, execute() delegates to web_app.process(), cleanup() stops server and joins thread, MyWSGIRefServer.stop() on never-initialized server logs warning without crash, _RequestLoggingMiddleware logs method/path/status/duration including on app errors
  • context (7 tests): create_child_context returns shallow copy with child logger while sharing config/status/args, print_to_log redacts sensitive fields (passwords, API keys), handles present/absent path pairs gracefully, Args.as_dict() serializes all fields as strings including None values

Test plan

  • cd src/python && PYTHONPATH=. python3 -m pytest tests/unittests/test_web/test_web_app_job.py tests/unittests/test_common/test_context.py -v — 14 passed
  • python3 -m ruff check — all checks passed
  • python3 -m ruff format --check — already formatted

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Tests
    • Added comprehensive test coverage for application context creation, child context initialization, and logging behavior
    • Added test coverage for web app job lifecycle management, server initialization, and request logging middleware

Cover two previously untested modules:
- web_app_job: setup creates server and starts thread, execute calls
  process, cleanup stops server and joins thread, never-initialized
  server logs warning, request logging middleware logs method/path/status
- context: create_child_context returns copy with child logger,
  print_to_log redacts sensitive fields, handles present/absent path
  pairs, Args.as_dict serializes all fields as strings

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 1, 2026

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 912f1a8b-a413-4c01-af55-d7ae155195c8

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

This PR introduces two new unittest files that establish baseline test coverage for core components: one validates Context lifecycle methods and utility functions, while the other verifies WebAppJob lifecycle behavior and associated web server/middleware functionality.

Changes

Cohort / File(s) Summary
Test Coverage - Context and WebAppJob
src/python/tests/unittests/test_common/test_context.py, src/python/tests/unittests/test_web/test_web_app_job.py
Adds 249 lines of new test code covering Context child creation, logging with password redaction, Args serialization, and WebAppJob setup/execute/cleanup lifecycle including server initialization and request logging middleware behavior.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 55.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding unit tests for two Python modules (WebAppJob and Context). It is specific, concise, and clearly identifies the primary contribution.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/web-app-job-context

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.

@nitrobass24 nitrobass24 changed the title Add web app job and context unit tests (14 tests) PR 3: Python — Web App Job & Context tests May 1, 2026
@nitrobass24
Copy link
Copy Markdown
Owner Author

@CodeRabbit review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 1, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown

@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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/python/tests/unittests/test_web/test_web_app_job.py`:
- Around line 138-140: The test currently nests self.assertRaises(RuntimeError)
outside self.assertLogs, so the RuntimeError propagates and assertLogs cannot
verify captured records; modify the nesting so
self.assertLogs("test_request_logging_error", level="DEBUG") is the outer
context and self.assertRaises(RuntimeError) wraps the call to
list(middleware(environ, start_response)) inside it, ensuring the RuntimeError
is caught by assertRaises and assertLogs can exit normally and assert that
_RequestLoggingMiddleware emitted the expected logs.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: aa6ee468-5370-4ebb-9d4f-7418d32a723b

📥 Commits

Reviewing files that changed from the base of the PR and between ed2bdfe and 6124146.

📒 Files selected for processing (2)
  • src/python/tests/unittests/test_common/test_context.py
  • src/python/tests/unittests/test_web/test_web_app_job.py

Comment on lines +138 to +140
with self.assertRaises(RuntimeError):
with self.assertLogs("test_request_logging_error", level="DEBUG"):
list(middleware(environ, start_response))
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

assertLogs does not verify log emission when an exception propagates through it — test makes an unenforceable claim.

assertLogs.__exit__ short-circuits its records check when exc_type is not None. Because RuntimeError is raised inside the inner with self.assertLogs(...) block and propagates outward to assertRaises, assertLogs exits with a live exception and never confirms that any log records were captured. The test would pass identically if the finally block in _RequestLoggingMiddleware were removed, completely invalidating the intended assertion.

Fix: invert the nesting so assertRaises (inner) catches and suppresses the RuntimeError first, allowing assertLogs (outer) to exit cleanly and verify its records:

🐛 Proposed fix
-        with self.assertRaises(RuntimeError):
-            with self.assertLogs("test_request_logging_error", level="DEBUG"):
-                list(middleware(environ, start_response))
+        with self.assertLogs("test_request_logging_error", level="DEBUG") as log_ctx:
+            with self.assertRaises(RuntimeError):
+                list(middleware(environ, start_response))
+        self.assertTrue(any("POST" in msg and "/fail" in msg for msg in log_ctx.output))
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
with self.assertRaises(RuntimeError):
with self.assertLogs("test_request_logging_error", level="DEBUG"):
list(middleware(environ, start_response))
with self.assertLogs("test_request_logging_error", level="DEBUG") as log_ctx:
with self.assertRaises(RuntimeError):
list(middleware(environ, start_response))
self.assertTrue(any("POST" in msg and "/fail" in msg for msg in log_ctx.output))
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/python/tests/unittests/test_web/test_web_app_job.py` around lines 138 -
140, The test currently nests self.assertRaises(RuntimeError) outside
self.assertLogs, so the RuntimeError propagates and assertLogs cannot verify
captured records; modify the nesting so
self.assertLogs("test_request_logging_error", level="DEBUG") is the outer
context and self.assertRaises(RuntimeError) wraps the call to
list(middleware(environ, start_response)) inside it, ensuring the RuntimeError
is caught by assertRaises and assertLogs can exit normally and assert that
_RequestLoggingMiddleware emitted the expected logs.

assertLogs must be the outer context so it can validate captured log
records on normal exit. With assertRaises as the outer context, the
RuntimeError propagated through assertLogs preventing its validation
from running — making the log assertion a no-op.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@nitrobass24 nitrobass24 merged commit 8d93a20 into develop May 1, 2026
18 checks passed
@nitrobass24 nitrobass24 deleted the test/web-app-job-context branch May 1, 2026 20:51
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.

1 participant