PR 2: Python — Controller Core tests (pair_context, scanners, delete)#444
Conversation
Cover four previously untested modules: - pair_context: PairContext init state, validate_config (missing fields, extract path logic), configure_lftp (mandatory/optional settings, xfer_verify) - active_scanner: empty scan, set_active_files, queue draining, missing file debug logging, unexpected error warning logging - local_scanner: missing path handling, successful scan, ScannerError, temp file suffix - delete_process: local file/dir deletion, path traversal blocking, remote SSH command construction, tilde path escaping Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
📝 WalkthroughWalkthroughThis PR adds comprehensive unit test suites for multiple controller subsystems, including delete process handling (local and remote), pair context configuration, and scanner implementations. All changes consist of new test code validating control flow, error handling, path validation, and configuration behaviors across these modules. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Review rate limit: 0/1 reviews remaining, refill in 60 minutes.Comment |
|
@CodeRabbit review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
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_controller/test_delete/test_delete_process.py`:
- Around line 14-19: The setUp method adds a StreamHandler to the root logger
every test but never removes it, causing duplicated logs across tests; update
tests to clean up handlers by either clearing existing handlers before adding
(inspect logger.handlers and remove any existing StreamHandler instances) or by
storing the created handler reference in setUp and removing it in a tearDown
method via logger.removeHandler(handler); apply this change to the
setUp/tearDown pair surrounding the code that creates logger, handler,
logger.addHandler(handler), and logger.setLevel(logging.DEBUG) so handlers are
not leaked between tests.
🪄 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: de2d8716-b0da-4051-8da4-91316e004ba1
📒 Files selected for processing (5)
src/python/tests/unittests/test_controller/test_delete/__init__.pysrc/python/tests/unittests/test_controller/test_delete/test_delete_process.pysrc/python/tests/unittests/test_controller/test_pair_context.pysrc/python/tests/unittests/test_controller/test_scan/test_active_scanner.pysrc/python/tests/unittests/test_controller/test_scan/test_local_scanner.py
| def setUp(self): | ||
| logger = logging.getLogger() | ||
| handler = logging.StreamHandler(sys.stdout) | ||
| logger.addHandler(handler) | ||
| logger.setLevel(logging.DEBUG) | ||
|
|
There was a problem hiding this comment.
Clean up logger handlers in setUp to prevent cross-test leakage.
Both setUp methods add a new handler every test but never remove it. This can duplicate log emission and pollute later tests (especially with root logger usage).
Proposed fix
class TestDeleteLocalProcess(unittest.TestCase):
@@
def setUp(self):
- logger = logging.getLogger()
+ logger = logging.getLogger("test_delete_local_process")
handler = logging.StreamHandler(sys.stdout)
logger.addHandler(handler)
logger.setLevel(logging.DEBUG)
+ self.addCleanup(logger.removeHandler, handler)
+ self.addCleanup(handler.close)
@@
class TestDeleteRemoteProcess(unittest.TestCase):
@@
def setUp(self):
- logger = logging.getLogger()
+ logger = logging.getLogger("test_delete_remote_process")
handler = logging.StreamHandler(sys.stdout)
logger.addHandler(handler)
logger.setLevel(logging.DEBUG)
+ self.addCleanup(logger.removeHandler, handler)
+ self.addCleanup(handler.close)Also applies to: 80-85
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In
`@src/python/tests/unittests/test_controller/test_delete/test_delete_process.py`
around lines 14 - 19, The setUp method adds a StreamHandler to the root logger
every test but never removes it, causing duplicated logs across tests; update
tests to clean up handlers by either clearing existing handlers before adding
(inspect logger.handlers and remove any existing StreamHandler instances) or by
storing the created handler reference in setUp and removing it in a tearDown
method via logger.removeHandler(handler); apply this change to the
setUp/tearDown pair surrounding the code that creates logger, handler,
logger.addHandler(handler), and logger.setLevel(logging.DEBUG) so handlers are
not leaked between tests.
Summary
PairContextinitialization tracking state,validate_configwith missing fields/extract path logic/boundary checks,configure_lftpmandatory/optional settings and xfer_verify enable/disableset_active_fileswith queue draining, missing file debug logging, unexpected error warning logging, base logger, temp suffix forwardingSystemScannerErrorraises localizedScannerError, base logger, temp file suffix../absolute path rejection, tilde path double-quote escapingTest plan
cd src/python && PYTHONPATH=. python3 -m pytest tests/unittests/test_controller/test_pair_context.py tests/unittests/test_controller/test_scan/test_active_scanner.py tests/unittests/test_controller/test_scan/test_local_scanner.py tests/unittests/test_controller/test_delete/test_delete_process.py -v— 36 passedpython3 -m ruff check— all checks passedpython3 -m ruff format --check— already formatted🤖 Generated with Claude Code
Summary by CodeRabbit