Guard macOS restore paths for deleted worktrees#3
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fab00e9a9f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| let standardized = URL(fileURLWithPath: path).standardizedFileURL.path | ||
| var isDirectory: ObjCBool = false | ||
| guard FileManager.default.fileExists(atPath: standardized, isDirectory: &isDirectory), |
There was a problem hiding this comment.
Validate raw restore paths before canonicalizing
normalizedExistingDirectoryPath standardizes the input before checking existence, which can turn an invalid path into a valid parent (for example, "/tmp/missing/../" becomes "/tmp" and passes). Because this helper is now used for restoring and persisting pwd/worktree state, malformed or stale paths containing .. can be silently accepted as a different directory instead of being rejected, undermining the deleted-worktree guard.
Useful? React with 👍 / 👎.
This change prevents crash-loop restoration when saved terminal/worktree paths no longer exist on disk. It adds a shared RestorablePath helper and sanitizes restored and persisted pwd/worktree paths so only existing directories are used. It also clears invalid representedURL values before encode/load to avoid stale AppKit restoration state. Added RestorablePathTests for existing-directory normalization and rejection of missing/file paths.