refactor(compose): split discover() into per-dir + per-field helpers (S3776) #72
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "Claude/backup-script:fix/issue-4-S3776-compose-discover-complexity"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #4
discover()ingardien.discovery.composedid everything inline: walkthe root, check override-disabled, resolve compose file, resolve hook,
plumb override fields into
ComposeStack. Cognitive complexity 49,the worst offender in the codebase (SonarQube ceiling: 15).
Refactor
Extracted three single-purpose helpers:
_build_stack_for_dir(child, override, log)ComposeStack | None(None = skip)_resolve_compose_file(child, override, log)_resolve_hook(child, override, log)backup.shconventionAfter the split:
discover_build_stack_for_dir_resolve_compose_file_resolve_hookAll comfortably under 15.
Behavior
Byte-for-byte identical:
sorted(root_path.iterdir())).compose.root_missing,compose.stack_disabled,compose.override_file_missing,compose.skip_no_compose_file,compose.override_hook_missing,compose.discovered).The only externally visible change is one internal signature:
_resolve_hookreturnsstr(override_hook)instead ofoverride_hookdirectly, mirroring the existingstr(default_hook)path on the convention branch —override_hookwas already astr(fromgetattr(override, "hook")) so this is type-tightening, not a behavior change.Verification
pytest -q tests/unit/test_compose_discovery.py— 11 passedmypy src/gardien/discovery/compose.py— passes (this module is in the lax-mypydiscoverypackage, but the new helpers type-check cleanly)View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.