Skip to content

Automate browser based workflows with AI

Reuse saved credentials and recover login selection in Copilot (SKY-15796) (#8491)

Andrew Neilsonfa5bd084e0c3
diff --git a/skyvern-frontend/src/routes/workflows/copilot/WorkflowCopilotChat.credentialCard.test.tsx b/skyvern-frontend/src/routes/workflows/copilot/WorkflowCopilotChat.credentialCard.test.tsx
index 73205b583..33d3cac16 100644
--- a/skyvern-frontend/src/routes/workflows/copilot/WorkflowCopilotChat.credentialCard.test.tsx
+++ b/skyvern-frontend/src/routes/workflows/copilot/WorkflowCopilotChat.credentialCard.test.tsx
@@ -500,7 +500,9 @@ describe("WorkflowCopilotChat — credential card wiring", () => {
streamCalls[0]!.onMessage(credentialFrame());
});
expect(
- screen.getByText(/Copilot needs to sign in to news\.ycombinator\.com/),
+ screen.getByText(
+ "Copilot needs to sign in to https://news.ycombinator.com",
+ ),
).toBeTruthy();
expect(
screen.getByRole("button", { name: "Connect credential" }),
diff --git a/skyvern-frontend/src/routes/workflows/copilot/cards/CredentialCard.test.tsx b/skyvern-frontend/src/routes/workflows/copilot/cards/CredentialCard.test.tsx
index c0c8b3874..050373259 100644
--- a/skyvern-frontend/src/routes/workflows/copilot/cards/CredentialCard.test.tsx
+++ b/skyvern-frontend/src/routes/workflows/copilot/cards/CredentialCard.test.tsx
@@ -111,9 +111,13 @@ afterEach(() => {
});
describe("CredentialCard content", () => {
- it("renders the site parsed from login_page_urls in the headline", () => {
+ it.each([
+ "https://news.ycombinator.com",
+ "http://news.ycombinator.com",
+ "https://news.ycombinator.com:8443",
+ ])("renders the full origin %s in the headline", (origin) => {
const frame = buildCredentialRequiredFrame({
- login_page_urls: ["https://news.ycombinator.com/login?goto=news"],
+ login_page_urls: [`${origin}/login?goto=news`],
});
render(
<CredentialCard
@@ -124,7 +128,7 @@ describe("CredentialCard content", () => {
/>,
);
expect(
- screen.getByText("Copilot needs to sign in to news.ycombinator.com"),
+ screen.getByText(`Copilot needs to sign in to ${origin}`),
).toBeTruthy();
});
@@ -186,7 +190,9 @@ describe("CredentialCard content", () => {
);
expect(container.querySelector("p.text-sm")).toBeNull();
expect(
- screen.getByText("Copilot needs to sign in to news.ycombinator.com"),
+ screen.getByText(
+ "Copilot needs to sign in to https://news.ycombinator.com",
+ ),
).toBeTruthy();
});
diff --git a/skyvern-frontend/src/routes/workflows/copilot/cards/CredentialCard.tsx b/skyvern-frontend/src/routes/workflows/copilot/cards/CredentialCard.tsx
index 1c893e573..0be763e12 100644
--- a/skyvern-frontend/src/routes/workflows/copilot/cards/CredentialCard.tsx
+++ b/skyvern-frontend/src/routes/workflows/copilot/cards/CredentialCard.tsx
@@ -128,7 +128,7 @@ function siteFromLoginPageUrls(urls: string[] | undefined): string {
return "the site";
}
try {
- return new URL(first).hostname;
+ return new URL(first).origin;
} catch {
return first;
}
diff --git a/skyvern/config.py b/skyvern/config.py
index f0deffaf7..d777e6198 100644
--- a/skyvern/config.py
+++ b/skyvern/config.py
@@ -108,6 +108,7 @@ class Settings(BaseSettings):
BROWSER_WORKER_MAX_CONCURRENT_ACTIVITIES: int = 1
BROWSER_TYPE: str = "chromium-headful"
+ BROWSER_SESSION_STARTUP_TIMEOUT_SECONDS: float = 55.0
BROWSER_REMOTE_DEBUGGING_URL: str = "http://127.0.0.1:9222"
BROWSER_REMOTE_DEBUGGING_HOST_HEADER: str | None = None
BROWSER_REMOTE_DEBUGGING_CONNECT_HEADERS: str | None = None
diff --git a/skyvern/forge/sdk/copilot/context.py b/skyvern/forge/sdk/copilot/context.py
index c746e9748..a3a03a8b9 100644
--- a/skyvern/forge/sdk/copilot/context.py
+++ b/skyvern/forge/sdk/copilot/context.py
@@ -15,6 +15,7 @@ import structlog
from pydantic import AliasChoices, BaseModel, ConfigDict, Field, field_validator
from typing_extensions import NotRequired, TypedDict
+from skyvern.forge.sdk.browser_action_policy import canonicalize_origin
from skyvern.forge.sdk.copilot.authoring_parameter_binding import AuthoringParameterBindingDirective
from skyvern.forge.sdk.copilot.browser_ablation import BrowserAblationMetadata, CopilotEvalMode
from skyvern.forge.sdk.copilot.budget_expiry import BudgetExpiryState
@@ -203,8 +204,8 @@ class CredentialCheck(BaseModel):
class ApprovedCredential(BaseModel):
credential_id: str
- # Set only for an approval minted from a carried proposal, whose reach stays the page that
- # vouched for it. Empty for a credential the user named, which never carried an origin.
+ # Set for a credential-card selection or an answered carried proposal. The approval stays
+ # bound to that origin. Empty for a credential the user named without an origin.
admitted_url: str = ""
@@ -694,7 +695,7 @@ def record_approved_credentials_in_global_llm_context(ctx: CopilotContext, raw_c
sc.approved_connections.append(ApprovedCredential(credential_id=policy.selected_connected_account_id))
if len(sc.approved_connections) > _MAX_APPROVED_CREDENTIALS:
sc.approved_connections = sc.approved_connections[-_MAX_APPROVED_CREDENTIALS:]
- existing_ids = {record.credential_id for record in sc.approved_credentials}
+ existing_records = {record.credential_id: record for record in sc.approved_credentials}
for credential in policy.resolved_credentials:
# A credential the user picked from the card is durable approval even though the resume
# stamped an origin for it; only page-vouched ids have to be re-earned.
@@ -714,7 +715,28 @@ def record_approved_credentials_in_global_llm_context(ctx: CopilotContext, raw_c
and credential.credential_id != ctx.credential_pause_connected_credential_id
and not carry_stamp_the_user_answered
)
- if credential.credential_id in existing_ids or stamped_by_page:
+ card_selected = credential.credential_id == ctx.credential_pause_connected_credential_id
+ if (
+ credential.credential_id in policy.persisted_workflow_credential_ids
+ and credential.credential_id not in settled_ids
+ and not card_selected
+ and not carry_stamp_the_user_answered
+ ):
+ # A saved binding grants authority through that workflow, not an independent chat
+ # approval that would outlive removal of the binding.
+ continue
+ source_url = policy.live_page_admitted_urls.get(credential.credential_id, "")
+ if source_url and (card_selected or carry_stamp_the_user_answered) and canonicalize_origin(source_url) is None:
+ continue
+ admitted_url = safe_admitted_url(source_url) if card_selected or carry_stamp_the_user_answered else ""
+ existing_record = existing_records.get(credential.credential_id)
+ if existing_record is not None:
+ # A new explicit card answer can bind a prior name-only approval, or select a new
+ # login origin. Page observations alone never rewrite durable user approval.
+ if card_selected and admitted_url:
+ existing_record.admitted_url = admitted_url
+ continue
+ if stamped_by_page:
continue
# An approval minted from a carry keeps the origin that vouched for the credential. Without
# it the id is resolved on every later turn with nothing pinning it, and the fill seam's
@@ -722,14 +744,10 @@ def record_approved_credentials_in_global_llm_context(ctx: CopilotContext, raw_c
sc.approved_credentials.append(
ApprovedCredential(
credential_id=credential.credential_id,
- admitted_url=(
- policy.live_page_admitted_urls.get(credential.credential_id, "")
- if carry_stamp_the_user_answered
- else ""
- ),
+ admitted_url=admitted_url,
)
)
- existing_ids.add(credential.credential_id)
+ existing_records[credential.credential_id] = sc.approved_credentials[-1]
if len(sc.approved_credentials) > _MAX_APPROVED_CREDENTIALS:
sc.approved_credentials = sc.approved_credentials[-_MAX_APPROVED_CREDENTIALS:]
return sc.to_json_str()
diff --git a/skyvern/forge/sdk/copilot/credential_pause.py b/skyvern/forge/sdk/copilot/credential_pause.py
index 4187be7df..a86d0c4d2 100644
--- a/skyvern/forge/sdk/copilot/credential_pause.py
+++ b/skyvern/forge/sdk/copilot/credential_pause.py
@@ -449,6 +449,9 @@ async def _run_credential_pause(
policy = getattr(ctx, "request_policy", None)
# The FE credential card fetches the full org list itself; these ride the frame as `credential_refs`
# and seed the picker's "Suggested" group (pinned first), so the user still sees the full list.
+ if isinstance(policy, RequestPolicy):
+ # Bind an answer to the URLs on this card, never an earlier unanswered ask.
+ policy.credential_ask_login_page_urls = list(login_page_urls)
credential_refs = list(policy.credential_refs) if isinstance(policy, RequestPolicy) else []
timeout_seconds = copilot_config.credential_pause_timeout_seconds
now = datetime.now(timezone.utc)
diff --git a/skyvern/forge/sdk/copilot/credential_resolution.py b/skyvern/forge/sdk/copilot/credential_resolution.py
index 86678711b..6b2b028ab 100644
--- a/skyvern/forge/sdk/copilot/credential_resolution.py
+++ b/skyvern/forge/sdk/copilot/credential_resolution.py
@@ -84,7 +84,7 @@ def safe_admitted_url(url: str) -> str:
if parsed is None or not parsed.hostname:
return ""
try:
- port = f":{parsed.port}" if parsed.port else ""
+ port = f":{parsed.port}" if parsed.port is not None else ""
except ValueError:
port = ""
# urlparse strips the brackets an IPv6 literal needs; without them the port reads as part of
diff --git a/skyvern/forge/sdk/copilot/request_policy.py b/skyvern/forge/sdk/copilot/request_policy.py
index 069e51950..8b8cac3d1 100644
--- a/skyvern/forge/sdk/copilot/request_policy.py
+++ b/skyvern/forge/sdk/copilot/request_policy.py
@@ -923,14 +923,15 @@ class RequestPolicy:
raw_secret_safety_exonerated_citation_count: int = 0
raw_secret_safety_latency_ms: float = 0.0
clarification_reason: ClarificationReason = "none"
- # The login page URLs a tool ask was formed against. A model-supplied URL reaches this list only
- # after it matched a site in ``user_provided_site_urls``; the connected resume falls back to the
- # classifier-authored ``login_page_urls`` when it is empty, which carries no such grounding.
+ # The validated login URLs the credential card asked the user to select a login for. The
+ # connected resume falls back to classifier-authored login_page_urls when this is empty.
credential_ask_login_page_urls: list[str] = field(default_factory=list)
# Credentials this turn resolved from an explicit user reference — an exact saved name or a
# cred_ id — as distinct from approvals carried in from earlier turns. Naming a credential
# answers which one to use, which is what lets the login page answer where it may be typed.
current_turn_named_credential_ids: set[str] = field(default_factory=set)
+ # Explicit user approvals hydrated from the existing trusted structured chat context.
+ prior_approved_credential_ids: set[str] = field(default_factory=set)
# Sites the user themselves provided anywhere in this chat, one URL per origin. A credential may
# only be released onto one of these (or a vault/tested match); a site only a model produced is
# never eligible.
@@ -4171,6 +4172,7 @@ async def _seed_prior_approved_credentials(
global_llm_context: str,
) -> None:
approved_ids = _prior_approved_credential_ids(global_llm_context)
+ policy.prior_approved_credential_ids = approved_ids
# An approval minted from a carry recorded the page that vouched for the credential; restoring it
# keeps the fill pinned there instead of falling through to any site named in the conversation.
for record in StructuredContext.from_json_str(global_llm_context).approved_credentials:
@@ -4450,14 +4452,17 @@ async def admit_credential_for_live_page(
)
return LiveCredentialAdmission(
False,
- steer=f"{_AMBIGUOUS_URL_CREDENTIAL_QUESTION} Ask the user which one to use, then fill it.",
+ steer=(
+ f"{_AMBIGUOUS_URL_CREDENTIAL_QUESTION} Call `request_credential` with this sign-in page URL "
+ "so the user can select or add the credential in Copilot."
+ ),
)
if resolution.verdict == "resolved":
return LiveCredentialAdmission(
False,
steer=(
- f"`{credential_id}` is not the saved credential for this login page. Ask the user which "
- "saved credential to use here."
+ f"`{credential_id}` does not match this login page. The page uniquely matches saved credential "
+ f"`{resolution.candidates[0].credential_id}`; use that credential to continue."
),
)
return LiveCredentialAdmission(False)
diff --git a/skyvern/forge/sdk/copilot/tools/__init__.py b/skyvern/forge/sdk/copilot/tools/__init__.py
index bf29f4f2b..1f92bbc2d 100644
--- a/skyvern/forge/sdk/copilot/tools/__init__.py
+++ b/skyvern/forge/sdk/copilot/tools/__init__.py
@@ -779,7 +779,8 @@ async def list_credentials_tool(
Use this to find credential IDs for login blocks.
When the agent selects a saved name or credential ID that appears as a complete
- credential reference in the latest literal user turn, pass it as `exact_reference`.
+ credential reference in the latest literal user turn, or is already selected in the saved
+ workflow or a credential-card reply, pass it as `exact_reference` without asking again.
Exact mode verifies provenance and organization-wide cardinality, then atomically binds
the single match into server-owned request authority. It does not classify the surrounding
prose and never falls back to fuzzy search, discovery, or pagination. Zero or multiple exact
@@ -808,10 +809,12 @@ async def list_credentials_tool(
async def request_credential_tool(ctx: RunContextWrapper, login_page_url: str, reason: str) -> str:
"""Ask the user, in chat, to add or pick a saved credential for a sign-in page.
- Use this instead of writing a prose question when the turn needs a login and no saved
- credential covers that site. `login_page_url` must be a page on a site the user themselves
- provided in this chat; `reason` is one sentence shown to the user saying why the login is
- needed. The call waits for the user's answer and comes back `connected` with the credential
+ Use this instead of a prose question when a login still needs selection or setup, including
+ a sign-in page discovered while navigating. Reuse the user's existing choice, the saved
+ workflow's binding, or an unambiguous website match without asking again when it can fill.
+ `login_page_url` is the absolute HTTP(S) sign-in URL shown on the card; selecting a credential
+ authorizes it for that site. `reason` is one sentence explaining why the login is needed.
+ The call waits for the user's answer and comes back `connected` with the credential
to bind, `skipped`, `unanswered`, or `unavailable` — follow the `next` or `fallback` it
carries. One ask per turn.
"""
@@ -1561,17 +1564,18 @@ async def fill_credential_field_tool(
An `empty` readback still succeeds when `landing_inferred_from_navigation` is true:
the page left the one the fill acted on, so the field was cleared by its own submit.
- Do not use this tool to reproduce an existing saved login block. Run that
- block unchanged with `run_blocks_and_collect_debug`, then inspect the page
- it reaches; the block's bound credential resolves in the workflow run.
+ To test an existing saved login block, run that block unchanged with `run_blocks_and_collect_debug`.
+ When repairing its login in the live browser, reuse the saved block's credential here;
+ its saved login origin, tested site, or vault site can authorize the fill without another ask.
`selector` must be a CSS selector for the exact input field (no comma-union
fallbacks — inspect the page first and target the proven field).
`credential_id`: when a page observation returns
`resolved_login_credential_id`, the server has already authorized that
credential for this login page — pass that id. When it returns
- `candidate_login_credentials`, ask the user which one to use and pass the
- `credential_id` they choose. `field` is one of `username`, `password`, `totp`.
+ `candidate_login_credentials`, reuse an existing user or saved-workflow choice if present;
+ otherwise call `request_credential` for the sign-in URL and pass the selected `credential_id`.
+ `field` is one of `username`, `password`, `totp`.
`submit_selector` is optional and submits in the SAME call: pass the CSS
selector of the form's submit control and this tool clicks it once the fill
diff --git a/skyvern/forge/sdk/copilot/tools/credential_fill.py b/skyvern/forge/sdk/copilot/tools/credential_fill.py
index 66bc95aae..8babc6fd2 100644
--- a/skyvern/forge/sdk/copilot/tools/credential_fill.py
+++ b/skyvern/forge/sdk/copilot/tools/credential_fill.py
@@ -21,7 +21,7 @@ from skyvern.forge.sdk.copilot.credential_pause import (
defang_card_text,
request_credential_pause,
)
-from skyvern.forge.sdk.copilot.credential_resolution import load_credentials, url_parts
+from skyvern.forge.sdk.copilot.credential_resolution import is_resolved_page_url, load_credentials, url_parts
from skyvern.forge.sdk.copilot.loop_detection import record_tool_step_result_for_ctx
from skyvern.forge.sdk.copilot.page_identity import safe_page_origin
from skyvern.forge.sdk.copilot.request_policy import (
@@ -44,6 +44,7 @@ from skyvern.forge.sdk.copilot.secret_scrub import (
register_secret_scrub_value,
scrub_secrets_from_text,
)
+from skyvern.forge.sdk.copilot.workflow_credential_utils import workflow_credential_origins
from skyvern.forge.sdk.credential_site_policy import same_site
from skyvern.forge.sdk.schemas.credentials import (
Credential,
@@ -278,9 +279,10 @@ def _credential_fill_authority_error(copilot_ctx: AgentContext, credential_id: s
if credential_id not in resolved_ids:
return (
f"The credential `{credential_id}` is not in the credentials resolved for this request, so it "
- "cannot be filled into the live browser. Only credentials the user referenced (listed under "
- "`resolved_credentials` in the request policy) may be scouted. Ask the user which saved "
- "credential to use, or bind the credential as an untested draft parameter without running it."
+ "cannot be filled into the live browser yet. Use `list_credentials(exact_reference=...)` "
+ "for a credential the user already chose or the saved workflow binds. If the login is still "
+ "unresolved, call `request_credential` with the sign-in page URL so the user can pick or add "
+ "a credential in chat, then continue."
)
return None
@@ -331,9 +333,9 @@ def _missing_credential_origin_error(credential_id: str, page_url: str | None) -
if page_url:
origin = loggable_origin(page_url)
return (
- f"Credential `{credential_id}` cannot be filled on {origin}: the user has not named this site "
- f"in this chat. Ask the user to confirm the sign-in site by pasting its URL — {origin} — "
- "then retry."
+ f"Credential `{credential_id}` has no established login origin for {origin}. "
+ f"Call `request_credential` with the sign-in page URL on {origin} so the user can "
+ "select or add its login in chat, then continue."
)
return (
f"Credential `{credential_id}` cannot be filled: no live page is open. "
@@ -369,18 +371,12 @@ _CREDENTIAL_CARD_FALLBACK = (
)
-def _unprovided_login_page_error(login_page_url: str) -> str:
- origin = loggable_origin(login_page_url) if login_page_url else "that page"
- return (
- f"No credential can be requested for {origin}: that site has not been named in this chat. "
- "The sign-in page URL has to come from the user before a login can be requested for it."
- )
-
-
async def _request_credential(login_page_url: str, reason: str, copilot_ctx: CopilotContext) -> dict[str, Any]:
policy = copilot_ctx.request_policy
- if not isinstance(policy, RequestPolicy) or _user_provided_site_url_match(policy, login_page_url)[0] is None:
- return {"ok": False, "error": _unprovided_login_page_error(login_page_url)}
+ if not isinstance(policy, RequestPolicy) or policy.raw_secret_detected:
+ return {"ok": False, "error": "Credential selection is unavailable on a raw-secret or ungrounded turn."}
+ if not is_resolved_page_url(login_page_url) or canonicalize_origin(login_page_url) is None:
+ return {"ok": False, "error": "Provide the absolute HTTP(S) sign-in page URL for the credential card."}
if copilot_ctx.credential_pause_used:
return {
@@ -446,10 +442,11 @@ async def _request_credential(login_page_url: str, reason: str, copilot_ctx: Cop
def _request_settled_credential(policy: RequestPolicy, credential_id: str) -> bool:
- """A non-model signal already answered which credential: the user named it this turn, or it is
- the only credential resolved for this request (e.g. the one card answer, carried)."""
+ """A user selection settles identity; a saved binding alone remains scoped to its saved origin."""
if policy.current_turn_named_credential_ids == {credential_id}:
return True
+ if credential_id in policy.persisted_workflow_credential_ids:
+ return credential_id in policy.prior_approved_credential_ids
return {credential.credential_id for credential in policy.resolved_credentials} == {credential_id}
@@ -472,9 +469,8 @@ def _ambiguous_unbound_credential_steer(credential_id: str, page_url: str) -> st
origin = loggable_origin(page_url)
return (
f"`{credential_id}` has no saved login page, so it is not established that it belongs to {origin}. "
- "Ask the user to say which saved credential to use *and* to name the sign-in page, for example "
- f'"use <exact name or cred_ id> at {origin}". A reply carrying only the credential grounds no '
- "origin and refuses again, and a bare yes authorizes nothing."
+ f"Call `request_credential` with the sign-in page URL on {origin}; the user's card selection "
+ "settles both the credential and the site so the build can continue."
)
@@ -488,13 +484,22 @@ async def _credential_fill_origin_grant(
if prerequisite_error:
return None, prerequisite_error
policy = copilot_ctx.request_policy
- authority_error = _credential_fill_authority_error(copilot_ctx, credential_id)
async def load_once() -> list[Credential]:
if copilot_ctx.org_credentials_for_turn is None:
copilot_ctx.org_credentials_for_turn = await load_credentials(copilot_ctx.organization_id)
return copilot_ctx.org_credentials_for_turn
+ if (
+ isinstance(policy, RequestPolicy)
+ and credential_id in policy.persisted_workflow_credential_ids
+ and credential_id not in {credential.credential_id for credential in policy.resolved_credentials}
+ ):
+ saved = next((item for item in await load_once() if item.credential_id == credential_id), None)
+ if saved is not None:
+ policy.resolved_credentials.append(saved)
+ authority_error = _credential_fill_authority_error(copilot_ctx, credential_id)
+
if not authority_error:
if not isinstance(policy, RequestPolicy):
return None, _missing_credential_origin_error(credential_id, None)
@@ -503,6 +508,14 @@ async def _credential_fill_origin_grant(
_log_fill_grant("admitted_or_tested", intended_url, credential_id)
return _CredentialFillOriginGrant(intended_url), None
page_url = await _live_working_page_url(copilot_ctx) or ""
+ if page_url and any(
+ _still_on_admitted_site(page_url, origin)
+ for origin in workflow_credential_origins(
+ copilot_ctx.persisted_workflow_yaml or "", require_canonical_origin=True
+ ).get(credential_id, [])
+ ):
+ _log_fill_grant("saved_workflow", page_url, credential_id)
+ return _CredentialFillOriginGrant(page_url), None
# The vault entry names the site the user filed this credential under, so it answers where
# the secret belongs without anyone having to run the test flow first.
if page_url and any(_same_site(page_url, uri) for uri in await _vault_named_sites(copilot_ctx, credential_id)):
@@ -511,9 +524,18 @@ async def _credential_fill_origin_grant(
if page_url:
matched_url, site_level = _user_provided_site_url_match(policy, page_url)
if matched_url is not None:
- if _request_settled_credential(
- policy, credential_id
- ) or credential_id == await _sole_org_password_credential_id(load_once):
+ settled = _request_settled_credential(policy, credential_id)
+ if not settled and credential_id in policy.persisted_workflow_credential_ids:
+ admission = await admit_credential_for_live_page(
+ policy,
+ organization_id=copilot_ctx.organization_id,
+ credential_id=credential_id,
+ page_url=page_url,
+ load_org_credentials=load_once,
+ )
+ if admission.steer:
+ return None, admission.steer
+ if settled or credential_id == await _sole_org_password_credential_id(load_once):
# An origin-only match (no registrable site) keeps the origin-scoped grant so the
# release guard can still compare it; site matches travel the whole site.
_log_fill_grant("user_url", page_url, credential_id, policy.user_site_url_sources.get(matched_url))
@@ -805,12 +827,8 @@ async def _fill_credential_field_impl(
if not isinstance(lock, asyncio.Lock):
lock = asyncio.Lock()
copilot_ctx.credential_fill_lock = lock
- async with lock:
- async with browser_page_custody_lock(copilot_ctx):
- async with browser_evidence_commit_lock(copilot_ctx):
- return await _fill_credential_field_impl_serial(
- copilot_ctx, selector, credential_id, field, submit_selector
- )
+ async with lock, browser_page_custody_lock(copilot_ctx), browser_evidence_commit_lock(copilot_ctx):
+ return await _fill_credential_field_impl_serial(copilot_ctx, selector, credential_id, field, submit_selector)
async def _fill_credential_field_impl_serial(
diff --git a/skyvern/forge/sdk/copilot/tools/credentials.py b/skyvern/forge/sdk/copilot/tools/credentials.py
index 2cb4ac990..c760ea23c 100644
--- a/skyvern/forge/sdk/copilot/tools/credentials.py
+++ b/skyvern/forge/sdk/copilot/tools/credentials.py
@@ -766,10 +766,12 @@ async def _resolve_exact_credential(reference: str, ctx: AgentContext) -> dict[s
matches = list(matches_by_id.values())
literal_reference = bool(credential_reference_spans(policy.canonical_user_message, reference))
typed_resume_arm = _typed_resume_arm(reference, policy)
+ if len(matches) == 1 and matches[0].credential_id in _saved_workflow_credential_ids(policy):
+ typed_resume_arm = typed_resume_arm or "saved_workflow"
# The agent owns natural-language interpretation. This boundary verifies only
- # objective provenance and identity: the proposed exact reference must be a
- # complete saved reference in the literal current turn. It deliberately does
- # not implement a second English policy language beside the agent.
+ # objective provenance and identity: an exact reference is grounded in the current
+ # turn, a structured selection, or the server-saved workflow. It deliberately
+ # does not implement a second English policy language beside the agent.
if typed_resume_arm is None and reference not in grounded_references and (matches or not literal_reference):
LOG.info(
"copilot_credential_reference_not_literal",
diff --git a/skyvern/forge/sdk/copilot/workflow_credential_utils.py b/skyvern/forge/sdk/copilot/workflow_credential_utils.py
index a123ef295..d2f48946f 100644
--- a/skyvern/forge/sdk/copilot/workflow_credential_utils.py
+++ b/skyvern/forge/sdk/copilot/workflow_credential_utils.py
@@ -5,6 +5,7 @@ from collections.abc import Iterable, Mapping
from typing import Any
from urllib.parse import urlparse
+from skyvern.forge.sdk.browser_action_policy import canonicalize_origin
from skyvern.forge.sdk.copilot.workflow_block_traversal import workflow_block_locations
from skyvern.utils.yaml_loader import safe_load_no_dates
@@ -145,16 +146,18 @@ def workflow_credential_ids_from_parsed(parsed: dict[str, Any]) -> set[str]:
return credential_ids
-def workflow_credential_origins(workflow_yaml: str) -> dict[str, set[str]]:
+def workflow_credential_origins(workflow_yaml: str, *, require_canonical_origin: bool = False) -> dict[str, set[str]]:
if not workflow_yaml:
return {}
parsed = parse_workflow_yaml(workflow_yaml)
if not isinstance(parsed, dict):
return {}
- return workflow_credential_origins_from_parsed(parsed)
+ return workflow_credential_origins_from_parsed(parsed, require_canonical_origin=require_canonical_origin)
-def workflow_credential_origins_from_parsed(parsed: dict[str, Any]) -> dict[str, set[str]]:
+def workflow_credential_origins_from_parsed(
+ parsed: dict[str, Any], *, require_canonical_origin: bool = False
+) -> dict[str, set[str]]:
workflow_definition = parsed.get("workflow_definition")
if not isinstance(workflow_definition, dict):
return {}
@@ -168,8 +171,14 @@ def workflow_credential_origins_from_parsed(parsed: dict[str, Any]) -> dict[str,
block_url = block.get("url")
if not isinstance(block_url, str) or not block_url.strip():
continue
- origin = url_origin(block_url)
- if not origin:
+ # Release authorization requires an unambiguous raw URL. Output scope comparison
+ # must retain other parseable origins: omitting them would hide a changed destination.
+ if require_canonical_origin:
+ canonical_origin = canonicalize_origin(block_url)
+ origin = canonical_origin.canonical if canonical_origin is not None else None
+ else:
+ origin = url_origin(block_url)
+ if origin is None:
continue
for credential_id in credential_ids:
origins_by_id.setdefault(credential_id, set()).add(origin)
diff --git a/tests/unit/test_copilot_context.py b/tests/unit/test_copilot_context.py
index 6de6b85d2..c5bed71f2 100644
--- a/tests/unit/test_copilot_context.py
+++ b/tests/unit/test_copilot_context.py
@@ -329,6 +329,7 @@ def _policy_ctx(
seeded_proposal_credential_ids=set(),
carry_cited_credential_ids=set(),
current_turn_named_credential_ids=set(),
+ persisted_workflow_credential_ids=set(),
selected_connected_account_id=selected_connected_account_id,
),
)
diff --git a/tests/unit/test_copilot_credential_pause.py b/tests/unit/test_copilot_credential_pause.py
index 07067bc3e..04f3d57dd 100644
--- a/tests/unit/test_copilot_credential_pause.py
+++ b/tests/unit/test_copilot_credential_pause.py
@@ -36,8 +36,9 @@ from skyvern.forge import app
from skyvern.forge.sdk.cache.base import NoopLock
from skyvern.forge.sdk.copilot import credential_pause as credential_pause_module
from skyvern.forge.sdk.copilot import tools as tools_module
-from skyvern.forge.sdk.copilot.config import CopilotConfig
+from skyvern.forge.sdk.copilot.config import BlockAuthoringPolicy, CopilotConfig
from skyvern.forge.sdk.copilot.context import (
+ ApprovedCredential,
CopilotContext,
StructuredContext,
record_approved_credentials_in_global_llm_context,
@@ -73,6 +74,7 @@ from skyvern.forge.sdk.copilot.hooks import CopilotRunHooks
from skyvern.forge.sdk.copilot.request_policy import (
_CREDENTIALS_UI_DIRECTIONS,
RequestPolicy,
+ _seed_prior_approved_credentials,
credential_prompt_reason,
)
from skyvern.forge.sdk.copilot.tools._shared import TOTAL_TIMEOUT_SECONDS, _copilot_seconds_remaining
@@ -297,7 +299,10 @@ async def test_a_run_that_hits_a_login_still_gets_a_card_after_an_unanswered_too
ctx.client_supports_credential_pause = True
ctx.workflow_copilot_chat_id = "chat-1"
ctx.last_run_skipped_unbound_credentials = True
- ctx.request_policy = RequestPolicy()
+ ctx.request_policy = RequestPolicy(
+ credential_ask_login_page_urls=["https://old.example.com/login"],
+ login_page_urls=["https://actual.example.com/login"],
+ )
# State left by a tool ask the user skipped.
ctx.credential_pause_used = True
ctx.credential_pause_reaskable_by_run = True
@@ -325,6 +330,11 @@ async def test_a_run_that_hits_a_login_still_gets_a_card_after_an_unanswered_too
assert resume_msgs is not None
assert ctx.credential_pause_outcome == "connected"
+ assert ctx.request_policy.live_page_admitted_urls == {"cred_1": "https://actual.example.com/login"}
+ carried = record_approved_credentials_in_global_llm_context(ctx, None)
+ assert StructuredContext.from_json_str(carried).approved_credentials == [
+ ApprovedCredential(credential_id="cred_1", admitted_url="https://actual.example.com/login")
+ ]
# Handed back once only, so the turn cannot loop on repeated cards.
assert ctx.credential_pause_reaskable_by_run is False
@@ -1626,9 +1636,13 @@ def test_connected_resume_does_not_duplicate_an_already_resolved_credential() ->
assert [resolved.credential_id for resolved in policy.resolved_credentials] == ["cred_1"]
-def test_a_card_connected_credential_keeps_its_durable_cross_turn_approval() -> None:
+ "login_urls",
+ [[], ["https://portal.example.com/login"], ["https://portal.example.com/login", "https://other.example.com/login"]],
+)
+def test_a_card_connected_credential_keeps_its_durable_cross_turn_approval(login_urls: list[str]) -> None:
ctx = make_copilot_context()
- policy = _ask_origin_policy("https://portal.example.com/login")
+ policy = _ask_origin_policy(*login_urls)
ctx.request_policy = policy
credential_pause_module._apply_connected_credential_to_policy(ctx, policy, _make_credential())
@@ -1639,6 +1653,124 @@ def test_a_card_connected_credential_keeps_its_durable_cross_turn_approval() ->
]
[email protected]("previous_origin", [None, "", "https://old.example.com/login"])
+ "login_url",
+ [
+ "https://portal.example.com/login",
+ "https://portal.example.com/login?code=synthetic-code&state=synthetic-state#synthetic-token",
+ ],
+)
+async def test_card_selection_keeps_its_origin_on_the_next_turn(
+ monkeypatch: pytest.MonkeyPatch, previous_origin: str | None, login_url: str
+) -> None:
+ ctx = make_copilot_context()
+ ctx.request_policy = _ask_origin_policy(login_url)
+ ctx.request_policy.persisted_workflow_credential_ids = {"cred_1"}
+ previous = StructuredContext()
+ if previous_origin is not None:
+ previous.approved_credentials = [ApprovedCredential(credential_id="cred_1", admitted_url=previous_origin)]
+ credential_pause_module._apply_connected_credential_to_policy(ctx, ctx.request_policy, _make_credential())
+ carried = record_approved_credentials_in_global_llm_context(ctx, previous.to_json_str())
+ assert carried is not None
+ records = StructuredContext.from_json_str(carried).approved_credentials
+ assert records == [ApprovedCredential(credential_id="cred_1", admitted_url="https://portal.example.com/login")]
+
+ next_policy = RequestPolicy()
+ _stub_credential_lookup(monkeypatch, _make_credential())
+ await _seed_prior_approved_credentials(next_policy, organization_id="org-1", global_llm_context=carried)
+ next_ctx = make_copilot_context()
+ next_ctx.request_policy = next_policy
+ next_ctx.block_authoring_policy = BlockAuthoringPolicy.CODE_ONLY_BROWSER
+ grant, error = await tools_module.credential_fill._credential_fill_origin_grant(next_ctx, "cred_1")
+ assert error is None
+ assert grant is not None
+ assert tools_module.credential_fill._within_grant("https://portal.example.com/password", grant)
+ assert not tools_module.credential_fill._within_grant("https://elsewhere.example.com/login", grant)
+ assert not tools_module.credential_fill._within_grant("https://old.example.com/login", grant)
+
+
+ "login_url",
+ [
+ r"https://trusted.example\@evil.example/login",
+ "https://synthetic-user:[email protected]/login",
+ "https://portal.example.com:invalid/login",
+ ],
+)
+async def test_invalid_card_origin_cannot_create_cross_turn_approval(
+ monkeypatch: pytest.MonkeyPatch, login_url: str
+) -> None:
+ ctx = _tool_ctx(monkeypatch, _answered_cache("connected", "cred_1"))
+ _stub_credential_lookup(monkeypatch, _make_credential())
+ result = await _ask(ctx, login_url)
+ assert result["ok"] is False
+ assert ctx.credential_pause_connected_credential_id is None
+
+ # Retained state must also fail closed if it predates validation at the card boundary.
+ ctx.request_policy = _ask_origin_policy(login_url)
+ credential_pause_module._apply_connected_credential_to_policy(ctx, ctx.request_policy, _make_credential())
+ carried = record_approved_credentials_in_global_llm_context(ctx, None)
+ assert StructuredContext.from_json_str(carried).approved_credentials == []
+
+
[email protected]("user_named", [False, True])
+async def test_saved_workflow_resolution_requires_user_selection_for_chat_approval(
+ monkeypatch: pytest.MonkeyPatch, user_named: bool
+) -> None:
+ ctx = make_copilot_context()
+ ctx.request_policy = RequestPolicy(
+ resolved_credentials=[_make_credential()],
+ persisted_workflow_credential_ids={"cred_1"},
+ current_turn_named_credential_ids={"cred_1"} if user_named else set(),
+ )
+ carried = record_approved_credentials_in_global_llm_context(ctx, None)
+ next_policy = RequestPolicy()
+ _stub_credential_lookup(monkeypatch, _make_credential())
+ await _seed_prior_approved_credentials(next_policy, organization_id="org-1", global_llm_context=carried)
+ assert [credential.credential_id for credential in next_policy.resolved_credentials] == (
+ ["cred_1"] if user_named else []
+ )
+
+
+async def test_card_approval_preserves_explicit_port_zero(monkeypatch: pytest.MonkeyPatch) -> None:
+ ctx = make_copilot_context()
+ ctx.request_policy = _ask_origin_policy("https://portal.example.com:0/login?code=synthetic-code")
+ credential_pause_module._apply_connected_credential_to_policy(ctx, ctx.request_policy, _make_credential())
+ carried = record_approved_credentials_in_global_llm_context(ctx, None)
+ next_policy = RequestPolicy()
+ _stub_credential_lookup(monkeypatch, _make_credential())
+ await _seed_prior_approved_credentials(next_policy, organization_id="org-1", global_llm_context=carried)
+ next_ctx = make_copilot_context()
+ next_ctx.request_policy = next_policy
+ next_ctx.block_authoring_policy = BlockAuthoringPolicy.CODE_ONLY_BROWSER
+ grant, error = await tools_module.credential_fill._credential_fill_origin_grant(next_ctx, "cred_1")
+ assert error is None
+ assert grant is not None
+ assert tools_module.credential_fill._within_grant("https://portal.example.com:0/password", grant)
+ assert not tools_module.credential_fill._within_grant("https://portal.example.com/password", grant)
+
+
[email protected]("already_approved", [False, True])
+def test_page_only_admission_does_not_become_durable_approval(already_approved: bool) -> None:
+ ctx = make_copilot_context()
+ ctx.request_policy = RequestPolicy(
+ resolved_credentials=[_make_credential()],
+ live_page_admitted_urls={"cred_1": "https://portal.example.com/login"},
+ )
+ previous = StructuredContext()
+ if already_approved:
+ previous.approved_credentials = [
+ ApprovedCredential(credential_id="cred_1", admitted_url="https://old.example.com/login")
+ ]
+ carried = record_approved_credentials_in_global_llm_context(ctx, previous.to_json_str())
+ assert StructuredContext.from_json_str(carried).approved_credentials == previous.approved_credentials
+
+
def _answered_cache(action: str, credential_id: str | None = None) -> _FakeCache:
cache = _FakeCache()
cache.store[credential_response_cache_key("org-1", "chat-1", "turn-1")] = encode_credential_response(
@@ -1713,15 +1845,27 @@ async def test_an_unanswered_card_returns_a_typed_outcome_rather_than_an_error(
@pytest.mark.asyncio
-async def test_the_tool_refuses_a_sign_in_site_the_user_never_provided(monkeypatch: pytest.MonkeyPatch) -> None:
- """The connected credential's origin is bound from this argument, so a model-invented site
- would hand the card's answer fill authority the user never granted."""
- ctx = _tool_ctx(monkeypatch)
+async def test_the_tool_offers_a_discovered_site_and_binds_only_the_users_card_answer(
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ ctx = _tool_ctx(monkeypatch, _answered_cache("connected", "cred_1"))
+ _stub_credential_lookup(monkeypatch, _make_credential())
result = await _ask(ctx, "https://elsewhere.example.net/login")
+ assert result["status"] == "connected"
+ frame = ctx.stream.send.await_args_list[0].args[0]
+ assert frame.login_page_urls == ["https://elsewhere.example.net/login"]
+ assert ctx.request_policy.live_page_admitted_urls == {"cred_1": "https://elsewhere.example.net/login"}
+ assert ctx.request_policy.current_turn_named_credential_ids == {"cred_1"}
+
+
[email protected]("login_url", ["", "javascript:alert(1)", "not-a-url"])
+async def test_the_card_requires_a_real_sign_in_url(monkeypatch: pytest.MonkeyPatch, login_url: str) -> None:
+ ctx = _tool_ctx(monkeypatch)
+ result = await _ask(ctx, login_url)
assert result["ok"] is False
- assert ctx.request_policy.credential_ask_login_page_urls == []
ctx.stream.send.assert_not_awaited()
@@ -1962,7 +2106,7 @@ async def test_an_announced_ask_that_never_reaches_the_card_still_releases_the_w
await _announce_ask(ctx)
async def ask() -> None:
- await _invoke_ask_tool(ctx, "https://elsewhere.example.net/login")
+ await _invoke_ask_tool(ctx, "not-a-url")
await asyncio.wait_for(asyncio.gather(await_pending_credential_pause(ctx), ask()), timeout=5)
@@ -1995,3 +2139,12 @@ async def test_a_repeat_ask_in_a_later_response_releases_the_gate_it_armed(
await _invoke_ask_tool(ctx, "https://portal.example.com/login")
await asyncio.wait_for(await_pending_credential_pause(ctx), timeout=1)
+
+
+async def test_raw_secret_turn_cannot_open_the_credential_card(monkeypatch: pytest.MonkeyPatch) -> None:
+ ctx = _tool_ctx(monkeypatch)
+ ctx.request_policy.raw_secret_detected = True
+ result = await _ask(ctx)
+ assert result["ok"] is False
+ ctx.stream.send.assert_not_awaited()
diff --git a/tests/unit/test_copilot_fill_credential_field.py b/tests/unit/test_copilot_fill_credential_field.py
index 3b8679091..2cf4176d8 100644
--- a/tests/unit/test_copilot_fill_credential_field.py
+++ b/tests/unit/test_copilot_fill_credential_field.py
@@ -24,7 +24,13 @@ from structlog.testing import capture_logs
from skyvern.forge import app
from skyvern.forge.sdk.copilot import tools as tools_module
from skyvern.forge.sdk.copilot.config import BlockAuthoringPolicy
-from skyvern.forge.sdk.copilot.request_policy import RequestPolicy, _ground_user_provided_sites
+from skyvern.forge.sdk.copilot.request_policy import (
+ RequestPolicy,
+ _build_request_policy_bootstrap,
+ _ground_user_provided_sites,
+ _seed_prior_approved_credentials,
+ admit_credential_for_live_page,
+)
from skyvern.forge.sdk.copilot.runtime import (
SENSITIVE_ORIGIN_PAGE_ERROR,
OriginRunRedactionRegistry,
@@ -42,6 +48,7 @@ from skyvern.forge.sdk.copilot.tools import scouting as scouting_module
from skyvern.forge.sdk.copilot.turn_origin import TurnOrigin
from skyvern.forge.sdk.schemas.credentials import CredentialType, CredentialVaultType, PasswordCredential, TotpType
from skyvern.forge.sdk.schemas.workflow_copilot import WorkflowCopilotChatHistoryMessage, WorkflowCopilotChatSender
+from tests.unit.conftest import make_copilot_context
from tests.unit.copilot_test_helpers import (
SENSITIVE_DISCLOSURE_WITHHOLDING_ARMS,
remove_sensitive_disclosure_prerequisite,
@@ -70,6 +77,7 @@ def _policy(**overrides: Any) -> RequestPolicy:
def _ctx(**overrides: Any) -> SimpleNamespace:
ns = SimpleNamespace(
organization_id="o_1",
+ persisted_workflow_yaml=None,
turn_origin=TurnOrigin.interactive,
request_policy=_policy(),
block_authoring_policy=BlockAuthoringPolicy.CODE_ONLY_BROWSER,
@@ -1583,7 +1591,7 @@ class TestCredentialFillLivePageAdmission:
result = await tools_module._fill_credential_field_impl(ctx, "#passwordInput", "cred_123", "password")
assert result["ok"] is False
- assert "cannot be filled" in result["error"]
+ assert "request_credential" in result["error"]
assert page.fill_calls == []
async def _unbound_grant(
@@ -1647,7 +1655,7 @@ class TestCredentialFillLivePageAdmission:
assert grant is None
assert error is not None
- assert "has not named this site" in error
+ assert "request_credential" in error
@pytest.mark.asyncio
async def test_a_lookalike_domain_does_not_match_the_user_site(self) -> None:
@@ -1729,9 +1737,7 @@ class TestCredentialFillLivePageAdmission:
assert grant is None
assert error is not None
- # Only an exact name or a cred_ id is read back off the next message, so an ask that would
- # settle for "yes" re-asks forever — the loop this seam exists to end.
- assert "exact name" in error and "cred_" in error
+ assert "request_credential" in error
@pytest.mark.asyncio
async def test_naming_this_turn_settles_among_several_resolved(self) -> None:
@@ -2483,3 +2489,113 @@ async def test_a_terminal_credential_run_does_not_authorize_a_credential_without
assert result["ok"] is False
assert result["error"] != SENSITIVE_ORIGIN_PAGE_ERROR
assert page.fill_calls == []
+
+
+ "origin_arm",
+ [
+ "saved_login",
+ "vault",
+ "tested",
+ "wrong_origin",
+ "unavailable",
+ "canvas_only",
+ "ambiguous_authority",
+ "saved_other_user_site",
+ "saved_other_named",
+ "saved_other_approved",
+ ],
+)
+async def test_saved_workflow_login_fills_without_repeating_the_credential_choice(
+ monkeypatch: pytest.MonkeyPatch,
+ origin_arm: str,
+) -> None:
+ page = _FakePage()
+ _wire_impl(monkeypatch, page)
+ credential = _org_credential("cred_123", "authtest simple", _FIXTURE_LOGIN_URL if origin_arm == "tested" else None)
+ saved_yaml = f"""
+workflow_definition:
+ parameters:
+ - parameter_type: credential
+ key: login
+ credential_id: cred_123
+ blocks:
+ - block_type: login
+ label: login
+ url: {_FIXTURE_LOGIN_URL if origin_arm == "saved_login" else "https://public.example.org/book"}
+ parameter_keys: [login]
+"""
+ if origin_arm == "ambiguous_authority":
+ saved_yaml = saved_yaml.replace(
+ "https://public.example.org/book", r"https://trusted.example\@authenticationtest.com/simpleFormAuth/"
+ )
+ policy = await _build_request_policy_bootstrap(
+ user_message="Run the whole workflow again",
+ workflow_yaml=saved_yaml.replace("https://public.example.org/book", _FIXTURE_LOGIN_URL),
+ persisted_workflow_yaml=saved_yaml if origin_arm != "canvas_only" else None,
+ chat_history=[],
+ global_llm_context="",
+ organization_id="o_1",
+ )
+ ctx = make_copilot_context()
+ ctx.organization_id = "o_1"
+ ctx.browser_session_id = "pbs_1"
+ ctx.block_authoring_policy = BlockAuthoringPolicy.CODE_ONLY_BROWSER
+ ctx.request_policy = policy
+ ctx.persisted_workflow_yaml = saved_yaml if origin_arm != "canvas_only" else None
+ ctx.vault_login_uris_by_credential_id = {"cred_123": [_FIXTURE_LOGIN_URL] if origin_arm == "vault" else []}
+ if origin_arm == "wrong_origin":
+ credential.tested_url = "https://wrong.example.net/login"
+ candidates = [credential]
+ if origin_arm in {"saved_other_user_site", "saved_other_named", "saved_other_approved"}:
+ policy.user_provided_site_urls = [_FIXTURE_LOGIN_URL]
+ candidates.append(_org_credential("cred_other", "other login", _FIXTURE_LOGIN_URL))
+ if origin_arm == "saved_other_named":
+ policy.current_turn_named_credential_ids = {"cred_123"}
+ if origin_arm == "saved_other_approved":
+ with patch(
+ "skyvern.forge.sdk.copilot.request_policy.app.DATABASE.credentials.get_credentials_by_ids",
+ AsyncMock(return_value=[credential]),
+ ):
+ await _seed_prior_approved_credentials(
+ policy,
+ organization_id="o_1",
+ global_llm_context=json.dumps({"approved_credentials": [{"credential_id": "cred_123"}]}),
+ )
+ with patch.object(credential_fill_module, "load_credentials", AsyncMock(return_value=candidates)):
+ result = await tools_module._fill_credential_field_impl(ctx, "#passwordInput", "cred_123", "password")
+ allowed = origin_arm in {"saved_login", "vault", "tested", "saved_other_named", "saved_other_approved"}
+ assert result["ok"] is allowed
+ assert bool(page.fill_calls) is allowed
+ assert _FAKE_PASSWORD not in json.dumps(result)
+
+
+async def test_unresolved_fill_names_the_in_chat_selection_recovery(monkeypatch: pytest.MonkeyPatch) -> None:
+ page = _FakePage()
+ _wire_impl(monkeypatch, page)
+ ctx = _ctx(request_policy=RequestPolicy(), org_credentials_for_turn=[])
+ result = await tools_module._fill_credential_field_impl(ctx, "#passwordInput", "cred_123", "password")
+ assert result["ok"] is False
+ assert "request_credential" in result["error"]
+ assert page.fill_calls == []
+
+
[email protected]("ambiguous", [False, True])
+async def test_live_admission_exposes_the_existing_selection_path(ambiguous: bool) -> None:
+ candidates = [_org_credential("cred_site", "site login", _FIXTURE_LOGIN_URL)]
+ if ambiguous:
+ candidates.append(_org_credential("cred_other", "other login", _FIXTURE_LOGIN_URL))
+ admission = await admit_credential_for_live_page(
+ RequestPolicy(),
+ organization_id="o_1",
+ credential_id="cred_unselected",
+ page_url=_FIXTURE_LOGIN_URL,
+ load_org_credentials=AsyncMock(return_value=candidates),
+ )
+ assert admission.admitted is False
+ assert admission.steer is not None
+ assert "request_credential" in admission.steer if ambiguous else "cred_site" in admission.steer
+ assert "Ask the user which" not in admission.steer
diff --git a/tests/unit/test_copilot_output_policy.py b/tests/unit/test_copilot_output_policy.py
index 91448347a..7eb720d68 100644
--- a/tests/unit/test_copilot_output_policy.py
+++ b/tests/unit/test_copilot_output_policy.py
@@ -1107,7 +1107,11 @@ def test_allows_existing_workflow_credential_id_on_unrelated_turn() -> None:
assert OutputPolicyReason.UNAPPROVED_CREDENTIAL_REFERENCE not in verdict.reason_codes
-def test_rejects_existing_workflow_credential_id_on_new_origin() -> None:
+ "url",
+ ["https://evil.example.test/login", "https://bücher.example/login", r"https://evil.example.test\login"],
+)
+def test_rejects_existing_workflow_credential_id_on_new_origin(url: str) -> None:
verdict = evaluate_output_policy(
request_policy=_policy(
resolved_credentials=[],
@@ -1115,7 +1119,7 @@ def test_rejects_existing_workflow_credential_id_on_new_origin() -> None:
existing_workflow_credential_origins={"cred_safe": ["https://login.example.test"]},
credential_input_kind="none",
),
- workflow_yaml=_workflow_yaml(url="https://evil.example.test/login"),
+ workflow_yaml=_workflow_yaml(url=url),
)
assert not verdict.allowed
diff --git a/tests/unit/test_copilot_tools_list_credentials.py b/tests/unit/test_copilot_tools_list_credentials.py
index 455df2682..db5f7deb0 100644
--- a/tests/unit/test_copilot_tools_list_credentials.py
+++ b/tests/unit/test_copilot_tools_list_credentials.py
@@ -144,3 +144,17 @@ async def test_the_user_naming_another_credential_settles_the_fill_on_that_one()
assert data["status"] == "resolved"
assert policy.current_turn_named_credential_ids == {"cred_other"}
assert _request_settled_credential(policy, "cred_other")
+
+
[email protected]("saved", [True, False])
+async def test_saved_workflow_selection_resolves_but_a_canvas_proposal_does_not(saved: bool) -> None:
+ credential = _password_credential()
+ policy = RequestPolicy(
+ canonical_user_message="Run the whole workflow again",
+ persisted_workflow_credential_ids=[credential.credential_id] if saved else [],
+ existing_workflow_credential_ids=[credential.credential_id],
+ )
+ data = await _resolve(credential.name, policy, [credential])
+ assert data["status"] == ("resolved" if saved else "denied")
+ assert policy.current_turn_named_credential_ids == set()