fix(sync): stop rewriting keep.lock on every sync#227
Merged
Conversation
…heal compare Bare `capy` sync rewrote keep.lock on every run — even with an empty .env. The self-heal step compares the local keep.lock against the server's keep_file and overwrites on any difference. But the local copy is read off disk (so it carries the injected `_comment` and is already sorted) while the server's copy has neither, so the bare JSON.stringify comparison ALWAYS reported a difference and rewrote the file. - Extract the canonical lockfile serialization into `serializeKeep()` (the single source of truth for on-disk form) and have the self-heal comparison normalize both sides through it. - Give `writeKeepFile()` a no-op guard so it skips the write when the on-disk file is already byte-identical to the canonical output. - Add regression tests covering the canonical comparison and the no-op guard.
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
Running bare
capy(sync) rewriteskeep.lockon every run — even when.envis empty and nothing has changed. This produces a spurious git diff after every sync.Root cause
During sync, the self-heal step compares the local
keep.lockagainst the server'skeep_fileand overwrites local on any difference:But the two sides are never in the same shape:
readKeepFile()(raw as KeepFile), so it still carries the injected_commentfield and is already key-sorted.keep_filehas neither_commentnor guaranteed ordering.So
JSON.stringify(local) !== JSON.stringify(server)is always true →writeKeepFile()fires on every sync, independent of.envcontents.Fix
serializeKeep()— the single source of truth for the on-disk form (_comment, fixed key order, sorted variables, stable per-entry field order). The self-heal comparison now normalizes both sides through it, so it only rewrites on a real change.writeKeepFile()a no-op guard: if the on-disk file is already byte-identical to the canonical output, skip the write entirely. Defense-in-depth that also stops churn from otherwriteKeepFilecallers.Tests
tests/files/fileManager.test.ts:serializeKeep canonical comparison (sync self-heal)— asserts an on-disk keep (with_comment) and a server keep (without) serialize identically (the fix), and documents that the old bare-JSON.stringifycomparison saw them as different (the bug). Plus order/extra-field independence and a positive test that a realvalue_hashchange is still detected.writeKeepFile no-op guard— skips the write when on-disk content already matches; rewrites when it differs.All affected suites pass individually (
fileManager,capyCommand,branchKeepFile);tsc --noEmitclean.