Skip to content

Commit ae82b75

Browse files
Require concrete started job-id input types
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent d82ef32 commit ae82b75

2 files changed

Lines changed: 9 additions & 66 deletions

File tree

hyperbrowser/client/polling.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ def build_fetch_operation_name(operation_name: object) -> str:
234234

235235

236236
def ensure_started_job_id(job_id: object, *, error_message: str) -> str:
237-
if not isinstance(job_id, str):
237+
if type(job_id) is not str:
238238
raise HyperbrowserError(error_message)
239239
try:
240240
normalized_job_id = job_id.strip()

tests/test_polling.py

Lines changed: 8 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,14 @@ def test_ensure_started_job_id_rejects_non_string_values():
210210
ensure_started_job_id(123, error_message="Failed to start job")
211211

212212

213+
def test_ensure_started_job_id_rejects_string_subclass_values():
214+
class _JobId(str):
215+
pass
216+
217+
with pytest.raises(HyperbrowserError, match="Failed to start job"):
218+
ensure_started_job_id(_JobId("job_123"), error_message="Failed to start job")
219+
220+
213221
def test_ensure_started_job_id_rejects_blank_values():
214222
with pytest.raises(HyperbrowserError, match="Failed to start job"):
215223
ensure_started_job_id(" ", error_message="Failed to start job")
@@ -235,71 +243,6 @@ def test_ensure_started_job_id_keeps_non_blank_control_characters():
235243
)
236244

237245

238-
def test_ensure_started_job_id_wraps_strip_runtime_failures():
239-
class _BrokenJobId(str):
240-
def strip(self, chars=None): # type: ignore[override]
241-
_ = chars
242-
raise RuntimeError("job_id strip exploded")
243-
244-
with pytest.raises(HyperbrowserError, match="Failed to start job") as exc_info:
245-
ensure_started_job_id(
246-
_BrokenJobId("job_123"),
247-
error_message="Failed to start job",
248-
)
249-
250-
assert isinstance(exc_info.value.original_error, RuntimeError)
251-
252-
253-
def test_ensure_started_job_id_preserves_hyperbrowser_strip_failures():
254-
class _BrokenJobId(str):
255-
def strip(self, chars=None): # type: ignore[override]
256-
_ = chars
257-
raise HyperbrowserError("custom job_id strip failure")
258-
259-
with pytest.raises(
260-
HyperbrowserError, match="custom job_id strip failure"
261-
) as exc_info:
262-
ensure_started_job_id(
263-
_BrokenJobId("job_123"),
264-
error_message="Failed to start job",
265-
)
266-
267-
assert exc_info.value.original_error is None
268-
269-
270-
def test_ensure_started_job_id_wraps_non_string_strip_results():
271-
class _BrokenJobId(str):
272-
def strip(self, chars=None): # type: ignore[override]
273-
_ = chars
274-
return object()
275-
276-
with pytest.raises(HyperbrowserError, match="Failed to start job") as exc_info:
277-
ensure_started_job_id(
278-
_BrokenJobId("job_123"),
279-
error_message="Failed to start job",
280-
)
281-
282-
assert isinstance(exc_info.value.original_error, TypeError)
283-
284-
285-
def test_ensure_started_job_id_wraps_string_subclass_strip_results():
286-
class _BrokenJobId(str):
287-
class _NormalizedJobId(str):
288-
pass
289-
290-
def strip(self, chars=None): # type: ignore[override]
291-
_ = chars
292-
return self._NormalizedJobId("job_123")
293-
294-
with pytest.raises(HyperbrowserError, match="Failed to start job") as exc_info:
295-
ensure_started_job_id(
296-
_BrokenJobId("job_123"),
297-
error_message="Failed to start job",
298-
)
299-
300-
assert isinstance(exc_info.value.original_error, TypeError)
301-
302-
303246
def test_build_operation_name_keeps_short_names_unchanged():
304247
assert build_operation_name("crawl job ", "123") == "crawl job 123"
305248

0 commit comments

Comments
 (0)