Skip to content

The agent that grows with you

fix(bot-screen): dock Browser entry follows the profile path after a rename

teknium16c406fd53c7d
diff --git a/tests/tools/test_bot_desktop_launcher_seed.py b/tests/tools/test_bot_desktop_launcher_seed.py
index c75296ce309..347a568ffa4 100644
--- a/tests/tools/test_bot_desktop_launcher_seed.py
+++ b/tests/tools/test_bot_desktop_launcher_seed.py
@@ -14,9 +14,9 @@ LAUNCHER = Path(__file__).resolve().parents[2] / "tools" / "bot_desktop" / "laun
pytestmark = pytest.mark.linux_only
-def _seed(tmp_path: Path, fake_bins: list[str], browser_exec: str = "") -> Path:
+def _seed(tmp_path: Path, fake_bins: list[str], browser_exec: str = "", profile_dir: str = "") -> Path:
bindir = tmp_path / "bin"
- bindir.mkdir()
+ bindir.mkdir(exist_ok=True)
for name in fake_bins:
exe = bindir / name
exe.write_text("#!/bin/sh\n", encoding="utf-8")
@@ -35,7 +35,7 @@ def _seed(tmp_path: Path, fake_bins: list[str], browser_exec: str = "") -> Path:
"HERMES_BD_SOCKET": str(tmp_path / "rfb.sock"), "HERMES_BD_XAUTH": str(tmp_path / "Xauthority"),
"HERMES_BD_ENV_FILE": str(tmp_path / "env"), "HERMES_BD_CONFIG_HOME": str(cfg),
"HERMES_BD_SEED_ONLY": "1",
- **({"HERMES_BD_BROWSER_EXEC": browser_exec, "HERMES_BD_BROWSER_EXEC_LINE": f"Exec={browser_exec} --user-data-dir={tmp_path}/bp"} if browser_exec else {}),
+ **({"HERMES_BD_BROWSER_EXEC": browser_exec, "HERMES_BD_BROWSER_EXEC_LINE": f"Exec={browser_exec} --user-data-dir={profile_dir or f'{tmp_path}/bp'}"} if browser_exec else {}),
}
subprocess.run(["bash", str(LAUNCHER)], env=env, check=True, stdin=subprocess.DEVNULL, capture_output=True, timeout=30)
return cfg
@@ -55,6 +55,24 @@ def test_dock_lists_only_programs_present_on_path(tmp_path):
assert execs == [f"{chrome} --user-data-dir={tmp_path}/bp", "xfce4-terminal"]
+def test_browser_launcher_follows_the_profile_without_reseeding_the_panel(tmp_path):
+ """The panel layout is seeded once (the human may have rearranged it), but the Browser entry's Exec=
+ binds the bot's user-data-dir by absolute path: after `hermes profile rename` the dock must open the
+ renamed profile's cookie jar, the same one agent-browser now drives, while the layout stays untouched."""
+ chrome = tmp_path / "bin" / "chrome"
+ cfg = _seed(tmp_path, ["xfce4-terminal", "chrome"], browser_exec=str(chrome), profile_dir="/old name/bp")
+ panel_xml = cfg / "xfce4/xfconf/xfce-perchannel-xml/xfce4-panel.xml"
+ layout_before = panel_xml.read_text(encoding="utf-8")
+ shutil.rmtree(tmp_path / "bin")
+ _seed(tmp_path, ["xfce4-terminal", "chrome"], browser_exec=str(chrome), profile_dir="/new name/bp")
+ execs = [
+ line for d in (cfg / "xfce4/panel").glob("launcher-*/hermes.desktop")
+ for line in d.read_text(encoding="utf-8").splitlines() if line.startswith("Exec=") and "user-data-dir" in line
+ ]
+ assert execs == [f"Exec={chrome} --user-data-dir=/new name/bp"]
+ assert panel_xml.read_text(encoding="utf-8") == layout_before
+
+
def test_look_is_seeded_with_wallpaper_and_theme(tmp_path):
cfg = _seed(tmp_path, ["xfce4-terminal"])
desktop = (cfg / "xfce4/xfconf/xfce-perchannel-xml/xfce4-desktop.xml").read_text(encoding="utf-8")
diff --git a/tools/bot_desktop/launcher.sh b/tools/bot_desktop/launcher.sh
index a480bf50c2a..4e90ee3eed4 100755
--- a/tools/bot_desktop/launcher.sh
+++ b/tools/bot_desktop/launcher.sh
@@ -147,7 +147,8 @@ if [[ ! -e "$X/xfce4-panel.xml" ]]; then
# The bot's browser: runtime.py resolves the executable agent-browser drives plus the profile's
# persistent user-data-dir, so a human taking over lands in the bot's own cookie jar.
[[ -n "${HERMES_BD_BROWSER_EXEC:-}" ]] && \
- add_launcher "Browser" internet-web-browser "$HERMES_BD_BROWSER_EXEC" "${HERMES_BD_BROWSER_EXEC_LINE:-}"
+ add_launcher "Browser" internet-web-browser "$HERMES_BD_BROWSER_EXEC" "${HERMES_BD_BROWSER_EXEC_LINE:-}" && \
+ echo "$n" > "$L/.hermes-browser-launcher"
add_launcher "Files" system-file-manager "thunar"
add_launcher "Text Editor" accessories-text-editor "mousepad"
dock_plugins=""; dock_items=""
@@ -222,6 +223,16 @@ for a in xfce4-screensaver light-locker xfce4-power-manager xfce-polkit \
[[ -e "$XDG_CONFIG_HOME/autostart/$a.desktop" ]] || \
printf '[Desktop Entry]\nType=Application\nName=%s\nHidden=true\n' "$a" > "$XDG_CONFIG_HOME/autostart/$a.desktop"
done
+# The Browser launcher's Exec= line binds the bot's user-data-dir by absolute path. The panel layout is
+# seeded once (the human may have rearranged it), but this one line is ours and must follow the profile:
+# after `hermes profile rename` the old path would open a browser with an empty, unshared cookie jar.
+L="$XDG_CONFIG_HOME/xfce4/panel"
+if [[ -n "${HERMES_BD_BROWSER_EXEC:-}" && -n "${HERMES_BD_BROWSER_EXEC_LINE:-}" && -r "$L/.hermes-browser-launcher" ]]; then
+ bn="$(cat "$L/.hermes-browser-launcher")"
+ d="$L/launcher-$bn/hermes.desktop"
+ [[ -f "$d" ]] && sed -i "s|^Exec=.*|$(printf '%s' "$HERMES_BD_BROWSER_EXEC_LINE" | sed 's/[&|\\]/\\&/g')|" "$d"
+fi
+
# Tests seed the config tree on a fake PATH and stop here (no X server needed).
[[ -n "${HERMES_BD_SEED_ONLY:-}" ]] && exit 0