Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions hermes_cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1278,6 +1278,14 @@ def _launch_tui(
if "--expose-gc" not in _tokens:
_tokens.append("--expose-gc")
env["NODE_OPTIONS"] = " ".join(_tokens)
# HERMES_TUI_RESUME is an internal hand-off from the Python wrapper to the
# Ink app. Because we start from os.environ.copy(), an exported/stale value
# in the user's shell would otherwise make a plain `hermes --tui` try to
# resume a non-existent session and leave the UI at "error: session not
# found" with no live session. Only forward a resume id that argparse
# resolved for this invocation; direct `node ui-tui/dist/entry.js` users can
# still set HERMES_TUI_RESUME themselves.
env.pop("HERMES_TUI_RESUME", None)
if resume_session_id:
env["HERMES_TUI_RESUME"] = resume_session_id

Expand Down
42 changes: 42 additions & 0 deletions tests/hermes_cli/test_tui_resume_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,48 @@ def fake_call(argv, cwd=None, env=None):
assert env["NODE_ENV"] == "production"


def test_launch_tui_drops_stale_resume_env_without_resume_arg(monkeypatch, main_mod):
captured = {}

monkeypatch.setenv("HERMES_TUI_RESUME", "stale-missing-session")
monkeypatch.setattr(
main_mod,
"_make_tui_argv",
lambda tui_dir, tui_dev: (["node", "dist/entry.js"], Path(".")),
)
monkeypatch.setattr(
main_mod.subprocess,
"call",
lambda argv, cwd=None, env=None: captured.update({"env": env}) or 1,
)

with pytest.raises(SystemExit):
main_mod._launch_tui()

assert "HERMES_TUI_RESUME" not in captured["env"]


def test_launch_tui_sets_resume_env_from_resume_arg(monkeypatch, main_mod):
captured = {}

monkeypatch.setenv("HERMES_TUI_RESUME", "stale-missing-session")
monkeypatch.setattr(
main_mod,
"_make_tui_argv",
lambda tui_dir, tui_dev: (["node", "dist/entry.js"], Path(".")),
)
monkeypatch.setattr(
main_mod.subprocess,
"call",
lambda argv, cwd=None, env=None: captured.update({"env": env}) or 1,
)

with pytest.raises(SystemExit):
main_mod._launch_tui(resume_session_id="20260518_000000_goodid")

assert captured["env"]["HERMES_TUI_RESUME"] == "20260518_000000_goodid"


def test_make_tui_argv_dev_prebuilds_hermes_ink(monkeypatch, main_mod, tmp_path):
tui_dir = tmp_path / "ui-tui"
tsx = tui_dir / "node_modules" / ".bin" / "tsx"
Expand Down