Skip to content

The agent that grows with you

fix(projects): NFC-normalize path identity so accented folders keep their sessions (#65014)

Ayush Nangia284765d3d919
diff --git a/apps/desktop/src/app/chat/sidebar/projects/workspace-groups.test.ts b/apps/desktop/src/app/chat/sidebar/projects/workspace-groups.test.ts
index 5bbf2b8f57b..fdf77e67fa2 100644
--- a/apps/desktop/src/app/chat/sidebar/projects/workspace-groups.test.ts
+++ b/apps/desktop/src/app/chat/sidebar/projects/workspace-groups.test.ts
@@ -560,6 +560,24 @@ describe('liveSessionProjectId', () => {
'/work/notes'
)
})
+
+ it('matches NFD and NFC spellings of the same accented folder (#65014)', () => {
+ // The same on-disk folder can reach us as NFC (typed paths, backend cwd)
+ // or NFD (macOS file pickers) — byte-different, visually identical.
+ const nfc = '/projects/sv/bist\u00e5nd'
+ const nfd = nfc.normalize('NFD')
+
+ expect(nfd).not.toBe(nfc) // premise: distinct byte strings
+ expect(liveSessionProjectId(makeSession(nfd), [makeProject('p_bistand', [nfc])])).toBe('p_bistand')
+ })
+
+ it('matches a Windows cwd differing in both case and normalization form (#65014)', () => {
+ const id = liveSessionProjectId(makeSession('d:/projects/sv/bist\u00e5nd'.normalize('NFD')), [
+ makeProject('p_sv', ['D:\\Projects\\SV\\Bist\u00e5nd'.normalize('NFC')])
+ ])
+
+ expect(id).toBe('p_sv')
+ })
})
describe('sessionProjectColor', () => {
diff --git a/apps/desktop/src/app/chat/sidebar/projects/workspace-groups.ts b/apps/desktop/src/app/chat/sidebar/projects/workspace-groups.ts
index 7a1a26ef0bf..07724739608 100644
--- a/apps/desktop/src/app/chat/sidebar/projects/workspace-groups.ts
+++ b/apps/desktop/src/app/chat/sidebar/projects/workspace-groups.ts
@@ -95,9 +95,15 @@ const isWindowsPath = (path: string): boolean =>
* Segments for identity comparison: Windows paths fold case (and separators, via
* {@link segments}) so `C:\Work` and `c:/work` are one lane; POSIX stays
* case-sensitive. Comparison-only — emitted ids/labels keep their spelling.
+ *
+ * Segments are NFC-normalized before comparing: the same on-disk folder can
+ * reach us as NFC (typed paths, backend cwd) or NFD (macOS file pickers,
+ * HFS+/APFS round-trips), and case folding does not unify the two forms — an
+ * accented project folder would otherwise render empty (#65014). Mirrors
+ * `_comparison_segments` in `tui_gateway/project_tree.py`.
*/
const comparisonSegments = (path: string): string[] => {
- const segs = segments(path)
+ const segs = segments(path).map(seg => seg.normalize('NFC'))
return isWindowsPath(path) ? segs.map(seg => seg.toLowerCase()) : segs
}
diff --git a/tests/tui_gateway/test_project_tree.py b/tests/tui_gateway/test_project_tree.py
index b98c913d459..a09dff9e58d 100644
--- a/tests/tui_gateway/test_project_tree.py
+++ b/tests/tui_gateway/test_project_tree.py
@@ -356,6 +356,44 @@ def test_posix_path_identity_remains_case_sensitive():
]
+def test_unicode_normalization_forms_share_one_project_identity():
+ # The same on-disk folder can reach the tree as different byte strings:
+ # macOS file pickers emit NFD ("a" + U+030A) while typed paths and
+ # os.getcwd() are usually NFC (U+00E5). Identity comparison must treat
+ # them as one path or the project renders empty (#65014).
+ import unicodedata
+
+ nfc = unicodedata.normalize("NFC", "/projects/sv/bist\u00e5nd")
+ nfd = unicodedata.normalize("NFD", nfc)
+ assert nfc != nfd # premise: distinct byte strings for the same folder
+
+ explicit = _project("p_bistand", "Bist\u00e5nd", [nfc])
+ session = _session(nfd)
+
+ tree = pt.build_tree([explicit], [session], [], resolve=lambda _cwd: None, hydrate=True)
+
+ project = next(p for p in tree["projects"] if p["id"] == "p_bistand")
+ assert project["sessionCount"] == 1
+ # No stray auto-project for the NFD spelling of the same folder.
+ assert not any(p.get("isAuto") and "bist" in str(p["id"]) for p in tree["projects"])
+
+
+def test_windows_unicode_normalization_and_case_share_one_identity():
+ import unicodedata
+
+ folder_nfc = unicodedata.normalize("NFC", "D:/Projects/SV/Bist\u00e5nd")
+ cwd_nfd = unicodedata.normalize("NFD", "d:/projects/sv/bist\u00e5nd")
+ assert folder_nfc != cwd_nfd
+
+ explicit = _project("p_sv", "SV", [folder_nfc])
+ session = _session(cwd_nfd)
+
+ tree = pt.build_tree([explicit], [session], [], resolve=lambda _cwd: None, hydrate=True)
+
+ project = next(p for p in tree["projects"] if p["id"] == "p_sv")
+ assert project["sessionCount"] == 1
+
+
def test_explicit_project_claims_sessions_and_beats_auto():
project = _project("p_app", "App", ["/www/app"])
resolve = _resolver(
diff --git a/tui_gateway/project_tree.py b/tui_gateway/project_tree.py
index dc412ba2d5f..767a41ed018 100644
--- a/tui_gateway/project_tree.py
+++ b/tui_gateway/project_tree.py
@@ -10,6 +10,7 @@ lane = the worktree path. Linked worktrees fold under their MAIN repo (common-di
from __future__ import annotations
import re
+import unicodedata
from typing import Any, Callable, Optional
# cwd -> ``{"repo_root", "worktree_root"}`` (COMMON main root / this cwd's checkout root);
@@ -62,10 +63,19 @@ def _is_windows_path(path: str) -> bool:
def _comparison_segments(path: str) -> list[str]:
- """Segments for identity comparison: Windows paths casefold (even on POSIX); display
- paths and emitted IDs keep their spelling."""
- segs = _segments(path)
- return [s.casefold() for s in segs] if _is_windows_path(path) else segs
+ """Path segments suitable for identity comparisons on any host.
+
+ Windows paths remain case-insensitive even when tests or remote backends run
+ on POSIX. Display paths and emitted IDs keep their original spelling.
+
+ Segments are NFC-normalized before comparing: the same on-disk folder can
+ reach us as NFC (typed paths, os.getcwd()) or NFD (macOS file pickers,
+ HFS+/APFS round-trips), and ``casefold()`` does not unify the two forms —
+ an accented project folder would otherwise render empty (#65014). Mirrors
+ ``comparisonSegments`` in the desktop's ``workspace-groups.ts``.
+ """
+ segs = [unicodedata.normalize("NFC", segment) for segment in _segments(path)]
+ return [segment.casefold() for segment in segs] if _is_windows_path(path) else segs
def _path_key(path: str) -> str: