@@ -699,6 +699,12 @@ def test_sandbox_request_models_serialize_expected_wire_keys():
699699 "allowOut" : [],
700700 "denyOut" : [],
701701 }
702+ assert SandboxNetworkPolicy (allow_internet_access = True ).model_dump (
703+ by_alias = True , exclude_none = True
704+ ) == {"allowInternetAccess" : True , "allowOut" : [], "denyOut" : []}
705+ assert SandboxNetworkPolicy (allow_internet_access = True ).model_dump (
706+ by_alias = True , exclude_none = True , exclude_unset = True
707+ ) == {"allowInternetAccess" : True }
702708
703709 assert SandboxImageListParams (
704710 page = 2 ,
@@ -1074,6 +1080,30 @@ def test_sync_sandbox_control_manager_uses_expected_wire_keys():
10741080 assert unexpose_call ["url" ].endswith ("/sandbox/sbx_123/unexpose" )
10751081
10761082
1083+ def test_sync_sandbox_update_network_omits_only_unset_lists ():
1084+ client = FakeSyncClient ()
1085+ manager = SandboxManager (client )
1086+ sandbox = manager .attach (SandboxDetail (** SANDBOX_DETAIL_PAYLOAD ))
1087+
1088+ sandbox .update_network (SandboxNetworkPolicy (allow_internet_access = True ))
1089+ sandbox .update_network (
1090+ SandboxNetworkPolicy (
1091+ allow_internet_access = True ,
1092+ allow_out = [],
1093+ deny_out = [],
1094+ )
1095+ )
1096+
1097+ preserve_call = client .transport .client .calls [0 ]
1098+ clear_call = client .transport .client .calls [1 ]
1099+ assert preserve_call ["json" ] == {"allowInternetAccess" : True }
1100+ assert clear_call ["json" ] == {
1101+ "allowInternetAccess" : True ,
1102+ "allowOut" : [],
1103+ "denyOut" : [],
1104+ }
1105+
1106+
10771107def test_snapshot_summary_allows_missing_compatibility_tag ():
10781108 snapshot = SandboxSnapshotSummary (** SNAPSHOT_PAYLOAD_WITHOUT_COMPATIBILITY_TAG )
10791109
@@ -1528,6 +1558,31 @@ async def test_async_sandbox_control_manager_uses_expected_wire_keys():
15281558 assert unexpose_call ["json" ] == {"port" : 3000 }
15291559
15301560
1561+ @pytest .mark .anyio
1562+ async def test_async_sandbox_update_network_omits_only_unset_lists ():
1563+ client = FakeAsyncClient ()
1564+ manager = AsyncSandboxManager (client )
1565+ sandbox = manager .attach (SandboxDetail (** SANDBOX_DETAIL_PAYLOAD ))
1566+
1567+ await sandbox .update_network (SandboxNetworkPolicy (allow_internet_access = True ))
1568+ await sandbox .update_network (
1569+ SandboxNetworkPolicy (
1570+ allow_internet_access = True ,
1571+ allow_out = [],
1572+ deny_out = [],
1573+ )
1574+ )
1575+
1576+ preserve_call = client .transport .client .calls [0 ]
1577+ clear_call = client .transport .client .calls [1 ]
1578+ assert preserve_call ["json" ] == {"allowInternetAccess" : True }
1579+ assert clear_call ["json" ] == {
1580+ "allowInternetAccess" : True ,
1581+ "allowOut" : [],
1582+ "denyOut" : [],
1583+ }
1584+
1585+
15311586@pytest .mark .anyio
15321587async def test_async_sandbox_runtime_apis_use_expected_wire_keys ():
15331588 transport = AsyncRecordingTransport ()
0 commit comments