Skip to content
10 changes: 8 additions & 2 deletions src/extensions/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2713,14 +2713,16 @@ impl ExtensionManager {
.unwrap_or("");

if archive_names.is_wasm(filename) {
let mut data = Vec::with_capacity(entry.size() as usize);
let mut data =
Vec::with_capacity((entry.size() as usize).min(MAX_ENTRY_SIZE as usize));
std::io::Read::read_to_end(&mut entry.by_ref().take(MAX_ENTRY_SIZE), &mut data)
.map_err(|e| ExtensionError::InstallFailed(e.to_string()))?;
std::fs::write(target_wasm, &data)
.map_err(|e| ExtensionError::InstallFailed(e.to_string()))?;
found_wasm = true;
} else if archive_names.is_caps(filename) {
let mut data = Vec::with_capacity(entry.size() as usize);
let mut data =
Vec::with_capacity((entry.size() as usize).min(MAX_ENTRY_SIZE as usize));
std::io::Read::read_to_end(&mut entry.by_ref().take(MAX_ENTRY_SIZE), &mut data)
.map_err(|e| ExtensionError::InstallFailed(e.to_string()))?;
std::fs::write(target_caps, &data)
Expand Down Expand Up @@ -9485,6 +9487,10 @@ mod tests {
// have their colon URL-encoded to %3A, as this breaks the validation endpoint.
// Previously: form_urlencoded::byte_serialize encoded the token, causing 404s.
// Fixed by removing URL-encoding and using the token directly.
//
// Hold the env mutex so concurrent tests that override
// IRONCLAW_TEST_TELEGRAM_API_BASE_URL don't change the base URL mid-read.
let _guard = crate::config::helpers::lock_env();
let token = "123456789:AABBccDDeeFFgg_Test-Token";

let url = telegram_bot_api_url(token, "getMe");
Expand Down
5 changes: 5 additions & 0 deletions tests/e2e/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1112,6 +1112,11 @@ async def page(ironclaw_server, browser):
await pg.goto(f"{ironclaw_server}/?token={AUTH_TOKEN}")
# Wait for the app to initialize (auth screen hidden, SSE connected)
await pg.wait_for_selector("#auth-screen", state="hidden", timeout=15000)
# Wait for SSE connection (onopen sets sseHasConnectedBefore = true)
await pg.wait_for_function(
Comment thread
henrypark133 marked this conversation as resolved.
Resolved
"() => typeof sseHasConnectedBefore !== 'undefined' && sseHasConnectedBefore === true",
timeout=10000,
)
yield pg
await context.close()

Expand Down
2 changes: 0 additions & 2 deletions tests/e2e/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
# Auth
"auth_screen": "#auth-screen",
"token_input": "#token-input",
# Connection
"sse_status": "#sse-status",
# Tabs
"tab_button": '.tab-bar button[data-tab="{tab}"]',
"tab_panel": "#tab-{tab}",
Expand Down
11 changes: 5 additions & 6 deletions tests/e2e/scenarios/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@

async def test_page_loads_and_connects(page):
"""After auth, the app shows Connected status and all tabs."""
Comment thread
henrypark133 marked this conversation as resolved.
Resolved
# Connection status
status = page.locator(SEL["sse_status"])
await status.wait_for(state="visible", timeout=10000)
text = await status.text_content()
assert text is not None
assert "connect" in text.lower(), f"Expected 'Connected', got '{text}'"
# Connection status — verify SSE has connected via the JS flag set in onopen.
await page.wait_for_function(
"() => typeof sseHasConnectedBefore !== 'undefined' && sseHasConnectedBefore === true",
timeout=10000,
)

# All 6 main tabs visible
for tab in TABS:
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/scenarios/test_oauth_refresh.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ async def _wait_for_gmail_tool_call(base_url: str, thread_id: str, timeout: floa
response.raise_for_status()
history = response.json()

pending = history.get("pending_approval")
pending = history.get("pending_gate")
if pending and pending["request_id"] not in approved_request_ids:
await _approve_pending_request(base_url, thread_id, pending["request_id"])
approved_request_ids.add(pending["request_id"])
Expand Down Expand Up @@ -137,7 +137,7 @@ async def _wait_for_tool_call(
response.raise_for_status()
history = response.json()

pending = history.get("pending_approval")
pending = history.get("pending_gate")
if pending and pending["request_id"] not in approved_request_ids:
await _approve_pending_request(base_url, thread_id, pending["request_id"])
approved_request_ids.add(pending["request_id"])
Expand Down
10 changes: 5 additions & 5 deletions tests/e2e/scenarios/test_owner_scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,24 +136,24 @@ async def _wait_for_http_thread(base_url: str, title_fragment: str, timeout: flo
)


async def _wait_for_pending_approval(
async def _wait_for_pending_gate(
base_url: str,
thread_id: str,
timeout: float = 20.0,
) -> dict:
"""Poll chat history until the thread exposes a pending approval payload."""
"""Poll chat history until the thread exposes a pending gate payload."""
for _ in range(int(timeout * 2)):
response = await api_get(
base_url,
f"/api/chat/history?thread_id={thread_id}",
timeout=10,
)
response.raise_for_status()
pending = response.json().get("pending_approval")
pending = response.json().get("pending_gate")
if pending:
return pending
await _poll_sleep()
raise AssertionError(f"Thread '{thread_id}' did not expose a pending approval")
raise AssertionError(f"Thread '{thread_id}' did not expose a pending gate")


async def _approve_pending_request(base_url: str, thread_id: str, request_id: str) -> None:
Expand Down Expand Up @@ -256,7 +256,7 @@ async def test_http_created_full_job_routine_is_visible_in_web_after_approval(
)

thread_id = await _wait_for_http_thread(ironclaw_server, routine_name)
pending = await _wait_for_pending_approval(ironclaw_server, thread_id)
pending = await _wait_for_pending_gate(ironclaw_server, thread_id)
assert pending["tool_name"] == "routine_create"
await _approve_pending_request(
ironclaw_server,
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/scenarios/test_skill_oauth_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ async def _wait_for_response(

# Auto-approve pending tool calls if requested
if auto_approve:
pending = history.get("pending_approval")
pending = history.get("pending_gate")
if pending and pending["request_id"] not in approved:
await api_post(
base_url,
Expand Down
38 changes: 20 additions & 18 deletions tests/e2e/scenarios/test_sse_reconnect.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,17 @@ async def _open_gateway_page(browser, base_url: str):


async def _wait_for_connected(page, *, timeout: int = 10000) -> None:
"""Wait until the frontend reports an active SSE connection."""
status = page.locator(SEL["sse_status"])
await status.wait_for(state="visible", timeout=timeout)
deadline = asyncio.get_running_loop().time() + (timeout / 1000)
while asyncio.get_running_loop().time() < deadline:
if await status.text_content() == "Connected":
return
await asyncio.sleep(0.2)
raise AssertionError("SSE status did not return to Connected before timeout")
"""Wait until the frontend reports an active SSE connection.

Uses the ``sseHasConnectedBefore`` JS flag which is set to ``true``
inside ``EventSource.onopen``. This is more reliable than checking
CSS state on ``#sse-dot`` because the dot starts without the
``disconnected`` class before SSE even connects.
"""
await page.wait_for_function(
"() => typeof sseHasConnectedBefore !== 'undefined' && sseHasConnectedBefore === true",
timeout=timeout,
)


async def _wait_for_last_event_id(page, *, timeout: int = 15000) -> str:
Expand All @@ -59,21 +61,21 @@ async def _wait_for_turn_in_history(base_url: str, thread_id: str, expected_resp


async def test_sse_status_shows_connected(page):
Comment thread
henrypark133 marked this conversation as resolved.
Resolved
"""SSE status should show Connected after page load."""
status = page.locator(SEL["sse_status"])
await status.wait_for(state="visible", timeout=5000)
text = await status.text_content()
assert text == "Connected", f"Expected 'Connected', got '{text}'"
"""SSE dot should show connected state after page load."""
dot = page.locator("#sse-dot")
cls = await dot.get_attribute("class") or ""
assert "disconnected" not in cls, f"Expected connected dot, got class='{cls}'"


async def test_sse_reconnect_after_disconnect(page):
"""After programmatic disconnect, SSE should reconnect and show Connected."""
"""After programmatic disconnect, SSE should reconnect."""
await _wait_for_connected(page, timeout=5000)
Comment thread
henrypark133 marked this conversation as resolved.
Resolved
await page.evaluate("if (eventSource) eventSource.close()")
await page.evaluate("connectSSE()")
# Reset the flag so _wait_for_connected can detect the new onopen.
# The history-reload path (sseHasConnectedBefore=true on reconnect)
# is covered by test_sse_reconnect_preserves_chat_history.
await page.evaluate("sseHasConnectedBefore = false; connectSSE()")
await _wait_for_connected(page, timeout=10000)
status = page.locator(SEL["sse_status"])
assert await status.text_content() == "Connected"


async def test_sse_reconnect_preserves_chat_history(page):
Expand Down
6 changes: 3 additions & 3 deletions tests/e2e/scenarios/test_tool_approval.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ async def _wait_for_history(
)
assert response.status_code == 200, response.text
history = response.json()
pending = history.get("pending_approval")
pending = history.get("pending_gate")
turns = history.get("turns", [])
latest_response = turns[-1].get("response") if turns else None

Expand Down Expand Up @@ -259,7 +259,7 @@ async def test_chat_reply_approve_resumes_pending_tool(ironclaw_server):
turn_count_at_least=1,
)

assert history.get("pending_approval") is None
assert history.get("pending_gate") is None
assert history["turns"][-1]["response"] is not None


Expand Down Expand Up @@ -309,5 +309,5 @@ async def test_chat_reply_always_auto_approves_next_same_tool(ironclaw_server):
turn_count_at_least=2,
)

assert history.get("pending_approval") is None
assert history.get("pending_gate") is None
assert len(history["turns"]) >= 2
40 changes: 20 additions & 20 deletions tests/e2e/scenarios/test_v2_engine_approval_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@ async def _wait_for_approval(
*,
timeout: float = 45.0,
) -> dict:
"""Poll /api/chat/history until pending_approval appears.
"""Poll /api/chat/history until pending_gate appears.

Returns the pending_approval dict containing request_id, tool_name, etc.
Returns the pending_gate dict containing request_id, tool_name, etc.
"""
for _ in range(int(timeout * 2)):
r = await api_get(
Expand All @@ -168,7 +168,7 @@ async def _wait_for_approval(
)
r.raise_for_status()
history = r.json()
pending = history.get("pending_approval")
pending = history.get("pending_gate")
if pending and pending.get("request_id"):
return pending
Comment thread
henrypark133 marked this conversation as resolved.
Resolved
await asyncio.sleep(0.5)
Expand All @@ -179,7 +179,7 @@ async def _wait_for_approval(
r = await api_get(base_url, f"/api/chat/history?thread_id={thread_id}", timeout=15)
data = r.json()
turns = data.get("turns", [])
pending = data.get("pending_approval")
pending = data.get("pending_gate")
debug_info = f"turns={len(turns)}, pending={pending}"
if turns:
last_turn = turns[-1]
Expand All @@ -191,7 +191,7 @@ async def _wait_for_approval(
except Exception as e:
debug_info = f"error: {e}"
raise AssertionError(
f"Timed out waiting for pending_approval in thread {thread_id}. "
f"Timed out waiting for pending_gate in thread {thread_id}. "
f"Debug: {debug_info}"
)

Expand Down Expand Up @@ -230,15 +230,15 @@ async def _wait_for_response(
)


async def _wait_for_no_pending_approval(base_url: str, thread_id: str, *, timeout: float = 45.0):
async def _wait_for_no_pending_gate(base_url: str, thread_id: str, *, timeout: float = 45.0):
for _ in range(int(timeout * 2)):
r = await api_get(base_url, f"/api/chat/history?thread_id={thread_id}", timeout=15)
r.raise_for_status()
history = r.json()
if not history.get("pending_approval"):
if not history.get("pending_gate"):
return history
await asyncio.sleep(0.5)
raise AssertionError(f"Timed out waiting for pending_approval to clear in thread {thread_id}")
raise AssertionError(f"Timed out waiting for pending_gate to clear in thread {thread_id}")


async def _approve(
Expand Down Expand Up @@ -294,17 +294,17 @@ async def test_same_user_approvals_are_thread_scoped(self, v2_approval_server):

approve_a = await _approve(base_url, thread_a, pending_a["request_id"], "approve")
assert approve_a.status_code == 202, approve_a.text
await _wait_for_no_pending_approval(base_url, thread_a, timeout=60)
await _wait_for_no_pending_gate(base_url, thread_a, timeout=60)

history_b = await api_get(base_url, f"/api/chat/history?thread_id={thread_b}", timeout=15)
history_b.raise_for_status()
still_pending_b = history_b.json().get("pending_approval")
still_pending_b = history_b.json().get("pending_gate")
assert still_pending_b is not None, history_b.json()
assert still_pending_b["request_id"] == pending_b["request_id"]

approve_b = await _approve(base_url, thread_b, pending_b["request_id"], "approve")
assert approve_b.status_code == 202, approve_b.text
await _wait_for_no_pending_approval(base_url, thread_b, timeout=60)
await _wait_for_no_pending_gate(base_url, thread_b, timeout=60)

"""Test the v2 engine tool approval lifecycle.

Expand Down Expand Up @@ -352,14 +352,14 @@ async def test_approval_yes(self, v2_approval_server):
last = (turns[-1].get("response") or "").lower()
if last and "requires approval" not in last:
break
# Also check if pending_approval is cleared (approval processed)
if not history.get("pending_approval"):
# Also check if pending_gate is cleared (approval processed)
if not history.get("pending_gate"):
break

# After approval, pending_approval should be cleared
assert history.get("pending_approval") is None, (
f"After approval, pending_approval should be cleared. "
f"Got: {history.get('pending_approval')}"
# After approval, pending_gate should be cleared
assert history.get("pending_gate") is None, (
f"After approval, pending_gate should be cleared. "
f"Got: {history.get('pending_gate')}"
)

async def test_approval_no(self, v2_approval_server):
Expand Down Expand Up @@ -409,9 +409,9 @@ async def test_approval_no(self, v2_approval_server):
).lower()

# After denial, approval prompt should no longer be pending
assert history.get("pending_approval") is None, (
f"After denial, pending_approval should be cleared. "
f"Got: {history.get('pending_approval')}"
assert history.get("pending_gate") is None, (
f"After denial, pending_gate should be cleared. "
f"Got: {history.get('pending_gate')}"
)

async def test_approval_always(self, v2_approval_server):
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/scenarios/test_v2_engine_error_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ async def _wait_for_response(

# Auto-approve pending approvals so the loop doesn't stall
if auto_approve:
pending = history.get("pending_approval")
pending = history.get("pending_gate")
if pending:
request_id = pending.get("request_id", "")
if request_id:
Expand Down
Loading