fix: expanduser in project_root, remove redundant cwd, add tests

- get_myclaude_project_root() now expands ~ in MYCLAUDE_PROJECT_ROOT
  (was resolving to ./~/path instead of $HOME/path)
- Extract hardcoded 16/8 depth limits as _MAX_WALK_DEPTH / _MAX_SOURCE_DEPTH
- Remove redundant cwd= from _run_pip_editable (already specified via -e)
- Add test_cwd_invalid_directory and test_env_var_expands_tilde
- Remove incorrect test_extra_args_forwarded (click.Group does not
  support forwarding arbitrary args; ctx.args is always empty)
This commit is contained in:
Zhengshou Lai
2026-05-27 11:23:14 +08:00
parent 854a69d3d8
commit b580eecc43
4 changed files with 34 additions and 4 deletions
+9
View File
@@ -99,3 +99,12 @@ class TestCliDefaultBehavior:
assert result.exit_code == 0
call_args = mock_run.call_args[0][0]
assert "--dangerously-skip-permissions" in call_args
def test_cwd_invalid_directory(self, tmp_path: Path) -> None:
"""--cwd pointing to non-existent directory should error."""
runner = CliRunner()
bad_dir = tmp_path / "does_not_exist"
result = runner.invoke(cli, ["--cwd", str(bad_dir)])
assert result.exit_code == 1
assert "not a directory" in result.output.lower()
+18
View File
@@ -20,6 +20,24 @@ class TestGetMyclaudeProjectRoot:
result = get_myclaude_project_root()
assert result == fake_root.resolve()
def test_env_var_expands_tilde(self, tmp_path: Path) -> None:
"""MYCLAUDE_PROJECT_ROOT should expand ~ to home directory."""
home = tmp_path / "home"
home.mkdir()
fake_root = home / "fake_repo"
fake_root.mkdir()
(fake_root / "pyproject.toml").write_text('name = "myclaude"\n')
with patch.dict(
os.environ,
{
"MYCLAUDE_PROJECT_ROOT": "~/fake_repo",
"HOME": str(home),
},
):
result = get_myclaude_project_root()
assert result == fake_root.resolve()
def test_fallback_when_not_in_repo(self) -> None:
"""When not in a repo, fallback to ~/.myclaude."""
with (