@@ -175,6 +175,53 @@ def raising_isfile(path: str) -> bool:
175175 assert exc_info.value.original_error is not None
176176
177177
178+ def test_ensure_existing_file_path_wraps_non_boolean_exists_results(monkeypatch):
179+ class _BrokenTruthValue:
180+ def __bool__(self) -> bool:
181+ raise RuntimeError("cannot coerce exists result")
182+
183+ def invalid_exists(path: str):
184+ _ = path
185+ return _BrokenTruthValue()
186+
187+ monkeypatch.setattr(file_utils.os.path, "exists", invalid_exists)
188+
189+ with pytest.raises(HyperbrowserError, match="file_path is invalid") as exc_info:
190+ ensure_existing_file_path(
191+ "/tmp/maybe-invalid",
192+ missing_file_message="missing",
193+ not_file_message="not-file",
194+ )
195+
196+ assert exc_info.value.original_error is not None
197+
198+
199+ def test_ensure_existing_file_path_wraps_non_boolean_isfile_results(
200+ monkeypatch, tmp_path: Path
201+ ):
202+ class _BrokenTruthValue:
203+ def __bool__(self) -> bool:
204+ raise RuntimeError("cannot coerce isfile result")
205+
206+ file_path = tmp_path / "target.txt"
207+ file_path.write_text("content")
208+
209+ def invalid_isfile(path: str):
210+ _ = path
211+ return _BrokenTruthValue()
212+
213+ monkeypatch.setattr(file_utils.os.path, "isfile", invalid_isfile)
214+
215+ with pytest.raises(HyperbrowserError, match="file_path is invalid") as exc_info:
216+ ensure_existing_file_path(
217+ str(file_path),
218+ missing_file_message="missing",
219+ not_file_message="not-file",
220+ )
221+
222+ assert exc_info.value.original_error is not None
223+
224+
178225def test_ensure_existing_file_path_wraps_fspath_runtime_errors():
179226 class _BrokenPathLike:
180227 def __fspath__(self) -> str:
0 commit comments