mirror of
https://github.com/outbackdingo/optimclaw.git
synced 2026-08-25 14:53:34 +00:00
* feat(extensions): unify auth and configure into single entrypoint Refactors the extension lifecycle to eliminate the divergence between chat and gateway paths that caused Telegram setup via chat to fail (missing webhook secret auto-generation, no token validation). Key changes: - Rename save_setup_secrets() → configure(): single entrypoint for providing secrets to any extension (WasmChannel, WasmTool, MCP). Validates, stores, auto-generates, and activates. - Add configure_token(): convenience wrapper for single-token callers (chat auth card, WebSocket, agent auth mode). - Refactor auth() to pure status check: remove token parameter, delete token-storing branches from auth_mcp/auth_wasm_tool, rename auth_wasm_channel → auth_wasm_channel_status. - Add ConfigureResult/MissingSecret types for structured responses. - Replace hardcoded Telegram token validation with generic validation_endpoint from capabilities.json. - Update all callers (9 files) to use the new interface. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]> * fix: use ValidationFailed error variant instead of string matching Replace brittle msg.contains("Invalid token") checks with a proper ExtensionError::ValidationFailed variant. configure() now returns this variant for token validation failures, and callers match on it directly instead of parsing error message strings. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]> * fix: address review — SSRF protection, error typing, missing-secret selection, WS auth 1. SSRF: call validate_fetch_url() before validation_endpoint HTTP request 2. Transport errors map to ExtensionError::Other (not ValidationFailed) 3. configure_token() picks first *missing* secret, not first non-optional 4. WebSocket error path re-emits AuthRequired on ValidationFailed Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]> * test: add regression tests for extension lifecycle refactoring - test_configure_token_picks_first_missing_secret: verifies multi-secret channels can be configured one secret at a time (commit ce106f4) - test_auth_is_read_only_for_wasm_channel: verifies auth() has no side effects and doesn't store secrets (commit 47f8eb6) - test_validation_failed_is_distinct_error_variant: verifies the typed error variant can be pattern-matched (commit a318161) Co-Authored-By: Claude Opus 4.6 <[email protected]> * fix: address review comments — activation dispatch, dead code, caps consolidation - Fix configure() fallthrough bug: dispatch activation by ExtensionKind instead of unconditionally calling activate_wasm_channel() for all non-WasmTool types (MCP servers and channel relays now use their correct activation methods) - Remove dead MissingSecret struct and missing_secrets field (never populated, flagged by reviewer) - Consolidate capabilities file parsing in configure(): parse once and reuse for allowed names, validation_endpoint, and auto-generation - Fix auth() doc comment: note MCP OAuth side effects - Fix stale save_setup_secrets reference in server.rs comment - Add regression test for activation dispatch bug Co-Authored-By: Claude Opus 4.6 <[email protected]> * fix(extensions): fix 5 extension lifecycle bugs found during E2E testing Bug fixes in src/extensions/manager.rs: - Add auth guard to activate_wasm_tool() blocking activation when secrets are missing (NeedsSetup), matching activate_wasm_channel() behavior - Evict WasmToolRuntime module cache on remove() so reinstall uses fresh binary - Clear activation_errors on remove() for both WasmTool and WasmChannel - Clean up in-progress OAuth flows on remove() (abort TCP listener, purge pending flow entries) Bug fix in src/channels/web/server.rs: - Broadcast AuthCompleted SSE event on expired OAuth callback so web UI doesn't stay stuck showing "auth required" E2E test coverage: - test_wasm_lifecycle.py: 35 tests covering install/configure/activate/ remove/reinstall lifecycle with regression tests for bugs 1 and 3 - test_extension_oauth.py: 9 tests covering OAuth round-trip flow - test_tool_execution.py: 5 tests for tool invocation via chat - test_pairing.py: 4 tests for pairing request lifecycle - Enhanced conftest.py, helpers.py, mock_llm.py for OAuth mock support [skip-regression-check] Co-Authored-By: Claude Opus 4.6 <[email protected]> * fix(web): unify extension auth UX and add lifecycle regressions * test: fix pending oauth flow fixtures after rebase * test(e2e): fix playwright route ordering for extensions reloads * test: address e2e review follow-ups * test: address remaining PR review comments --------- Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>
165 lines
6.5 KiB
Python
165 lines
6.5 KiB
Python
"""Shared helpers for E2E tests."""
|
||
|
||
import asyncio
|
||
import re
|
||
import time
|
||
|
||
import httpx
|
||
|
||
# -- DOM Selectors --------------------------------------------------------
|
||
# Keep all selectors in one place so changes to the frontend only need
|
||
# one update.
|
||
|
||
SEL = {
|
||
# 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}",
|
||
# Chat
|
||
"chat_input": "#chat-input",
|
||
"chat_messages": "#chat-messages",
|
||
"message_user": "#chat-messages .message.user",
|
||
"message_assistant": "#chat-messages .message.assistant",
|
||
# Skills
|
||
"skill_search_input": "#skill-search-input",
|
||
"skill_search_results": "#skill-search-results",
|
||
"skill_search_result": ".skill-search-result",
|
||
"skill_installed": "#skills-list .ext-card",
|
||
# SSE status
|
||
"sse_dot": "#sse-dot",
|
||
# Approval overlay
|
||
"approval_card": ".approval-card",
|
||
"approval_header": ".approval-header",
|
||
"approval_tool_name": ".approval-tool-name",
|
||
"approval_description": ".approval-description",
|
||
"approval_params_toggle": ".approval-params-toggle",
|
||
"approval_params": ".approval-params",
|
||
"approval_actions": ".approval-actions",
|
||
"approval_approve_btn": ".approval-actions button.approve",
|
||
"approval_always_btn": ".approval-actions button.always",
|
||
"approval_deny_btn": ".approval-actions button.deny",
|
||
"approval_resolved": ".approval-resolved",
|
||
# Extensions tab – sections
|
||
"extensions_list": "#extensions-list",
|
||
"available_wasm_list": "#available-wasm-list",
|
||
"mcp_servers_list": "#mcp-servers-list",
|
||
"tools_tbody": "#tools-tbody",
|
||
"tools_empty": "#tools-empty",
|
||
# Extensions tab – cards
|
||
"ext_card_installed": "#extensions-list .ext-card",
|
||
"ext_card_available": "#available-wasm-list .ext-card.ext-available",
|
||
"ext_card_mcp": "#mcp-servers-list .ext-card",
|
||
"ext_name": ".ext-name",
|
||
"ext_kind": ".ext-kind",
|
||
"ext_auth_dot": ".ext-auth-dot",
|
||
"ext_auth_dot_authed": ".ext-auth-dot.authed",
|
||
"ext_auth_dot_unauthed": ".ext-auth-dot.unauthed",
|
||
"ext_active_label": ".ext-active-label",
|
||
"ext_pairing_label": ".ext-pairing-label",
|
||
"ext_error": ".ext-error",
|
||
"ext_tools": ".ext-tools",
|
||
# Extensions tab – action buttons
|
||
"ext_install_btn": ".btn-ext.install",
|
||
"ext_remove_btn": ".btn-ext.remove",
|
||
"ext_activate_btn": ".btn-ext.activate",
|
||
"ext_configure_btn": ".btn-ext.configure",
|
||
# Configure modal
|
||
"configure_overlay": ".configure-overlay",
|
||
"configure_modal": ".configure-modal",
|
||
"configure_field": ".configure-field",
|
||
"configure_input": ".configure-modal input[type='password']",
|
||
"configure_save_btn": ".configure-actions button.btn-ext.activate",
|
||
"configure_cancel_btn": ".configure-actions button.btn-ext.remove",
|
||
"field_provided": ".field-provided",
|
||
"field_autogen": ".field-autogen",
|
||
"field_optional": ".field-optional",
|
||
# Auth card (SSE-triggered, injected into chat-messages)
|
||
"auth_card": ".auth-card",
|
||
"auth_header": ".auth-header",
|
||
"auth_instructions": ".auth-instructions",
|
||
"auth_oauth_btn": ".auth-oauth",
|
||
"auth_token_input": ".auth-token-input input",
|
||
"auth_submit_btn": ".auth-submit",
|
||
"auth_cancel_btn": ".auth-cancel",
|
||
"auth_error": ".auth-error",
|
||
# WASM channel progress stepper
|
||
"ext_stepper": ".ext-stepper",
|
||
"stepper_step": ".stepper-step",
|
||
"stepper_circle": ".stepper-circle",
|
||
# Toast notifications
|
||
"toast": ".toast",
|
||
"toast_success": ".toast.toast-success",
|
||
"toast_error": ".toast.toast-error",
|
||
"toast_info": ".toast.toast-info",
|
||
}
|
||
|
||
TABS = ["chat", "memory", "jobs", "routines", "extensions", "skills"]
|
||
|
||
# Auth token used across all tests
|
||
AUTH_TOKEN = "e2e-test-token"
|
||
|
||
|
||
async def wait_for_ready(url: str, *, timeout: float = 60, interval: float = 0.5):
|
||
"""Poll a URL until it returns 200 or timeout."""
|
||
deadline = time.monotonic() + timeout
|
||
async with httpx.AsyncClient() as client:
|
||
while time.monotonic() < deadline:
|
||
try:
|
||
resp = await client.get(url, timeout=5)
|
||
if resp.status_code == 200:
|
||
return
|
||
except (httpx.ConnectError, httpx.ReadError, httpx.TimeoutException):
|
||
pass
|
||
await asyncio.sleep(interval)
|
||
raise TimeoutError(f"Service at {url} not ready after {timeout}s")
|
||
|
||
|
||
async def wait_for_port_line(process, pattern: str, *, timeout: float = 60) -> int:
|
||
"""Read process stdout line by line until a port-bearing line matches."""
|
||
deadline = time.monotonic() + timeout
|
||
while time.monotonic() < deadline:
|
||
remaining = deadline - time.monotonic()
|
||
if remaining <= 0:
|
||
break
|
||
try:
|
||
line = await asyncio.wait_for(process.stdout.readline(), timeout=remaining)
|
||
except asyncio.TimeoutError:
|
||
break
|
||
decoded = line.decode("utf-8", errors="replace").strip()
|
||
if match := re.search(pattern, decoded):
|
||
return int(match.group(1))
|
||
raise TimeoutError(f"Port pattern '{pattern}' not found in stdout after {timeout}s")
|
||
|
||
|
||
# -- API helpers -----------------------------------------------------------
|
||
|
||
def auth_headers() -> dict[str, str]:
|
||
"""Return Authorization header dict for authenticated API calls."""
|
||
return {"Authorization": f"Bearer {AUTH_TOKEN}"}
|
||
|
||
|
||
async def api_get(base_url: str, path: str, **kwargs) -> httpx.Response:
|
||
"""Make an authenticated GET request to the ironclaw API."""
|
||
async with httpx.AsyncClient() as client:
|
||
return await client.get(
|
||
f"{base_url}{path}",
|
||
headers=auth_headers(),
|
||
timeout=kwargs.pop("timeout", 10),
|
||
**kwargs,
|
||
)
|
||
|
||
|
||
async def api_post(base_url: str, path: str, **kwargs) -> httpx.Response:
|
||
"""Make an authenticated POST request to the ironclaw API."""
|
||
async with httpx.AsyncClient() as client:
|
||
return await client.post(
|
||
f"{base_url}{path}",
|
||
headers=auth_headers(),
|
||
timeout=kwargs.pop("timeout", 10),
|
||
**kwargs,
|
||
)
|