|
2 | 2 | from types import SimpleNamespace |
3 | 3 |
|
4 | 4 | import hyperbrowser.client.managers.async_manager.agents.browser_use as async_browser_use_module |
| 5 | +import hyperbrowser.client.managers.async_manager.agents.claude_computer_use as async_claude_module |
5 | 6 | import hyperbrowser.client.managers.async_manager.agents.cua as async_cua_module |
| 7 | +import hyperbrowser.client.managers.async_manager.agents.gemini_computer_use as async_gemini_module |
| 8 | +import hyperbrowser.client.managers.async_manager.agents.hyper_agent as async_hyper_agent_module |
6 | 9 | import hyperbrowser.client.managers.async_manager.web.batch_fetch as async_batch_fetch_module |
7 | 10 | import hyperbrowser.client.managers.async_manager.web.crawl as async_web_crawl_module |
8 | 11 | import hyperbrowser.client.managers.async_manager.crawl as async_crawl_module |
9 | 12 | import hyperbrowser.client.managers.async_manager.extract as async_extract_module |
10 | 13 | import hyperbrowser.client.managers.sync_manager.agents.browser_use as sync_browser_use_module |
| 14 | +import hyperbrowser.client.managers.sync_manager.agents.claude_computer_use as sync_claude_module |
11 | 15 | import hyperbrowser.client.managers.sync_manager.agents.cua as sync_cua_module |
| 16 | +import hyperbrowser.client.managers.sync_manager.agents.gemini_computer_use as sync_gemini_module |
| 17 | +import hyperbrowser.client.managers.sync_manager.agents.hyper_agent as sync_hyper_agent_module |
12 | 18 | import hyperbrowser.client.managers.sync_manager.web.batch_fetch as sync_batch_fetch_module |
13 | 19 | import hyperbrowser.client.managers.sync_manager.web.crawl as sync_web_crawl_module |
14 | 20 | import hyperbrowser.client.managers.sync_manager.crawl as sync_crawl_module |
@@ -640,3 +646,239 @@ async def fake_wait_for_job_result_async(**kwargs): |
640 | 646 | assert captured["operation_name"].startswith("CUA task job ") |
641 | 647 |
|
642 | 648 | asyncio.run(run()) |
| 649 | + |
| 650 | + |
| 651 | +def test_sync_scrape_manager_bounds_operation_name_in_wait_helper(monkeypatch): |
| 652 | + manager = sync_scrape_module.ScrapeManager(_DummyClient()) |
| 653 | + long_job_id = " \n" + ("x" * 500) + "\t" |
| 654 | + captured = {} |
| 655 | + |
| 656 | + monkeypatch.setattr( |
| 657 | + manager, |
| 658 | + "start", |
| 659 | + lambda params: SimpleNamespace(job_id=long_job_id), |
| 660 | + ) |
| 661 | + |
| 662 | + def fake_wait_for_job_result(**kwargs): |
| 663 | + operation_name = kwargs["operation_name"] |
| 664 | + _assert_valid_operation_name(operation_name) |
| 665 | + captured["operation_name"] = operation_name |
| 666 | + return {"ok": True} |
| 667 | + |
| 668 | + monkeypatch.setattr( |
| 669 | + sync_scrape_module, |
| 670 | + "wait_for_job_result", |
| 671 | + fake_wait_for_job_result, |
| 672 | + ) |
| 673 | + |
| 674 | + result = manager.start_and_wait(params=object()) # type: ignore[arg-type] |
| 675 | + |
| 676 | + assert result == {"ok": True} |
| 677 | + assert captured["operation_name"].startswith("scrape job ") |
| 678 | + |
| 679 | + |
| 680 | +def test_async_scrape_manager_bounds_operation_name_in_wait_helper(monkeypatch): |
| 681 | + async def run() -> None: |
| 682 | + manager = async_scrape_module.ScrapeManager(_DummyClient()) |
| 683 | + long_job_id = " \n" + ("x" * 500) + "\t" |
| 684 | + captured = {} |
| 685 | + |
| 686 | + async def fake_start(params): |
| 687 | + return SimpleNamespace(job_id=long_job_id) |
| 688 | + |
| 689 | + async def fake_wait_for_job_result_async(**kwargs): |
| 690 | + operation_name = kwargs["operation_name"] |
| 691 | + _assert_valid_operation_name(operation_name) |
| 692 | + captured["operation_name"] = operation_name |
| 693 | + return {"ok": True} |
| 694 | + |
| 695 | + monkeypatch.setattr(manager, "start", fake_start) |
| 696 | + monkeypatch.setattr( |
| 697 | + async_scrape_module, |
| 698 | + "wait_for_job_result_async", |
| 699 | + fake_wait_for_job_result_async, |
| 700 | + ) |
| 701 | + |
| 702 | + result = await manager.start_and_wait(params=object()) # type: ignore[arg-type] |
| 703 | + |
| 704 | + assert result == {"ok": True} |
| 705 | + assert captured["operation_name"].startswith("scrape job ") |
| 706 | + |
| 707 | + asyncio.run(run()) |
| 708 | + |
| 709 | + |
| 710 | +def test_sync_claude_manager_bounds_operation_name_in_wait_helper(monkeypatch): |
| 711 | + manager = sync_claude_module.ClaudeComputerUseManager(_DummyClient()) |
| 712 | + long_job_id = " \n" + ("x" * 500) + "\t" |
| 713 | + captured = {} |
| 714 | + |
| 715 | + monkeypatch.setattr( |
| 716 | + manager, |
| 717 | + "start", |
| 718 | + lambda params: SimpleNamespace(job_id=long_job_id), |
| 719 | + ) |
| 720 | + |
| 721 | + def fake_wait_for_job_result(**kwargs): |
| 722 | + operation_name = kwargs["operation_name"] |
| 723 | + _assert_valid_operation_name(operation_name) |
| 724 | + captured["operation_name"] = operation_name |
| 725 | + return {"ok": True} |
| 726 | + |
| 727 | + monkeypatch.setattr( |
| 728 | + sync_claude_module, |
| 729 | + "wait_for_job_result", |
| 730 | + fake_wait_for_job_result, |
| 731 | + ) |
| 732 | + |
| 733 | + result = manager.start_and_wait(params=object()) # type: ignore[arg-type] |
| 734 | + |
| 735 | + assert result == {"ok": True} |
| 736 | + assert captured["operation_name"].startswith("Claude Computer Use task job ") |
| 737 | + |
| 738 | + |
| 739 | +def test_async_claude_manager_bounds_operation_name_in_wait_helper(monkeypatch): |
| 740 | + async def run() -> None: |
| 741 | + manager = async_claude_module.ClaudeComputerUseManager(_DummyClient()) |
| 742 | + long_job_id = " \n" + ("x" * 500) + "\t" |
| 743 | + captured = {} |
| 744 | + |
| 745 | + async def fake_start(params): |
| 746 | + return SimpleNamespace(job_id=long_job_id) |
| 747 | + |
| 748 | + async def fake_wait_for_job_result_async(**kwargs): |
| 749 | + operation_name = kwargs["operation_name"] |
| 750 | + _assert_valid_operation_name(operation_name) |
| 751 | + captured["operation_name"] = operation_name |
| 752 | + return {"ok": True} |
| 753 | + |
| 754 | + monkeypatch.setattr(manager, "start", fake_start) |
| 755 | + monkeypatch.setattr( |
| 756 | + async_claude_module, |
| 757 | + "wait_for_job_result_async", |
| 758 | + fake_wait_for_job_result_async, |
| 759 | + ) |
| 760 | + |
| 761 | + result = await manager.start_and_wait(params=object()) # type: ignore[arg-type] |
| 762 | + |
| 763 | + assert result == {"ok": True} |
| 764 | + assert captured["operation_name"].startswith("Claude Computer Use task job ") |
| 765 | + |
| 766 | + asyncio.run(run()) |
| 767 | + |
| 768 | + |
| 769 | +def test_sync_gemini_manager_bounds_operation_name_in_wait_helper(monkeypatch): |
| 770 | + manager = sync_gemini_module.GeminiComputerUseManager(_DummyClient()) |
| 771 | + long_job_id = " \n" + ("x" * 500) + "\t" |
| 772 | + captured = {} |
| 773 | + |
| 774 | + monkeypatch.setattr( |
| 775 | + manager, |
| 776 | + "start", |
| 777 | + lambda params: SimpleNamespace(job_id=long_job_id), |
| 778 | + ) |
| 779 | + |
| 780 | + def fake_wait_for_job_result(**kwargs): |
| 781 | + operation_name = kwargs["operation_name"] |
| 782 | + _assert_valid_operation_name(operation_name) |
| 783 | + captured["operation_name"] = operation_name |
| 784 | + return {"ok": True} |
| 785 | + |
| 786 | + monkeypatch.setattr( |
| 787 | + sync_gemini_module, |
| 788 | + "wait_for_job_result", |
| 789 | + fake_wait_for_job_result, |
| 790 | + ) |
| 791 | + |
| 792 | + result = manager.start_and_wait(params=object()) # type: ignore[arg-type] |
| 793 | + |
| 794 | + assert result == {"ok": True} |
| 795 | + assert captured["operation_name"].startswith("Gemini Computer Use task job ") |
| 796 | + |
| 797 | + |
| 798 | +def test_async_gemini_manager_bounds_operation_name_in_wait_helper(monkeypatch): |
| 799 | + async def run() -> None: |
| 800 | + manager = async_gemini_module.GeminiComputerUseManager(_DummyClient()) |
| 801 | + long_job_id = " \n" + ("x" * 500) + "\t" |
| 802 | + captured = {} |
| 803 | + |
| 804 | + async def fake_start(params): |
| 805 | + return SimpleNamespace(job_id=long_job_id) |
| 806 | + |
| 807 | + async def fake_wait_for_job_result_async(**kwargs): |
| 808 | + operation_name = kwargs["operation_name"] |
| 809 | + _assert_valid_operation_name(operation_name) |
| 810 | + captured["operation_name"] = operation_name |
| 811 | + return {"ok": True} |
| 812 | + |
| 813 | + monkeypatch.setattr(manager, "start", fake_start) |
| 814 | + monkeypatch.setattr( |
| 815 | + async_gemini_module, |
| 816 | + "wait_for_job_result_async", |
| 817 | + fake_wait_for_job_result_async, |
| 818 | + ) |
| 819 | + |
| 820 | + result = await manager.start_and_wait(params=object()) # type: ignore[arg-type] |
| 821 | + |
| 822 | + assert result == {"ok": True} |
| 823 | + assert captured["operation_name"].startswith("Gemini Computer Use task job ") |
| 824 | + |
| 825 | + asyncio.run(run()) |
| 826 | + |
| 827 | + |
| 828 | +def test_sync_hyper_agent_manager_bounds_operation_name_in_wait_helper(monkeypatch): |
| 829 | + manager = sync_hyper_agent_module.HyperAgentManager(_DummyClient()) |
| 830 | + long_job_id = " \n" + ("x" * 500) + "\t" |
| 831 | + captured = {} |
| 832 | + |
| 833 | + monkeypatch.setattr( |
| 834 | + manager, |
| 835 | + "start", |
| 836 | + lambda params: SimpleNamespace(job_id=long_job_id), |
| 837 | + ) |
| 838 | + |
| 839 | + def fake_wait_for_job_result(**kwargs): |
| 840 | + operation_name = kwargs["operation_name"] |
| 841 | + _assert_valid_operation_name(operation_name) |
| 842 | + captured["operation_name"] = operation_name |
| 843 | + return {"ok": True} |
| 844 | + |
| 845 | + monkeypatch.setattr( |
| 846 | + sync_hyper_agent_module, |
| 847 | + "wait_for_job_result", |
| 848 | + fake_wait_for_job_result, |
| 849 | + ) |
| 850 | + |
| 851 | + result = manager.start_and_wait(params=object()) # type: ignore[arg-type] |
| 852 | + |
| 853 | + assert result == {"ok": True} |
| 854 | + assert captured["operation_name"].startswith("HyperAgent task ") |
| 855 | + |
| 856 | + |
| 857 | +def test_async_hyper_agent_manager_bounds_operation_name_in_wait_helper(monkeypatch): |
| 858 | + async def run() -> None: |
| 859 | + manager = async_hyper_agent_module.HyperAgentManager(_DummyClient()) |
| 860 | + long_job_id = " \n" + ("x" * 500) + "\t" |
| 861 | + captured = {} |
| 862 | + |
| 863 | + async def fake_start(params): |
| 864 | + return SimpleNamespace(job_id=long_job_id) |
| 865 | + |
| 866 | + async def fake_wait_for_job_result_async(**kwargs): |
| 867 | + operation_name = kwargs["operation_name"] |
| 868 | + _assert_valid_operation_name(operation_name) |
| 869 | + captured["operation_name"] = operation_name |
| 870 | + return {"ok": True} |
| 871 | + |
| 872 | + monkeypatch.setattr(manager, "start", fake_start) |
| 873 | + monkeypatch.setattr( |
| 874 | + async_hyper_agent_module, |
| 875 | + "wait_for_job_result_async", |
| 876 | + fake_wait_for_job_result_async, |
| 877 | + ) |
| 878 | + |
| 879 | + result = await manager.start_and_wait(params=object()) # type: ignore[arg-type] |
| 880 | + |
| 881 | + assert result == {"ok": True} |
| 882 | + assert captured["operation_name"].startswith("HyperAgent task ") |
| 883 | + |
| 884 | + asyncio.run(run()) |
0 commit comments