Files
hermes-agent/tests/test_session_workspace_binding.py
Teknium 53db597201 simplify(compat): hermes_state — drop 81 re-exports + 3 registry aliases + 3 shims, repoint 45 callers + 60 test files
hermes_state.py: delete every '# noqa: F401 (re-exported...)' import block (hermes_state_common/errors/guard/
readpool/sessions/fts/dbfile/wal/repair/registry + agent.context_compressor _DB_PERSISTED_MARKER_KEY); keep
only the names hermes_state.py itself uses, without noqa.
hermes_state_registry.py: drop get_shared_session_db/release_shared_session_db/close_shared_session_dbs
aliases; every caller (gateway/, tools/, tui_gateway/, cron/, mcp_serve, run_agent, tests) now imports
acquire/release/close_all/release_or_close from hermes_state_registry.
hermes_state_titles.py: drop set_auto_title_if_empty shim (title_generator keeps its getattr fallback).
Re-remove shim-only names restored by 34abf954bd: latest_user_message_row_id (tests call
latest_message_row_id(key, role='user'); role-targeting assertions kept) and get_session_activity (tests
build the snapshot via agent.session_activity.build_activity_snapshot over db.get_session(sid)).
hermes_state_wal._log_once resolves its dedupe sets as module globals instead of via hermes_state;
hermes_state_repair helpers call module globals directly (tests patch hermes_state_repair.<name>).
Frozen updater surface untouched (update_cmd_maint imports only SessionDB from hermes_state).
2026-09-03 13:46:50 -07:00

40 lines
1.5 KiB
Python

"""Session <-> workspace grouping key (hermes_state_sessions.workspace_key).
The key is what `hermes sessions list --workspace` groups/filters on. It is a
coarse workspace identity derived from fields already recorded on sessions
(git_repo_root, cwd) — no git shelling, no new columns. Branch is deliberately
NOT part of the key.
"""
import hermes_state_sessions
from hermes_state_sessions import workspace_key
def test_repo_root_is_the_key_when_known():
row = {"git_repo_root": "/www/app", "cwd": "/www/app/src", "git_branch": "feat"}
assert workspace_key(row) == "/www/app"
def test_falls_back_to_cwd_for_non_git_sessions():
assert workspace_key({"cwd": "/work/notes"}) == "/work/notes"
assert workspace_key({"git_repo_root": "", "cwd": "/work/notes"}) == "/work/notes"
def test_none_when_unbound():
assert workspace_key({}) is None
assert workspace_key({"cwd": "", "git_repo_root": ""}) is None
assert workspace_key({"cwd": " "}) is None
def test_branch_does_not_affect_the_key():
# Two sessions on the same repo, different branches, group together.
a = {"git_repo_root": "/www/app", "git_branch": "main"}
b = {"git_repo_root": "/www/app", "git_branch": "feature-x"}
assert workspace_key(a) == workspace_key(b) == "/www/app"
def test_repo_root_wins_over_a_differing_cwd():
# A worktree/subdir session still groups under its repo root, not its cwd.
row = {"git_repo_root": "/www/app", "cwd": "/www/app/.worktrees/x"}
assert workspace_key(row) == "/www/app"