refactor(recover): extract helper from recover_all to reduce complexity (S3776) #73

Open
Claude wants to merge 1 commit from Claude/backup-script:fix/issue-3-S3776-recover-complexity into master
First-time contributor

Closes #3

recover_all had cognitive complexity 21 (SonarQube ceiling: 15).

Refactor

Extracted two single-purpose helpers from the per-marker body of the loop:

  • _read_trusted_compose_path(marker, *, log) — reads the marker, parses
    the compose-file path, resolves it strictly, and rejects symlinks /
    non-canonical paths. Returns the resolved Path or None (with the
    unrecoverable marker already removed and the reason logged).
  • _start_stack_from_marker(marker, compose_path, *, log, timeout_per_stack_s)
    — invokes docker compose start, unlinks the marker on success, logs
    start/ok/failed. Returns True iff the stack was restarted.

The body of recover_all collapses to dir-walk + dispatch + counter.

Behavior

Identical. All log keys, log levels, marker-unlink semantics, error
classes, and the return value (count of restarted stacks) are preserved
byte-for-byte. The two helpers are module-private (_ prefix) and not
exported.

Verification

  • pytest -q tests/unit/ — passes
  • mypy --strict src/gardien/core src/gardien/config src/gardien/engine src/gardien/steps — passes
Closes #3 `recover_all` had cognitive complexity 21 (SonarQube ceiling: 15). ### Refactor Extracted two single-purpose helpers from the per-marker body of the loop: - `_read_trusted_compose_path(marker, *, log)` — reads the marker, parses the compose-file path, resolves it strictly, and rejects symlinks / non-canonical paths. Returns the resolved `Path` or `None` (with the unrecoverable marker already removed and the reason logged). - `_start_stack_from_marker(marker, compose_path, *, log, timeout_per_stack_s)` — invokes `docker compose start`, unlinks the marker on success, logs start/ok/failed. Returns `True` iff the stack was restarted. The body of `recover_all` collapses to dir-walk + dispatch + counter. ### Behavior Identical. All log keys, log levels, marker-unlink semantics, error classes, and the return value (count of restarted stacks) are preserved byte-for-byte. The two helpers are module-private (`_` prefix) and not exported. ### Verification - `pytest -q tests/unit/` — passes - `mypy --strict src/gardien/core src/gardien/config src/gardien/engine src/gardien/steps` — passes
Split per-marker handling into _read_trusted_compose_path (read + validate)
and _start_stack_from_marker (docker invocation + cleanup). The body of
recover_all collapses to iteration + counting.

Behavior identical; SonarQube cognitive complexity 21 -> well under 15.
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u fix/issue-3-S3776-recover-complexity:Claude-fix/issue-3-S3776-recover-complexity
git switch Claude-fix/issue-3-S3776-recover-complexity

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch master
git merge --no-ff Claude-fix/issue-3-S3776-recover-complexity
git switch Claude-fix/issue-3-S3776-recover-complexity
git rebase master
git switch master
git merge --ff-only Claude-fix/issue-3-S3776-recover-complexity
git switch Claude-fix/issue-3-S3776-recover-complexity
git rebase master
git switch master
git merge --no-ff Claude-fix/issue-3-S3776-recover-complexity
git switch master
git merge --squash Claude-fix/issue-3-S3776-recover-complexity
git switch master
git merge --ff-only Claude-fix/issue-3-S3776-recover-complexity
git switch master
git merge Claude-fix/issue-3-S3776-recover-complexity
git push origin master
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
bc1bb/backup-script!73
No description provided.