Skip to content

Commit d819f77

Browse files
committed
fix tests
1 parent f0a6ae4 commit d819f77

5 files changed

Lines changed: 72 additions & 20 deletions

File tree

packages/js-sdk/tests/connectionConfig.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ let originalEnv: { [key: string]: string | undefined }
77
beforeEach(() => {
88
originalEnv = {
99
E2B_API_URL: process.env.E2B_API_URL,
10+
E2B_DOMAIN: process.env.E2B_DOMAIN,
1011
E2B_DEBUG: process.env.E2B_DEBUG,
1112
}
1213
})
@@ -25,6 +26,7 @@ afterEach(() => {
2526
test('api_url defaults correctly', () => {
2627
// Ensure no env vars interfere
2728
delete process.env.E2B_API_URL
29+
delete process.env.E2B_DOMAIN
2830
delete process.env.E2B_DEBUG
2931

3032
const config = new ConnectionConfig()

packages/js-sdk/tests/setup.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export async function wait(ms: number) {
101101
* Supports msw path parameters like :templateID
102102
*/
103103
export function apiUrl(path: string): string {
104-
const domain = process.env.E2B_DOMAIN || 'e2b.dev'
104+
const domain = process.env.E2B_DOMAIN || 'e2b.app'
105105
return `https://api.${domain}${path}`
106106
}
107107

packages/python-sdk/e2b/template_async/main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,12 @@ async def _build(
5858

5959
# Create template
6060
if on_build_logs:
61+
tags_msg = f" with tags: {', '.join(tags)}" if tags else ""
6162
on_build_logs(
6263
LogEntry(
6364
timestamp=datetime.now(),
6465
level="info",
65-
message=f"Requesting build for template: {name}{f' with tags: {", ".join(tags)}' if tags else ''}",
66+
message=f"Requesting build for template: {name}{tags_msg}",
6667
)
6768
)
6869

packages/python-sdk/e2b/template_sync/main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,12 @@ def _build(
5858

5959
# Create template
6060
if on_build_logs:
61+
tags_msg = f" with tags: {', '.join(tags)}" if tags else ""
6162
on_build_logs(
6263
LogEntry(
6364
timestamp=datetime.now(),
6465
level="info",
65-
message=f"Requesting build for template: {name}{f' with tags: {", ".join(tags)}' if tags else ''}",
66+
message=f"Requesting build for template: {name}{tags_msg}",
6667
)
6768
)
6869

packages/python-sdk/tests/conftest.py

Lines changed: 65 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import asyncio
22
import os
33
import uuid
4-
from typing import Callable, Optional
4+
from typing import Callable, Dict, Optional
55
from uuid import uuid4
66

77
import pytest
@@ -101,14 +101,38 @@ def _build(
101101
skip_cache: bool = False,
102102
on_build_logs: Optional[Callable[[LogEntry], None]] = None,
103103
):
104-
return Template.build(
105-
template,
106-
name or f"e2b-test-{uuid4()}",
107-
cpu_count=1,
108-
memory_mb=1024,
109-
skip_cache=skip_cache,
110-
on_build_logs=on_build_logs,
111-
)
104+
build_name = name or f"e2b-test-{uuid4()}"
105+
build_info: Dict[str, Optional[str]] = {"template_id": None, "build_id": None}
106+
107+
def capture_logs(log: LogEntry):
108+
import re
109+
110+
if "Template created with ID:" in log.message:
111+
match = re.search(
112+
r"Template created with ID: ([^,]+), Build ID: (.+)", log.message
113+
)
114+
if match:
115+
build_info["template_id"] = match.group(1)
116+
build_info["build_id"] = match.group(2)
117+
if on_build_logs:
118+
on_build_logs(log)
119+
120+
try:
121+
return Template.build(
122+
template,
123+
build_name,
124+
cpu_count=1,
125+
memory_mb=1024,
126+
skip_cache=skip_cache,
127+
on_build_logs=capture_logs,
128+
)
129+
except Exception as e:
130+
print(
131+
f"\n[BUILD FAILED] name={build_name}, "
132+
f"template_id={build_info['template_id']}, "
133+
f"build_id={build_info['build_id']}, error={e}"
134+
)
135+
raise
112136

113137
return _build
114138

@@ -121,14 +145,38 @@ async def _async_build(
121145
skip_cache: bool = False,
122146
on_build_logs: Optional[Callable[[LogEntry], None]] = None,
123147
):
124-
return await AsyncTemplate.build(
125-
template,
126-
name or f"e2b-test-{uuid4()}",
127-
cpu_count=1,
128-
memory_mb=1024,
129-
skip_cache=skip_cache,
130-
on_build_logs=on_build_logs,
131-
)
148+
build_name = name or f"e2b-test-{uuid4()}"
149+
build_info: Dict[str, Optional[str]] = {"template_id": None, "build_id": None}
150+
151+
def capture_logs(log: LogEntry):
152+
import re
153+
154+
if "Template created with ID:" in log.message:
155+
match = re.search(
156+
r"Template created with ID: ([^,]+), Build ID: (.+)", log.message
157+
)
158+
if match:
159+
build_info["template_id"] = match.group(1)
160+
build_info["build_id"] = match.group(2)
161+
if on_build_logs:
162+
on_build_logs(log)
163+
164+
try:
165+
return await AsyncTemplate.build(
166+
template,
167+
build_name,
168+
cpu_count=1,
169+
memory_mb=1024,
170+
skip_cache=skip_cache,
171+
on_build_logs=capture_logs,
172+
)
173+
except Exception as e:
174+
print(
175+
f"\n[BUILD FAILED] name={build_name}, "
176+
f"template_id={build_info['template_id']}, "
177+
f"build_id={build_info['build_id']}, error={e}"
178+
)
179+
raise
132180

133181
return _async_build
134182

0 commit comments

Comments
 (0)