Undo local file rename when CLI fails to send rename to plugin#606
Undo local file rename when CLI fails to send rename to plugin#606huntercaron wants to merge 3 commits intomainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR prevents local/remote desync when the CLI detects a local file rename but fails to notify the Framer plugin, by reverting the rename on disk and using hash-tracker “echo prevention” so the watcher ignores the undo.
Changes:
- Add an
undoLocalRename()path to revert the on-disk rename when no socket is available,sendMessagereturnsfalse, orsendMessagethrows. - Add Vitest coverage for the undo behavior across the three failure modes above.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| packages/code-link-cli/src/controller.ts | Adds undoLocalRename() and invokes it on rename-send failures to keep disk state aligned with plugin state. |
| packages/code-link-cli/src/controller.rename.test.ts | Adds tests ensuring the file is renamed back on failure and echo-prevention markers are set. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Read fresh file content from disk before setting echo-prevention hash, since effect.content may be stale if the user edited the renamed file - Clear echo-prevention markers in the catch block when fs.rename fails, preventing stale markers from poisoning tracker state - Clean up hashTracker timers in tests to avoid dangling setTimeout
|
I'm missing some context, so pardon my ignorance, but was wondering if it would be possible to track renames in memory and try to sync when the link comes back online? Also wonder if it could attempt to synchronize on the difference between the project & disk state when the link comes back online? (so that even if you'd edit a file without the CLI running it would synchronize when the connection comes back) There may be reasons why this is not feasible, just curious |
Description
When the code-link CLI detects a local file rename and fails to send it to the Framer plugin (no socket, send returns false, or throws), the local file stays renamed while the plugin still has the old name — causing a desync. This PR adds an
undoLocalRename()helper that renames the file back on disk and sets up echo prevention so the watcher ignores the undo, keeping local and remote in sync.Changelog
Testing