From e89d56e48d03c6082142558fd687d35aed539ff5 Mon Sep 17 00:00:00 2001 From: Teknium <127238744+teknium1@users.noreply.github.com> Date: Thu, 16 Jul 2026 02:32:34 -0700 Subject: [PATCH] test(system_prompt): cover surface-aware context-file cwd contract Updates TestContextFileCwd for the #64590 rework: the CLI now receives its launch dir explicitly (previously None), daemon surfaces receive None, and a configured TERMINAL_CWD wins on every surface. --- tests/agent/test_system_prompt.py | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/tests/agent/test_system_prompt.py b/tests/agent/test_system_prompt.py index 0536de1dccd..acd989ae230 100644 --- a/tests/agent/test_system_prompt.py +++ b/tests/agent/test_system_prompt.py @@ -46,15 +46,29 @@ def _captured_context_cwd(agent): class TestContextFileCwd: - def test_none_when_terminal_cwd_unset(self, monkeypatch): - # Unset → None, so discovery falls back to the launch dir inside - # build_context_files_prompt (the local-CLI #19242 contract). + def test_cli_launch_dir_when_terminal_cwd_unset(self, monkeypatch, tmp_path): + # Unset → the interactive CLI (empty/None platform defaults to it) + # promotes its launch dir to an explicit choice, so discovery loads + # context files from it even inside the Hermes checkout (#64590). monkeypatch.delenv("TERMINAL_CWD", raising=False) - assert _captured_context_cwd(_make_agent()) is None + monkeypatch.chdir(tmp_path) + assert _captured_context_cwd(_make_agent()) == str(tmp_path) + + def test_daemon_none_when_terminal_cwd_unset(self, monkeypatch, tmp_path): + # Daemon surfaces pass None so build_context_files_prompt's + # install-tree fallback guard applies — their process cwd is an + # accident of spawning, not a user choice (#64590). + monkeypatch.delenv("TERMINAL_CWD", raising=False) + monkeypatch.chdir(tmp_path) + assert _captured_context_cwd(_make_agent(platform="tui")) is None def test_configured_dir_when_terminal_cwd_set(self, monkeypatch, tmp_path): monkeypatch.setenv("TERMINAL_CWD", str(tmp_path)) - assert _captured_context_cwd(_make_agent()) == tmp_path + assert _captured_context_cwd(_make_agent()) == str(tmp_path) + + def test_configured_dir_wins_on_daemon_surface(self, monkeypatch, tmp_path): + monkeypatch.setenv("TERMINAL_CWD", str(tmp_path)) + assert _captured_context_cwd(_make_agent(platform="telegram")) == str(tmp_path) def _stable_prompt(agent):