fix(update): repair receipt entries for files already identical to a template - #575
fix(update): repair receipt entries for files already identical to a template#575sdelmas wants to merge 1 commit into
Conversation
…template `.template-hashes.json` recorded hashes that disagreed with the files written, and omitted entries for files that exist. Both make the receipt useless as a drift signal: a clean vendored tree reports as locally modified, so real customizations cannot be told apart from noise. Root cause: `analyzeChanges` classifies a file whose content already equals its template as `unchanged`, and the write-back drew only from `newFiles`, `autoUpdateFiles` and overwritten `changedFiles`. `unchangedFiles` was never written back, so a wrong or absent entry beside an already-correct file could not be repaired by any number of `trellis update` runs. Identical content across versions is not what saves such an entry from going stale — it is exactly what freezes it, because the file never leaves the `unchanged` bucket. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review. 📝 WalkthroughWalkthroughThe update command now repairs missing or incorrect hash receipts for unchanged template files. It preserves exclusions and avoids re-hashing customized or mixed-ownership paths. Integration tests cover repair behavior in normal and already-up-to-date update flows. ChangesTemplate hash receipt repair
Estimated code review effort: 3 (Moderate) | ~20 minutes Merge Risk: ⚪ Minimal · up to The change repairs receipt entries for files already matching their templates and includes passing build and test results; no actionable merge-blocking risk remains. Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Pull request overview
This PR fixes .template-hashes.json “receipt” staleness for files whose on-disk content is already byte-identical to their template, so incorrect/missing hash entries can be repaired even when analyzeChanges classifies those files as unchanged.
Changes:
- Repair and write back missing/incorrect receipt entries for
unchangedFilesduringtrellis update(including the “Already up to date” early-exit path). - Export
shouldExcludeFromHashso update logic can avoid creating entries for intentionally untracked paths. - Add integration coverage for poisoned/missing entries, customized files, and mixed-ownership paths.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| packages/cli/src/commands/update.ts | Adds unchanged-file receipt repair and ensures the early “up to date” exit still updates the receipt. |
| packages/cli/src/utils/template-hash.ts | Exposes shouldExcludeFromHash for reuse by update-time repair logic. |
| packages/cli/test/commands/update.integration.test.ts | Adds integration tests to validate repair behavior and guard against re-hashing real user customizations. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| // An entry that already exists and disagrees with the file is repaired | ||
| // whatever the path: a wrong value is strictly worse than an absent one, | ||
| // because it reads as a real local modification. | ||
| if (recorded !== computeHash(file.newContent)) { | ||
| files.set(key, file.newContent); |
Slice B of the #534 resplit. Branched off current
main(64e66369). Independent of #574 — different files, no ordering constraint between them.The bug
.template-hashes.jsonrecorded hashes that disagreed with the files written, and omitted entries for files that exist. Either way the receipt stops working as a drift signal: a clean vendored tree reports as locally modified, so genuine customizations can't be told apart from noise. This surfaced during an 8-repo rollout where the receipt was the tool for deciding which local edits were real — it produced false positives on every repo.Root cause
analyzeChangesclassifies a file whose content already equals its template asunchanged. The write-back drew only fromnewFiles,autoUpdateFiles, and overwrittenchangedFiles—unchangedFileswas never written back. So a wrong or absent entry sitting beside an already-correct file could not be repaired by any number oftrellis updateruns.Worth stating plainly because it inverts the original reasoning: identical content across versions is not what keeps such an entry fresh — it is exactly what freezes it, because the file never leaves the
unchangedbucket.An earlier reading blamed key construction for dropping a platform segment. That was disproved: the collector emits the correct hash, and 0.6.7 hashed bytes read from disk. The keys were always right; the repair path was always missing.
Files (3)
cli/src/commands/update.ts— write backunchangedFilestoocli/src/utils/template-hash.tscli/test/commands/update.integration.test.ts— +124 linesThe source commit also carried
.trellis/tasks/08-19-template-hashes-stale/; dropped per your scrub list.Testing
No
.trellis/paths, no-sd.Nidentity (stays0.6.15), no marketplace gitlink.🤖 Generated with Claude Code
Summary by CodeRabbit