fix(tui_gateway): report a lazy session's own cwd, not the launch dir
`_fallback_session_info` returned `_default_session_cwd()` — the directory the
gateway process happened to start in — so a session resumed without a built
agent told its client the wrong workspace, and the desktop Files pane painted
the wrong project even after the renderer rebound correctly.
Return the session's own cwd and always emit `branch` ("" outside a git repo)
so a client can clear a stale label instead of retaining it. This matches the
contract `_lazy_session_info` already follows a few hundred lines above.
Co-authored-by: ZHJay <ZHJay@users.noreply.github.com>
This commit is contained in:
@@ -16375,3 +16375,38 @@ def test_prompt_submit_releases_old_history_before_heap_trim(monkeypatch):
|
||||
assert cleanup_order == ["trim", "reset_home"]
|
||||
finally:
|
||||
server._sessions.pop("sid_trim", None)
|
||||
|
||||
|
||||
def test_fallback_session_info_reports_session_cwd_not_launch_dir(monkeypatch):
|
||||
"""A lazily-resumed session must report ITS workspace, not the gateway's.
|
||||
|
||||
``_fallback_session_info`` used ``_default_session_cwd()`` — the directory the
|
||||
gateway process happened to start in — so the desktop Files pane painted the
|
||||
wrong project for any session resumed without a built agent (#71254).
|
||||
"""
|
||||
monkeypatch.setattr(server, "_default_session_cwd", lambda: "/gateway/launch/dir")
|
||||
monkeypatch.setattr(server, "_git_branch_for_cwd", lambda cwd: "bb/feature")
|
||||
monkeypatch.setattr(server, "_project_info_for_cwd", lambda cwd: None)
|
||||
monkeypatch.setattr(server, "_resolve_model", lambda: "test-model")
|
||||
|
||||
info = server._fallback_session_info({"cwd": "/projects/session-own-repo"})
|
||||
|
||||
assert info["cwd"] == "/projects/session-own-repo"
|
||||
assert info["branch"] == "bb/feature"
|
||||
|
||||
|
||||
def test_fallback_session_info_always_emits_branch(monkeypatch):
|
||||
"""``branch`` is always present so a client can CLEAR a stale label.
|
||||
|
||||
Omitting the key left the desktop showing the previous conversation's branch
|
||||
after switching into a non-git session.
|
||||
"""
|
||||
monkeypatch.setattr(server, "_default_session_cwd", lambda: "/gateway/launch/dir")
|
||||
monkeypatch.setattr(server, "_git_branch_for_cwd", lambda cwd: "")
|
||||
monkeypatch.setattr(server, "_project_info_for_cwd", lambda cwd: None)
|
||||
monkeypatch.setattr(server, "_resolve_model", lambda: "test-model")
|
||||
|
||||
info = server._fallback_session_info({"cwd": "/plain/folder"})
|
||||
|
||||
assert "branch" in info
|
||||
assert info["branch"] == ""
|
||||
|
||||
@@ -7968,9 +7968,17 @@ def _fallback_session_info(session: dict) -> dict:
|
||||
agent = session.get("agent")
|
||||
if agent is not None:
|
||||
return _session_info(agent)
|
||||
cwd = _default_session_cwd()
|
||||
# The SESSION's own workspace, not the gateway's launch directory. Reporting
|
||||
# `_default_session_cwd()` here told a lazily-resumed session's client that
|
||||
# its workspace was wherever the gateway process happened to start, so the
|
||||
# desktop Files pane painted the wrong project even after the renderer
|
||||
# rebound correctly (#71254). `branch` is always emitted ("" outside a git
|
||||
# repo) so a client can clear a stale label instead of retaining it — the
|
||||
# same contract `_lazy_session_info` above already follows.
|
||||
cwd = _session_cwd(session)
|
||||
return {
|
||||
"cwd": cwd,
|
||||
"branch": _git_branch_for_cwd(cwd),
|
||||
"project": _project_info_for_cwd(cwd),
|
||||
"lazy": True,
|
||||
"model": _resolve_model(),
|
||||
|
||||
Reference in New Issue
Block a user