Skip to content

Commit 4384cae

Browse files
Require plain CreateExtensionParams in extension managers
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent f1a97f8 commit 4384cae

3 files changed

Lines changed: 8 additions & 58 deletions

File tree

hyperbrowser/client/managers/async_manager/extension.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def __init__(self, client):
1212
self._client = client
1313

1414
async def create(self, params: CreateExtensionParams) -> ExtensionResponse:
15-
if not isinstance(params, CreateExtensionParams):
15+
if type(params) is not CreateExtensionParams:
1616
raise HyperbrowserError("params must be CreateExtensionParams")
1717
try:
1818
raw_file_path = params.file_path

hyperbrowser/client/managers/sync_manager/extension.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def __init__(self, client):
1212
self._client = client
1313

1414
def create(self, params: CreateExtensionParams) -> ExtensionResponse:
15-
if not isinstance(params, CreateExtensionParams):
15+
if type(params) is not CreateExtensionParams:
1616
raise HyperbrowserError("params must be CreateExtensionParams")
1717
try:
1818
raw_file_path = params.file_path

tests/test_extension_manager.py

Lines changed: 6 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -221,12 +221,9 @@ def test_sync_extension_create_rejects_invalid_params_type():
221221
manager.create({"name": "bad", "filePath": "/tmp/ext.zip"}) # type: ignore[arg-type]
222222

223223

224-
def test_sync_extension_create_wraps_invalid_params_file_path_state(tmp_path):
224+
def test_sync_extension_create_rejects_subclass_params(tmp_path):
225225
class _BrokenParams(CreateExtensionParams):
226-
def __getattribute__(self, item: str):
227-
if item == "file_path":
228-
raise RuntimeError("broken file_path state")
229-
return super().__getattribute__(item)
226+
pass
230227

231228
manager = SyncExtensionManager(_FakeClient(_SyncTransport()))
232229
params = _BrokenParams(
@@ -235,28 +232,7 @@ def __getattribute__(self, item: str):
235232
)
236233

237234
with pytest.raises(
238-
HyperbrowserError, match="params.file_path is invalid"
239-
) as exc_info:
240-
manager.create(params)
241-
242-
assert isinstance(exc_info.value.original_error, RuntimeError)
243-
244-
245-
def test_sync_extension_create_preserves_hyperbrowser_file_path_state_errors(tmp_path):
246-
class _BrokenParams(CreateExtensionParams):
247-
def __getattribute__(self, item: str):
248-
if item == "file_path":
249-
raise HyperbrowserError("custom file_path state failure")
250-
return super().__getattribute__(item)
251-
252-
manager = SyncExtensionManager(_FakeClient(_SyncTransport()))
253-
params = _BrokenParams(
254-
name="bad-extension",
255-
file_path=_create_test_extension_zip(tmp_path),
256-
)
257-
258-
with pytest.raises(
259-
HyperbrowserError, match="custom file_path state failure"
235+
HyperbrowserError, match="params must be CreateExtensionParams"
260236
) as exc_info:
261237
manager.create(params)
262238

@@ -293,12 +269,9 @@ async def run():
293269
asyncio.run(run())
294270

295271

296-
def test_async_extension_create_wraps_invalid_params_file_path_state(tmp_path):
272+
def test_async_extension_create_rejects_subclass_params(tmp_path):
297273
class _BrokenParams(CreateExtensionParams):
298-
def __getattribute__(self, item: str):
299-
if item == "file_path":
300-
raise RuntimeError("broken file_path state")
301-
return super().__getattribute__(item)
274+
pass
302275

303276
manager = AsyncExtensionManager(_FakeClient(_AsyncTransport()))
304277
params = _BrokenParams(
@@ -308,30 +281,7 @@ def __getattribute__(self, item: str):
308281

309282
async def run():
310283
with pytest.raises(
311-
HyperbrowserError, match="params.file_path is invalid"
312-
) as exc_info:
313-
await manager.create(params)
314-
assert isinstance(exc_info.value.original_error, RuntimeError)
315-
316-
asyncio.run(run())
317-
318-
319-
def test_async_extension_create_preserves_hyperbrowser_file_path_state_errors(tmp_path):
320-
class _BrokenParams(CreateExtensionParams):
321-
def __getattribute__(self, item: str):
322-
if item == "file_path":
323-
raise HyperbrowserError("custom file_path state failure")
324-
return super().__getattribute__(item)
325-
326-
manager = AsyncExtensionManager(_FakeClient(_AsyncTransport()))
327-
params = _BrokenParams(
328-
name="bad-extension",
329-
file_path=_create_test_extension_zip(tmp_path),
330-
)
331-
332-
async def run():
333-
with pytest.raises(
334-
HyperbrowserError, match="custom file_path state failure"
284+
HyperbrowserError, match="params must be CreateExtensionParams"
335285
) as exc_info:
336286
await manager.create(params)
337287
assert exc_info.value.original_error is None

0 commit comments

Comments
 (0)