|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
| 3 | +import json |
3 | 4 | from pathlib import Path |
4 | 5 |
|
5 | 6 | from click.testing import CliRunner |
@@ -34,6 +35,56 @@ def test_transfer_no_sessions_errors(tmp_path: Path, monkeypatch) -> None: |
34 | 35 | ) |
35 | 36 |
|
36 | 37 |
|
| 38 | +def test_transfer_session_id_is_scoped_to_project(tmp_path: Path, monkeypatch) -> None: |
| 39 | + monkeypatch.setenv("HOME", str(tmp_path)) |
| 40 | + monkeypatch.setattr("pathlib.Path.home", lambda: tmp_path) |
| 41 | + |
| 42 | + from handoff.agents.codex import CodexInjector |
| 43 | + from handoff.canonical import CanonicalTranscript, Message, Metadata, now_iso |
| 44 | + |
| 45 | + source_project = tmp_path / "source-project" |
| 46 | + other_project = tmp_path / "other-project" |
| 47 | + source_project.mkdir() |
| 48 | + other_project.mkdir() |
| 49 | + |
| 50 | + transcript = CanonicalTranscript( |
| 51 | + metadata=Metadata( |
| 52 | + session_id="src", |
| 53 | + source_agent="claude", |
| 54 | + source_session_path="/tmp/src.jsonl", |
| 55 | + created_at=now_iso(), |
| 56 | + last_activity=now_iso(), |
| 57 | + message_count=1, |
| 58 | + cwd=str(other_project), |
| 59 | + model="gpt-5.4", |
| 60 | + ), |
| 61 | + transcript=[ |
| 62 | + Message( |
| 63 | + id="1", |
| 64 | + timestamp=now_iso(), |
| 65 | + author="user", |
| 66 | + type="message", |
| 67 | + content="Continue from the other project", |
| 68 | + ) |
| 69 | + ], |
| 70 | + ) |
| 71 | + session_path = CodexInjector(tmp_path / ".codex").inject(transcript) |
| 72 | + |
| 73 | + first_line = session_path.read_text(encoding="utf-8").splitlines()[0] |
| 74 | + session_uuid = json.loads(first_line)["payload"]["id"] |
| 75 | + |
| 76 | + runner = CliRunner() |
| 77 | + result = runner.invoke( |
| 78 | + main, |
| 79 | + ["codex", "claude", "--cwd", str(source_project), "--session-id", session_uuid], |
| 80 | + ) |
| 81 | + |
| 82 | + assert result.exit_code != 0 |
| 83 | + output = result.output.lower() |
| 84 | + assert "no codex session with id starting with" in output |
| 85 | + assert str(source_project).lower() in output |
| 86 | + |
| 87 | + |
37 | 88 | def test_unknown_agent_errors(tmp_path: Path, monkeypatch) -> None: |
38 | 89 | monkeypatch.setattr("pathlib.Path.home", lambda: tmp_path) |
39 | 90 | runner = CliRunner() |
|
0 commit comments