Skip to content

Automate browser based workflows with AI

SKY-11218 Align code-only guidance with security gate (#6709)

Andrew Neilsonab9c09280672
diff --git a/skyvern-frontend/src/routes/workflows/copilot/NarrativeView.test.ts b/skyvern-frontend/src/routes/workflows/copilot/NarrativeView.test.ts
index e03c50389..ec93b6b3e 100644
--- a/skyvern-frontend/src/routes/workflows/copilot/NarrativeView.test.ts
+++ b/skyvern-frontend/src/routes/workflows/copilot/NarrativeView.test.ts
@@ -774,6 +774,44 @@ describe("computeTurnSummary — typed terminal adjudication", () => {
expect(summary.accent).toBe("ok");
});
+ it("renders a clean built-unverified run as ran, not stopped", () => {
+ const summary = computeTurnSummary(
+ buildTurn({
+ draft: draft3,
+ blocks: [
+ summaryBlock("block_one"),
+ summaryBlock("block_two"),
+ summaryBlock("block_three"),
+ ],
+ proposalDisposition: "auto_applicable",
+ responseKind: "build",
+ verifiedSuccess: false,
+ }),
+ );
+ expect(summary.headline).toBe("Built and ran the workflow");
+ expect(summary.accent).toBe("ok");
+ expect(summary.glyph).toBe("✓");
+ });
+
+ it("renders a clean built-unverified edit as ran, not re-tested", () => {
+ const summary = computeTurnSummary(
+ buildTurn({
+ draft: draft3,
+ blocks: [
+ summaryBlock("block_one"),
+ summaryBlock("block_two"),
+ summaryBlock("block_three"),
+ ],
+ priorBlockCount: 2,
+ responseKind: "build",
+ verifiedSuccess: false,
+ }),
+ );
+ expect(summary.headline).toBe("Applied edits and ran the workflow");
+ expect(summary.accent).toBe("ok");
+ expect(summary.glyph).toBe("✓");
+ });
+
it.each([
[buildTurn({ responseKind: "build", verifiedSuccess: false }), "Stopped"],
[
@@ -813,7 +851,7 @@ describe("computeTurnSummary — typed terminal adjudication", () => {
"Workflow ready for review",
],
])(
- "never renders green when the verdict refused the success claim (%#)",
+ "keeps stopped or review-required states when there is no clean completed run (%#)",
(turn, headline) => {
const summary = computeTurnSummary(turn);
expect(summary.headline).toBe(headline);
diff --git a/skyvern-frontend/src/routes/workflows/copilot/WorkflowCopilotChat.test.ts b/skyvern-frontend/src/routes/workflows/copilot/WorkflowCopilotChat.test.ts
index 028be3e56..49bf92199 100644
--- a/skyvern-frontend/src/routes/workflows/copilot/WorkflowCopilotChat.test.ts
+++ b/skyvern-frontend/src/routes/workflows/copilot/WorkflowCopilotChat.test.ts
@@ -20,6 +20,16 @@ describe("shouldAutoApplyWorkflowResponse", () => {
expect(shouldAutoApplyWorkflowResponse(response(), true, false)).toBe(true);
});
+ it("auto-applies proposals already committed by the backend", () => {
+ expect(
+ shouldAutoApplyWorkflowResponse(
+ response({ workflow_applied: true }),
+ false,
+ false,
+ ),
+ ).toBe(true);
+ });
+
it.each(["review_untested", "review_tested"] as const)(
"forces explicit review for %s proposals",
(proposal_disposition) => {
diff --git a/skyvern-frontend/src/routes/workflows/copilot/narrativeState.ts b/skyvern-frontend/src/routes/workflows/copilot/narrativeState.ts
index f6a14c69a..eae284f59 100644
--- a/skyvern-frontend/src/routes/workflows/copilot/narrativeState.ts
+++ b/skyvern-frontend/src/routes/workflows/copilot/narrativeState.ts
@@ -853,6 +853,7 @@ function adjudicatedSummaryParts(
needsTestedProposalReview: boolean;
hasEdited: boolean;
hasDrafts: boolean;
+ hasCleanCompletedBuild: boolean;
},
): AdjudicatedParts | null {
if (turn.responseKind === null) return null;
@@ -876,6 +877,15 @@ function adjudicatedSummaryParts(
return { headline: "Workflow ready for review", accent: "qa", glyph: "!" };
}
if (!turn.verifiedSuccess) {
+ if (flags.hasCleanCompletedBuild) {
+ return {
+ headline: flags.hasEdited
+ ? "Applied edits and ran the workflow"
+ : "Built and ran the workflow",
+ accent: "ok",
+ glyph: "✓",
+ };
+ }
return { headline: "Stopped", accent: "qa", glyph: "!" };
}
if (flags.hasEdited) {
@@ -912,6 +922,10 @@ export function computeTurnSummary(turn: TurnNarrativeState): TurnSummary {
const needsTestedProposalReview =
hasDrafts && turn.proposalDisposition === "review_tested";
const hasEdited = (turn.priorBlockCount ?? 0) > 0 && hasDrafts;
+ const hasCleanCompletedBuild =
+ hasDrafts &&
+ rollupBlocks.length > 0 &&
+ rollupBlocks.every((block) => isBlockOk(block));
const hasReviewableDraft =
hasDrafts &&
(turn.proposalDisposition === "review_untested" ||
@@ -928,6 +942,7 @@ export function computeTurnSummary(turn: TurnNarrativeState): TurnSummary {
needsTestedProposalReview,
hasEdited,
hasDrafts,
+ hasCleanCompletedBuild,
});
const headline = adjudicated
diff --git a/skyvern-frontend/src/routes/workflows/copilot/proposalDisposition.ts b/skyvern-frontend/src/routes/workflows/copilot/proposalDisposition.ts
index fab591451..642432e3e 100644
--- a/skyvern-frontend/src/routes/workflows/copilot/proposalDisposition.ts
+++ b/skyvern-frontend/src/routes/workflows/copilot/proposalDisposition.ts
@@ -7,7 +7,7 @@ export const shouldAutoApplyWorkflowResponse = (
) => {
return Boolean(
response.updated_workflow &&
- autoAccept &&
+ (autoAccept || response.workflow_applied === true) &&
response.proposal_disposition === "auto_applicable" &&
!response.cancelled &&
!userCancelledThisTurn,
diff --git a/skyvern-frontend/src/routes/workflows/copilot/workflowCopilotTypes.ts b/skyvern-frontend/src/routes/workflows/copilot/workflowCopilotTypes.ts
index 3ee0cb177..3523cd0ad 100644
--- a/skyvern-frontend/src/routes/workflows/copilot/workflowCopilotTypes.ts
+++ b/skyvern-frontend/src/routes/workflows/copilot/workflowCopilotTypes.ts
@@ -111,6 +111,7 @@ export interface WorkflowCopilotStreamResponseUpdate {
response_time: string;
response_type?: CopilotResponseType;
proposal_disposition: ProposalDisposition;
+ workflow_applied?: boolean;
// Cancel forces explicit review.
cancelled?: boolean;
// Optional so the FE tolerates an older backend that does not emit the
diff --git a/skyvern/forge/sdk/copilot/agent.py b/skyvern/forge/sdk/copilot/agent.py
index 9ea145a3b..11e662a83 100644
--- a/skyvern/forge/sdk/copilot/agent.py
+++ b/skyvern/forge/sdk/copilot/agent.py
@@ -957,6 +957,32 @@ def _verified_workflow_or_none(ctx: CopilotContext) -> tuple[Any, str | None]:
return None, None
+_BUILT_UNVERIFIED_COMPLETED_REPLY = (
+ "I built the workflow and the test run completed, but the goal outcome was not independently verified. "
+ "The workflow is available on the canvas for review."
+)
+
+
+def _should_use_built_unverified_completed_reply(
+ ctx: CopilotContext,
+ *,
+ response_type: str,
+ updated_workflow: Any,
+ validated: bool,
+ blocker_active: bool,
+) -> bool:
+ return (
+ response_type == "REPLY"
+ and updated_workflow is not None
+ and validated
+ and not blocker_active
+ and ctx.last_test_ok is True
+ and ctx.last_full_workflow_test_ok is True
+ and not ctx.last_test_suspicious_success
+ and not verified_goal_claim_authorized(ctx)
+ )
+
+
def _make_agent_result(
ctx: CopilotContext | None,
*,
@@ -1000,11 +1026,25 @@ def _make_agent_result(
result = AgentResult(global_llm_context=final_context, turn_outcome=turn_outcome, **kwargs)
if ctx is not None and result.turn_outcome is not None:
result.turn_outcome = with_copilot_code_mode_diagnostics(result.turn_outcome, ctx)
+ if ctx is not None and not result.apply_without_review:
+ result.apply_without_review = _should_apply_code_only_success_without_review(ctx, result.proposal_disposition)
if ctx is not None and result.completion_criteria_turn_state is None:
result.completion_criteria_turn_state = getattr(ctx, "completion_criteria_turn_state", None)
return result
+def _should_apply_code_only_success_without_review(ctx: CopilotContext, disposition: object) -> bool:
+ return (
+ disposition == "auto_applicable"
+ and ctx.block_authoring_policy == BlockAuthoringPolicy.CODE_ONLY_BROWSER
+ and ctx.last_test_ok is True
+ and ctx.last_full_workflow_test_ok is True
+ and not ctx.last_test_suspicious_success
+ and ctx.has_staged_proposal
+ and ctx.staged_workflow is not None
+ )
+
+
def _build_outcome_adjudication_payload(ctx: CopilotContext) -> NarrativeOutcomeAdjudication | None:
turn_state = getattr(ctx, "completion_criteria_turn_state", None)
if turn_state is None:
@@ -2323,6 +2363,14 @@ async def _translate_to_agent_result(
structured.merge_turn_summary(ctx.tool_activity)
enriched_context = structured.to_json_str()
workflow_attempted = ctx.last_update_block_count is not None or ctx.last_test_ok is not None
+ if _should_use_built_unverified_completed_reply(
+ ctx,
+ response_type=resp_type,
+ updated_workflow=last_workflow,
+ validated=not unvalidated,
+ blocker_active=blocker_active,
+ ):
+ user_response = _BUILT_UNVERIFIED_COMPLETED_REPLY
output_kind = derive_output_kind(
response_type=resp_type,
request_policy=ctx.request_policy,
diff --git a/skyvern/forge/sdk/copilot/context.py b/skyvern/forge/sdk/copilot/context.py
index 9c08a3e2a..6c1a1341d 100644
--- a/skyvern/forge/sdk/copilot/context.py
+++ b/skyvern/forge/sdk/copilot/context.py
@@ -309,6 +309,9 @@ class AgentResult:
cancelled: bool = False
# Controls whether the route may auto-apply the proposal or must force explicit review.
proposal_disposition: ProposalDisposition = "auto_applicable"
+ # Successful code-only build turns can be applied without requiring the
+ # chat's sticky "Always accept" setting.
+ apply_without_review: bool = False
output_policy_diagnostics: dict[str, Any] | None = None
turn_outcome: TurnOutcome | None = None
turn_id: str | None = None
diff --git a/skyvern/forge/sdk/copilot/tools/banned_blocks.py b/skyvern/forge/sdk/copilot/tools/banned_blocks.py
index 20985658b..5a3c23686 100644
--- a/skyvern/forge/sdk/copilot/tools/banned_blocks.py
+++ b/skyvern/forge/sdk/copilot/tools/banned_blocks.py
@@ -250,10 +250,16 @@ Runtime facts:
- `code` is async Python with a Playwright `page` object and workflow parameters by key.
- Valid Python identifier parameter keys are local variables; normalize before page inputs.
- Use deterministic, bounded Playwright calls: `goto`, `click`, `fill`, `press`,
- `wait_for_load_state`, and `evaluate`.
+ `wait_for_load_state`, `locator`, `get_by_role`, and locator text/count APIs.
+- For browser reads, prefer visible anchors, locator text, block outputs, and
+ MCP/scout evidence gathered before authoring.
- A `credential_id` workflow parameter resolves to a credential object with
`<key>.username`, `<key>.password`, and fresh `<key>.totp`; scout fields with
`fill_credential_field`, never embed literal secrets.
+- Credentialed login code must be idempotent. After `goto`, wait for either the
+ login form or an already-authenticated page anchor; only fill username/password
+ when the login fields are visible, and after submit wait for a logged-in page
+ anchor instead of relying only on `networkidle`.
- Return JSON-safe structured data plus visible evidence text for records, totals,
confirmations, and identifiers.
- For an extraction-intent `code` block, propose a typed `extraction_schema` (named
diff --git a/skyvern/forge/sdk/routes/workflow_copilot.py b/skyvern/forge/sdk/routes/workflow_copilot.py
index 719eeca6c..44f952112 100644
--- a/skyvern/forge/sdk/routes/workflow_copilot.py
+++ b/skyvern/forge/sdk/routes/workflow_copilot.py
@@ -444,7 +444,7 @@ def _effective_auto_accept(auto_accept: bool | None, agent_result: object | None
"""Only auto-applicable proposals may honor ``auto_accept=True``."""
if getattr(agent_result, "cancelled", False) is True or _proposal_disposition(agent_result) != "auto_applicable":
return False
- return auto_accept is True
+ return auto_accept is True or getattr(agent_result, "apply_without_review", False) is True
def _should_restore_persisted_workflow(auto_accept: bool | None, agent_result: object | None) -> bool:
@@ -656,7 +656,15 @@ async def _persist_proposed_workflow_state(chat: Any, agent_result: AgentResult,
workflow_copilot_chat_id=chat.workflow_copilot_chat_id,
proposed_workflow=_build_proposed_workflow_data(updated_workflow, agent_result),
)
- elif chat.proposed_workflow is not None and (restored or agent_result.clear_proposed_workflow):
+ elif chat.proposed_workflow is not None and (
+ restored
+ or agent_result.clear_proposed_workflow
+ or (
+ getattr(agent_result, "apply_without_review", False) is True
+ and auto_accept_effective
+ and not _output_policy_blocked_final_response(agent_result)
+ )
+ ):
# Null any persisted proposed_workflow the assistant just invalidated
# so a reload does not resurrect a stale Accept/Reject card. Runs
# under both auto_accept values — a stale proposal can survive an
@@ -843,6 +851,7 @@ async def _finalise_normal_turn(
await _persist_proposed_workflow_state(chat, agent_result, restored)
await _persist_completion_criteria_state(chat, agent_result, chat_request.message)
proposal_disposition = _proposal_disposition(agent_result)
+ workflow_applied = _effective_auto_accept(chat.auto_accept, agent_result)
narrative_payload = _with_terminal_narrative_metadata(
agent_result.narrative_payload,
cancelled=False,
@@ -877,6 +886,7 @@ async def _finalise_normal_turn(
total_tokens=agent_result.total_tokens,
response_type=agent_result.response_type,
proposal_disposition=proposal_disposition,
+ workflow_applied=workflow_applied,
output_policy_diagnostics=agent_result.output_policy_diagnostics,
turn_id=agent_result.turn_id,
narrative_summary=agent_result.narrative_summary,
diff --git a/skyvern/forge/sdk/schemas/workflow_copilot.py b/skyvern/forge/sdk/schemas/workflow_copilot.py
index 06766809f..beb1e21a1 100644
--- a/skyvern/forge/sdk/schemas/workflow_copilot.py
+++ b/skyvern/forge/sdk/schemas/workflow_copilot.py
@@ -199,6 +199,10 @@ class WorkflowCopilotStreamResponseUpdate(BaseModel):
"auto_applicable",
description="Whether this proposal may auto-apply or must be reviewed explicitly.",
)
+ workflow_applied: bool = Field(
+ False,
+ description="True when the backend already committed this terminal workflow proposal.",
+ )
cancelled: bool = Field(
False,
description="When true, this RESPONSE was emitted by a user cancel; clients must not auto-apply.",
diff --git a/tests/unit/test_copilot_agent_helpers.py b/tests/unit/test_copilot_agent_helpers.py
index 6cbce8b4d..c40eac901 100644
--- a/tests/unit/test_copilot_agent_helpers.py
+++ b/tests/unit/test_copilot_agent_helpers.py
@@ -2047,6 +2047,32 @@ workflow_definition:
assert agent_result.updated_workflow is wf
assert agent_result.proposal_disposition == "auto_applicable"
+ assert agent_result.apply_without_review is False
+
+ def test_code_only_verified_build_applies_without_review(self) -> None:
+ from skyvern.forge.sdk.copilot.config import BlockAuthoringPolicy
+
+ wf = SimpleNamespace(name="drafted")
+ ctx = _ctx(
+ block_authoring_policy=BlockAuthoringPolicy.CODE_ONLY_BROWSER,
+ last_workflow=wf,
+ last_workflow_yaml="title: drafted",
+ last_test_ok=True,
+ last_full_workflow_test_ok=True,
+ last_update_block_count=3,
+ has_staged_proposal=True,
+ staged_workflow=wf,
+ )
+ result = _fake_run_result({"type": "REPLY", "user_response": "All set."})
+ agent_result = asyncio.run(
+ agent_module._translate_to_agent_result(
+ result, ctx, global_llm_context=None, chat_request=_chat_request(), organization_id="org-1"
+ )
+ )
+
+ assert agent_result.updated_workflow is wf
+ assert agent_result.proposal_disposition == "auto_applicable"
+ assert agent_result.apply_without_review is True
def test_goal_reached_true_explicit_keeps_verified_path(self) -> None:
wf = SimpleNamespace(name="drafted")
@@ -2221,7 +2247,7 @@ workflow_definition:
assert agent_result.updated_workflow is None
assert agent_result.workflow_yaml is None
- def test_unbacked_workflow_claim_not_rewritten_when_proposal_exists(self) -> None:
+ def test_clean_unverified_run_uses_deterministic_terminal_copy_when_proposal_exists(self) -> None:
wf = SimpleNamespace(name="drafted")
ctx = _ctx(
last_workflow=wf,
@@ -2236,7 +2262,10 @@ workflow_definition:
)
)
- assert agent_result.user_response == "Here's the workflow."
+ assert agent_result.user_response == (
+ "I built the workflow and the test run completed, but the goal outcome was not independently verified. "
+ "The workflow is available on the canvas for review."
+ )
assert agent_result.updated_workflow is wf
def test_goal_reached_false_on_failed_test_does_not_double_unvalidate(self) -> None:
@@ -2369,6 +2398,28 @@ workflow_definition:
assert agent_result.response_type == "REPLY"
assert agent_result.clear_proposed_workflow is False
+ def test_reply_with_unverified_clean_run_uses_deterministic_terminal_copy(self) -> None:
+ workflow = SimpleNamespace(name="final")
+ ctx = _ctx(
+ last_workflow=workflow,
+ last_workflow_yaml="final: yaml",
+ last_test_ok=True,
+ last_full_workflow_test_ok=True,
+ )
+ result = _fake_run_result({"type": "REPLY", "user_response": "The workflow is ready."})
+ agent_result = asyncio.run(
+ agent_module._translate_to_agent_result(
+ result, ctx, global_llm_context=None, chat_request=_chat_request(), organization_id="org-1"
+ )
+ )
+
+ assert agent_result.updated_workflow is workflow
+ assert "the workflow is ready" not in agent_result.user_response.lower()
+ assert "not independently verified" in agent_result.user_response.lower()
+ assert agent_result.proposal_disposition == "auto_applicable"
+ assert agent_result.narrative_payload is not None
+ assert agent_result.narrative_payload["verifiedSuccess"] is False
+
class TestCredentialRefusalReachesAgent:
"""Prove the SKY-9189 refusal rule is actually delivered to the agent.
diff --git a/tests/unit/test_copilot_schema_overlay_ban.py b/tests/unit/test_copilot_schema_overlay_ban.py
index 05ba83aa1..b4a1177cb 100644
--- a/tests/unit/test_copilot_schema_overlay_ban.py
+++ b/tests/unit/test_copilot_schema_overlay_ban.py
@@ -17,6 +17,7 @@ from skyvern.forge.sdk.copilot.tools import (
from skyvern.forge.sdk.copilot.tools.banned_blocks import (
_COPILOT_CODE_ONLY_BROWSER_BANNED_BLOCK_TYPES,
CopilotBlockPolicyStatus,
+ _code_only_browser_authoring_prompt,
)
from skyvern.forge.sdk.copilot.tools.mcp_hooks import _validate_block_pre_hook
@@ -192,6 +193,23 @@ async def test_code_schema_guidance_is_policy_rendered_and_allows_helper_validat
assert "Do not persist navigation/action/login" not in " ".join(out["data"]["code_only_guidance"])
+def test_code_only_authoring_prompt_does_not_recommend_blocked_page_evaluate() -> None:
+ prompt = _code_only_browser_authoring_prompt()
+
+ assert "`evaluate`" not in prompt
+ assert "locator" in prompt
+ assert "MCP/scout evidence" in prompt
+
+
+def test_code_only_authoring_prompt_requires_idempotent_credential_login() -> None:
+ prompt = _code_only_browser_authoring_prompt()
+
+ assert "Credentialed login code must be idempotent" in prompt
+ assert "already-authenticated page anchor" in prompt
+ assert "only fill username/password" in prompt
+ assert "login fields are visible" in prompt
+
+
@pytest.mark.parametrize("block_type", ["task", "task_v2"])
@pytest.mark.asyncio
async def test_standard_validate_block_pre_hook_preserves_existing_behavior(block_type: str, ctx: MagicMock) -> None:
diff --git a/tests/unit/test_workflow_copilot_route.py b/tests/unit/test_workflow_copilot_route.py
index ccab8b168..a227088e3 100644
--- a/tests/unit/test_workflow_copilot_route.py
+++ b/tests/unit/test_workflow_copilot_route.py
@@ -904,6 +904,105 @@ async def test_proposed_workflow_cleared_on_restore(
assert len(response_frames) == 1, f"expected exactly one RESPONSE frame, got {response_frames!r}"
expected_payload_workflow = proposal.model_dump.return_value if has_valid_proposal else None
assert response_frames[0].updated_workflow == expected_payload_workflow
+ if not auto_accept:
+ assert response_frames[0].workflow_applied is False
+
+
+async def test_apply_without_review_commits_and_clears_proposal_when_auto_accept_off(
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ monkeypatch.setattr(settings, "ENABLE_WORKFLOW_COPILOT_V2", True)
+
+ captured = _install_fake_create(monkeypatch)
+
+ chat = SimpleNamespace(
+ workflow_copilot_chat_id="chat-1",
+ workflow_permanent_id="wpid-1",
+ organization_id="org-1",
+ proposed_workflow={"workflow_id": "stale"},
+ auto_accept=False,
+ )
+ original_workflow = SimpleNamespace(
+ workflow_id="wf-canonical",
+ title="Original",
+ description="Original description",
+ workflow_definition=None,
+ )
+ proposal = MagicMock()
+ proposal.model_dump.return_value = {"workflow_id": "wf-applied"}
+ proposal.title = "Applied"
+ proposal.description = "Applied description"
+ proposal.workflow_definition = SimpleNamespace(blocks=[])
+ proposal.proxy_location = None
+ proposal.webhook_callback_url = None
+ proposal.totp_verification_url = None
+ proposal.totp_identifier = None
+ proposal.persist_browser_session = False
+ proposal.browser_profile_id = None
+ proposal.model = None
+ proposal.max_screenshot_scrolls = None
+ proposal.extra_http_headers = None
+ proposal.cdp_connect_headers = None
+ proposal.run_with = "agent"
+ proposal.ai_fallback = None
+ proposal.cache_key = None
+ proposal.adaptive_caching = False
+ proposal.code_version = 2
+ proposal.run_sequentially = False
+ proposal.sequential_key = None
+ agent_result = SimpleNamespace(
+ user_response="done",
+ updated_workflow=proposal,
+ global_llm_context=None,
+ workflow_yaml="title: Applied",
+ workflow_was_persisted=False,
+ clear_proposed_workflow=False,
+ proposal_disposition="auto_applicable",
+ apply_without_review=True,
+ has_staged_proposal=True,
+ staged_workflow=proposal,
+ turn_outcome=None,
+ )
+
+ restore_mock = _setup_new_copilot_mocks(monkeypatch, chat, original_workflow, agent_result)
+ workflow_service = SimpleNamespace(update_workflow_definition=AsyncMock())
+ monkeypatch.setattr(app, "WORKFLOW_SERVICE", workflow_service)
+ monkeypatch.setattr(
+ workflow_copilot_route,
+ "resolve_copilot_created_by_stamp",
+ AsyncMock(return_value="copilot"),
+ )
+
+ request = MagicMock()
+ request.headers = {"x-api-key": "sk-test-key"}
+ organization = SimpleNamespace(organization_id="org-1")
+
+ response = await workflow_copilot_chat_post(request, _make_chat_request(), organization)
+ assert response is captured["sentinel"]
+
+ stream = MagicMock()
+ stream.send = AsyncMock(return_value=True)
+ stream.is_disconnected = AsyncMock(return_value=False)
+
+ handler = captured["handler"]
+ assert callable(handler)
+ await handler(stream)
+
+ restore_mock.assert_not_awaited()
+ workflow_service.update_workflow_definition.assert_awaited_once()
+ update_calls = app.DATABASE.workflow_params.update_workflow_copilot_chat.await_args_list
+ assert [c for c in update_calls if c.kwargs.get("proposed_workflow") is not None] == []
+ assert [c for c in update_calls if c.kwargs.get("proposed_workflow") is None]
+
+ response_frames = [
+ call.args[0]
+ for call in stream.send.await_args_list
+ if isinstance(call.args[0], WorkflowCopilotStreamResponseUpdate)
+ ]
+ assert len(response_frames) == 1
+ assert response_frames[0].workflow_applied is True
+ assert response_frames[0].updated_workflow == {"workflow_id": "wf-applied"}
@pytest.mark.asyncio
diff --git a/tests/unit/test_workflow_copilot_route_helpers.py b/tests/unit/test_workflow_copilot_route_helpers.py
index 5dbf7d4a4..9594f4718 100644
--- a/tests/unit/test_workflow_copilot_route_helpers.py
+++ b/tests/unit/test_workflow_copilot_route_helpers.py
@@ -41,6 +41,7 @@ def _agent_result(
r.proposal_disposition = proposal_disposition
r.cancelled = cancelled
r.updated_workflow = updated_workflow
+ r.apply_without_review = kwargs.pop("apply_without_review", False)
# SKY-10318: explicitly set the new staging flag so MagicMock truthiness
# doesn't accidentally trigger the degraded-path branch in
# `_should_restore_persisted_workflow`.
@@ -128,11 +129,21 @@ class TestEffectiveAutoAccept:
validated = MagicMock()
validated.proposal_disposition = "auto_applicable"
validated.cancelled = False
+ validated.apply_without_review = False
assert _effective_auto_accept(True, validated) is True
assert _effective_auto_accept(False, validated) is False
assert _effective_auto_accept(None, validated) is False
+ def test_apply_without_review_overrides_auto_accept_setting(self) -> None:
+ validated = MagicMock()
+ validated.proposal_disposition = "auto_applicable"
+ validated.cancelled = False
+ validated.apply_without_review = True
+
+ assert _effective_auto_accept(False, validated) is True
+ assert _effective_auto_accept(None, validated) is True
+
def test_no_agent_result_is_not_auto_applicable(self) -> None:
assert _proposal_disposition(None) == "no_proposal"
assert _effective_auto_accept(True, None) is False