test(execute-code): cover session cwd record precedence in project mode
Follow-up for salvaged PRs #56055 + #56803, adapted to the per-session cwd record store (PR #65213): the record (live cd state) is rung 1, the registered session.cwd.set override rung 2, TERMINAL_CWD rung 3 — the same ladder file tools and the terminal resolve against. Covers record-over-override, record-only, and stale-record fall-through.
This commit is contained in:
parent
4d6686c18a
commit
a3c0de1a36
1 changed files with 52 additions and 0 deletions
|
|
@ -231,6 +231,58 @@ class TestResolveChildCwd(unittest.TestCase):
|
|||
terminal_tool.register_task_env_overrides(task_id, {"cwd": td})
|
||||
self.assertEqual(_resolve_child_cwd("project", "/tmp/staging", task_id=task_id), td)
|
||||
|
||||
def test_project_prefers_session_cwd_record_over_override(self):
|
||||
"""The session's cwd RECORD (its live `cd` state) outranks the
|
||||
registration-time workspace override — same ladder as file tools
|
||||
and the terminal, so a `cd` before execute_code is honored."""
|
||||
import tempfile
|
||||
import tools.terminal_tool as terminal_tool
|
||||
|
||||
with tempfile.TemporaryDirectory() as reg, tempfile.TemporaryDirectory() as cded:
|
||||
task_id = "session-record-test"
|
||||
with patch.dict(os.environ, {"TERMINAL_CWD": "/does/not/exist"}):
|
||||
with patch.object(terminal_tool, "_task_env_overrides", {}, create=False), \
|
||||
patch.object(terminal_tool, "_session_cwd", {}, create=False):
|
||||
terminal_tool.register_task_env_overrides(task_id, {"cwd": reg})
|
||||
# Simulate a later `cd`: post-command tracking rewrites the record.
|
||||
terminal_tool.record_session_cwd(task_id, cded)
|
||||
self.assertEqual(
|
||||
_resolve_child_cwd("project", "/tmp/staging", task_id=task_id), cded
|
||||
)
|
||||
|
||||
def test_project_uses_session_cwd_record_without_any_override(self):
|
||||
"""A session that only `cd`'d (no session.cwd.set registration) still
|
||||
resolves to its recorded directory."""
|
||||
import tempfile
|
||||
import tools.terminal_tool as terminal_tool
|
||||
|
||||
with tempfile.TemporaryDirectory() as cded:
|
||||
task_id = "record-only-test"
|
||||
with patch.dict(os.environ, {"TERMINAL_CWD": "/does/not/exist"}):
|
||||
with patch.object(terminal_tool, "_task_env_overrides", {}, create=False), \
|
||||
patch.object(terminal_tool, "_session_cwd", {}, create=False):
|
||||
terminal_tool.record_session_cwd(task_id, cded)
|
||||
self.assertEqual(
|
||||
_resolve_child_cwd("project", "/tmp/staging", task_id=task_id), cded
|
||||
)
|
||||
|
||||
def test_project_stale_record_falls_through_to_override(self):
|
||||
"""A recorded directory that no longer exists is skipped; the
|
||||
registered override is the next rung."""
|
||||
import tempfile
|
||||
import tools.terminal_tool as terminal_tool
|
||||
|
||||
with tempfile.TemporaryDirectory() as reg:
|
||||
task_id = "stale-record-test"
|
||||
with patch.dict(os.environ, {"TERMINAL_CWD": "/does/not/exist"}):
|
||||
with patch.object(terminal_tool, "_task_env_overrides", {}, create=False), \
|
||||
patch.object(terminal_tool, "_session_cwd", {}, create=False):
|
||||
terminal_tool.register_task_env_overrides(task_id, {"cwd": reg})
|
||||
terminal_tool.record_session_cwd(task_id, "/deleted/dir/gone")
|
||||
self.assertEqual(
|
||||
_resolve_child_cwd("project", "/tmp/staging", task_id=task_id), reg
|
||||
)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Schema description
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue