diff --git a/tests/agent/test_prompt_builder.py b/tests/agent/test_prompt_builder.py index 588e3093654..856a047253f 100644 --- a/tests/agent/test_prompt_builder.py +++ b/tests/agent/test_prompt_builder.py @@ -3,7 +3,6 @@ import builtins import importlib import logging -import os import sys import pytest @@ -19,7 +18,6 @@ from agent.prompt_builder import ( build_skills_system_prompt, build_nous_subscription_prompt, build_context_files_prompt, - build_environment_hints, CONTEXT_FILE_MAX_CHARS, DEFAULT_AGENT_IDENTITY, TOOL_USE_ENFORCEMENT_GUIDANCE, @@ -929,6 +927,29 @@ class TestEnvironmentHints: assert "Terminal backend: docker" in result assert "inside" in result.lower() + def test_build_environment_hints_uses_terminal_cwd_over_launch_dir(self, monkeypatch, tmp_path): + """THE BUG: gateway/cron set TERMINAL_CWD but the prompt emitted os.getcwd() + (the daemon launch dir). Regression for #24882/#24969/#27383/#29265.""" + import agent.prompt_builder as _pb + monkeypatch.setattr(_pb, "is_wsl", lambda: False) + monkeypatch.delenv("TERMINAL_ENV", raising=False) + configured = tmp_path / "workspace" + configured.mkdir() + monkeypatch.setenv("TERMINAL_CWD", str(configured)) + monkeypatch.chdir(tmp_path) + _pb._clear_backend_probe_cache() + assert f"Current working directory: {configured}" in _pb.build_environment_hints() + + def test_build_environment_hints_falls_back_to_launch_dir(self, monkeypatch, tmp_path): + """The #19242 local-CLI contract: no TERMINAL_CWD → the launch dir.""" + import agent.prompt_builder as _pb + monkeypatch.setattr(_pb, "is_wsl", lambda: False) + monkeypatch.delenv("TERMINAL_ENV", raising=False) + monkeypatch.delenv("TERMINAL_CWD", raising=False) + monkeypatch.chdir(tmp_path) + _pb._clear_backend_probe_cache() + assert f"Current working directory: {tmp_path}" in _pb.build_environment_hints() + def test_build_environment_hints_uses_live_probe_when_available(self, monkeypatch): """When the probe succeeds, its output must appear in the hint block.""" import agent.prompt_builder as _pb @@ -1249,26 +1270,3 @@ class TestOpenAIModelExecutionGuidance: # ========================================================================= - - - -class TestBuildEnvironmentHints: - """The cwd line must reflect the configured TERMINAL_CWD, not the daemon launch dir. - - Regression for the gateway working-directory cluster (#24882, #24969, #27383, #29265): - gateway/cron set TERMINAL_CWD, but build_environment_hints emitted os.getcwd() — telling - the model the wrong directory. - """ - - def test_uses_terminal_cwd_when_set(self, monkeypatch, tmp_path): - monkeypatch.delenv("TERMINAL_ENV", raising=False) - monkeypatch.setenv("TERMINAL_CWD", str(tmp_path)) - monkeypatch.chdir(os.path.expanduser("~")) - assert f"Current working directory: {tmp_path}" in build_environment_hints() - - def test_falls_back_to_launch_dir_when_unset(self, monkeypatch, tmp_path): - # The #19242 local-CLI contract: no TERMINAL_CWD → the launch dir. - monkeypatch.delenv("TERMINAL_ENV", raising=False) - monkeypatch.delenv("TERMINAL_CWD", raising=False) - monkeypatch.chdir(tmp_path) - assert f"Current working directory: {tmp_path}" in build_environment_hints()