Skip to content

Automate browser based workflows with AI

Name the bounded replacement when a CodeBlock expect_* member is denied (SKY-14861) (#8286)

Andrew Neilson336360386b32
diff --git a/skyvern/forge/sdk/copilot/reached_download_target.py b/skyvern/forge/sdk/copilot/reached_download_target.py
index 36476a44d..ae8bb6ee4 100644
--- a/skyvern/forge/sdk/copilot/reached_download_target.py
+++ b/skyvern/forge/sdk/copilot/reached_download_target.py
@@ -392,7 +392,10 @@ def code_is_download_intent(code: str) -> bool:
"""True when a code block authors a download: it uses the `page.expect_download` context-manager
idiom, any event-based `"download"` capture (`wait_for_event`/`expect_event`/`on`/`once`/
`add_listener`), or the `click_and_claim_download` helper anywhere, or returns/binds a dict
- literal carrying an execution-layer download registration key."""
+ literal carrying an execution-layer download registration key. It stays deliberately broader
+ than the runner's own policy — the denied `page.expect_download` idiom still counts — because
+ its consumer is the unregistered-download telemetry in workflow/models/block.py, which measures
+ authorship rather than validity."""
if not code.strip():
return False
try:
diff --git a/skyvern/forge/sdk/copilot/tools/workflow_update.py b/skyvern/forge/sdk/copilot/tools/workflow_update.py
index c4809a6c7..2cc93b41d 100644
--- a/skyvern/forge/sdk/copilot/tools/workflow_update.py
+++ b/skyvern/forge/sdk/copilot/tools/workflow_update.py
@@ -3454,39 +3454,6 @@ def _extraction_schema_incompatibility(
)
-_EXPECT_DOWNLOAD_ATTR = "expect_download"
-
-
-def _call_is_expect_download(node: ast.expr) -> bool:
- if isinstance(node, ast.Await):
- return _call_is_expect_download(node.value)
- if isinstance(node, ast.Call) and isinstance(node.func, ast.Attribute):
- return node.func.attr == _EXPECT_DOWNLOAD_ATTR
- return False
-
-
-def _code_registers_download(code: str) -> bool:
- """Either terminal that actually fires a registered download: the ``expect_download`` idiom or
- the worker-owned download claim."""
- return _code_uses_expect_download(code) or code_uses_download_claim(code)
-
-
-def _code_uses_expect_download(code: str) -> bool:
- """True only for the registering form: `expect_download()` called as the context
- expression of an `async with`/`with`. A bare `page.expect_download` attribute or an
- uncaptured call fires no download, so it does not count."""
- try:
- tree = ast.parse(textwrap.dedent(code).strip() or "pass")
- except SyntaxError:
- return False
- for node in ast.walk(tree):
- if isinstance(node, (ast.AsyncWith, ast.With)):
- for item in node.items:
- if _call_is_expect_download(item.context_expr):
- return True
- return False
-
-
_DOWNLOAD_DESCRIPTOR_LEAK_KEY_SET = frozenset({"downloaded_file_path", "download_url"})
@@ -3562,12 +3529,12 @@ def _artifact_declares_registration_keys(artifact: Mapping[str, Any]) -> bool:
def _is_download_intent(artifact: Mapping[str, Any], code: str) -> bool:
"""Disjoint from extraction-intent (`goal_value_paths` on non-registration keys):
- a block is download-intent when it carries the expect_download idiom, self-asserts a
- registration key in a top-level dict, or declares a registration key as a goal path."""
+ a block is download-intent when it claims a download, self-asserts a registration key in a
+ top-level dict, or declares a registration key as a goal path."""
if not code.strip():
return False
return (
- _code_registers_download(code)
+ code_uses_download_claim(code)
or _code_returns_registration_keys(code)
or _artifact_declares_registration_keys(artifact)
)
diff --git a/skyvern/forge/sdk/encrypt/bootstrap.py b/skyvern/forge/sdk/encrypt/bootstrap.py
index 26e606c6f..6450c675d 100644
--- a/skyvern/forge/sdk/encrypt/bootstrap.py
+++ b/skyvern/forge/sdk/encrypt/bootstrap.py
@@ -46,9 +46,9 @@ def create_aes_encryptor(
"secret; empty values and the default placeholder 'fillmein' both fail closed."
)
fallback_parameters = list(fallback_decrypt_keys or ())
- if not (salt and iv):
- # Legacy ciphertext has no version marker, so retry the pre-derivation parameters on decrypt.
- fallback_parameters.insert(0, (salt, iv))
+ # Legacy ciphertext has no version marker. Always retry the pre-SHA-normalization
+ # parameters on decrypt, including explicit deployment salt/IV settings.
+ fallback_parameters.insert(0, (salt, iv))
return AES(
secret_key=secret_key,
salt=salt or _derive_from_secret_key(secret_key, _SALT_DERIVATION_LABEL),
diff --git a/tests/unit/test_aes_fallback_decrypt.py b/tests/unit/test_aes_fallback_decrypt.py
index 27a0eafd2..5c8d29cf8 100644
--- a/tests/unit/test_aes_fallback_decrypt.py
+++ b/tests/unit/test_aes_fallback_decrypt.py
@@ -7,6 +7,18 @@ PRIMARY_SALT = "primary_salt_value_xxxxxxxxxxxxxxx"
PRIMARY_IV = "primary_iv_xxxxxxxxx"
PRIOR_SALT = "prior_salt_value_xxxxxxxxxxxxxxxxx"
PRIOR_IV = "prior_iv_value_xxxxx"
+LEGACY_PRIMARY_CIPHERTEXT = "rvmea7ou1gzyata3OwKEQg=="
+
+
+async def test_decrypts_ciphertext_created_with_legacy_primary_normalization() -> None:
+ aes = AES(
+ secret_key=SECRET,
+ salt=PRIMARY_SALT,
+ iv=PRIMARY_IV,
+ fallback_decrypt_keys=[(PRIMARY_SALT, PRIMARY_IV)],
+ )
+ assert await aes.decrypt(LEGACY_PRIMARY_CIPHERTEXT) == "legacy primary"
@pytest.mark.asyncio
diff --git a/tests/unit/test_copilot_code_artifact_metadata_violations.py b/tests/unit/test_copilot_code_artifact_metadata_violations.py
index 8b6dd6feb..922280b5b 100644
--- a/tests/unit/test_copilot_code_artifact_metadata_violations.py
+++ b/tests/unit/test_copilot_code_artifact_metadata_violations.py
@@ -19,6 +19,7 @@ from skyvern.forge.sdk.copilot.tools.workflow_update import (
_code_block_returns_flat_string,
_code_block_returns_uninvoked_structured_function,
_download_descriptor_leak_finding,
+ _is_download_intent,
_normalize_code_artifact_metadata_detailed,
)
@@ -688,6 +689,44 @@ def _download_intent_metadata(label: str) -> dict:
return metadata
+class TestDownloadIntentTerminals:
+ """Which engine will run a block is unknown when it is authored, and `click_and_claim_download`
+ is the only download terminal that registers on both, so it is the only one this gate credits.
+ A block relying on the `page.expect_download` idiom therefore loses the download exemption and
+ is held to the extraction-shape checks."""
+
+ def test_expect_download_alone_is_not_download_intent(self) -> None:
+ code = textwrap.dedent(
+ """
+ async with page.expect_download(timeout=30000) as download_event:
+ await page.click("a#statement-pdf")
+ """
+ )
+ assert _is_download_intent({}, code) is False
+
+ def test_download_claim_is_download_intent(self) -> None:
+ code = 'saved = await click_and_claim_download(page, "a#statement-pdf")\nreturn {"saved_as": saved}'
+ assert _is_download_intent({}, code) is True
+
+ def test_declared_registration_key_still_carries_download_intent(self) -> None:
+ code = "async with page.expect_download() as download_event:\n await page.click('a#statement-pdf')"
+ assert _is_download_intent(_download_intent_metadata("dl_block"), code) is True
+
+ def test_expect_download_no_longer_exempts_a_block_from_the_extraction_validators(self) -> None:
+ code = """
+ async with page.expect_download() as dl_info:
+ await page.click("a#statement-pdf")
+ return page.inner_text("#results")
+ """
+ normalized, error = _normalize_code_artifact_metadata(
+ [_extraction_metadata("my_block", ["records[].number"])],
+ _extraction_code_block_yaml("my_block", code),
+ )
+ assert normalized == {}
+ assert error is not None
+ assert "flat text blob" in error
+
+
class TestDownloadDescriptorLeak:
"""A run cannot reveal this arm: the run succeeds and the path lands in workflow output.
The registration-detection arms were deleted precisely because a run does reveal those."""
@@ -707,7 +746,9 @@ class TestDownloadDescriptorLeak:
class TestDownloadShapesThatMustNotBeFlagged:
"""Negative space for the surviving descriptor-leak arm: a clean descriptor, an extraction
- block, and a non-download block must all normalize without a violation."""
+ block, and a non-download block must all normalize without a violation. The first arm passes
+ because its artifact declares a registration key, not because the `expect_download` idiom is
+ read as a download terminal."""
def test_expect_download_idiom_with_descriptor_passes(self) -> None:
code = """