Anchor --reconcile sweep root at the canonical base for nested subdirectories#21
Merged
Merged
Conversation
…ectories reconcile_scopes derived the sweep root from File.dirname(output_directory), which assumes subdirectory: is exactly one level deep. A nested subdirectory (e.g. "exclude-argocd/auth") pushed the sweep root one level too deep, so when a subdirectory: was renamed or nested deeper the files left at the old shallower path became siblings of the sweep root and were never swept. Anchor base_root at the entry's canonical base instead — <region>/<type>/<color> for non-SPP entries, <region>/<type>/<color>/spp/SPP-PLACEHOLDER for SPP entries — independent of subdirectory depth, so the sweep root stays put across renames. Under --reconcile, also enforce that non-SPP entries render within their canonical base; an entry rendering outside it (only reachable via the deprecated directory: field) now hard-errors before any writes, completing the layout hard-validation deferred in ADR-0001. The now-redundant spp_sweep_root helper is removed. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR fixes --reconcile stale-file cleanup for entries whose subdirectory: nests multiple levels by anchoring sweep roots at the canonical base path (instead of dirname(output_directory)), and adds a hard guard to prevent non-SPP entries from rendering outside their canonical base during reconcile.
Changes:
- Rework
ResourceSet#reconcile_scopesto return canonicalbase_rootvalues (non-SPP:<region>/<type>/<color>, SPP:<region>/<type>/<color>/spp/SPP-PLACEHOLDER) regardless ofsubdirectory:depth. - Enforce (under
--reconcile) that non-SPPoutput_directorymust fall within itsbase_root(reject legacydirectory:layouts that escape the canonical base). - Add/adjust end-to-end and unit specs covering deeper nested subdirectories, legacy
directory:behavior under reconcile, and the new guard; bump version + changelog.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| spec/kubernetes_template_rendering/template_directory_renderer_spec.rb | Adds end-to-end reproductions for orphaned stale files (SPP + non-SPP) and the new non-SPP out-of-scope hard error under --reconcile. |
| spec/kubernetes_template_rendering/resource_set_spec.rb | Updates/extends #reconcile_scopes expectations to assert canonical base rooting for nested subdirectories and legacy directory: output. |
| lib/kubernetes_template_rendering/version.rb | Bumps gem version to 0.6.2. |
| lib/kubernetes_template_rendering/template_directory_renderer.rb | Adds reconcile-time enforcement that non-SPP outputs must render within canonical base_root; simplifies SPP sweep-root derivation. |
| lib/kubernetes_template_rendering/resource_set.rb | Changes reconcile scope computation to use canonical base roots rather than dirname(output_directory). |
| CHANGELOG.md | Documents the reconcile sweep-root fix and the new reconcile-time non-SPP guard. |
Comments suppressed due to low confidence (1)
lib/kubernetes_template_rendering/template_directory_renderer.rb:155
--sppvalues are interpolated into filesystem paths viagsubwithout any validation. If a user passes a value containing path separators (e.g. "../"), reconcile could end up sweeping an unintended subtree underrendered_directory(even though it remains in-prefix). Consider rejecting any--sppname that is not a single safe path segment before constructing sweep roots.
root = scope[:base_root]
return [root] if @spps.empty?
return [root] unless root.include?(ResourceSet::SPP_PLACEHOLDER)
[root] + @spps.map { |spp_name| root.gsub(ResourceSet::SPP_PLACEHOLDER, spp_name) }
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
ishakun
approved these changes
Jul 15, 2026
yinonrousso
approved these changes
Jul 15, 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.
Problem
reconcile_scopesderived each entry's--reconcilesweep root fromFile.dirname(output_directory), which silently assumessubdirectory:is exactly one level deep. When a definition nests its subdirectory deeper — e.g.subdirectory: "exclude-argocd/auth"— the sweep root descended with it (to.../spp/<name>/exclude-argocd/instead of.../spp/<name>/). Files rendered under the old shallower layout (.../spp/<name>/auth/…) then sat as siblings of the sweep root, outside every sweep scope, so reconcile never deleted them.This was observed in a real SPP deploy: the render added
.../spp/staging-qa04a/exclude-argocd/auth/…but left the pre-existing.../spp/staging-qa04a/auth/…orphaned.Fix
Anchor
base_rootat the entry's canonical base, independent ofsubdirectory:depth:<region>/<cluster_type>/<color><region>/<cluster_type>/<color>/spp/SPP-PLACEHOLDERThe sweep root now stays put when a
subdirectory:is renamed or nested deeper, so leftovers at the old path are swept.Enforce render-under-root for non-SPP entries under
--reconcile. An entry that renders outside its canonical base (only reachable via the deprecateddirectory:field) now hard-errors (OutOfScopeError) before any writes. This completes the layout hard-validation deferred in ADR-0001; SPP entries were already constrained to thespp/SPP-PLACEHOLDERprefix.Removed the now-redundant
spp_sweep_roothelper (canonicalbase_rootalways ends inSPP-PLACEHOLDER).Tests
Written test-first (red → green):
#reconcile_scopescases provingbase_rootstays canonical at any subdirectory depth, including the legacydirectory:case.Full suite: 109 examples, 0 failures.
Notes
0.6.1 → 0.6.2.subdirectory:/base layout at one level (canonical base == olddirname), so existing sweep specs are untouched.kube-platform(region-exempt) never renders with--reconcile(separate consumer on gem 0.3.0), so the new non-SPP guard is not collateral.🤖 Generated with Claude Code