Files
hermes-webui/tests/test_issue1955_worktree_ui_static.py
Rui Xue 5f638a1694 feat(sessions): honor the agent's worktree config default in /api/session/new
/api/session/new treated an absent 'worktree' key as false, so the
agent's config-level 'worktree: true' default was never consulted for
WebUI sessions even though the WebUI reuses the agent's own worktree
helper. Both callers should agree on same-agent/same-repo isolation.

Three-value model:
- body 'worktree' absent -> agent config default applies (profile-aware
  via get_config_for_profile_home, so a user with worktree:true in one
  profile but not another gets per-profile behavior)
- explicit true/false -> honored verbatim; explicit always wins

Non-git workspaces: a config-default request degrades to a plain
session and surfaces 'worktree_skipped' in the payload; an explicit
worktree:true keeps the hard 400.

Frontend (same change, load-bearing): newSession() forwards explicit
true/false and omits the key otherwise; the boot-time auto-bind
(_maybeBindFreshDefaultWorkspaceSession) and the onboarding session
send worktree:false explicitly so a config default can never mint a
worktree + branch from merely opening the UI. Deliberate 'New Chat'
sends nothing and inherits the default.

Tests: route matrix (config on/off x body absent/true/false), non-git
fallback vs explicit 400, explicit-false-beats-config-true, config
helper (ambient/named-profile/fail-soft), static UI assertions that
auto-bind and onboarding opt out and New Chat paths don't pin a value.

Fixes #6022
2026-07-14 04:35:06 +00:00

47 lines
1.5 KiB
Python

from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
def read(path):
return (ROOT / path).read_text(encoding="utf-8")
def test_session_new_route_accepts_worktree_flag_and_uses_worktree_info():
src = read("api/routes.py")
assert "create_worktree_for_workspace" in src
assert 'body.get("worktree")' in src or "body.get('worktree')" in src
assert "worktree_info=" in src
def test_new_session_request_can_include_worktree_flag():
src = read("static/sessions.js")
assert "async function newSession(flash, options={})" in src
# Three-value contract (#6022): explicit true/false forwarded verbatim,
# absent key omitted so the server applies the config default.
assert "reqBody.worktree=!!options.worktree" in src
def test_workspace_dropdown_exposes_new_worktree_conversation_action():
src = read("static/panels.js")
assert "workspace_new_worktree_conversation" in src
assert "workspace_new_worktree_conversation_meta" in src
assert "newSession(false,{worktree:true})" in src
assert "li('git-branch',12)" in src
def test_session_sidebar_renders_worktree_indicator():
src = read("static/sessions.js")
assert "session-worktree-indicator" in src
assert "s.worktree_path" in src
assert "s.worktree_branch" in src
def test_worktree_indicator_styles_and_i18n_exist():
css = read("static/style.css")
i18n = read("static/i18n.js")
assert ".session-worktree-indicator" in css
assert "workspace_new_worktree_conversation" in i18n
assert "session_worktree_badge" in i18n