Skip to content

Commit b641234

Browse files
committed
test: simplify Windows drive-letter test to fix coverage
The previous tests mocked Path.resolve with a conditional that fell through to the original implementation — but with the fix in place, only the full path ever hits resolve(), so the fallthrough was dead code and missed coverage (lines 129, 146). Replace with a single parametrized test that records what resolve() was called with. Before the fix, a bare 'C:\path\server.py' would rsplit on the drive colon and call resolve(Path('C')); now it calls resolve on the full path. The recorder asserts that directly — no dead branches. Also covers the has_windows_drive=True + :object-suffix branch that was previously missed.
1 parent 1b1d404 commit b641234

File tree

1 file changed

+21
-28
lines changed

1 file changed

+21
-28
lines changed

tests/cli/test_claude.py

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -117,37 +117,30 @@ def fake_which(cmd: str) -> str | None:
117117
assert get_uv_path() == expected
118118

119119

120-
def test_windows_drive_letter_without_object(config_dir: Path, monkeypatch: pytest.MonkeyPatch):
121-
"""Windows paths like C:\\path\\server.py without :object should not split on drive letter."""
122-
# Mock Path.resolve to return a fake Windows-style path
123-
original_resolve = Path.resolve
120+
@pytest.mark.parametrize(
121+
"file_spec, expected_last_arg",
122+
[
123+
("C:\\Users\\server.py", "C:\\Users\\server.py"),
124+
("C:\\Users\\server.py:app", "C:\\Users\\server.py:app"),
125+
],
126+
)
127+
def test_windows_drive_letter_not_split(
128+
config_dir: Path, monkeypatch: pytest.MonkeyPatch, file_spec: str, expected_last_arg: str
129+
):
130+
"""Drive-letter paths like 'C:\\server.py' must not be split on the drive colon.
131+
132+
Before the fix, a bare 'C:\\path\\server.py' would hit rsplit(":", 1) and yield
133+
("C", "\\path\\server.py"), calling resolve() on Path("C") instead of the full path.
134+
"""
135+
seen: list[str] = []
124136

125137
def fake_resolve(self: Path) -> Path:
126-
if str(self) == "C:\\Users\\foo\\server.py":
127-
# Return the same path as if it were already resolved
128-
return self
129-
return original_resolve(self)
138+
seen.append(str(self))
139+
return self
130140

131141
monkeypatch.setattr(Path, "resolve", fake_resolve)
132142

133-
assert update_claude_config(file_spec="C:\\Users\\foo\\server.py", server_name="s")
143+
assert update_claude_config(file_spec=file_spec, server_name="s")
134144

135-
# Should use the full path without splitting on the drive letter colon
136-
assert _read_server(config_dir, "s")["args"][-1] == "C:\\Users\\foo\\server.py"
137-
138-
139-
def test_windows_drive_letter_with_object(config_dir: Path, monkeypatch: pytest.MonkeyPatch):
140-
"""Windows paths like C:\\path\\server.py:app should only split on the :app suffix."""
141-
original_resolve = Path.resolve
142-
143-
def fake_resolve(self: Path) -> Path:
144-
if str(self) == "C:\\Users\\foo\\server.py":
145-
return self
146-
return original_resolve(self)
147-
148-
monkeypatch.setattr(Path, "resolve", fake_resolve)
149-
150-
assert update_claude_config(file_spec="C:\\Users\\foo\\server.py:app", server_name="s")
151-
152-
# Should split on :app but not on C:
153-
assert _read_server(config_dir, "s")["args"][-1] == "C:\\Users\\foo\\server.py:app"
145+
assert seen == ["C:\\Users\\server.py"]
146+
assert _read_server(config_dir, "s")["args"][-1] == expected_last_arg

0 commit comments

Comments
 (0)