Skip to content

Automate browser based workflows with AI

Copilot uses a saved credential matching the login site automatically; credential create/update APIs accept tested_url (#7683)

pedrohsdbc9aabd38014f
diff --git a/docs/api-reference/openapi.json b/docs/api-reference/openapi.json
index 61b4cee30..2d03dd913 100644
--- a/docs/api-reference/openapi.json
+++ b/docs/api-reference/openapi.json
@@ -11222,6 +11222,18 @@
"title": "Rotate Proxy Session Id",
"description": "Rotate the Skyvern-managed proxy sticky-session id when updating this credential.",
"default": false
+ },
+ "tested_url": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "title": "Tested Url",
+ "description": "Login page URL used during the credential test"
}
},
"type": "object",
diff --git a/skyvern/client/client.py b/skyvern/client/client.py
index a76bd2074..db102f1d0 100644
--- a/skyvern/client/client.py
+++ b/skyvern/client/client.py
@@ -2490,6 +2490,7 @@ class Skyvern:
proxy_location: typing.Optional[CreateCredentialRequestProxyLocation] = OMIT,
proxy_session_id: typing.Optional[str] = OMIT,
rotate_proxy_session_id: typing.Optional[bool] = OMIT,
+ tested_url: typing.Optional[str] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> CredentialResponse:
"""
@@ -2518,6 +2519,9 @@ class Skyvern:
rotate_proxy_session_id : typing.Optional[bool]
Rotate the Skyvern-managed proxy sticky-session id when updating this credential.
+ tested_url : typing.Optional[str]
+ Login page URL used during the credential test
+
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
@@ -2550,6 +2554,7 @@ class Skyvern:
proxy_location=proxy_location,
proxy_session_id=proxy_session_id,
rotate_proxy_session_id=rotate_proxy_session_id,
+ tested_url=tested_url,
request_options=request_options,
)
return _response.data
@@ -2565,6 +2570,7 @@ class Skyvern:
proxy_location: typing.Optional[CreateCredentialRequestProxyLocation] = OMIT,
proxy_session_id: typing.Optional[str] = OMIT,
rotate_proxy_session_id: typing.Optional[bool] = OMIT,
+ tested_url: typing.Optional[str] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> CredentialResponse:
"""
@@ -2596,6 +2602,9 @@ class Skyvern:
rotate_proxy_session_id : typing.Optional[bool]
Rotate the Skyvern-managed proxy sticky-session id when updating this credential.
+ tested_url : typing.Optional[str]
+ Login page URL used during the credential test
+
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
@@ -2630,6 +2639,7 @@ class Skyvern:
proxy_location=proxy_location,
proxy_session_id=proxy_session_id,
rotate_proxy_session_id=rotate_proxy_session_id,
+ tested_url=tested_url,
request_options=request_options,
)
return _response.data
@@ -6678,6 +6688,7 @@ class AsyncSkyvern:
proxy_location: typing.Optional[CreateCredentialRequestProxyLocation] = OMIT,
proxy_session_id: typing.Optional[str] = OMIT,
rotate_proxy_session_id: typing.Optional[bool] = OMIT,
+ tested_url: typing.Optional[str] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> CredentialResponse:
"""
@@ -6706,6 +6717,9 @@ class AsyncSkyvern:
rotate_proxy_session_id : typing.Optional[bool]
Rotate the Skyvern-managed proxy sticky-session id when updating this credential.
+ tested_url : typing.Optional[str]
+ Login page URL used during the credential test
+
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
@@ -6746,6 +6760,7 @@ class AsyncSkyvern:
proxy_location=proxy_location,
proxy_session_id=proxy_session_id,
rotate_proxy_session_id=rotate_proxy_session_id,
+ tested_url=tested_url,
request_options=request_options,
)
return _response.data
@@ -6761,6 +6776,7 @@ class AsyncSkyvern:
proxy_location: typing.Optional[CreateCredentialRequestProxyLocation] = OMIT,
proxy_session_id: typing.Optional[str] = OMIT,
rotate_proxy_session_id: typing.Optional[bool] = OMIT,
+ tested_url: typing.Optional[str] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> CredentialResponse:
"""
@@ -6792,6 +6808,9 @@ class AsyncSkyvern:
rotate_proxy_session_id : typing.Optional[bool]
Rotate the Skyvern-managed proxy sticky-session id when updating this credential.
+ tested_url : typing.Optional[str]
+ Login page URL used during the credential test
+
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
@@ -6834,6 +6853,7 @@ class AsyncSkyvern:
proxy_location=proxy_location,
proxy_session_id=proxy_session_id,
rotate_proxy_session_id=rotate_proxy_session_id,
+ tested_url=tested_url,
request_options=request_options,
)
return _response.data
diff --git a/skyvern/client/raw_client.py b/skyvern/client/raw_client.py
index 2b386f51d..66b8141a3 100644
--- a/skyvern/client/raw_client.py
+++ b/skyvern/client/raw_client.py
@@ -3762,6 +3762,7 @@ class RawSkyvern:
proxy_location: typing.Optional[CreateCredentialRequestProxyLocation] = OMIT,
proxy_session_id: typing.Optional[str] = OMIT,
rotate_proxy_session_id: typing.Optional[bool] = OMIT,
+ tested_url: typing.Optional[str] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> HttpResponse[CredentialResponse]:
"""
@@ -3790,6 +3791,9 @@ class RawSkyvern:
rotate_proxy_session_id : typing.Optional[bool]
Rotate the Skyvern-managed proxy sticky-session id when updating this credential.
+ tested_url : typing.Optional[str]
+ Login page URL used during the credential test
+
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
@@ -3813,6 +3817,7 @@ class RawSkyvern:
),
"proxy_session_id": proxy_session_id,
"rotate_proxy_session_id": rotate_proxy_session_id,
+ "tested_url": tested_url,
},
headers={
"content-type": "application/json",
@@ -3857,6 +3862,7 @@ class RawSkyvern:
proxy_location: typing.Optional[CreateCredentialRequestProxyLocation] = OMIT,
proxy_session_id: typing.Optional[str] = OMIT,
rotate_proxy_session_id: typing.Optional[bool] = OMIT,
+ tested_url: typing.Optional[str] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> HttpResponse[CredentialResponse]:
"""
@@ -3888,6 +3894,9 @@ class RawSkyvern:
rotate_proxy_session_id : typing.Optional[bool]
Rotate the Skyvern-managed proxy sticky-session id when updating this credential.
+ tested_url : typing.Optional[str]
+ Login page URL used during the credential test
+
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
@@ -3911,6 +3920,7 @@ class RawSkyvern:
),
"proxy_session_id": proxy_session_id,
"rotate_proxy_session_id": rotate_proxy_session_id,
+ "tested_url": tested_url,
},
headers={
"content-type": "application/json",
@@ -9352,6 +9362,7 @@ class AsyncRawSkyvern:
proxy_location: typing.Optional[CreateCredentialRequestProxyLocation] = OMIT,
proxy_session_id: typing.Optional[str] = OMIT,
rotate_proxy_session_id: typing.Optional[bool] = OMIT,
+ tested_url: typing.Optional[str] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> AsyncHttpResponse[CredentialResponse]:
"""
@@ -9380,6 +9391,9 @@ class AsyncRawSkyvern:
rotate_proxy_session_id : typing.Optional[bool]
Rotate the Skyvern-managed proxy sticky-session id when updating this credential.
+ tested_url : typing.Optional[str]
+ Login page URL used during the credential test
+
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
@@ -9403,6 +9417,7 @@ class AsyncRawSkyvern:
),
"proxy_session_id": proxy_session_id,
"rotate_proxy_session_id": rotate_proxy_session_id,
+ "tested_url": tested_url,
},
headers={
"content-type": "application/json",
@@ -9447,6 +9462,7 @@ class AsyncRawSkyvern:
proxy_location: typing.Optional[CreateCredentialRequestProxyLocation] = OMIT,
proxy_session_id: typing.Optional[str] = OMIT,
rotate_proxy_session_id: typing.Optional[bool] = OMIT,
+ tested_url: typing.Optional[str] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> AsyncHttpResponse[CredentialResponse]:
"""
@@ -9478,6 +9494,9 @@ class AsyncRawSkyvern:
rotate_proxy_session_id : typing.Optional[bool]
Rotate the Skyvern-managed proxy sticky-session id when updating this credential.
+ tested_url : typing.Optional[str]
+ Login page URL used during the credential test
+
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
@@ -9501,6 +9520,7 @@ class AsyncRawSkyvern:
),
"proxy_session_id": proxy_session_id,
"rotate_proxy_session_id": rotate_proxy_session_id,
+ "tested_url": tested_url,
},
headers={
"content-type": "application/json",
diff --git a/skyvern/client/types/create_credential_request.py b/skyvern/client/types/create_credential_request.py
index 4cd292770..3077b16d9 100644
--- a/skyvern/client/types/create_credential_request.py
+++ b/skyvern/client/types/create_credential_request.py
@@ -50,6 +50,11 @@ class CreateCredentialRequest(UniversalBaseModel):
Rotate the Skyvern-managed proxy sticky-session id when updating this credential.
"""
+ tested_url: typing.Optional[str] = pydantic.Field(default=None)
+ """
+ Login page URL used during the credential test
+ """
+
if IS_PYDANTIC_V2:
model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2
else:
diff --git a/skyvern/forge/sdk/copilot/request_policy.py b/skyvern/forge/sdk/copilot/request_policy.py
index e47b1c927..abc4d83c2 100644
--- a/skyvern/forge/sdk/copilot/request_policy.py
+++ b/skyvern/forge/sdk/copilot/request_policy.py
@@ -8,7 +8,7 @@ import re
import time
from dataclasses import dataclass, field, replace
from typing import Any, Literal, cast, get_args
-from urllib.parse import urlparse
+from urllib.parse import parse_qsl, urlencode, urlparse
import structlog
@@ -43,7 +43,7 @@ from skyvern.forge.sdk.copilot.workflow_credential_utils import (
workflow_credential_ids,
workflow_credential_origins,
)
-from skyvern.forge.sdk.schemas.credentials import Credential
+from skyvern.forge.sdk.schemas.credentials import Credential, CredentialType
from skyvern.forge.sdk.schemas.workflow_copilot import (
WorkflowCopilotChatHistoryMessage,
WorkflowCopilotChatSender,
@@ -161,6 +161,7 @@ _STORED_CREDENTIAL_URL_QUESTION_STABLE_PREFIX = (
"Which website or login page should I use to look up the stored credential?"
)
_STORED_CREDENTIAL_URL_QUESTION = f"{_STORED_CREDENTIAL_URL_QUESTION_STABLE_PREFIX} {_CREDENTIALS_UI_DIRECTIONS}"
+_AMBIGUOUS_URL_CREDENTIAL_QUESTION = "I found multiple stored credentials for that login page. Which one should I use?"
_CREDENTIAL_ID_RE = re.compile(r"\bcred_[A-Za-z0-9][A-Za-z0-9_-]*\b")
# A credential ID typed with the wrong separator (`cred 530…`, `cred-530…`). The
# digit-only body and length floor keep this off prose like `cred and the password`.
@@ -3823,17 +3824,25 @@ def _url_parts(url: str) -> tuple[str, str] | None:
return None
host = parsed.netloc.lower()
path = parsed.path.rstrip("/")
- return f"{parsed.scheme.lower()}://{host}{path}", f"{parsed.scheme.lower()}://{host}"
-
-
-def _match_by_url(credentials: list[Credential], urls: list[str]) -> list[Credential]:
+ # Login pages can differ only by query (?tenant=a vs ?tenant=b), so the
+ # exact tier keys on the full URL with a param-order-insensitive query.
+ query = urlencode(sorted(parse_qsl(parsed.query, keep_blank_values=True)))
+ exact = f"{parsed.scheme.lower()}://{host}{path}"
+ if query:
+ exact = f"{exact}?{query}"
+ return exact, f"{parsed.scheme.lower()}://{host}"
+
+
+def _match_by_url(
+ credentials: list[Credential], urls: list[str], *, allow_host_fallback: bool = True
+) -> list[Credential]:
indexed = [
(credential, parts)
for credential in credentials
if credential.tested_url and (parts := _url_parts(credential.tested_url))
]
requested = [parts for url in urls if (parts := _url_parts(url))]
- for index in range(2):
+ for index in range(2 if allow_host_fallback else 1):
matches = [
credential for credential, parts in indexed if any(parts[index] == target[index] for target in requested)
]
@@ -3842,6 +3851,16 @@ def _match_by_url(credentials: list[Credential], urls: list[str]) -> list[Creden
return []
+def _login_url_candidates(policy: RequestPolicy, user_message: str) -> list[str]:
+ if policy.login_page_urls:
+ return _clean_list(policy.login_page_urls)
+ candidates = _clean_list([candidate.rstrip(".,;:!?") for candidate in URL_CANDIDATE_RE.findall(user_message)])
+ candidate_hosts = {parts[1] for candidate in candidates if (parts := _url_parts(candidate))}
+ if len(candidate_hosts) > 1:
+ return []
+ return candidates
+
+
_CLARIFICATION_DECISION_PREFIX = "request-policy clarification required:"
_PRIOR_CREDENTIAL_CLARIFICATION_REASONS = frozenset(
{
@@ -4073,6 +4092,7 @@ async def _resolve_credentials(
policy: RequestPolicy,
organization_id: str,
*,
+ user_message: str,
defer_unresolved_credential_name: bool = False,
) -> None:
if policy.credential_input_kind == "credential_id":
@@ -4112,7 +4132,43 @@ async def _resolve_credentials(
reason="missing_target_context",
)
return
- if policy.credential_input_kind not in ("credential_name", "website_stored_credential"):
+ if policy.credential_input_kind not in ("credential_name", "website_stored_credential", "none"):
+ return
+
+ if policy.credential_input_kind == "none":
+ if not policy.login_intent or policy.raw_secret_detected:
+ return
+ if policy.testing_intent == "skip_test" or policy.allow_missing_credentials_in_draft:
+ return
+ candidates = _login_url_candidates(policy, user_message)
+ if not candidates:
+ return
+ # Card/secret credentials can carry a tested_url too; a login turn
+ # must only ever auto-bind a password credential.
+ login_credentials = [
+ credential
+ for credential in await _load_credentials(organization_id)
+ if credential.credential_type == CredentialType.PASSWORD
+ ]
+ matches = _match_by_url(
+ login_credentials,
+ candidates,
+ # A URL merely mentioned in prose is a weaker signal than a
+ # classifier-extracted login page; require an exact tested-URL hit.
+ allow_host_fallback=bool(policy.login_page_urls),
+ )
+ if len(matches) == 1:
+ policy.resolved_credentials = matches
+ elif matches:
+ # Found-but-unbound keeps the unresolved-login override from
+ # relabeling this disambiguation ask as a missing-credential turn.
+ policy.discovered_credentials = matches
+ _block(
+ policy,
+ _AMBIGUOUS_URL_CREDENTIAL_QUESTION,
+ matches,
+ reason="credential_name_unresolved",
+ )
return
credentials = await _load_credentials(organization_id)
@@ -4148,7 +4204,7 @@ async def _resolve_credentials(
elif matches:
_block(
policy,
- "I found multiple stored credentials for that login page. Which one should I use?",
+ _AMBIGUOUS_URL_CREDENTIAL_QUESTION,
matches,
reason="credential_name_unresolved",
)
@@ -4381,6 +4437,7 @@ async def build_request_policy(
await _resolve_credentials(
policy,
organization_id,
+ user_message=user_message,
defer_unresolved_credential_name=_last_assistant_message_was_saved_credential_question(chat_history),
)
except Exception:
diff --git a/skyvern/forge/sdk/db/repositories/credentials.py b/skyvern/forge/sdk/db/repositories/credentials.py
index 5d47d4c38..bd53bf5b9 100644
--- a/skyvern/forge/sdk/db/repositories/credentials.py
+++ b/skyvern/forge/sdk/db/repositories/credentials.py
@@ -39,6 +39,7 @@ class CredentialRepository(BaseRepository):
card_brand: str | None,
totp_identifier: str | None = None,
secret_label: str | None = None,
+ tested_url: str | None = None,
proxy_location: ProxyLocationInput = None,
proxy_session_id: str | None = None,
) -> Credential:
@@ -60,6 +61,7 @@ class CredentialRepository(BaseRepository):
card_last4=card_last4,
card_brand=card_brand,
secret_label=secret_label,
+ tested_url=tested_url,
proxy_location=serialized_proxy_location,
proxy_session_id=proxy_session_id,
)
@@ -205,6 +207,7 @@ class CredentialRepository(BaseRepository):
card_last4: str | None = None,
card_brand: str | None = None,
secret_label: str | None = None,
+ tested_url: str | None = None,
proxy_location: ProxyLocationInput | object = _UNSET,
proxy_session_id: str | None | object = _UNSET,
rotate_proxy_session_id: bool = False,
@@ -230,6 +233,8 @@ class CredentialRepository(BaseRepository):
credential.card_last4 = card_last4
credential.card_brand = card_brand
credential.secret_label = secret_label
+ if tested_url is not None:
+ credential.tested_url = tested_url
apply_proxy_pin_to_model(
credential,
entity_id=credential_id,
diff --git a/skyvern/forge/sdk/schemas/credentials.py b/skyvern/forge/sdk/schemas/credentials.py
index b629dd625..5eb6cc147 100644
--- a/skyvern/forge/sdk/schemas/credentials.py
+++ b/skyvern/forge/sdk/schemas/credentials.py
@@ -235,6 +235,7 @@ class CreateCredentialRequest(BaseModel):
default=False,
description="Rotate the Skyvern-managed proxy sticky-session id when updating this credential.",
)
+ tested_url: str | None = Field(default=None, description="Login page URL used during the credential test")
@field_validator("proxy_location", mode="before")
@classmethod
diff --git a/skyvern/forge/sdk/services/credential/credential_vault_service.py b/skyvern/forge/sdk/services/credential/credential_vault_service.py
index a98a2a33c..47e91ad16 100644
--- a/skyvern/forge/sdk/services/credential/credential_vault_service.py
+++ b/skyvern/forge/sdk/services/credential/credential_vault_service.py
@@ -119,6 +119,7 @@ class CredentialVaultService(ABC):
totp_identifier=data.credential.totp_identifier,
card_last4=None,
card_brand=None,
+ tested_url=data.tested_url,
proxy_location=data.proxy_location,
proxy_session_id=data.proxy_session_id,
)
@@ -134,6 +135,7 @@ class CredentialVaultService(ABC):
card_last4=data.credential.card_number[-4:],
card_brand=data.credential.card_brand,
totp_identifier=None,
+ tested_url=data.tested_url,
proxy_location=data.proxy_location,
proxy_session_id=data.proxy_session_id,
)
@@ -150,6 +152,7 @@ class CredentialVaultService(ABC):
card_brand=None,
totp_identifier=None,
secret_label=data.credential.secret_label,
+ tested_url=data.tested_url,
proxy_location=data.proxy_location,
proxy_session_id=data.proxy_session_id,
)
@@ -182,6 +185,7 @@ class CredentialVaultService(ABC):
totp_identifier=data.credential.totp_identifier,
card_last4=None,
card_brand=None,
+ tested_url=data.tested_url,
**proxy_kwargs,
)
elif data.credential_type == CredentialType.CREDIT_CARD:
@@ -196,6 +200,7 @@ class CredentialVaultService(ABC):
card_last4=data.credential.card_number[-4:],
card_brand=data.credential.card_brand,
totp_identifier=None,
+ tested_url=data.tested_url,
**proxy_kwargs,
)
elif data.credential_type == CredentialType.SECRET:
@@ -211,6 +216,7 @@ class CredentialVaultService(ABC):
card_brand=None,
totp_identifier=None,
secret_label=data.credential.secret_label,
+ tested_url=data.tested_url,
**proxy_kwargs,
)
else:
diff --git a/tests/unit/test_copilot_request_policy_workflow_credentials.py b/tests/unit/test_copilot_request_policy_workflow_credentials.py
index 1f9238c40..d484ccc91 100644
--- a/tests/unit/test_copilot_request_policy_workflow_credentials.py
+++ b/tests/unit/test_copilot_request_policy_workflow_credentials.py
@@ -13,6 +13,7 @@ from skyvern.forge.sdk.copilot.context import (
record_approved_credentials_in_global_llm_context,
)
from skyvern.forge.sdk.copilot.request_policy import (
+ _LOGIN_CREDENTIAL_QUESTION,
CREDENTIAL_DEFERRED_DRAFT_REASONS,
CREDENTIAL_PROMPT_CLARIFICATION_REASONS,
RequestPolicy,
@@ -22,6 +23,7 @@ from skyvern.forge.sdk.copilot.request_policy import (
credential_prompt_reason,
)
from skyvern.forge.sdk.copilot.tools.credentials import _credential_run_approval_error
+from skyvern.forge.sdk.schemas.credentials import CredentialType
def _yaml(body: str) -> str:
@@ -450,8 +452,15 @@ async def test_request_policy_resolver_still_blocks_raw_secret_with_author_time_
assert policy.allow_run_blocks is False
-def _cred(name: str, credential_id: str, tested_url: str | None = None) -> SimpleNamespace:
- return SimpleNamespace(name=name, credential_id=credential_id, tested_url=tested_url)
+def _cred(
+ name: str,
+ credential_id: str,
+ tested_url: str | None = None,
+ credential_type: CredentialType = CredentialType.PASSWORD,
+) -> SimpleNamespace:
+ return SimpleNamespace(
+ name=name, credential_id=credential_id, tested_url=tested_url, credential_type=credential_type
+ )
async def _build_with_forced_classifier(
@@ -739,6 +748,290 @@ async def test_login_intent_without_credential_phrasing_asks_once_a_url_names_th
assert policy.clarification_question is not None
+async def test_login_intent_none_kind_one_message_url_with_single_match_resolves() -> None:
+ credential = _cred("portal-cred", "cred_url", tested_url="http://localhost:8941/analytics_console/")
+ policy = await _build_with_forced_classifier(
+ user_message="Sign in to http://localhost:8941/analytics_console/ and continue.",
+ classifier_policy=RequestPolicy(
+ login_intent=True,
+ credential_input_kind="none",
+ login_page_urls=[],
+ classifier_status="success",
+ ),
+ org_credentials=[credential],
+ )
+
+ assert policy.credential_input_kind == "none"
+ assert [c.credential_id for c in policy.resolved_credentials] == ["cred_url"]
+ assert policy.requires_user_clarification is False
+ assert policy.clarification_question is None
+
+
+async def test_login_intent_none_kind_multiple_host_matches_asks_pick_question() -> None:
+ first = _cred("portal-a", "cred_a", tested_url="http://localhost:8941/analytics_console/")
+ second = _cred("portal-b", "cred_b", tested_url="http://localhost:8941/analytics_console/")
+ policy = await _build_with_forced_classifier(
+ user_message="Sign in to http://localhost:8941/analytics_console/ and continue.",
+ classifier_policy=RequestPolicy(
+ login_intent=True,
+ credential_input_kind="none",
+ login_page_urls=[],
+ classifier_status="success",
+ ),
+ org_credentials=[first, second],
+ )
+
+ assert policy.credential_input_kind == "none"
+ assert policy.requires_user_clarification is True
+ assert policy.clarification_question is not None
+ assert (
+ "I found multiple stored credentials for that login page. Which one should I use?"
+ in policy.clarification_question
+ )
+ assert "`cred_a`" in policy.clarification_question
+ assert "`cred_b`" in policy.clarification_question
+ assert policy.clarification_reason == "credential_name_unresolved"
+
+
+async def test_login_intent_none_kind_prose_host_mention_does_not_bind() -> None:
+ credential = _cred("portal-cred", "cred_url", tested_url="https://example.com/login")
+ policy = await _build_with_forced_classifier(
+ user_message="Log into my account — the steps are documented at https://example.com/help if you need them.",
+ classifier_policy=RequestPolicy(
+ login_intent=True,
+ credential_input_kind="none",
+ login_page_urls=[],
+ classifier_status="success",
+ ),
+ org_credentials=[credential],
+ )
+
+ assert policy.resolved_credentials == []
+ assert policy.clarification_reason == "login_credentials_unresolved"
+ assert policy.clarification_question == _LOGIN_CREDENTIAL_QUESTION
+
+
+async def test_login_intent_none_kind_query_distinct_tenants_do_not_collapse() -> None:
+ tenant_a = _cred("tenant-a", "cred_a", tested_url="https://portal.example.com/login?tenant=a")
+ tenant_b = _cred("tenant-b", "cred_b", tested_url="https://portal.example.com/login?tenant=b")
+ policy = await _build_with_forced_classifier(
+ user_message="Sign in to https://portal.example.com/login?tenant=a and continue.",
+ classifier_policy=RequestPolicy(
+ login_intent=True,
+ credential_input_kind="none",
+ login_page_urls=[],
+ classifier_status="success",
+ ),
+ org_credentials=[tenant_a, tenant_b],
+ )
+
+ assert [c.credential_id for c in policy.resolved_credentials] == ["cred_a"]
+ assert policy.requires_user_clarification is False
+
+
+async def test_login_intent_none_kind_query_param_order_is_normalized() -> None:
+ credential = _cred("portal-cred", "cred_url", tested_url="https://portal.example.com/login?b=2&a=1")
+ policy = await _build_with_forced_classifier(
+ user_message="Sign in to https://portal.example.com/login?a=1&b=2 and continue.",
+ classifier_policy=RequestPolicy(
+ login_intent=True,
+ credential_input_kind="none",
+ login_page_urls=[],
+ classifier_status="success",
+ ),
+ org_credentials=[credential],
+ )
+
+ assert [c.credential_id for c in policy.resolved_credentials] == ["cred_url"]
+
+
+async def test_login_intent_none_kind_non_password_sole_match_does_not_bind() -> None:
+ card = _cred(
+ "corp-card",
+ "cred_card",
+ tested_url="https://portal.example.com/login",
+ credential_type=CredentialType.CREDIT_CARD,
+ )
+ policy = await _build_with_forced_classifier(
+ user_message="Sign in to https://portal.example.com/login and continue.",
+ classifier_policy=RequestPolicy(
+ login_intent=True,
+ credential_input_kind="none",
+ login_page_urls=[],
+ classifier_status="success",
+ ),
+ org_credentials=[card],
+ )
+
+ assert policy.resolved_credentials == []
+ assert policy.clarification_reason == "login_credentials_unresolved"
+ assert policy.clarification_question == _LOGIN_CREDENTIAL_QUESTION
+
+
+async def test_login_intent_none_kind_classifier_url_keeps_host_fallback() -> None:
+ credential = _cred("portal-cred", "cred_url", tested_url="https://example.com/login")
+ policy = await _build_with_forced_classifier(
+ user_message="Log into the portal and pull this week's report.",
+ classifier_policy=RequestPolicy(
+ login_intent=True,
+ credential_input_kind="none",
+ login_page_urls=["https://example.com/portal"],
+ classifier_status="success",
+ ),
+ org_credentials=[credential],
+ )
+
+ assert [c.credential_id for c in policy.resolved_credentials] == ["cred_url"]
+ assert policy.requires_user_clarification is False
+
+
+async def test_login_intent_none_kind_zero_url_matches_keeps_existing_login_unresolved_text() -> None:
+ policy = await _build_with_forced_classifier(
+ user_message="Sign in to http://localhost:8941/analytics_console/ and continue.",
+ classifier_policy=RequestPolicy(
+ login_intent=True,
+ credential_input_kind="none",
+ login_page_urls=[],
+ classifier_status="success",
+ ),
+ org_credentials=[_cred("other", "cred_other", tested_url="http://localhost:8999/other")],
+ )
+
+ assert policy.resolved_credentials == []
+ assert policy.clarification_reason == "login_credentials_unresolved"
+ assert policy.clarification_question == _LOGIN_CREDENTIAL_QUESTION
+
+
+async def test_login_intent_none_kind_multi_host_message_skips_resolution() -> None:
+ policy = await _build_with_forced_classifier(
+ user_message="Sign in to http://localhost:8941/analytics_console/ then check https://example.org/login.",
+ classifier_policy=RequestPolicy(
+ login_intent=True,
+ credential_input_kind="none",
+ login_page_urls=[],
+ classifier_status="success",
+ ),
+ org_credentials=[_cred("portal", "cred_url", tested_url="http://localhost:8941/analytics_console/")],
+ )
+
+ assert policy.resolved_credentials == []
+ assert policy.clarification_reason == "login_credentials_unresolved"
+ assert policy.clarification_question == _LOGIN_CREDENTIAL_QUESTION
+
+
+async def test_login_intent_none_kind_message_url_trailing_punctuation_still_matches() -> None:
+ credential = _cred("portal-cred", "cred_url", tested_url="http://localhost:8941/analytics_console/")
+ policy = await _build_with_forced_classifier(
+ user_message="Sign in to http://localhost:8941/analytics_console/.",
+ classifier_policy=RequestPolicy(
+ login_intent=True,
+ credential_input_kind="none",
+ login_page_urls=[],
+ classifier_status="success",
+ ),
+ org_credentials=[credential],
+ )
+
+ assert [c.credential_id for c in policy.resolved_credentials] == ["cred_url"]
+ assert policy.credential_input_kind == "none"
+
+
+async def test_login_intent_none_kind_bare_host_message_does_not_trigger_url_resolution() -> None:
+ policy = await _build_with_forced_classifier(
+ user_message="Log into portal.example.com and continue.",
+ classifier_policy=RequestPolicy(
+ login_intent=True,
+ credential_input_kind="none",
+ login_page_urls=[],
+ classifier_status="success",
+ ),
+ org_credentials=[_cred("portal", "cred_url", tested_url="https://portal.example.com/login")],
+ )
+
+ assert policy.resolved_credentials == []
+ assert policy.clarification_reason != "login_credentials_unresolved"
+ assert policy.user_response_policy == "proceed"
+
+
+async def test_login_intent_false_none_kind_never_loads_credentials_for_message_url() -> None:
+ with patch(
+ "skyvern.forge.sdk.copilot.request_policy._load_credentials",
+ new=AsyncMock(side_effect=AssertionError("_load_credentials should not be called")),
+ ):
+ policy = await _build_with_forced_classifier(
+ user_message="Go to http://localhost:8941/analytics_console/ and inspect the page.",
+ classifier_policy=RequestPolicy(
+ login_intent=False,
+ credential_input_kind="none",
+ login_page_urls=[],
+ classifier_status="success",
+ ),
+ org_credentials=[],
+ )
+
+ assert policy.user_response_policy == "proceed"
+ assert policy.resolved_credentials == []
+
+
+ ("testing_intent", "allow_missing_credentials_in_draft"),
+ [("skip_test", False), ("unspecified", True)],
+)
+async def test_login_intent_none_kind_skip_modes_do_not_lookup_credentials(
+ testing_intent: str,
+ allow_missing_credentials_in_draft: bool,
+) -> None:
+ with patch(
+ "skyvern.forge.sdk.copilot.request_policy._load_credentials",
+ new=AsyncMock(side_effect=AssertionError("_load_credentials should not be called")),
+ ):
+ policy = await _build_with_forced_classifier(
+ user_message="Sign in to http://localhost:8941/analytics_console/ and continue.",
+ classifier_policy=RequestPolicy(
+ login_intent=True,
+ credential_input_kind="none",
+ login_page_urls=[],
+ testing_intent=testing_intent,
+ allow_missing_credentials_in_draft=allow_missing_credentials_in_draft,
+ classifier_status="success",
+ ),
+ org_credentials=[],
+ )
+
+ assert policy.resolved_credentials == []
+
+
+async def test_login_intent_none_kind_prefers_classifier_login_page_urls_over_message_urls() -> None:
+ classifier_url_credential = _cred("classifier-url", "cred_classifier", tested_url="https://alpha.example.com/login")
+ message_url_credential = _cred("message-url", "cred_message", tested_url="https://beta.example.com/login")
+ policy = await _build_with_forced_classifier(
+ user_message="Sign in to https://beta.example.com/login and continue.",
+ classifier_policy=RequestPolicy(
+ login_intent=True,
+ credential_input_kind="none",
+ login_page_urls=["https://alpha.example.com/login"],
+ classifier_status="success",
+ ),
+ org_credentials=[classifier_url_credential, message_url_credential],
+ )
+
+ assert [c.credential_id for c in policy.resolved_credentials] == ["cred_classifier"]
+
+
@pytest.mark.asyncio
async def test_login_intent_on_an_existing_workflow_asks_without_a_url_in_the_message() -> None:
policy = await _build_with_forced_classifier(
diff --git a/tests/unit/test_credential_update_params.py b/tests/unit/test_credential_update_params.py
index 9886648e6..a983a1aa7 100644
--- a/tests/unit/test_credential_update_params.py
+++ b/tests/unit/test_credential_update_params.py
@@ -17,6 +17,7 @@ from skyvern.forge.sdk.schemas.credentials import (
Credential,
CredentialType,
CredentialVaultType,
+ TotpType,
)
from skyvern.forge.sdk.services.credential.credential_vault_service import CredentialVaultService
from skyvern.forge.sdk.workflow.models.workflow import WorkflowRunStatus
@@ -39,6 +40,35 @@ def _make_browser_sessions_repo(mock_browser_profile: MagicMock) -> BrowserSessi
return BrowserSessionsRepository(session_factory=lambda: MockAsyncSessionCtx(mock_session))
+def _make_password_credential(**overrides: object) -> Credential:
+ defaults: dict[str, object] = {
+ "credential_id": "cred_123",
+ "organization_id": "org_123",
+ "name": "test",
+ "vault_type": CredentialVaultType.AZURE_VAULT,
+ "item_id": "item_123",
+ "credential_type": CredentialType.PASSWORD,
+ "username": "[email protected]",
+ "totp_type": TotpType.NONE,
+ "totp_identifier": None,
+ "card_last4": None,
+ "card_brand": None,
+ "secret_label": None,
+ "browser_profile_id": None,
+ "tested_url": None,
+ "user_context": None,
+ "save_browser_session_intent": False,
+ "folder_id": None,
+ "proxy_location": None,
+ "proxy_session_id": None,
+ "created_at": datetime(2026, 1, 1),
+ "modified_at": datetime(2026, 1, 1),
+ "deleted_at": None,
+ }
+ defaults.update(overrides)
+ return Credential(**defaults)
+
+
# --- CredentialRepository tests ---
@@ -54,6 +84,7 @@ async def test_credential_vault_service_create_db_credential_passes_proxy_pin(
credential_type=CredentialType.PASSWORD,
credential={"username": "[email protected]", "password": "pw"},
proxy_location=ProxyLocation.RESIDENTIAL_ISP,
+ tested_url="https://example.com/login",
)
await CredentialVaultService._create_db_credential(
@@ -66,26 +97,17 @@ async def test_credential_vault_service_create_db_credential_passes_proxy_pin(
create_credential.assert_awaited_once()
assert create_credential.await_args.kwargs["proxy_location"] == ProxyLocation.RESIDENTIAL_ISP
assert create_credential.await_args.kwargs["proxy_session_id"] is None
+ assert create_credential.await_args.kwargs["tested_url"] == "https://example.com/login"
@pytest.mark.asyncio
async def test_create_credential_response_includes_generated_proxy_pin(monkeypatch: pytest.MonkeyPatch) -> None:
proxy_session_id = generate_proxy_session_id("cred_123")
- stored_credential = Credential(
- credential_id="cred_123",
- organization_id="org_123",
- name="test",
- vault_type=CredentialVaultType.AZURE_VAULT,
- item_id="item_123",
- credential_type=CredentialType.PASSWORD,
- username="[email protected]",
- card_last4=None,
- card_brand=None,
- secret_label=None,
+ stored_credential = _make_password_credential(
proxy_location=ProxyLocation.RESIDENTIAL_ISP,
proxy_session_id=proxy_session_id,
- created_at=datetime(2026, 1, 1),
- modified_at=datetime(2026, 1, 1),
+ tested_url="https://example.com/login",
+ totp_type=TotpType.AUTHENTICATOR,
)
vault_service = SimpleNamespace(create_credential=AsyncMock(return_value=stored_credential))
monkeypatch.setattr(credentials_routes, "_get_credential_vault_service", AsyncMock(return_value=vault_service))
@@ -105,6 +127,85 @@ async def test_create_credential_response_includes_generated_proxy_pin(monkeypat
assert response.proxy_location == ProxyLocation.RESIDENTIAL_ISP
assert response.proxy_session_id == proxy_session_id
+ assert response.tested_url == "https://example.com/login"
+ assert response.credential.totp_type == TotpType.AUTHENTICATOR
+
+
+async def test_credential_vault_service_update_db_credential_persists_tested_url(
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ update_credential = AsyncMock(return_value=MagicMock())
+ update_credential_vault_data = AsyncMock(return_value=MagicMock())
+ monkeypatch.setattr(forge_app.DATABASE.credentials, "update_credential", update_credential)
+ monkeypatch.setattr(forge_app.DATABASE.credentials, "update_credential_vault_data", update_credential_vault_data)
+
+ data = CreateCredentialRequest(
+ name="test",
+ credential_type=CredentialType.PASSWORD,
+ credential={"username": "[email protected]", "password": "pw"},
+ tested_url="https://example.com/login",
+ )
+ credential = SimpleNamespace(credential_id="cred_123", organization_id="org_123")
+ await CredentialVaultService._update_db_credential(credential=credential, data=data, item_id="item_123")
+
+ update_credential.assert_not_awaited()
+ update_credential_vault_data.assert_awaited_once()
+ assert update_credential_vault_data.await_args.kwargs["tested_url"] == "https://example.com/login"
+
+
+async def test_credential_vault_service_update_db_credential_skips_tested_url_when_none(
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ update_credential = AsyncMock(return_value=MagicMock())
+ update_credential_vault_data = AsyncMock(return_value=MagicMock())
+ monkeypatch.setattr(forge_app.DATABASE.credentials, "update_credential", update_credential)
+ monkeypatch.setattr(forge_app.DATABASE.credentials, "update_credential_vault_data", update_credential_vault_data)
+
+ data = CreateCredentialRequest(
+ name="test",
+ credential_type=CredentialType.PASSWORD,
+ credential={"username": "[email protected]", "password": "pw"},
+ tested_url=None,
+ )
+ credential = SimpleNamespace(credential_id="cred_123", organization_id="org_123")
+ await CredentialVaultService._update_db_credential(credential=credential, data=data, item_id="item_123")
+
+ update_credential.assert_not_awaited()
+ update_credential_vault_data.assert_awaited_once()
+ assert update_credential_vault_data.await_args.kwargs["tested_url"] is None
+
+
+async def test_create_credential_then_get_credential_returns_tested_url(monkeypatch: pytest.MonkeyPatch) -> None:
+ stored_credential = _make_password_credential(tested_url="https://example.com/login")
+ vault_service = SimpleNamespace(create_credential=AsyncMock(return_value=stored_credential))
+ monkeypatch.setattr(credentials_routes, "_get_credential_vault_service", AsyncMock(return_value=vault_service))
+ monkeypatch.setattr(
+ forge_app.DATABASE.credentials,
+ "get_credential",
+ AsyncMock(return_value=stored_credential),
+ )
+
+ create_data = CreateCredentialRequest(
+ name="test",
+ credential_type=CredentialType.PASSWORD,
+ credential={"username": "[email protected]", "password": "pw"},
+ tested_url="https://example.com/login",
+ )
+ create_response = await credentials_routes.create_credential(
+ background_tasks=BackgroundTasks(),
+ data=create_data,
+ current_org=SimpleNamespace(organization_id="org_123"),
+ )
+ get_response = await credentials_routes.get_credential(
+ credential_id="cred_123",
+ current_org=SimpleNamespace(organization_id="org_123"),
+ )
+
+ assert create_response.tested_url == "https://example.com/login"
+ assert get_response.tested_url == "https://example.com/login"
@pytest.mark.asyncio
@@ -136,6 +237,33 @@ async def test_repo_create_credential_clears_incompatible_proxy_pin() -> None:
assert stored_credential.proxy_session_id is None
+async def test_repo_create_credential_persists_tested_url() -> None:
+ mock_session = AsyncMock()
+ mock_session.add = MagicMock()
+ mock_session.flush = AsyncMock()
+ mock_session.commit = AsyncMock()
+ mock_session.refresh = AsyncMock()
+ repo = CredentialRepository(session_factory=lambda: MockAsyncSessionCtx(mock_session))
+
+ with patch("skyvern.forge.sdk.schemas.credentials.Credential.model_validate", return_value=MagicMock()):
+ await repo.create_credential(
+ organization_id="org_123",
+ name="test",
+ vault_type=CredentialVaultType.AZURE_VAULT,
+ item_id="item_123",
+ credential_type=CredentialType.PASSWORD,
+ username="[email protected]",
+ totp_type="none",
+ card_last4=None,
+ card_brand=None,
+ tested_url="https://example.com/login",
+ )
+
+ stored_credential = mock_session.add.call_args.args[0]
+ assert stored_credential.tested_url == "https://example.com/login"
+
+
@pytest.mark.asyncio
async def test_repo_update_credential_accepts_user_context() -> None:
mock_credential = MagicMock()
@@ -170,6 +298,23 @@ async def test_repo_update_credential_accepts_save_browser_session_intent() -> N
assert mock_credential.save_browser_session_intent is True
+async def test_repo_update_credential_accepts_tested_url() -> None:
+ mock_credential = MagicMock()
+ mock_credential.name = "test"
+ mock_credential.tested_url = None
+ repo = _make_credential_repo(mock_credential)
+
+ with patch("skyvern.forge.sdk.schemas.credentials.Credential.model_validate", return_value=MagicMock()):
+ await repo.update_credential(
+ credential_id="cred_123",
+ organization_id="org_123",
+ tested_url="https://example.com/login",
+ )
+
+ assert mock_credential.tested_url == "https://example.com/login"
+
+
@pytest.mark.asyncio
async def test_repo_update_credential_unset_params_not_applied() -> None:
mock_credential = MagicMock()
@@ -188,6 +333,23 @@ async def test_repo_update_credential_unset_params_not_applied() -> None:
assert mock_credential.save_browser_session_intent is True
+async def test_repo_update_credential_tested_url_none_preserves_existing_value() -> None:
+ mock_credential = MagicMock()
+ mock_credential.name = "test"
+ mock_credential.tested_url = "https://example.com/existing"
+ repo = _make_credential_repo(mock_credential)
+
+ with patch("skyvern.forge.sdk.schemas.credentials.Credential.model_validate", return_value=MagicMock()):
+ await repo.update_credential(
+ credential_id="cred_123",
+ organization_id="org_123",
+ tested_url=None,
+ )
+
+ assert mock_credential.tested_url == "https://example.com/existing"
+
+
@pytest.mark.asyncio
async def test_repo_update_credential_generates_proxy_session_id_for_proxy_location() -> None:
mock_credential = MagicMock()
@@ -253,6 +415,34 @@ async def test_repo_update_credential_vault_data_persists_proxy_pin() -> None:
assert is_proxy_session_id(mock_credential.proxy_session_id)
+async def test_repo_update_credential_vault_data_writes_tested_url_only_when_provided() -> None:
+ mock_credential = MagicMock()
+ mock_credential.name = "test"
+ mock_credential.tested_url = "https://old.example.com/login"
+ repo = _make_credential_repo(mock_credential)
+
+ with patch("skyvern.forge.sdk.schemas.credentials.Credential.model_validate", return_value=MagicMock()):
+ await repo.update_credential_vault_data(
+ credential_id="cred_123",
+ organization_id="org_123",
+ item_id="item_123",
+ name="test",
+ credential_type="password",
+ )
+ assert mock_credential.tested_url == "https://old.example.com/login"
+
+ await repo.update_credential_vault_data(
+ credential_id="cred_123",
+ organization_id="org_123",
+ item_id="item_123",
+ name="test",
+ credential_type="password",
+ tested_url="https://new.example.com/login",
+ )
+ assert mock_credential.tested_url == "https://new.example.com/login"
+
+
@pytest.mark.asyncio
async def test_repo_update_credential_preserves_existing_proxy_pin_on_resave() -> None:
mock_credential = MagicMock()
@@ -740,6 +930,28 @@ def test_credential_route_passes_rotate_proxy_session_id_intent() -> None:
}
+async def test_rename_credential_route_passes_tested_url(monkeypatch: pytest.MonkeyPatch) -> None:
+ existing = _make_password_credential(tested_url="https://example.com/original")
+ updated = _make_password_credential(name="renamed", tested_url="https://example.com/new")
+ update_credential = AsyncMock(return_value=updated)
+ monkeypatch.setattr(forge_app.DATABASE.credentials, "get_credential", AsyncMock(return_value=existing))
+ monkeypatch.setattr(forge_app.DATABASE.credentials, "update_credential", update_credential)
+
+ response = await credentials_routes.rename_credential(
+ credential_id="cred_123",
+ data=credentials_routes.UpdateCredentialRequest(
+ name="renamed",
+ tested_url="https://example.com/new",
+ ),
+ current_org=SimpleNamespace(organization_id="org_123"),
+ )
+
+ update_credential.assert_awaited_once()
+ assert update_credential.await_args.kwargs["tested_url"] == "https://example.com/new"
+ assert response.tested_url == "https://example.com/new"
+
+
def test_generate_proxy_session_id_rejects_empty_entity_id() -> None:
with pytest.raises(ValueError, match="empty entity id"):
generate_proxy_session_id(" ")
diff --git a/tests/unit/test_skyvern_credential_vault_service.py b/tests/unit/test_skyvern_credential_vault_service.py
index b65981c34..dce65669c 100644
--- a/tests/unit/test_skyvern_credential_vault_service.py
+++ b/tests/unit/test_skyvern_credential_vault_service.py
@@ -93,6 +93,16 @@ class _FailingUpdateCredentialRepository(_FakeCredentialRepository):
raise RuntimeError("database unavailable")
+class _CapturingCreateCredentialRepository(_FakeCredentialRepository):
+ def __init__(self) -> None:
+ super().__init__()
+ self.create_kwargs: dict[str, object] | None = None
+
+ async def create_credential(self, **kwargs: object) -> Credential:
+ self.create_kwargs = kwargs
+ return await super().create_credential(**kwargs)
+
+
def _password_request(name: str = "Login", password: str = "secret-password") -> CreateCredentialRequest:
return CreateCredentialRequest(
name=name,
@@ -240,3 +250,18 @@ def test_skyvern_credential_vault_key_file_creation_is_single_winner(tmp_path, m
assert len(set(returned_keys)) == 1
assert returned_keys[0] == stored_key
assert list(tmp_path.glob("*.tmp")) == []
+
+
+async def test_skyvern_credential_vault_create_threads_tested_url(tmp_path, monkeypatch) -> None:
+ monkeypatch.setattr(settings, "LOCAL_CREDENTIAL_VAULT_PATH", str(tmp_path))
+ monkeypatch.setattr(settings, "LOCAL_CREDENTIAL_VAULT_KEY", None)
+ repository = _CapturingCreateCredentialRepository()
+ monkeypatch.setattr(app.DATABASE, "credentials", repository)
+
+ request = _password_request()
+ request = request.model_copy(update={"tested_url": "https://example.com/login"})
+ await SkyvernCredentialVaultService().create_credential("org_test", request)
+
+ assert repository.create_kwargs is not None
+ assert repository.create_kwargs["tested_url"] == "https://example.com/login"