Skip to content

Enterprise agent platform for building, deploying, and operating AI teammates.

feat(smoke): treat a Composio-only provider as holding no native client (#3815)

蓝鱼bluefish89a0c73911cc
diff --git a/scripts/connector_smoke/README.md b/scripts/connector_smoke/README.md
index ffba74686..bd178630e 100644
--- a/scripts/connector_smoke/README.md
+++ b/scripts/connector_smoke/README.md
@@ -27,8 +27,15 @@ The registry decides Gmail's and full Google Drive's default visibility from
running the check, not the deployment's. Leave it unset where the check runs.
Against a deployment that has the gate open, pass `--include gmail,google-drive`.
-**Builtin OAuth providers.** The check launches each provider once, through one
-of its visible catalog apps (a registry app when there is one):
+**Builtin OAuth providers.** The launch is the web connect, so the check
+follows the app's web-connect rule, not its Composio switch alone: the catalog
+entry says `auth_backend: "composio"` only for an app whose web connect goes
+through Composio (today only Salesforce). An app whose switch is on but whose
+web connect stays native (Facebook, Drive, Gmail) keeps only the native checks
+below and adds no `oauth:<provider>:composio` line.
+
+The check launches each provider once per app backend it serves, through one of
+its visible catalog apps (a registry app when there is one):
1. `POST /api/auth/{provider}/login` starts the launch. The returned callback
origin must equal the environment's origin. An unset `<PROVIDER>_REDIRECT_URI`
@@ -37,6 +44,18 @@ of its visible catalog apps (a registry app when there is one):
redirect. The provider `Location` must carry a non-empty `client_id` and a
`redirect_uri` of `<origin>/api/auth/{provider}/callback`.
+A provider with any native app keeps these two checks through a native app, so
+turning one app over to Composio never drops them (`oauth:<provider>:callback`
+and `oauth:<provider>:authorize`). An operator-created app under a provider
+counts as a native target too. A provider with any app whose catalog entry says
+`auth_backend: "composio"` additionally gets one `oauth:<provider>:composio`
+check: its launch redeem must redirect to the shared Composio callback path
+with a `state`, on the callback origin its own launch start reports, which may
+be another host than the deployment's. A Composio-only provider (every app's web
+connect on Composio, with the Composio settings present) gets only that check.
+Every start is redeemed before the next one, so a launch ticket never expires
+mid-run.
+
Remote MCP OAuth apps (Notion, Atlassian, HubSpot, …) are not launched, because
their connect may register a client with the vendor on every call. L2 covers
them.
@@ -57,7 +76,13 @@ It prints one line per provider saying whether the client ID and secret
resolve, and from the `oauth_providers` row or the environment, never a value.
A row encrypted under another key fails as `unreadable`; a process with no
usable key fails once as `encryption-key`. It proves a value is present, not
-that the vendor accepts it. Its `--exclude` takes OAuth provider names
+that the vendor accepts it. A provider whose every app's web connect goes
+through Composio, with the Composio settings present, is reported as `SKIP`
+(connects through Composio): it needs no native client and never fails for a
+missing row or credential. With a Composio setting missing it is checked as a
+native provider, so it still fails. This is
+decided from the builtin registry's apps only; an operator-created app of the
+same provider is not considered. Its `--exclude` takes OAuth provider names
(`google`), not the catalog app IDs this script's `--exclude` takes.
Whether the vendor still accepts each client is checked by
@@ -69,7 +94,10 @@ and prints `CLIENT_OK`, `CLIENT_REJECTED`, `INCONCLUSIVE` or `UNVERIFIABLE`
(with the reason) per credential, plus the vendor's error code and where each
field resolved from, never a value. It exits 1 when any client is rejected;
`INCONCLUSIVE` lines do not fail it. A pre-registered remote MCP client is
-listed as `UNVERIFIABLE`. `--exclude` takes the same provider names.
+listed as `UNVERIFIABLE`. A provider whose every app's web connect goes
+through Composio, with the Composio settings present, is `UNVERIFIABLE` without
+a request to the vendor. `--exclude`
+takes the same provider names.
Microsoft checks a refresh token's format before the client, so its secret is
checked instead with one client-credentials request against the app's home
diff --git a/scripts/connector_smoke/cli.py b/scripts/connector_smoke/cli.py
index ef1671469..480f2c08e 100644
--- a/scripts/connector_smoke/cli.py
+++ b/scripts/connector_smoke/cli.py
@@ -62,12 +62,66 @@ def run_l1(
results = l1.check_catalog(apps, expected)
for target in l1.select_oauth_targets(apps, preferred=expected):
- results.extend(
- _check_oauth_target(client, target, expected_origin, oauth_accounts)
- )
+ if target.auth_backend == l1.COMPOSIO_BACKEND:
+ results.extend(_check_composio_target(client, target, oauth_accounts))
+ else:
+ results.extend(
+ _check_oauth_target(client, target, expected_origin, oauth_accounts)
+ )
return results
+def _check_composio_target(
+ client: SmokeClient,
+ target: l1.OAuthTarget,
+ oauth_accounts: Mapping[str, str],
+) -> list[l1.CheckResult]:
+ provider = target.provider
+ name = f"oauth:{provider}:composio"
+ account = oauth_accounts.get(provider)
+ if target.needs_account and account is None:
+ return [
+ l1.CheckResult(
+ name,
+ False,
+ f"needs an account label: pass --oauth-account {provider}=<label>",
+ )
+ ]
+ try:
+ start = client.start_launch(provider, target.app_id, account)
+ except SmokeError as exc:
+ return [l1.CheckResult(name, False, str(exc))]
+ if start.status_code != 200:
+ return [
+ l1.CheckResult(
+ name,
+ False,
+ "launch start refused: "
+ + l1.start_refused_detail(start.status_code, start.payload),
+ )
+ ]
+ origin = l1.start_callback_origin(start.payload)
+ if origin is None:
+ return [
+ l1.CheckResult(
+ name, False, "launch start returned no usable callback origin"
+ )
+ ]
+ try:
+ redeem = client.redeem_launch(provider, start.payload.get("authorization_url"))
+ except SmokeError as exc:
+ return [l1.CheckResult(name, False, str(exc))]
+ return [
+ l1.check_composio_callback(
+ provider,
+ status_code=redeem.status_code,
+ location=redeem.location,
+ body=redeem.body,
+ expected_origin=origin,
+ )
+ ]
+
+
def _check_oauth_target(
client: SmokeClient,
target: l1.OAuthTarget,
@@ -84,7 +138,6 @@ def _check_oauth_target(
f"needs an account label: pass --oauth-account {provider}=<label>",
)
]
-
try:
start = client.start_launch(provider, target.app_id, account)
except SmokeError as exc:
diff --git a/scripts/connector_smoke/client.py b/scripts/connector_smoke/client.py
index cbbe5c6cc..938668f7a 100644
--- a/scripts/connector_smoke/client.py
+++ b/scripts/connector_smoke/client.py
@@ -162,9 +162,11 @@ class SmokeClient:
return JSONResponse(response.status_code, payload)
def start_launch(
- self, provider: str, app_id: str, account: str | None = None
+ self, provider: str, app_id: str | None = None, account: str | None = None
) -> LaunchStart:
- body: dict[str, str] = {"app_id": app_id}
+ body: dict[str, str] = {}
+ if app_id is not None:
+ body["app_id"] = app_id
if account is not None:
body["account"] = account
response = self._request("POST", _launch_path(provider), json=body)
diff --git a/scripts/connector_smoke/l1.py b/scripts/connector_smoke/l1.py
index 3acc83ea9..fa8710c49 100644
--- a/scripts/connector_smoke/l1.py
+++ b/scripts/connector_smoke/l1.py
@@ -16,12 +16,15 @@ from dataclasses import dataclass
from typing import Any
from urllib.parse import parse_qs, urlsplit
+from xagent.web.composio_apps import _CALLBACK_PATHS as COMPOSIO_CALLBACK_PATHS
+
# Gmail sits behind the Google restricted-scope gate and can be refused while
# the provider itself is fine, so it only represents Google as a last resort.
_AVOID_AS_REPRESENTATIVE = frozenset({"gmail"})
_DEFAULT_PORTS = {"http": 80, "https": 443}
_REDIRECT_STATUSES = frozenset({301, 302, 303, 307, 308})
_MAX_REASON_DETAIL = 200
+COMPOSIO_BACKEND = "composio"
@dataclass(frozen=True)
@@ -36,6 +39,7 @@ class OAuthTarget:
provider: str
app_id: str
needs_account: bool = False
+ auth_backend: str | None = None
def format_result(result: CheckResult) -> str:
@@ -110,14 +114,8 @@ def check_catalog(
def select_oauth_targets(
apps: Iterable[Mapping[str, Any]], preferred: Iterable[str] = ()
) -> list[OAuthTarget]:
- """One launch per builtin OAuth provider, through a visible catalog app.
-
- The launch always names an app: providers whose apps need an app-scoped
- grant refuse a bare provider launch. Apps in ``preferred`` (the expected
- registry apps) represent their provider before operator-created ones,
- whose extra scopes could be refused for reasons unrelated to the
- provider's configuration.
- """
+ """One launch per builtin OAuth provider and per app backend it serves; each
+ names an app (a bare provider launch is refused), preferring registry apps."""
preferred = set(preferred)
by_provider: dict[str, list[Mapping[str, Any]]] = {}
for app in apps:
@@ -141,17 +139,32 @@ def select_oauth_targets(
str(app["id"]),
),
)
- app = candidates[0]
- targets.append(
- OAuthTarget(
- provider=provider,
- app_id=str(app["id"]),
- needs_account=bool(app.get("oauth_account_input")),
+ native = [app for app in candidates if not _is_composio(app)]
+ composio = [app for app in candidates if _is_composio(app)]
+ if native:
+ targets.append(_target(provider, native[0]))
+ if composio:
+ targets.append(
+ _target(provider, composio[0], auth_backend=COMPOSIO_BACKEND)
)
- )
return targets
+def _is_composio(app: Mapping[str, Any]) -> bool:
+ return app.get("auth_backend") == COMPOSIO_BACKEND
+
+
+def _target(
+ provider: str, app: Mapping[str, Any], *, auth_backend: str | None = None
+) -> OAuthTarget:
+ return OAuthTarget(
+ provider=provider,
+ app_id=str(app["id"]),
+ needs_account=bool(app.get("oauth_account_input")),
+ auth_backend=auth_backend,
+ )
+
+
def normalize_origin(value: object) -> str | None:
"""``scheme://host[:port]`` in canonical form, or None if not an origin."""
if not isinstance(value, str):
@@ -201,6 +214,56 @@ def check_callback_origin(
return CheckResult(name, True)
+def start_callback_origin(payload: object) -> str | None:
+ """The callback origin a launch start reports, if it reports one."""
+ if not isinstance(payload, Mapping):
+ return None
+ return normalize_origin(payload.get("callback_origin"))
+
+
+def start_refused_detail(status_code: int, payload: object) -> str:
+ """``HTTP <status>`` plus a value-free body summary, for a refused start."""
+ return f"HTTP {status_code}{_detail_suffix(payload)}"
+
+
+def check_composio_callback(
+ provider: str,
+ *,
+ status_code: int,
+ location: str | None,
+ body: str,
+ expected_origin: str,
+) -> CheckResult:
+ """A Composio app's redeem must begin at the shared Composio callback."""
+ name = f"oauth:{provider}:composio"
+ if status_code not in _REDIRECT_STATUSES or not location:
+ return CheckResult(
+ name,
+ False,
+ f"no Composio begin redirect: HTTP {status_code}{_detail_suffix(body)}",
+ )
+ try:
+ parts = urlsplit(location)
+ query = parse_qs(parts.query)
+ except ValueError:
+ return CheckResult(name, False, "Composio begin redirect is not a valid URL")
+
+ problems = []
+ origin = normalize_origin(location)
+ if origin != normalize_origin(expected_origin):
+ problems.append(
+ f"callback origin is {origin or 'an invalid origin'}, "
+ f"expected {expected_origin}"
+ )
+ if not parts.path.endswith(COMPOSIO_CALLBACK_PATHS):
+ problems.append("redirect is not to a shared Composio callback path")
+ if not "".join(query.get("state", [])).strip():
+ problems.append("state is missing")
+ if problems:
+ return CheckResult(name, False, "; ".join(problems))
+ return CheckResult(name, True)
+
+
def check_authorize_redirect(
provider: str,
*,
diff --git a/src/xagent/web/composio_apps.py b/src/xagent/web/composio_apps.py
index f0f135223..856eda461 100644
--- a/src/xagent/web/composio_apps.py
+++ b/src/xagent/web/composio_apps.py
@@ -16,7 +16,7 @@ from __future__ import annotations
import logging
import os
import re
-from collections.abc import Callable, Mapping
+from collections.abc import Callable, Iterable, Mapping
from typing import Any, NamedTuple
from urllib.parse import urlsplit
@@ -52,6 +52,13 @@ SALESFORCE_TOOLKIT_SLUG = "salesforce"
# On the org's own host: login.salesforce.com's userinfo does not serve
# sandbox orgs.
SALESFORCE_USERINFO_PATH = "/services/oauth2/userinfo"
+COMPOSIO_API_KEY_ENV = "COMPOSIO_API_KEY"
+COMPOSIO_USER_ID_SECRET_ENV = "COMPOSIO_USER_ID_SECRET"
+# Every Composio app's trips (begin, verification, denial) land on one shared
+# callback URL: XAGENT_COMPOSIO_CALLBACK_URL, else the Meta callback URL.
+COMPOSIO_CALLBACK_PATH = "/api/auth/composio/callback"
+# The two routes that accept the trips; the setting must name one of them.
+_CALLBACK_PATHS = (COMPOSIO_CALLBACK_PATH, "/api/auth/meta/callback")
class ComposioApp(NamedTuple):
@@ -334,3 +341,24 @@ def _uses_composio(app: ComposioApp) -> bool:
_WARNED_BACKENDS: set[tuple[str, str]] = set()
+
+
+def composio_config_present(app: ComposioApp) -> bool:
+ """Whether this deployment holds the Composio settings the app's connects need."""
+ return all(
+ _env(name)
+ for name in (
+ COMPOSIO_API_KEY_ENV,
+ app.auth_config_env,
+ COMPOSIO_USER_ID_SECRET_ENV,
+ )
+ )
+
+
+def provider_is_composio_only(provider: str, app_ids: Iterable[str]) -> bool:
+ """Whether every app listed runs its web connect through a configured
+ Composio; callers pass builtin registry apps only."""
+ apps = [composio_web_app(provider, app_id) for app_id in app_ids]
+ return bool(apps) and all(
+ app is not None and composio_config_present(app) for app in apps
+ )
diff --git a/src/xagent/web/composio_auth.py b/src/xagent/web/composio_auth.py
index d67dd7bdb..9b4aaa71e 100644
--- a/src/xagent/web/composio_auth.py
+++ b/src/xagent/web/composio_auth.py
@@ -120,6 +120,7 @@ from ..config import COMPOSIO_CALLBACK_URL as COMPOSIO_CALLBACK_URL_ENV
from ..config import get_composio_callback_url
from ..core.utils import public_requests as requests
from .auth_sessions import lock_current_session_epoch
+from .composio_apps import _CALLBACK_PATHS as _CALLBACK_PATHS
from .composio_apps import _GOOGLE_SUBJECT_RE as _GOOGLE_SUBJECT_RE
from .composio_apps import _GRAPH_ID_RE as _GRAPH_ID_RE
from .composio_apps import _SALESFORCE_HOST_RE as _SALESFORCE_HOST_RE
@@ -135,7 +136,9 @@ from .composio_apps import _WARNED_BACKENDS as _WARNED_BACKENDS
from .composio_apps import ( # noqa: F401 (re-exported: the switch lookup moved)
AUTH_BACKEND as AUTH_BACKEND,
)
+from .composio_apps import COMPOSIO_API_KEY_ENV as COMPOSIO_API_KEY_ENV
from .composio_apps import COMPOSIO_APPS as COMPOSIO_APPS
+from .composio_apps import COMPOSIO_CALLBACK_PATH as COMPOSIO_CALLBACK_PATH
from .composio_apps import (
COMPOSIO_FACEBOOK_AUTH_CONFIG_ID_ENV as COMPOSIO_FACEBOOK_AUTH_CONFIG_ID_ENV,
)
@@ -151,6 +154,7 @@ from .composio_apps import (
from .composio_apps import (
COMPOSIO_SALESFORCE_AUTH_CONFIG_ID_ENV as COMPOSIO_SALESFORCE_AUTH_CONFIG_ID_ENV,
)
+from .composio_apps import COMPOSIO_USER_ID_SECRET_ENV as COMPOSIO_USER_ID_SECRET_ENV
from .composio_apps import FACEBOOK_APP_ID as FACEBOOK_APP_ID
from .composio_apps import FACEBOOK_AUTH_BACKEND_ENV as FACEBOOK_AUTH_BACKEND_ENV
from .composio_apps import FACEBOOK_TOOLKIT_SLUG as FACEBOOK_TOOLKIT_SLUG
@@ -189,20 +193,9 @@ logger = logging.getLogger(__name__)
# the two lands second switches to the shared constant.
COMPOSIO_TOKEN_TYPE = "composio"
-COMPOSIO_API_KEY_ENV = "COMPOSIO_API_KEY"
-COMPOSIO_USER_ID_SECRET_ENV = "COMPOSIO_USER_ID_SECRET"
COMPOSIO_API_BASE_URL = "https://backend.composio.dev/api/v3.1"
-# Every Composio app's trips (begin, verification, denial) land on one shared
-# callback URL, whatever the app's own provider: Composio's OAuth user
-# verification is a single URL per project, and the flow and actor proof
-# cookies are scoped to the path they come back to. XAGENT_COMPOSIO_CALLBACK_URL
-# sets it (to COMPOSIO_CALLBACK_PATH after the cutover); unset, it is the Meta callback
-# URL, where these trips have always been accepted.
-COMPOSIO_CALLBACK_PATH = "/api/auth/composio/callback"
DEFAULT_CALLBACK_PROVIDER = META_PROVIDER
-# The two routes that accept the trips; the setting must name one of them.
-_CALLBACK_PATHS = (COMPOSIO_CALLBACK_PATH, "/api/auth/meta/callback")
# Logged as the provider of a trip whose app is not known yet.
UNKNOWN_APP_PROVIDER = "composio"
@@ -251,15 +244,6 @@ class ComposioError(Exception):
self.rejected = rejected
-def connect_guidance(provider: str, app_id: str | None) -> dict[str, str] | None:
- """The app's connect guidance while its new connects go through
- Composio; None otherwise, so a catalog entry can leave the field out."""
- app = composio_app(provider, app_id)
- if app is None or app.connect_guidance is None:
- return None
- return dict(app.connect_guidance)
-
-
def load_config(app_id: str) -> ComposioConfig | None:
api_key = _env(COMPOSIO_API_KEY_ENV)
auth_config_id = _env(COMPOSIO_APPS[app_id].auth_config_env)
diff --git a/src/xagent/web/mcp_apps.py b/src/xagent/web/mcp_apps.py
index 78a3cf6cb..c0e9cd52d 100644
--- a/src/xagent/web/mcp_apps.py
+++ b/src/xagent/web/mcp_apps.py
@@ -390,15 +390,17 @@ def _app_to_dict(app: PublicMCPApp) -> Dict[str, Any]:
account_host = get_oauth_account_host(execution_fields["provider_name"])
if account_host is not None and app_dict["auth_type"] == "builtin_oauth":
app_dict["oauth_account_input"] = account_host.input_metadata()
- # Only while the app's actor connect goes through Composio (Salesforce:
- # an org admin must install Composio's app first), so every other entry,
- # and Salesforce's while native, is unchanged.
+ # The switch alone does not set ``auth_backend``: only a web connect that
+ # also goes through Composio does.
if app_dict["auth_type"] == "builtin_oauth":
- from .composio_auth import connect_guidance
-
- guidance = connect_guidance(execution_fields["provider_name"] or "", app.app_id)
- if guidance is not None:
- app_dict["connect_guidance"] = guidance
+ from .composio_auth import AUTH_BACKEND, composio_app
+
+ composio = composio_app(execution_fields["provider_name"] or "", app.app_id)
+ if composio is not None:
+ if composio.connect_guidance is not None:
+ app_dict["connect_guidance"] = dict(composio.connect_guidance)
+ if composio.web_start:
+ app_dict["auth_backend"] = AUTH_BACKEND
return app_dict
diff --git a/src/xagent/web/oauth_client_verification.py b/src/xagent/web/oauth_client_verification.py
index 9ccd259bf..7d032e00b 100644
--- a/src/xagent/web/oauth_client_verification.py
+++ b/src/xagent/web/oauth_client_verification.py
@@ -16,7 +16,8 @@ checked this way today (see ``MCP_UNVERIFIABLE``).
- ``inconclusive``: anything else (a 5xx, a timeout, an answer that does not
tell the two apart).
- ``unverifiable``: this provider's token endpoint cannot tell the two apart,
- or depends on the customer's account; the line says why.
+ depends on the customer's account, or connects through a fully configured
+ Composio; the line says why.
A builtin provider's request is built by ``build_oauth_refresh_request``, the
same function a refresh uses, so the command checks exactly what a refresh
@@ -361,6 +362,10 @@ async def verify_builtin_provider(provider: str, row: Any | None) -> Verificatio
from .oauth_readiness import check_provider
readiness = check_provider(provider, row)
+ if readiness.composio_only:
+ return VerificationResult(
+ "oauth-client", provider, "unverifiable", "connects through Composio"
+ )
sources = f"client_id={readiness.client_id} client_secret={readiness.client_secret}"
# Rules are keyed like the refresh's own provider checks: lowercased.
name = provider.lower()
diff --git a/src/xagent/web/oauth_readiness.py b/src/xagent/web/oauth_readiness.py
index 026b44a0d..e757dd0d7 100644
--- a/src/xagent/web/oauth_readiness.py
+++ b/src/xagent/web/oauth_readiness.py
@@ -23,7 +23,9 @@ from, never a value or part of one.
It proves that a value is present, not that the vendor accepts it. A row
encrypted under a different key is reported as ``unreadable``: the runtime
would send the ciphertext as the value, and the environment variable cannot
-take over because the row is not blank.
+take over because the row is not blank. A provider whose every app's web
+connect goes through a fully configured Composio is reported as ``SKIP``: it
+needs no native client.
"""
from __future__ import annotations
@@ -41,6 +43,7 @@ from ..core.utils.encryption import (
decrypt_value_strict,
get_cipher,
)
+from .composio_apps import provider_is_composio_only
FieldSource = Literal["row", "env", "missing", "unreadable"]
_READY_SOURCES = frozenset({"row", "env"})
@@ -52,6 +55,7 @@ class ProviderReadiness:
has_row: bool
client_id: FieldSource
client_secret: FieldSource
+ composio_only: bool = False
@property
def ready(self) -> bool:
@@ -76,8 +80,22 @@ def _field_source(provider: str, stored: str | None, env_suffix: str) -> FieldSo
return "row" if from_row else "env"
-def check_provider(provider: str, row: Any | None) -> ProviderReadiness:
+def _builtin_app_ids(provider: str) -> list[str]:
+ from .builtin_mcp_registry import get_builtin_public_mcp_app_rows
+
+ return [
+ str(row["app_id"])
+ for row in get_builtin_public_mcp_app_rows()
+ if row.get("provider_name") == provider
+ ]
+
+
+def check_provider(
+ provider: str, row: Any | None, *, app_ids: Iterable[str] | None = None
+) -> ProviderReadiness:
"""Resolve one provider's client ID and secret the way a connect does."""
+ if app_ids is None:
+ app_ids = _builtin_app_ids(provider)
return ProviderReadiness(
provider=provider,
has_row=row is not None,
@@ -85,6 +103,7 @@ def check_provider(provider: str, row: Any | None) -> ProviderReadiness:
client_secret=_field_source(
provider, getattr(row, "client_secret", None), "CLIENT_SECRET"
),
+ composio_only=provider_is_composio_only(provider, app_ids),
)
@@ -109,6 +128,8 @@ def check_providers(
def format_result(result: ProviderReadiness) -> str:
+ if result.composio_only:
+ return f"SKIP oauth-client:{result.provider}: connects through Composio"
status = "PASS" if result.ready else "FAIL"
if not result.has_row:
detail = "no provider row"
@@ -182,7 +203,7 @@ def main(argv: Sequence[str] | None = None, *, out: TextIO | None = None) -> int
except ValueError as exc:
parser.error(str(exc))
- failed = sum(not result.ready for result in results)
+ failed = sum(not result.ready and not result.composio_only for result in results)
for result in results:
print(format_result(result), file=out)
print(f"{len(results)} checks, {failed} failed", file=out)
diff --git a/tests/scripts/test_connector_smoke_cli.py b/tests/scripts/test_connector_smoke_cli.py
index 8a80b71cd..5e5728b20 100644
--- a/tests/scripts/test_connector_smoke_cli.py
+++ b/tests/scripts/test_connector_smoke_cli.py
@@ -34,7 +34,9 @@ REGISTRY_ROWS = [
]
-def _catalog_app(app_id: str, provider: str | None, auth_type: str) -> dict[str, Any]:
+def _catalog_app(
+ app_id: str, provider: str | None, auth_type: str, **extra: Any
+) -> dict[str, Any]:
app: dict[str, Any] = {
"id": app_id,
"name": app_id,
@@ -45,6 +47,7 @@ def _catalog_app(app_id: str, provider: str | None, auth_type: str) -> dict[str,
}
if provider == "zendesk":
app["oauth_account_input"] = {"suffix": ".zendesk.com"}
+ app.update(extra)
return app
@@ -61,6 +64,8 @@ class FakeDeployment:
"zendesk": "zendesk-client-SECRET",
}
self.callback_origin = BASE
+ self.shared_callback_origin = "https://global.example.net"
+ self.composio_apps: set[str] = set()
self.requests: list[httpx.Request] = []
self.launch_bodies: dict[str, dict[str, Any]] = {}
self.require_login_route = False
@@ -94,14 +99,20 @@ class FakeDeployment:
return httpx.Response(404)
def _start(self, provider: str, request: httpx.Request) -> httpx.Response:
- self.launch_bodies[provider] = json.loads(request.content)
+ body = json.loads(request.content)
+ self.launch_bodies[provider] = body
ticket = f"ticket-{provider}-SECRET"
+ origin = (
+ self.shared_callback_origin
+ if body.get("app_id") in self.composio_apps
+ else self.callback_origin
+ )
return httpx.Response(
200,
json={
"authorization_url": f"/api/auth/{provider}/login?"
+ urlencode({"ticket": ticket}),
- "callback_origin": self.callback_origin,
+ "callback_origin": origin,
},
)
@@ -109,6 +120,16 @@ class FakeDeployment:
assert parse_qs(request.url.query.decode())["ticket"] == [
f"ticket-{provider}-SECRET"
]
+ app_id = self.launch_bodies.get(provider, {}).get("app_id")
+ if app_id in self.composio_apps:
+ query = urlencode({"state": STATE})
+ return httpx.Response(
+ 307,
+ headers={
+ "location": f"{self.shared_callback_origin}"
+ f"/api/auth/meta/callback?{query}"
+ },
+ )
client_id = self.client_ids.get(provider, "")
if not client_id:
env_name = f"{provider.upper()}_CLIENT_ID"
@@ -142,13 +163,16 @@ ENV = {
def _run(
- fake: FakeDeployment, *args: str, env: dict[str, str] | None = None
+ fake: FakeDeployment,
+ *args: str,
+ env: dict[str, str] | None = None,
+ registry_rows: list[dict[str, Any]] | None = None,
) -> tuple[int, list[str]]:
out = io.StringIO()
code = cli.main(
["l1", *args],
env={**ENV, **(env or {})},
- registry_rows=REGISTRY_ROWS,
+ registry_rows=REGISTRY_ROWS if registry_rows is None else registry_rows,
transport=httpx.MockTransport(fake.handler),
out=out,
)
@@ -239,6 +263,203 @@ def test_output_never_contains_tokens_tickets_or_redirect_values() -> None:
assert "example.net" not in output
+COMPOSIO_REGISTRY_ROWS = [
+ {"app_id": "slack", "is_visible_in_connector": True},
+ {"app_id": "salesforce", "is_visible_in_connector": True},
+]
+
+
+def _composio_deployment() -> FakeDeployment:
+ fake = FakeDeployment()
+ fake.catalog = [
+ _catalog_app("slack", "slack", "builtin_oauth"),
+ _catalog_app(
+ "salesforce", "salesforce", "builtin_oauth", auth_backend="composio"
+ ),
+ ]
+ fake.composio_apps = {"salesforce"}
+ fake.client_ids.pop("salesforce", None)
+ return fake
+
+
+def test_a_composio_only_provider_needs_no_native_client() -> None:
+ code, lines = _run(_composio_deployment(), registry_rows=COMPOSIO_REGISTRY_ROWS)
+
+ assert code == 0, lines
+ assert _failures(lines) == []
+ assert "PASS oauth:salesforce:composio" in lines
+ assert "PASS oauth:slack:callback" in lines
+ assert "oauth:salesforce:callback" not in "\n".join(lines)
+ assert "state-jwt-SECRET" not in "\n".join(lines)
+
+
+def _launch_events(fake: FakeDeployment) -> list[tuple[str, str, str | None]]:
+ events: list[tuple[str, str, str | None]] = []
+ for request in fake.requests:
+ parts = request.url.path.split("/")
+ if len(parts) != 5 or parts[1:3] != ["api", "auth"] or parts[4] != "login":
+ continue
+ app_id = None
+ if request.method == "POST":
+ app_id = json.loads(request.content).get("app_id")
+ events.append((request.method, parts[3], app_id))
+ return events
+
+
+def test_each_launch_is_redeemed_before_the_next_one_starts() -> None:
+ fake = _composio_deployment()
+ code, lines = _run(fake, registry_rows=COMPOSIO_REGISTRY_ROWS)
+
+ assert code == 0, lines
+ events = _launch_events(fake)
+ redeems = [index for index, event in enumerate(events) if event[0] == "GET"]
+ assert len(redeems) == len(events) // 2
+ for index in redeems:
+ method, provider, app_id = events[index - 1]
+ assert (method, provider) == ("POST", events[index][1])
+ assert app_id is not None
+
+
+def test_the_composio_redeem_is_checked_against_its_own_start_origin() -> None:
+ fake = _composio_deployment()
+ fake.shared_callback_origin = "https://connect.example.net"
+ assert fake.shared_callback_origin != BASE
+
+ code, lines = _run(fake, registry_rows=COMPOSIO_REGISTRY_ROWS)
+
+ assert code == 0, lines
+ assert "PASS oauth:salesforce:composio" in lines
+
+
+def test_a_composio_redeem_on_another_origin_than_its_start_fails() -> None:
+ fake = _composio_deployment()
+ original_redeem = fake._redeem
+
+ def redeem(provider: str, request: httpx.Request) -> httpx.Response:
+ if provider != "salesforce":
+ return original_redeem(provider, request)
+ return httpx.Response(
+ 307,
+ headers={
+ "location": "https://elsewhere.example.net"
+ f"/api/auth/composio/callback?{urlencode({'state': STATE})}"
+ },
+ )
+
+ fake._redeem = redeem # type: ignore[method-assign]
+
+ code, lines = _run(fake, registry_rows=COMPOSIO_REGISTRY_ROWS)
+
+ assert code == 1
+ assert _failures(lines) == [
+ "FAIL oauth:salesforce:composio: callback origin is "
+ "https://elsewhere.example.net, expected https://global.example.net"
+ ]
+
+
[email protected]("origin", [None, "", "/relative", "ftp://host"])
+def test_a_composio_start_without_a_valid_callback_origin_fails(
+ origin: str | None,
+) -> None:
+ fake = _composio_deployment()
+ original_start = fake._start
+
+ def start(provider: str, request: httpx.Request) -> httpx.Response:
+ response = original_start(provider, request)
+ if provider != "salesforce":
+ return response
+ payload = json.loads(response.content)
+ if origin is None:
+ del payload["callback_origin"]
+ else:
+ payload["callback_origin"] = origin
+ return httpx.Response(200, json=payload)
+
+ fake._start = start # type: ignore[method-assign]
+
+ code, lines = _run(fake, registry_rows=COMPOSIO_REGISTRY_ROWS)
+
+ assert code == 1
+ assert _failures(lines) == [
+ "FAIL oauth:salesforce:composio: launch start returned no usable "
+ "callback origin"
+ ]
+ assert ("GET", "salesforce", None) not in _launch_events(fake)
+
+
+def test_a_refused_composio_start_fails_without_a_redeem() -> None:
+ fake = _composio_deployment()
+ original_start = fake._start
+
+ def start(provider: str, request: httpx.Request) -> httpx.Response:
+ if provider != "salesforce":
+ return original_start(provider, request)
+ return httpx.Response(503, json={"detail": "unavailable"})
+
+ fake._start = start # type: ignore[method-assign]
+
+ code, lines = _run(fake, registry_rows=COMPOSIO_REGISTRY_ROWS)
+
+ assert code == 1
+ (failure,) = _failures(lines)
+ assert failure.startswith(
+ "FAIL oauth:salesforce:composio: launch start refused: HTTP 503"
+ )
+ assert ("GET", "salesforce", None) not in _launch_events(fake)
+
+
+def _real_catalog_app(app_id: str) -> dict[str, Any]:
+ """The entry the server's own catalog code builds for a builtin app."""
+ from xagent.web.builtin_mcp_registry import get_builtin_public_mcp_app
+ from xagent.web.mcp_apps import _app_to_dict
+ from xagent.web.models.public_mcp import PublicMCPApp
+
+ row = get_builtin_public_mcp_app(app_id)
+ assert row is not None
+ return _app_to_dict(PublicMCPApp(**row))
+
+
+def test_the_facebook_switch_leaves_meta_native_and_adds_no_composio_check(
+ monkeypatch,
+) -> None:
+ monkeypatch.setenv("XAGENT_FACEBOOK_AUTH_BACKEND", "composio")
+ monkeypatch.setenv("COMPOSIO_FACEBOOK_AUTH_CONFIG_ID", "ac_facebook")
+ monkeypatch.setenv("XAGENT_SALESFORCE_AUTH_BACKEND", "composio")
+ monkeypatch.setenv("COMPOSIO_SALESFORCE_AUTH_CONFIG_ID", "ac_salesforce")
+ monkeypatch.setenv("COMPOSIO_API_KEY", "key")
+ monkeypatch.setenv("COMPOSIO_USER_ID_SECRET", "secret")
+ fake = FakeDeployment()
+ fake.shared_callback_origin = BASE
+ fake.catalog = [_real_catalog_app("facebook"), _real_catalog_app("salesforce")]
+ fake.composio_apps = {"salesforce"}
+ fake.client_ids["meta"] = "meta-client-SECRET"
+ fake.client_ids.pop("salesforce", None)
+
+ code, lines = _run(
+ fake,
+ registry_rows=[
+ {"app_id": "facebook", "is_visible_in_connector": True},
+ {"app_id": "salesforce", "is_visible_in_connector": True},
+ ],
+ )
+
+ assert code == 0, lines
+ assert "PASS oauth:meta:callback" in lines
+ assert "PASS oauth:meta:authorize" in lines
+ assert "PASS oauth:salesforce:composio" in lines
+ assert not [line for line in lines if "oauth:meta:composio" in line]
+ events = _launch_events(fake)
+ assert events == [
+ ("POST", "meta", "facebook"),
+ ("GET", "meta", None),
+ ("POST", "salesforce", "salesforce"),
+ ("GET", "salesforce", None),
+ ]
+ assert [event[1] for event in events if event[0] == "POST"] == [
+ event[1] for event in events if event[0] == "GET"
+ ]
+
+
def test_launch_names_the_catalog_app_and_never_follows_the_redirect() -> None:
fake = FakeDeployment()
diff --git a/tests/scripts/test_connector_smoke_l1.py b/tests/scripts/test_connector_smoke_l1.py
index 10e690092..0dd06894a 100644
--- a/tests/scripts/test_connector_smoke_l1.py
+++ b/tests/scripts/test_connector_smoke_l1.py
@@ -231,6 +231,44 @@ def test_account_hosted_provider_target_is_marked() -> None:
]
+def test_a_composio_app_target_carries_its_backend() -> None:
+ catalog = [
+ _app(
+ "salesforce",
+ "salesforce",
+ "builtin_oauth",
+ auth_backend="composio",
+ )
+ ]
+
+ assert l1.select_oauth_targets(catalog) == [
+ l1.OAuthTarget(
+ provider="salesforce", app_id="salesforce", auth_backend="composio"
+ )
+ ]
+
+
+def test_a_native_app_target_carries_no_backend() -> None:
+ catalog = [_app("slack", "slack", "builtin_oauth")]
+
+ assert l1.select_oauth_targets(catalog) == [
+ l1.OAuthTarget(provider="slack", app_id="slack")
+ ]
+
+
+def test_a_composio_app_beside_native_apps_adds_a_second_target() -> None:
+ # Facebook sorts first, but the native checks must keep a native app.
+ catalog = [
+ _app("facebook", "meta", "builtin_oauth", auth_backend="composio"),
+ _app("instagram", "meta", "builtin_oauth"),
+ ]
+
+ assert l1.select_oauth_targets(catalog) == [
+ l1.OAuthTarget(provider="meta", app_id="instagram"),
+ l1.OAuthTarget(provider="meta", app_id="facebook", auth_backend="composio"),
+ ]
+
+
def test_hidden_or_providerless_oauth_apps_are_not_targets() -> None:
catalog = [
_app("slack", "slack", "builtin_oauth", is_visible_in_connector=False),
@@ -284,6 +322,105 @@ def test_callback_check_fails_when_the_launch_start_is_refused() -> None:
assert "Unsupported provider" in result.reason
+# --- Composio begin (from the launch redeem) -----------------------------------
+
+SHARED_COMPOSIO_ORIGIN = "https://global.example.net"
+COMPOSIO_BEGIN = f"{SHARED_COMPOSIO_ORIGIN}/api/auth/meta/callback?state=signed-state"
+
+
+def test_a_composio_begin_on_the_shared_origin_passes() -> None:
+ result = l1.check_composio_callback(
+ "salesforce",
+ status_code=307,
+ location=COMPOSIO_BEGIN,
+ body="",
+ expected_origin=SHARED_COMPOSIO_ORIGIN,
+ )
+
+ assert result.ok
+ assert result.name == "oauth:salesforce:composio"
+
+
+def test_a_composio_begin_behind_a_proxy_prefix_passes() -> None:
+ # XAGENT_COMPOSIO_CALLBACK_URL may put a reverse proxy prefix before a
+ # callback path; so may the fallback Meta URL.
+ result = l1.check_composio_callback(
+ "salesforce",
+ status_code=307,
+ location=(
+ f"{SHARED_COMPOSIO_ORIGIN}/composio/auth/api/auth/meta/callback?state=s"
+ ),
+ body="",
+ expected_origin=SHARED_COMPOSIO_ORIGIN,
+ )
+
+ assert result.ok, result.reason
+
+
+def test_a_composio_begin_on_the_deployment_origin_fails() -> None:
+ result = l1.check_composio_callback(
+ "salesforce",
+ status_code=307,
+ location="https://cloud.example.com/api/auth/meta/callback?state=s",
+ body="",
+ expected_origin=SHARED_COMPOSIO_ORIGIN,
+ )
+
+ assert not result.ok
+ assert "callback origin is https://cloud.example.com" in result.reason
+ assert SHARED_COMPOSIO_ORIGIN in result.reason
+
+
+def test_a_composio_begin_without_a_state_fails() -> None:
+ result = l1.check_composio_callback(
+ "salesforce",
+ status_code=307,
+ location=f"{SHARED_COMPOSIO_ORIGIN}/api/auth/meta/callback",
+ body="",
+ expected_origin=SHARED_COMPOSIO_ORIGIN,
+ )
+
+ assert not result.ok
+ assert "state is missing" in result.reason
+
+
+def test_a_composio_begin_on_another_path_fails() -> None:
+ result = l1.check_composio_callback(
+ "salesforce",
+ status_code=307,
+ location=f"{SHARED_COMPOSIO_ORIGIN}/api/auth/salesforce/callback?state=s",
+ body="",
+ expected_origin=SHARED_COMPOSIO_ORIGIN,
+ )
+
+ assert not result.ok
+ assert "shared Composio callback path" in result.reason
+
+
+def test_a_refused_composio_redeem_fails_with_its_status() -> None:
+ result = l1.check_composio_callback(
+ "salesforce",
+ status_code=500,
+ location=None,
+ body="<h1>Error: OAuth provider not configured</h1>",
+ expected_origin=SHARED_COMPOSIO_ORIGIN,
+ )
+
+ assert not result.ok
+ assert "HTTP 500" in result.reason
+
+
+def test_a_launch_start_callback_origin_is_normalized() -> None:
+ payload = {
+ "authorization_url": "/api/auth/meta/login?ticket=x",
+ "callback_origin": "https://Global.Example.net:443",
+ }
+
+ assert l1.start_callback_origin(payload) == SHARED_COMPOSIO_ORIGIN
+ assert l1.start_callback_origin("not a mapping") is None
+ assert l1.start_callback_origin({}) is None
+
+
# --- authorization redirect (from the launch redeem) ----------------------------
AUTHORIZE = "https://slack.com/oauth/v2/authorize"
diff --git a/tests/web/test_composio_provider_only.py b/tests/web/test_composio_provider_only.py
new file mode 100644
index 000000000..f6d00ea7f
--- /dev/null
+++ b/tests/web/test_composio_provider_only.py
@@ -0,0 +1,175 @@
+"""A provider is Composio-only only when every app it serves is."""
+
+from __future__ import annotations
+
+import pytest
+
+from xagent.web import composio_apps
+
+SWITCHES = (
+ (
+ composio_apps.FACEBOOK_AUTH_BACKEND_ENV,
+ composio_apps.COMPOSIO_FACEBOOK_AUTH_CONFIG_ID_ENV,
+ ),
+ (
+ composio_apps.INSTAGRAM_AUTH_BACKEND_ENV,
+ composio_apps.COMPOSIO_INSTAGRAM_AUTH_CONFIG_ID_ENV,
+ ),
+ (
+ composio_apps.GMAIL_AUTH_BACKEND_ENV,
+ composio_apps.COMPOSIO_GMAIL_AUTH_CONFIG_ID_ENV,
+ ),
+ (
+ composio_apps.GOOGLE_DRIVE_AUTH_BACKEND_ENV,
+ composio_apps.COMPOSIO_GOOGLE_DRIVE_AUTH_CONFIG_ID_ENV,
+ ),
+ (
+ composio_apps.SALESFORCE_AUTH_BACKEND_ENV,
+ composio_apps.COMPOSIO_SALESFORCE_AUTH_CONFIG_ID_ENV,
+ ),
+)
+
+
[email protected](autouse=True)
+def clean_env(monkeypatch):
+ for switch, auth_config in SWITCHES:
+ monkeypatch.delenv(switch, raising=False)
+ monkeypatch.delenv(auth_config, raising=False)
+ monkeypatch.delenv(composio_apps.COMPOSIO_API_KEY_ENV, raising=False)
+ monkeypatch.delenv(composio_apps.COMPOSIO_USER_ID_SECRET_ENV, raising=False)
+ composio_apps._WARNED_BACKENDS.clear()
+
+
+def _on(monkeypatch, switch, auth_config, *, api_key="key"):
+ monkeypatch.setenv(switch, "composio")
+ monkeypatch.setenv(auth_config, "ac_test")
+ monkeypatch.setenv(composio_apps.COMPOSIO_USER_ID_SECRET_ENV, "secret")
+ if api_key is not None:
+ monkeypatch.setenv(composio_apps.COMPOSIO_API_KEY_ENV, api_key)
+
+
+def test_every_app_on_makes_the_provider_composio_only(monkeypatch):
+ _on(
+ monkeypatch,
+ composio_apps.SALESFORCE_AUTH_BACKEND_ENV,
+ composio_apps.COMPOSIO_SALESFORCE_AUTH_CONFIG_ID_ENV,
+ )
+
+ assert composio_apps.provider_is_composio_only("salesforce", ["salesforce"])
+
+
+def test_one_app_off_keeps_the_native_client(monkeypatch):
+ _on(
+ monkeypatch,
+ composio_apps.SALESFORCE_AUTH_BACKEND_ENV,
+ composio_apps.COMPOSIO_SALESFORCE_AUTH_CONFIG_ID_ENV,
+ )
+ extra = composio_apps.COMPOSIO_APPS["salesforce"]._replace(
+ app_id="salesforce-extra", backend_env="XAGENT_SALESFORCE_EXTRA_AUTH_BACKEND"
+ )
+ monkeypatch.setitem(composio_apps.COMPOSIO_APPS, "salesforce-extra", extra)
+ monkeypatch.delenv(extra.backend_env, raising=False)
+ assert composio_apps.provider_is_composio_only("salesforce", ["salesforce"])
+
+ assert not composio_apps.provider_is_composio_only(
+ "salesforce", ["salesforce", "salesforce-extra"]
+ )
+
+
+def test_a_switched_on_app_whose_web_connect_stays_native_keeps_the_native_client(
+ monkeypatch,
+):
+ """Every app's switch is on, yet one web connect does not go through Composio."""
+ _on(
+ monkeypatch,
+ composio_apps.SALESFORCE_AUTH_BACKEND_ENV,
+ composio_apps.COMPOSIO_SALESFORCE_AUTH_CONFIG_ID_ENV,
+ )
+ extra = composio_apps.COMPOSIO_APPS["salesforce"]._replace(
+ app_id="salesforce-extra", web_start=False
+ )
+ monkeypatch.setitem(composio_apps.COMPOSIO_APPS, "salesforce-extra", extra)
+
+ assert not composio_apps.provider_is_composio_only(
+ "salesforce", ["salesforce", "salesforce-extra"]
+ )
+
+
+def test_one_app_without_a_composio_app_keeps_the_native_client(monkeypatch):
+ _on(
+ monkeypatch,
+ composio_apps.SALESFORCE_AUTH_BACKEND_ENV,
+ composio_apps.COMPOSIO_SALESFORCE_AUTH_CONFIG_ID_ENV,
+ )
+
+ assert not composio_apps.provider_is_composio_only(
+ "salesforce", ["salesforce", "salesforce-admin"]
+ )
+
+
+def test_a_provider_with_a_native_only_app_is_never_composio_only(monkeypatch):
+ _on(
+ monkeypatch,
+ composio_apps.GMAIL_AUTH_BACKEND_ENV,
+ composio_apps.COMPOSIO_GMAIL_AUTH_CONFIG_ID_ENV,
+ )
+ _on(
+ monkeypatch,
+ composio_apps.GOOGLE_DRIVE_AUTH_BACKEND_ENV,
+ composio_apps.COMPOSIO_GOOGLE_DRIVE_AUTH_CONFIG_ID_ENV,
+ )
+ _on(
+ monkeypatch,
+ composio_apps.FACEBOOK_AUTH_BACKEND_ENV,
+ composio_apps.COMPOSIO_FACEBOOK_AUTH_CONFIG_ID_ENV,
+ )
+ _on(
+ monkeypatch,
+ composio_apps.INSTAGRAM_AUTH_BACKEND_ENV,
+ composio_apps.COMPOSIO_INSTAGRAM_AUTH_CONFIG_ID_ENV,
+ )
+
+ assert not composio_apps.provider_is_composio_only(
+ "google", ["gmail", "google-drive", "google-calendar"]
+ )
+ assert not composio_apps.provider_is_composio_only(
+ "meta", ["facebook", "instagram", "meta-ads", "whatsapp"]
+ )
+
+
+def test_missing_composio_config_keeps_the_native_client(monkeypatch):
+ _on(
+ monkeypatch,
+ composio_apps.SALESFORCE_AUTH_BACKEND_ENV,
+ composio_apps.COMPOSIO_SALESFORCE_AUTH_CONFIG_ID_ENV,
+ api_key=None,
+ )
+
+ assert not composio_apps.provider_is_composio_only("salesforce", ["salesforce"])
+
+
+def test_the_real_registry_keeps_google_and_meta_native(monkeypatch):
+ from xagent.web.builtin_mcp_registry import get_builtin_public_mcp_app_rows
+
+ for switch, auth_config in SWITCHES:
+ _on(monkeypatch, switch, auth_config)
+ rows = get_builtin_public_mcp_app_rows()
+
+ def app_ids(provider: str) -> list[str]:
+ return [
+ str(row["app_id"]) for row in rows if row.get("provider_name") == provider
+ ]
+
+ assert not composio_apps.provider_is_composio_only("google", app_ids("google"))
+ assert not composio_apps.provider_is_composio_only("meta", app_ids("meta"))
+ assert composio_apps.provider_is_composio_only("salesforce", app_ids("salesforce"))
+
+
+def test_a_provider_without_apps_is_not_composio_only(monkeypatch):
+ _on(
+ monkeypatch,
+ composio_apps.SALESFORCE_AUTH_BACKEND_ENV,
+ composio_apps.COMPOSIO_SALESFORCE_AUTH_CONFIG_ID_ENV,
+ )
+
+ assert not composio_apps.provider_is_composio_only("salesforce", [])
diff --git a/tests/web/test_composio_salesforce_connect.py b/tests/web/test_composio_salesforce_connect.py
index fa4906f52..ab4ba5974 100644
--- a/tests/web/test_composio_salesforce_connect.py
+++ b/tests/web/test_composio_salesforce_connect.py
@@ -874,3 +874,28 @@ def test_other_apps_on_composio_carry_no_connect_guidance(salesforce):
assert [
app_id for app_id, entry in entries.items() if "connect_guidance" in entry
] == ["salesforce"]
+
+
+# --- Catalog auth backend -------------------------------------------------------
+
+
+def test_the_catalog_marks_only_an_app_whose_web_connect_is_on_composio(salesforce):
+ db, _user, _composio = salesforce
+ from xagent.web.mcp_apps import get_all_mcp_apps
+
+ entries = {entry["id"]: entry for entry in get_all_mcp_apps(db)}
+
+ assert entries["salesforce"]["auth_backend"] == "composio"
+ # Facebook's switch is on too; its web connect stays native.
+ assert "auth_backend" not in entries["facebook"]
+
+
[email protected]("backend", [None, "native", "other"])
+def test_a_native_app_has_no_auth_backend(salesforce, monkeypatch, backend):
+ db, _user, _composio = salesforce
+ if backend is None:
+ monkeypatch.delenv("XAGENT_SALESFORCE_AUTH_BACKEND")
+ else:
+ monkeypatch.setenv("XAGENT_SALESFORCE_AUTH_BACKEND", backend)
+
+ assert "auth_backend" not in _catalog_entry(db, "salesforce")
diff --git a/tests/web/test_oauth_client_verification.py b/tests/web/test_oauth_client_verification.py
index 56954e453..612fff5eb 100644
--- a/tests/web/test_oauth_client_verification.py
+++ b/tests/web/test_oauth_client_verification.py
@@ -246,6 +246,66 @@ def test_an_unverifiable_provider_sends_nothing(monkeypatch, provider):
assert sent == []
+def test_a_composio_only_provider_is_unverifiable_without_a_request(monkeypatch):
+ monkeypatch.setenv("XAGENT_SALESFORCE_AUTH_BACKEND", "composio")
+ monkeypatch.setenv("COMPOSIO_API_KEY", "key")
+ monkeypatch.setenv("COMPOSIO_SALESFORCE_AUTH_CONFIG_ID", "ac_test")
+ monkeypatch.setenv("COMPOSIO_USER_ID_SECRET", "secret")
+ sent = _vendor(monkeypatch, 400, {"error": "invalid_client_id"})
+
+ result = asyncio.run(
+ verification.verify_builtin_provider("salesforce", _row("salesforce"))
+ )
+
+ assert result.verdict == "unverifiable"
+ assert result.detail == "connects through Composio"
+ assert sent == []
+
+
+def test_a_provider_whose_web_connects_stay_native_is_still_verified(monkeypatch):
+ monkeypatch.setenv("XAGENT_FACEBOOK_AUTH_BACKEND", "composio")
+ monkeypatch.setenv("COMPOSIO_FACEBOOK_AUTH_CONFIG_ID", "ac_facebook")
+ monkeypatch.setenv("XAGENT_INSTAGRAM_AUTH_BACKEND", "composio")
+ monkeypatch.setenv("COMPOSIO_INSTAGRAM_AUTH_CONFIG_ID", "ac_instagram")
+ monkeypatch.setenv("COMPOSIO_API_KEY", "key")
+ monkeypatch.setenv("COMPOSIO_USER_ID_SECRET", "secret")
+ sent = _vendor(monkeypatch, *DOCUMENTED_OK["meta"])
+
+ result = asyncio.run(verification.verify_builtin_provider("meta", _row("meta")))
+
+ assert result.verdict == "client_ok"
+ assert len(sent) == 1
+
+
+def test_excluding_a_composio_only_provider_is_valid(monkeypatch):
+ monkeypatch.setenv("XAGENT_SALESFORCE_AUTH_BACKEND", "composio")
+ monkeypatch.setenv("COMPOSIO_API_KEY", "key")
+ monkeypatch.setenv("COMPOSIO_SALESFORCE_AUTH_CONFIG_ID", "ac_test")
+ monkeypatch.setenv("COMPOSIO_USER_ID_SECRET", "secret")
+
+ excluded = asyncio.run(
+ verification.verify_all(
+ [],
+ builtin_providers=["salesforce"],
+ mcp_apps=[],
+ exclude={"salesforce"},
+ )
+ )
+ kept = asyncio.run(
+ verification.verify_all(
+ [],
+ builtin_providers=["salesforce"],
+ mcp_apps=[],
+ exclude=set(),
+ )
+ )
+
+ assert excluded == []
+ assert [(result.name, result.verdict, result.detail) for result in kept] == [
+ ("salesforce", "unverifiable", "connects through Composio")
+ ]
+
+
def test_a_missing_credential_is_left_to_oauth_readiness(monkeypatch):
sent = _vendor(monkeypatch, 400, {"error": "invalid_client"})
row = _row("xero")
diff --git a/tests/web/test_oauth_readiness.py b/tests/web/test_oauth_readiness.py
index d6545919d..7e4b1bd84 100644
--- a/tests/web/test_oauth_readiness.py
+++ b/tests/web/test_oauth_readiness.py
@@ -143,6 +143,9 @@ def test_format_reports_status_and_source_only():
ready = oauth_readiness.ProviderReadiness("google", True, "row", "env")
missing = oauth_readiness.ProviderReadiness("zoom", True, "env", "missing")
no_row = oauth_readiness.ProviderReadiness("jira", False, "env", "env")
+ composio = oauth_readiness.ProviderReadiness(
+ "salesforce", False, "missing", "missing", composio_only=True
+ )
assert (
oauth_readiness.format_result(ready)
@@ -155,6 +158,44 @@ def test_format_reports_status_and_source_only():
assert oauth_readiness.format_result(no_row) == (
"FAIL oauth-client:jira: no provider row"
)
+ assert oauth_readiness.format_result(composio) == (
+ "SKIP oauth-client:salesforce: connects through Composio"
+ )
+
+
+def _set_composio_only(monkeypatch):
+ monkeypatch.setenv("XAGENT_SALESFORCE_AUTH_BACKEND", "composio")
+ monkeypatch.setenv("COMPOSIO_API_KEY", "key")
+ monkeypatch.setenv("COMPOSIO_SALESFORCE_AUTH_CONFIG_ID", "ac_test")
+ monkeypatch.setenv("COMPOSIO_USER_ID_SECRET", "secret")
+
+
+def test_a_composio_only_provider_needs_no_row_or_credentials(monkeypatch):
+ _set_composio_only(monkeypatch)
+
+ result = oauth_readiness.check_provider("salesforce", None)
+
+ assert result.composio_only
+ assert not result.ready
+ assert oauth_readiness.format_result(result) == (
+ "SKIP oauth-client:salesforce: connects through Composio"
+ )
+
+
+def test_a_provider_whose_web_connects_stay_native_is_not_skipped(monkeypatch):
+ monkeypatch.setenv("XAGENT_GMAIL_AUTH_BACKEND", "composio")
+ monkeypatch.setenv("COMPOSIO_GMAIL_AUTH_CONFIG_ID", "ac_gmail")
+ monkeypatch.setenv("XAGENT_GOOGLE_DRIVE_AUTH_BACKEND", "composio")
+ monkeypatch.setenv("COMPOSIO_GOOGLE_DRIVE_AUTH_CONFIG_ID", "ac_drive")
+ monkeypatch.setenv("COMPOSIO_API_KEY", "key")
+ monkeypatch.setenv("COMPOSIO_USER_ID_SECRET", "secret")
+
+ result = oauth_readiness.check_provider("google", None)
+
+ assert not result.composio_only
+ assert oauth_readiness.format_result(result) == (
+ "FAIL oauth-client:google: no provider row"
+ )
@pytest.fixture
@@ -253,6 +294,22 @@ def test_main_passes_when_every_provider_is_ready(database, monkeypatch):
assert output.splitlines()[-1] == f"{len(BUILTIN_PROVIDERS)} checks, 0 failed"
+def test_main_skips_a_composio_only_provider(database, monkeypatch):
+ for provider in BUILTIN_PROVIDERS:
+ if provider != "salesforce":
+ _add_provider(database, provider, "row-id", "row-secret")
+ database.commit()
+ _set_composio_only(monkeypatch)
+
+ code, output = _run()
+
+ assert code == 0
+ assert "SKIP oauth-client:salesforce: connects through Composio" in (
+ output.splitlines()
+ )
+ assert output.splitlines()[-1] == f"{len(BUILTIN_PROVIDERS)} checks, 0 failed"
+
+
def test_main_excludes_providers(database, monkeypatch):
for provider in BUILTIN_PROVIDERS:
if provider not in {"zoom", "xero"}: