refactor: slim RhizaTemplate to a pure data class#427
Merged
Conversation
…lass - Move _expand_paths, _excluded_set, _prepare_snapshot to module-level functions in _git_utils.py - Add GitContext.update_sparse_checkout, get_head_sha, clone_repository, clone_at_sha instance methods - Update _merge_with_base to use new GitContext methods and module-level _prepare_snapshot - Move from_project to _load_template_from_project in sync.py - Extract clone as _clone_template(template, git_ctx, branch) in sync.py returning (upstream_dir, upstream_sha, resolved_include) - Inline snapshot logic in sync.py - Add resolve_include_paths method to RhizaTemplate - Slim template.py to ~53 statements (data fields, from_config, config, git_url, resolve_include_paths) - Update all test mocks to point to new locations (GitContext.clone_at_sha, etc.) - All 491 tests pass with 100% coverage Co-authored-by: tschm <2046079+tschm@users.noreply.github.com>
… functions Remove _logger optional parameter from _expand_paths, _load_template_from_project, and _clone_template; use module-level loguru logger directly for consistency with the rest of the codebase. Co-authored-by: tschm <2046079+tschm@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Refactor RhizaTemplate to separate data and operations
refactor: slim RhizaTemplate to a pure data class
Mar 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
RhizaTemplatehad grown to 597 lines mixing data modelling, git operations, file-tree utilities, workflow orchestration, and command-layer logic. This PR redistributes those responsibilities to their natural homes.Changes
src/rhiza/models/template.py— 213 → 53 statementsfrom_config,config,git_url,resolve_include_paths_files/filesmutation pattern (was a surprising side-effect ofclone())from rhiza.commands.validate import validatecircular-import workaroundsrc/rhiza/models/_git_utils.py_expand_paths,_excluded_set,_prepare_snapshot(were@staticmethodonRhizaTemplatewith noselfusage)GitContextinstance methods:update_sparse_checkout,get_head_sha,clone_repository(from_clone_template_repository),clone_at_sha(from_clone_at_sha) — all now takegit_url: strexplicitly instead of readingself.git_url_merge_with_baseupdated to callself.clone_at_sha(template.git_url, ...)and module-level_prepare_snapshot(...)directlysrc/rhiza/commands/sync.py_load_template_from_project(target)— extracted fromRhizaTemplate.from_project_clone_template(template, git_ctx, branch)— extracted fromRhizaTemplate.clone; returns(upstream_dir, upstream_sha, resolved_include)without mutating the template object_excluded_set+_prepare_snapshotdataclasses.replaceused to pass a bundle-resolved template view tosync_merge/_merge_with_baseTests
Mock paths updated throughout:
RhizaTemplate._clone_at_sha→GitContext.clone_at_shaRhizaTemplate._clone_template_repository→GitContext.clone_repositoryRhizaTemplate._get_head_sha→GitContext.get_head_shaRhizaTemplate._prepare_snapshot→rhiza.models._git_utils._prepare_snapshotpopulate_base(sha, dest, include_paths, git_ctx_)→populate_base(git_url, sha, dest, include_paths)to match the newGitContext.clone_at_shasignaturepatch.object(RhizaTemplate, "clone", ...)→patch("rhiza.commands.sync._clone_template", ...)with 3-tuple returnOriginal prompt
This pull request was created from Copilot chat.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.