|
| 1 | +# SPDX-License-Identifier: Proprietary |
| 2 | +# Copyright (C) 2026 ProtocolWarden |
| 3 | +"""Launch anchoring: OC-launched Claude sessions must export CL_ANCHOR, and the |
| 4 | +cross-repo group tab must anchor at PlatformManifest (not the bare workspace root).""" |
| 5 | + |
| 6 | +from __future__ import annotations |
| 7 | + |
| 8 | +from pathlib import Path |
| 9 | + |
| 10 | +from operator_console.bootstrap import get_claude_command |
| 11 | +from operator_console.launcher import _multi_pane_block |
| 12 | + |
| 13 | + |
| 14 | +def _console_dir(tmp_path: Path) -> Path: |
| 15 | + cd = tmp_path / "console" |
| 16 | + (cd / "config" / "profiles").mkdir(parents=True) |
| 17 | + return cd |
| 18 | + |
| 19 | + |
| 20 | +def test_claude_wrapper_exports_cl_anchor_equal_to_cwd(tmp_path): |
| 21 | + console_dir = _console_dir(tmp_path) |
| 22 | + anchor = tmp_path / "PlatformManifest" |
| 23 | + cmd = get_claude_command( |
| 24 | + {"name": "platform", "repo_root": str(tmp_path / "repo")}, |
| 25 | + tmp_path / "repo", |
| 26 | + console_dir=console_dir, |
| 27 | + session_key="platform", |
| 28 | + claude_cwd=anchor, |
| 29 | + ) |
| 30 | + # cmd == "bash '<script>'" — read the generated wrapper |
| 31 | + script_path = cmd.split("'")[1] |
| 32 | + script = Path(script_path).read_text(encoding="utf-8") |
| 33 | + assert f"export CL_ANCHOR='{anchor.resolve()}'" in script |
| 34 | + |
| 35 | + |
| 36 | +def test_group_tab_anchors_at_platform_manifest(tmp_path): |
| 37 | + console_dir = _console_dir(tmp_path) |
| 38 | + profiles = [ |
| 39 | + {"name": "a", "repo_root": str(tmp_path / "A")}, |
| 40 | + {"name": "b", "repo_root": str(tmp_path / "B")}, |
| 41 | + ] |
| 42 | + block = _multi_pane_block(profiles, console_dir=console_dir, tab_name="platform") |
| 43 | + # Panes cd into PlatformManifest, not the bare ~/Documents/GitHub root. |
| 44 | + assert "PlatformManifest" in block |
| 45 | + assert "cd '" in block and "/PlatformManifest'" in block |
0 commit comments