Skip to content

Commit d13818b

Browse files
committed
update
1 parent 09fd225 commit d13818b

File tree

7 files changed

+55
-52
lines changed

7 files changed

+55
-52
lines changed

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,20 +116,19 @@ sandbox = client.sandboxes.create(
116116
CreateSandboxParams(
117117
image_name="node",
118118
cpu=4,
119-
memory=4096,
120-
disk=8192,
119+
memory_mib=4096,
120+
disk_mib=8192,
121121
exposed_ports=[SandboxExposeParams(port=3000, auth=True)],
122122
)
123123
)
124124

125125
print(sandbox.exposed_ports[0].browser_url)
126-
print(sandbox.cpu, sandbox.memory, sandbox.disk)
126+
print(sandbox.cpu, sandbox.memory_mib, sandbox.disk_mib)
127127
sandbox.stop()
128128
client.close()
129129
```
130130

131-
`cpu`, `memory`, and `disk` are only supported for image launches. `memory` and
132-
`disk` are specified in MiB.
131+
`cpu`, `memory_mib`, and `disk_mib` are only supported for image launches.
133132

134133
### List sandboxes with filters
135134

@@ -172,7 +171,9 @@ from hyperbrowser.models import CreateSandboxParams, SandboxExposeParams
172171

173172
client = Hyperbrowser(api_key="test-key")
174173
sandbox = client.sandboxes.create(
175-
CreateSandboxParams(image_name="node", cpu=2, memory=2048, disk=8192)
174+
CreateSandboxParams(
175+
image_name="node", cpu=2, memory_mib=2048, disk_mib=8192
176+
)
176177
)
177178

178179
result = sandbox.expose(SandboxExposeParams(port=8080, auth=True))

hyperbrowser/client/managers/async_manager/sandbox.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,12 @@ def cpu(self):
119119
return self._detail.cpu
120120

121121
@property
122-
def memory(self):
123-
return self._detail.memory
122+
def memory_mib(self):
123+
return self._detail.memory_mib
124124

125125
@property
126-
def disk(self):
127-
return self._detail.disk
126+
def disk_mib(self):
127+
return self._detail.disk_mib
128128

129129
@property
130130
def exposed_ports(self):

hyperbrowser/client/managers/sync_manager/sandbox.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,12 @@ def cpu(self):
119119
return self._detail.cpu
120120

121121
@property
122-
def memory(self):
123-
return self._detail.memory
122+
def memory_mib(self):
123+
return self._detail.memory_mib
124124

125125
@property
126-
def disk(self):
127-
return self._detail.disk
126+
def disk_mib(self):
127+
return self._detail.disk_mib
128128

129129
@property
130130
def exposed_ports(self):

hyperbrowser/models/sandbox.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ class Sandbox(SandboxBaseModel):
117117
duration: int
118118
proxy_bytes_used: Optional[int] = Field(default=None, alias="proxyBytesUsed")
119119
cpu: Optional[int] = Field(default=None, alias="vcpus")
120-
memory: Optional[int] = Field(default=None, alias="memMiB")
121-
disk: Optional[int] = Field(default=None, alias="diskSizeMiB")
120+
memory_mib: Optional[int] = Field(default=None, alias="memMiB")
121+
disk_mib: Optional[int] = Field(default=None, alias="diskSizeMiB")
122122
runtime: SandboxRuntimeTarget
123123
exposed_ports: List[SandboxExposeResult] = Field(
124124
default_factory=list,
@@ -132,8 +132,8 @@ class Sandbox(SandboxBaseModel):
132132
"proxy_data_consumed",
133133
"proxy_bytes_used",
134134
"cpu",
135-
"memory",
136-
"disk",
135+
"memory_mib",
136+
"disk_mib",
137137
mode="before",
138138
)
139139
@classmethod
@@ -184,8 +184,10 @@ class CreateSandboxParams(SandboxBaseModel):
184184
default=None, serialization_alias="timeoutMinutes"
185185
)
186186
cpu: Optional[int] = Field(default=None, ge=1, serialization_alias="vcpus")
187-
memory: Optional[int] = Field(default=None, ge=1, serialization_alias="memMiB")
188-
disk: Optional[int] = Field(default=None, ge=1, serialization_alias="diskSizeMiB")
187+
memory_mib: Optional[int] = Field(default=None, ge=1, serialization_alias="memMiB")
188+
disk_mib: Optional[int] = Field(
189+
default=None, ge=1, serialization_alias="diskSizeMiB"
190+
)
189191

190192
@model_validator(mode="after")
191193
def validate_launch_source(self):
@@ -201,10 +203,10 @@ def validate_launch_source(self):
201203
"Provide exactly one start source: snapshot_name or image_name"
202204
)
203205
if self.snapshot_name and any(
204-
value is not None for value in (self.cpu, self.memory, self.disk)
206+
value is not None for value in (self.cpu, self.memory_mib, self.disk_mib)
205207
):
206208
raise ValueError(
207-
"cpu, memory, and disk are only supported for image launches"
209+
"cpu, memory_mib, and disk_mib are only supported for image launches"
208210
)
209211
return self
210212

tests/sandbox/e2e/test_resource_config.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,24 +39,24 @@ def test_sandbox_resource_config_e2e():
3939
CreateSandboxParams(
4040
image_name=DEFAULT_IMAGE_NAME,
4141
cpu=REQUESTED_CPU,
42-
memory=REQUESTED_MEMORY_MIB,
43-
disk=REQUESTED_DISK_MIB,
42+
memory_mib=REQUESTED_MEMORY_MIB,
43+
disk_mib=REQUESTED_DISK_MIB,
4444
)
4545
)
4646

4747
assert sandbox.cpu == REQUESTED_CPU
48-
assert sandbox.memory == REQUESTED_MEMORY_MIB
49-
assert sandbox.disk == REQUESTED_DISK_MIB
48+
assert sandbox.memory_mib == REQUESTED_MEMORY_MIB
49+
assert sandbox.disk_mib == REQUESTED_DISK_MIB
5050

5151
detail = sandbox.info()
5252
assert detail.cpu == REQUESTED_CPU
53-
assert detail.memory == REQUESTED_MEMORY_MIB
54-
assert detail.disk == REQUESTED_DISK_MIB
53+
assert detail.memory_mib == REQUESTED_MEMORY_MIB
54+
assert detail.disk_mib == REQUESTED_DISK_MIB
5555

5656
reloaded = client.sandboxes.get(sandbox.id)
5757
assert reloaded.cpu == REQUESTED_CPU
58-
assert reloaded.memory == REQUESTED_MEMORY_MIB
59-
assert reloaded.disk == REQUESTED_DISK_MIB
58+
assert reloaded.memory_mib == REQUESTED_MEMORY_MIB
59+
assert reloaded.disk_mib == REQUESTED_DISK_MIB
6060

6161
wait_for_runtime_ready(sandbox)
6262

@@ -84,24 +84,24 @@ async def test_async_sandbox_resource_config_e2e():
8484
CreateSandboxParams(
8585
image_name=DEFAULT_IMAGE_NAME,
8686
cpu=REQUESTED_CPU,
87-
memory=REQUESTED_MEMORY_MIB,
88-
disk=REQUESTED_DISK_MIB,
87+
memory_mib=REQUESTED_MEMORY_MIB,
88+
disk_mib=REQUESTED_DISK_MIB,
8989
)
9090
)
9191

9292
assert sandbox.cpu == REQUESTED_CPU
93-
assert sandbox.memory == REQUESTED_MEMORY_MIB
94-
assert sandbox.disk == REQUESTED_DISK_MIB
93+
assert sandbox.memory_mib == REQUESTED_MEMORY_MIB
94+
assert sandbox.disk_mib == REQUESTED_DISK_MIB
9595

9696
detail = await sandbox.info()
9797
assert detail.cpu == REQUESTED_CPU
98-
assert detail.memory == REQUESTED_MEMORY_MIB
99-
assert detail.disk == REQUESTED_DISK_MIB
98+
assert detail.memory_mib == REQUESTED_MEMORY_MIB
99+
assert detail.disk_mib == REQUESTED_DISK_MIB
100100

101101
reloaded = await client.sandboxes.get(sandbox.id)
102102
assert reloaded.cpu == REQUESTED_CPU
103-
assert reloaded.memory == REQUESTED_MEMORY_MIB
104-
assert reloaded.disk == REQUESTED_DISK_MIB
103+
assert reloaded.memory_mib == REQUESTED_MEMORY_MIB
104+
assert reloaded.disk_mib == REQUESTED_DISK_MIB
105105

106106
await wait_for_runtime_ready_async(sandbox)
107107

tests/test_create_sandbox_params.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ def test_create_sandbox_params_serializes_exposed_ports():
2222
params = CreateSandboxParams(
2323
image_name="node",
2424
cpu=4,
25-
memory=4096,
26-
disk=8192,
25+
memory_mib=4096,
26+
disk_mib=8192,
2727
exposed_ports=[SandboxExposeParams(port=3000, auth=True)],
2828
)
2929

@@ -81,9 +81,9 @@ def test_create_sandbox_params_requires_snapshot_name_for_snapshot_id():
8181
def test_create_sandbox_params_rejects_resource_config_for_snapshot_source():
8282
with pytest.raises(
8383
ValidationError,
84-
match="cpu, memory, and disk are only supported for image launches",
84+
match="cpu, memory_mib, and disk_mib are only supported for image launches",
8585
):
86-
CreateSandboxParams(snapshot_name="snap", cpu=2, memory=2048, disk=8192)
86+
CreateSandboxParams(snapshot_name="snap", cpu=2, memory_mib=2048, disk_mib=8192)
8787

8888

8989
def test_sandbox_exec_params_serialize_process_timeout_sec_as_snake_case():

tests/test_sandbox_wire_contract.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -493,8 +493,8 @@ def test_sandbox_request_models_serialize_expected_wire_keys():
493493
image_name="node",
494494
image_id="img-id",
495495
cpu=4,
496-
memory=4096,
497-
disk=8192,
496+
memory_mib=4096,
497+
disk_mib=8192,
498498
enable_recording=True,
499499
exposed_ports=[SandboxExposeParams(port=3000, auth=True)],
500500
timeout_minutes=15,
@@ -624,8 +624,8 @@ def test_sync_sandbox_control_manager_uses_expected_wire_keys():
624624
image_name="node",
625625
image_id="img-id",
626626
cpu=4,
627-
memory=4096,
628-
disk=8192,
627+
memory_mib=4096,
628+
disk_mib=8192,
629629
enable_recording=True,
630630
exposed_ports=[SandboxExposeParams(port=3000, auth=True)],
631631
timeout_minutes=15,
@@ -684,8 +684,8 @@ def test_sync_sandbox_control_manager_uses_expected_wire_keys():
684684
"snapshotName": "snap",
685685
}
686686
assert sandbox.cpu == 2
687-
assert sandbox.memory == 2048
688-
assert sandbox.disk == 8192
687+
assert sandbox.memory_mib == 2048
688+
assert sandbox.disk_mib == 8192
689689
assert sandbox.exposed_ports[0].browser_url is not None
690690
assert expose_call["json"] == {"port": 3000, "auth": True}
691691
assert exposed.browser_url is not None
@@ -846,8 +846,8 @@ async def test_async_sandbox_control_manager_uses_expected_wire_keys():
846846
image_name="node",
847847
image_id="img-id",
848848
cpu=4,
849-
memory=4096,
850-
disk=8192,
849+
memory_mib=4096,
850+
disk_mib=8192,
851851
enable_recording=True,
852852
exposed_ports=[SandboxExposeParams(port=3000, auth=True)],
853853
timeout_minutes=15,
@@ -906,8 +906,8 @@ async def test_async_sandbox_control_manager_uses_expected_wire_keys():
906906
"snapshotName": "snap",
907907
}
908908
assert sandbox.cpu == 2
909-
assert sandbox.memory == 2048
910-
assert sandbox.disk == 8192
909+
assert sandbox.memory_mib == 2048
910+
assert sandbox.disk_mib == 8192
911911
assert sandbox.exposed_ports[0].browser_url is not None
912912
assert expose_call["json"] == {"port": 3000, "auth": True}
913913
assert exposed.browser_url is not None

0 commit comments

Comments
 (0)