Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

fix(desktop): match the Start-menu shortcut when the install path has a short name (#699)

Ruben Lütkedeb213602fa7
diff --git a/jarvis/ui/icon_utils.py b/jarvis/ui/icon_utils.py
index 81d6a874bb..edefa7576e 100644
--- a/jarvis/ui/icon_utils.py
+++ b/jarvis/ui/icon_utils.py
@@ -749,6 +749,20 @@ def _launcher_arguments() -> str:
return " ".join(("-m", _LAUNCHER_MODULE, *_LAUNCHER_ARGS))
+def _same_file_path(actual: str, expected: Path) -> bool:
+ """Whether two spellings name the same file, short (8.3) names included.
+
+ A shortcut stores the long path; ``sys.executable`` can carry a short one
+ (``ADMINI~1`` for ``Administrator``), and ``abspath`` keeps it short.
+ Compared as text they never matched, so every launch rewrote the shortcut.
+ """
+ if not actual:
+ return False
+ return os.path.normcase(os.path.realpath(actual)) == os.path.normcase(
+ os.path.realpath(expected)
+ )
+
+
def _shortcut_matches_install(
lnk: Path,
*,
@@ -784,18 +798,11 @@ def _shortcut_matches_install(
icon_raw = (sc.IconLocation or "").rsplit(",", 1)[0].strip().strip('"')
target_raw = (sc.TargetPath or "").strip().strip('"')
- def _same_path(actual: str, expected: Path) -> bool:
- if not actual:
- return False
- return os.path.normcase(os.path.abspath(actual)) == os.path.normcase(
- os.path.abspath(expected)
- )
-
return (
Path(icon_raw).is_file()
and Path(target_raw).is_file()
- and _same_path(icon_raw, expected_icon)
- and _same_path(target_raw, expected_target)
+ and _same_file_path(icon_raw, expected_icon)
+ and _same_file_path(target_raw, expected_target)
and (sc.Arguments or "").strip() == expected_arguments
)
except Exception as exc: # noqa: BLE001
diff --git a/tests/unit/ui/test_start_menu_shortcut_target.py b/tests/unit/ui/test_start_menu_shortcut_target.py
index 714e86b4fb..b68dd3f881 100644
--- a/tests/unit/ui/test_start_menu_shortcut_target.py
+++ b/tests/unit/ui/test_start_menu_shortcut_target.py
@@ -540,3 +540,23 @@ class TestShortcutWriterRefusesASpeechLessInterpreter:
"the shortcut, which is how local speech silently disappears"
)
assert result is True, "an existing entry is still present, so report it"
+
+
+@windows_only
+def test_a_short_spelling_of_the_install_path_still_matches(tmp_path: Path) -> None:
+ """``sys.executable`` under an 8.3 name made every launch rewrite the shortcut."""
+ import ctypes
+
+ folder = tmp_path / "a folder with a long name"
+ folder.mkdir()
+ exe = folder / "PersonalJarvis.exe"
+ exe.write_bytes(b"")
+ buffer = ctypes.create_unicode_buffer(1024)
+ ctypes.windll.kernel32.GetShortPathNameW(str(exe), buffer, len(buffer))
+ short = buffer.value
+ if not short or short.lower() == str(exe).lower():
+ pytest.skip("this volume keeps no short names")
+ assert icon_utils._same_file_path(str(exe), Path(short))
+ assert icon_utils._same_file_path(short, exe)
+ assert not icon_utils._same_file_path(str(exe), folder / "other.exe")
+ assert not icon_utils._same_file_path("", exe)