Skip to content

PR 2: Python — Controller Core tests (pair_context, scanners, delete)#444

Merged
nitrobass24 merged 1 commit into
developfrom
test/controller-core
May 1, 2026
Merged

PR 2: Python — Controller Core tests (pair_context, scanners, delete)#444
nitrobass24 merged 1 commit into
developfrom
test/controller-core

Conversation

@nitrobass24
Copy link
Copy Markdown
Owner

@nitrobass24 nitrobass24 commented May 1, 2026

Summary

  • Adds unit tests for four previously untested controller modules
  • pair_context (15 tests): PairContext initialization tracking state, validate_config with missing fields/extract path logic/boundary checks, configure_lftp mandatory/optional settings and xfer_verify enable/disable
  • active_scanner (7 tests): empty scan, set_active_files with queue draining, missing file debug logging, unexpected error warning logging, base logger, temp suffix forwarding
  • local_scanner (5 tests): missing scan path returns empty + warning, successful scan, SystemScannerError raises localized ScannerError, base logger, temp file suffix
  • delete_process (9 tests): local file/dir deletion, symlink/path-traversal blocking, non-existent file error logging, remote SSH command construction, ../absolute path rejection, tilde path double-quote escaping

Test 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 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 deletion operations (local and remote paths).
    • Added validation tests for configuration initialization and LFTP settings.
    • Added unit tests for file scanning and system operations.

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>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 1, 2026

📝 Walkthrough

Walkthrough

This 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

Cohort / File(s) Summary
Delete Process Tests
src/python/tests/unittests/test_controller/test_delete/test_delete_process.py
Tests for DeleteLocalProcess and DeleteRemoteProcess validating directory/file removal via shutil.rmtree and os.remove, error logging for non-existent paths, path traversal blocking with error-level logging, and SSH command construction with quote escaping for home-directory (~) paths.
Pair Context Configuration Tests
src/python/tests/unittests/test_controller/test_pair_context.py
Tests for PairContext constructor initialization, validate_config error handling with specific missing-field identifiers (LFTP fields, controller extract-path, scanfs arg, verbose flag, auto_delete_remote), and configure_lftp behavior including mandatory/optional numeric settings transfer and xfer verification toggle logic.
Scanner Tests
src/python/tests/unittests/test_controller/test_scan/test_active_scanner.py, src/python/tests/unittests/test_controller/test_scan/test_local_scanner.py
Tests for ActiveScanner scan queue behavior and error handling (SystemScannerError logging at DEBUG/WARNING levels), child logger naming conventions, and LocalScanner path existence validation, system file list return ordering, and LFTP temp file suffix configuration.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • PR #161: The new tests for PairContext, validate_config, and configure_lftp directly exercise controller functionality introduced in this referenced refactor PR.
  • PR #412: New tests for PairContext module and configuration logic directly target functions and classes added by this PR.
  • PR #415: Controller-focused unit tests for pair context, scanners, and delete logic align with the same controller modules and boundaries refactored in this PR.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 54.76% 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 directly describes the primary changes: adding controller core unit tests for four modules (pair_context, scanners, delete), matching the changeset's focus on 36 new tests across these four test files.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/controller-core

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
Review rate limit: 0/1 reviews remaining, refill in 60 minutes.

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

@nitrobass24 nitrobass24 changed the title Add controller core unit tests (36 tests) PR 2: Python — Controller Core tests (pair_context, scanners, delete) 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_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

📥 Commits

Reviewing files that changed from the base of the PR and between cf856e6 and 72fdbfc.

📒 Files selected for processing (5)
  • src/python/tests/unittests/test_controller/test_delete/__init__.py
  • src/python/tests/unittests/test_controller/test_delete/test_delete_process.py
  • src/python/tests/unittests/test_controller/test_pair_context.py
  • src/python/tests/unittests/test_controller/test_scan/test_active_scanner.py
  • src/python/tests/unittests/test_controller/test_scan/test_local_scanner.py

Comment on lines +14 to +19
def setUp(self):
logger = logging.getLogger()
handler = logging.StreamHandler(sys.stdout)
logger.addHandler(handler)
logger.setLevel(logging.DEBUG)

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 | 🟡 Minor | ⚡ Quick win

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.

@nitrobass24 nitrobass24 merged commit ed2bdfe into develop May 1, 2026
17 checks passed
@nitrobass24 nitrobass24 deleted the test/controller-core branch May 1, 2026 19:11
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