Automate browser based workflows with AI
Python aiapiautomationbrowserbrowser-automationcomputergptllmplaywrightpowerautomatepuppeteerpythonrpaseleniumvisionworkflow
SKY-10565: invalidate copilot verified-block trust when a workflow edit changes a block (#6391)
Andrew Neilsond63a103e292d
diff --git a/skyvern/forge/sdk/copilot/tools.py b/skyvern/forge/sdk/copilot/tools.pyindex 86b6dc4c4..be970d81b 100644--- a/skyvern/forge/sdk/copilot/tools.py+++ b/skyvern/forge/sdk/copilot/tools.py@@ -2765,6 +2765,109 @@ def _earliest_invalidated(requested_labels: list[str], invalidated: set[str]) ->return None+def _clear_runtime_anchor_evidence(copilot_ctx: Any) -> None:+ # Clears the runtime-anchor *trust* flags only. evidence.current_url /+ # page_title / workflow_run_id are left intact: an edit does not move the+ # browser, so they remain accurate observational context — the cleared flags+ # are what mark that state as no longer verified.+ evidence = copilot_ctx.workflow_verification_evidence+ copilot_ctx.verified_prefix_current_url = None+ evidence.live_page_state_verified = False+ evidence.verified_from_current_browser_state = False+ evidence.current_url_observed_after_workflow_run = False+ evidence.current_url_may_encode_runtime_state = False+++def _reset_all_verified_trust(copilot_ctx: Any) -> None:+ evidence = copilot_ctx.workflow_verification_evidence+ copilot_ctx.verified_prefix_labels = []+ copilot_ctx.verified_block_outputs = {}+ copilot_ctx.last_full_workflow_test_ok = False+ evidence.block_verified = []+ evidence.full_workflow_verified = False+ _clear_runtime_anchor_evidence(copilot_ctx)+++def _workflow_parameters_changed(prior_definition: object | None, new_definition: object | None) -> bool:+ new_by_key = {getattr(p, "key", None): p for p in (getattr(new_definition, "parameters", None) or [])}+ prior_by_key = {getattr(p, "key", None): p for p in (getattr(prior_definition, "parameters", None) or [])}+ # Any added or removed parameter is a change: a block may reference a key by+ # template without a config edit, so an added/removed key can alter behavior+ # the block-diff alone won't catch. Pure reordering is ignored (keyed access).+ if set(prior_by_key) != set(new_by_key):+ return True+ for key, prior_param in prior_by_key.items():+ try:+ if _stable_parameter_fingerprint(prior_param) != _stable_parameter_fingerprint(new_by_key[key]):+ return True+ except Exception:+ LOG.debug("Parameter fingerprint comparison failed on edit", exc_info=True)+ return True+ return False+++def _invalidate_verified_state_on_edit(+ copilot_ctx: Any,+ prior_definition: object | None,+ new_definition: object | None,+) -> None:+ evidence = copilot_ctx.workflow_verification_evidence+ if new_definition is None:+ # An unknown new definition can't be reconciled against; fail closed.+ if copilot_ctx.verified_prefix_labels or evidence.block_verified:+ _reset_all_verified_trust(copilot_ctx)+ return+ prior_labels = _workflow_definition_block_labels(prior_definition)+ trusted = set(copilot_ctx.verified_prefix_labels or []) | set(evidence.block_verified or [])++ invalidated: set[str] = set()+ if trusted:+ # No reconcilable prior, or a parameter change that could alter any+ # block's behavior — fail closed rather than reuse unproven trust.+ if prior_definition is None or _workflow_parameters_changed(prior_definition, new_definition):+ _reset_all_verified_trust(copilot_ctx)+ return+ # Diff the full prior chain, not just trusted labels, so a change to an+ # unverified upstream block still propagates to downstream trusted ones.+ full_order = list(prior_labels)+ for label in list(copilot_ctx.verified_prefix_labels or []) + list(evidence.block_verified or []):+ if label not in full_order:+ full_order.append(label)+ try:+ invalidated = _find_invalidated_labels(prior_definition, new_definition, full_order) & trusted+ except Exception:+ LOG.debug("Verified-state invalidation diff failed on edit", exc_info=True)+ _reset_all_verified_trust(copilot_ctx)+ return++ if invalidated:+ copilot_ctx.verified_prefix_labels = [+ label for label in copilot_ctx.verified_prefix_labels if label not in invalidated+ ]+ for label in invalidated:+ copilot_ctx.verified_block_outputs.pop(label, None)+ evidence.block_verified = [label for label in evidence.block_verified if label not in invalidated]+ # The recorded prefix-end URL came from a run that included a now-invalid+ # block, so it is no longer a safe runtime anchor for a re-run.+ _clear_runtime_anchor_evidence(copilot_ctx)++ # The kept prefix must still be a contiguous leading run of the new workflow;+ # a reorder or upstream insertion breaks that (set-membership trust is+ # order-blind), so fail closed when it no longer is.+ current_labels = _workflow_definition_block_labels(new_definition)+ remaining = list(copilot_ctx.verified_prefix_labels or [])+ if remaining and remaining != current_labels[: len(remaining)]:+ _reset_all_verified_trust(copilot_ctx)+ return++ # The end-to-end claim survives only an identical block list whose every block+ # is still verified, so append/removal/reorder/config edits all drop it.+ verified = set(remaining) | set(evidence.block_verified or [])+ if not (current_labels == prior_labels and all(label in verified for label in current_labels)):+ evidence.full_workflow_verified = False+ copilot_ctx.last_full_workflow_test_ok = False++def _nearest_upstream_state_establisher(requested_labels: list[str], target_label: str, new_definition: object | None) -> str | None:@@ -5547,7 +5650,9 @@ def _build_skyvern_mcp_overlays() -> dict[str, SchemaOverlay]:}-def _record_workflow_update_result(copilot_ctx: Any, result: dict[str, Any]) -> None:+def _record_workflow_update_result(+ copilot_ctx: Any, result: dict[str, Any], prior_definition: object | None = None+) -> None:if not (result.get("ok") and "_workflow" in result):return@@ -5575,6 +5680,8 @@ def _record_workflow_update_result(copilot_ctx: Any, result: dict[str, Any]) -># via update_workflow gets a LOOP DETECTED on the next legitimate run.clear_failed_step_tracker_for_tools_in_ctx(copilot_ctx, BLOCK_RUNNING_TOOLS)+ _invalidate_verified_state_on_edit(copilot_ctx, prior_definition, getattr(wf, "workflow_definition", None))+def _last_update_is_single_goto_bootstrap(copilot_ctx: CopilotContext) -> bool:last_workflow = copilot_ctx.last_workflow@@ -6483,13 +6590,14 @@ async def update_workflow_tool(sanitized = sanitize_tool_result_for_llm("update_workflow", result)return json.dumps(sanitized)+ prior_definition = await _get_prior_workflow_definition(copilot_ctx)with copilot_span("update_workflow", data={"yaml_length": len(workflow_yaml)}):result = await _update_workflow({**arguments, "raw_block_observation_refs": block_observation_refs},copilot_ctx,allow_missing_credentials=getattr(copilot_ctx, "allow_untested_workflow_draft", False) is True,)- _record_workflow_update_result(copilot_ctx, result)+ _record_workflow_update_result(copilot_ctx, result, prior_definition)record_tool_step_result_for_ctx(copilot_ctx, "update_workflow", arguments, result)sanitized = sanitize_tool_result_for_llm("update_workflow", result)return json.dumps(sanitized)@@ -6824,7 +6932,7 @@ async def update_and_run_blocks_tool(copilot_ctx,allow_missing_credentials=skip_run_after_update,)- _record_workflow_update_result(copilot_ctx, update_result)+ _record_workflow_update_result(copilot_ctx, update_result, prior_definition)if not update_result.get("ok"):record_tool_step_result_for_ctx(copilot_ctx, "update_and_run_blocks", arguments, update_result)@@ -6889,30 +6997,11 @@ async def update_and_run_blocks_tool()return json.dumps(skip_result)- # Step 2: Compute frontier and run the blocks+ # Step 2: Compute frontier and run the blocks.new_definition = Noneif copilot_ctx.last_workflow is not None:new_definition = getattr(copilot_ctx.last_workflow, "workflow_definition", None)- # YAML-diff-based invalidation: drop any verified-prefix entries whose- # block config changed (or are downstream of a change) BEFORE the next- # run plans the frontier. This is the only point where we shrink verified- # state — failed runs leave it intact so subsequent edits can still use- # the optimization. On append-only diffs this is a no-op.- if prior_definition is not None and new_definition is not None and copilot_ctx.verified_prefix_labels:- try:- edit_invalidated = _find_invalidated_labels(- prior_definition, new_definition, list(copilot_ctx.verified_prefix_labels)- )- except Exception:- edit_invalidated = set()- if edit_invalidated:- for label in edit_invalidated:- copilot_ctx.verified_block_outputs.pop(label, None)- copilot_ctx.verified_prefix_labels = [- label for label in copilot_ctx.verified_prefix_labels if label not in edit_invalidated- ]-labels_to_execute, block_outputs_to_seed, frontier_start_label = _plan_frontier(copilot_ctx, block_labels, prior_definition, new_definition)diff --git a/tests/unit/test_copilot_frontier.py b/tests/unit/test_copilot_frontier.pyindex 8ae578fca..ea6aec0ca 100644--- a/tests/unit/test_copilot_frontier.py+++ b/tests/unit/test_copilot_frontier.py@@ -27,7 +27,9 @@ from skyvern.forge.sdk.copilot.output_utils import (from skyvern.forge.sdk.copilot.tools import (_find_invalidated_labels,_frontier_run_size_error,+ _invalidate_verified_state_on_edit,_plan_frontier,+ _record_workflow_update_result,_referenced_output_labels,)from skyvern.forge.sdk.workflow.models.parameter import RESERVED_PARAMETER_KEYS@@ -58,8 +60,12 @@ class _FakeBlock:class _FakeParameter:- def __init__(self, key: str) -> None:+ def __init__(self, key: str, default_value: object = None) -> None:self.key = key+ self.default_value = default_value++ def model_dump(self, mode: str = "json") -> dict[str, Any]:+ return {"key": self.key, "default_value": self.default_value}class _FakeDefinition:@@ -1448,5 +1454,396 @@ def test_yaml_diff_invalidation_drops_edited_label_and_downstream() -> None:assert ctx.verified_block_outputs == {"a": "nav"}+# --------------------------------------------------------------------------- #+# Edit-time verified-state invalidation #+# --------------------------------------------------------------------------- #+++def _wf_def(*specs: tuple[str, str, dict[str, Any]], params: list[_FakeParameter] | None = None) -> _FakeDefinition:+ return _FakeDefinition(+ [_FakeBlock(label, block_type, config) for label, block_type, config in specs],+ parameters=params,+ )+++def _seed_verified(ctx: CopilotContext, labels: list[str], *, current_url: str | None, full: bool) -> None:+ ctx.verified_prefix_labels = list(labels)+ ctx.verified_block_outputs = {label: {"output": label} for label in labels}+ ctx.verified_prefix_current_url = current_url+ ctx.last_full_workflow_test_ok = full+ evidence = ctx.workflow_verification_evidence+ evidence.block_verified = list(labels)+ evidence.full_workflow_verified = full+ evidence.live_page_state_verified = True+ evidence.verified_from_current_browser_state = True+ evidence.current_url_observed_after_workflow_run = True+ evidence.current_url_may_encode_runtime_state = True+++def test_edit_invalidates_verified_goal_block_on_split_path() -> None:+ prior = _wf_def(+ ("open", "goto_url", {"url": "https://example.com"}),+ ("search", "navigation", {"prompt": "search"}),+ ("extract", "extraction", {"prompt": "grab results"}),+ )+ new = _wf_def(+ ("open", "goto_url", {"url": "https://example.com"}),+ ("search", "navigation", {"prompt": "search"}),+ ("extract", "extraction", {"prompt": "grab DIFFERENT results"}),+ )+ ctx = _make_ctx()+ _seed_verified(ctx, ["open", "search", "extract"], current_url="https://example.com/results", full=True)++ _invalidate_verified_state_on_edit(ctx, prior, new)++ assert ctx.verified_prefix_labels == ["open", "search"]+ assert "extract" not in ctx.verified_block_outputs+ assert ctx.workflow_verification_evidence.block_verified == ["open", "search"]+ assert ctx.verified_prefix_current_url is None+ assert ctx.last_full_workflow_test_ok is False+ assert ctx.workflow_verification_evidence.full_workflow_verified is False+ assert ctx.workflow_verification_evidence.live_page_state_verified is False+ assert ctx.workflow_verification_evidence.verified_from_current_browser_state is False++ # Split path: run_blocks passes old==new; the pruned prefix makes the edited+ # block the frontier again instead of reusing it as verified.+ labels, _seed, frontier = _plan_frontier(ctx, ["open", "search", "extract"], new, new)+ assert frontier == "extract"+ assert "extract" in labels+++def test_append_only_edit_keeps_prefix_but_drops_end_to_end_claim() -> None:+ prior = _wf_def(+ ("open", "goto_url", {"url": "https://example.com"}),+ ("search", "navigation", {"prompt": "search"}),+ )+ new = _wf_def(+ ("open", "goto_url", {"url": "https://example.com"}),+ ("search", "navigation", {"prompt": "search"}),+ ("extract", "extraction", {"prompt": "grab results"}),+ )+ ctx = _make_ctx()+ _seed_verified(ctx, ["open", "search"], current_url="https://example.com/after", full=True)++ _invalidate_verified_state_on_edit(ctx, prior, new)++ # Append-after-success optimization stays intact.+ assert ctx.verified_prefix_labels == ["open", "search"]+ assert set(ctx.verified_block_outputs) == {"open", "search"}+ assert ctx.workflow_verification_evidence.block_verified == ["open", "search"]+ assert ctx.verified_prefix_current_url == "https://example.com/after"+ # But the workflow is no longer verified end to end.+ assert ctx.workflow_verification_evidence.full_workflow_verified is False+ assert ctx.last_full_workflow_test_ok is False+++def test_remove_trailing_block_clears_full_workflow_evidence() -> None:+ prior = _wf_def(+ ("a", "goto_url", {"url": "https://example.com"}),+ ("b", "navigation", {"prompt": "b"}),+ ("c", "extraction", {"prompt": "c"}),+ )+ new = _wf_def(+ ("a", "goto_url", {"url": "https://example.com"}),+ ("b", "navigation", {"prompt": "b"}),+ )+ ctx = _make_ctx()+ _seed_verified(ctx, ["a", "b", "c"], current_url="https://example.com/c", full=True)++ _invalidate_verified_state_on_edit(ctx, prior, new)++ assert "c" not in ctx.verified_prefix_labels+ assert "c" not in ctx.verified_block_outputs+ assert "c" not in ctx.workflow_verification_evidence.block_verified+ assert ctx.verified_prefix_current_url is None+ assert ctx.workflow_verification_evidence.full_workflow_verified is False+ assert ctx.last_full_workflow_test_ok is False+++def test_no_op_resave_preserves_verified_state() -> None:+ specs = (+ ("a", "goto_url", {"url": "https://example.com"}),+ ("b", "navigation", {"prompt": "b"}),+ )+ ctx = _make_ctx()+ _seed_verified(ctx, ["a", "b"], current_url="https://example.com/b", full=True)++ _invalidate_verified_state_on_edit(ctx, _wf_def(*specs), _wf_def(*specs))++ assert ctx.verified_prefix_labels == ["a", "b"]+ assert ctx.verified_prefix_current_url == "https://example.com/b"+ assert ctx.workflow_verification_evidence.full_workflow_verified is True+ assert ctx.last_full_workflow_test_ok is True+++def test_no_op_resave_preserves_block_verified_only_end_to_end_claim() -> None:+ specs = (+ ("a", "goto_url", {"url": "https://example.com"}),+ ("b", "navigation", {"prompt": "b"}),+ )+ ctx = _make_ctx()+ evidence = ctx.workflow_verification_evidence+ evidence.block_verified = ["a", "b"]+ evidence.full_workflow_verified = True+ ctx.last_full_workflow_test_ok = True++ _invalidate_verified_state_on_edit(ctx, _wf_def(*specs), _wf_def(*specs))++ assert evidence.full_workflow_verified is True+ assert ctx.last_full_workflow_test_ok is True+++def test_missing_new_definition_with_trust_fails_closed() -> None:+ specs = (+ ("a", "goto_url", {"url": "https://example.com"}),+ ("b", "navigation", {"prompt": "b"}),+ )+ ctx = _make_ctx()+ _seed_verified(ctx, ["a", "b"], current_url="https://example.com/b", full=True)++ _invalidate_verified_state_on_edit(ctx, _wf_def(*specs), None)++ assert ctx.verified_prefix_labels == []+ assert ctx.verified_block_outputs == {}+ assert ctx.workflow_verification_evidence.block_verified == []+ assert ctx.last_full_workflow_test_ok is False+ assert ctx.workflow_verification_evidence.full_workflow_verified is False+++def test_edit_unverified_upstream_invalidates_downstream_verified() -> None:+ prior = _wf_def(+ ("open", "goto_url", {"url": "https://example.com"}),+ ("search", "navigation", {"prompt": "search"}),+ ("extract", "extraction", {"prompt": "extract"}),+ )+ new = _wf_def(+ ("open", "goto_url", {"url": "https://example.com"}),+ ("search", "navigation", {"prompt": "search CHANGED"}),+ ("extract", "extraction", {"prompt": "extract"}),+ )+ ctx = _make_ctx()+ # Non-contiguous verified state: open + extract verified, search NOT verified.+ ctx.verified_prefix_labels = ["open", "extract"]+ ctx.verified_block_outputs = {"open": 1, "extract": 3}+ ctx.workflow_verification_evidence.block_verified = ["open", "extract"]++ _invalidate_verified_state_on_edit(ctx, prior, new)++ assert "extract" not in ctx.verified_prefix_labels+ assert "extract" not in ctx.workflow_verification_evidence.block_verified+ assert "open" in ctx.verified_prefix_labels+++def test_chokepoint_uses_passed_prior_when_last_workflow_absent() -> None:+ prior = _wf_def(+ ("open", "goto_url", {"url": "https://example.com"}),+ ("extract", "extraction", {"prompt": "extract"}),+ )+ new = _wf_def(+ ("open", "goto_url", {"url": "https://example.com"}),+ ("extract", "extraction", {"prompt": "extract CHANGED"}),+ )+ ctx = _make_ctx()+ # Saved workflow verified via run_blocks without ever populating last_workflow.+ ctx.last_workflow = None+ ctx.verified_prefix_labels = ["open", "extract"]+ ctx.verified_block_outputs = {"open": 1, "extract": 2}+ ctx.workflow_verification_evidence.block_verified = ["open", "extract"]++ _record_workflow_update_result(ctx, {"ok": True, "_workflow": _FakeWorkflow(new)}, prior)++ assert ctx.last_workflow is not None+ assert "extract" not in ctx.verified_prefix_labels+ assert "extract" not in ctx.verified_block_outputs+ assert "extract" in tools._unverified_current_workflow_labels(ctx)+++def test_unavailable_prior_with_trust_fails_closed() -> None:+ new = _wf_def(+ ("open", "goto_url", {"url": "https://example.com"}),+ ("extract", "extraction", {"prompt": "extract"}),+ )+ ctx = _make_ctx()+ _seed_verified(ctx, ["open", "extract"], current_url="https://example.com/x", full=True)++ _invalidate_verified_state_on_edit(ctx, None, new)++ assert ctx.verified_prefix_labels == []+ assert ctx.verified_block_outputs == {}+ assert ctx.workflow_verification_evidence.block_verified == []+ assert ctx.verified_prefix_current_url is None+ assert ctx.workflow_verification_evidence.full_workflow_verified is False+ assert ctx.last_full_workflow_test_ok is False+++def test_differ_exception_fails_closed(monkeypatch: pytest.MonkeyPatch) -> None:+ prior = _wf_def(("a", "goto_url", {"url": "https://example.com"}))+ new = _wf_def(("a", "goto_url", {"url": "https://example.com/2"}))+ ctx = _make_ctx()+ _seed_verified(ctx, ["a"], current_url="https://example.com", full=True)++ def _boom(*_args: object, **_kwargs: object) -> set[str]:+ raise RuntimeError("differ blew up")++ monkeypatch.setattr(tools, "_find_invalidated_labels", _boom)++ _invalidate_verified_state_on_edit(ctx, prior, new)++ assert ctx.verified_prefix_labels == []+ assert ctx.verified_block_outputs == {}+ assert ctx.workflow_verification_evidence.block_verified == []+ assert ctx.workflow_verification_evidence.full_workflow_verified is False+ assert ctx.last_full_workflow_test_ok is False+ assert ctx.verified_prefix_current_url is None+++def test_fused_and_split_leave_identical_verified_state() -> None:+ prior = _wf_def(+ ("open", "goto_url", {"url": "https://example.com"}),+ ("search", "navigation", {"prompt": "search"}),+ ("extract", "extraction", {"prompt": "extract"}),+ )+ new = _wf_def(+ ("open", "goto_url", {"url": "https://example.com"}),+ ("search", "navigation", {"prompt": "search"}),+ ("extract", "extraction", {"prompt": "extract CHANGED"}),+ )++ def _build() -> CopilotContext:+ c = _make_ctx()+ _seed_verified(c, ["open", "search", "extract"], current_url="https://example.com/results", full=True)+ return c++ split_ctx = _build()+ _invalidate_verified_state_on_edit(split_ctx, prior, new)+ fused_ctx = _build()+ _invalidate_verified_state_on_edit(fused_ctx, prior, new)++ assert split_ctx.verified_prefix_labels == fused_ctx.verified_prefix_labels == ["open", "search"]+ assert split_ctx.verified_block_outputs == fused_ctx.verified_block_outputs+ assert (+ split_ctx.workflow_verification_evidence.block_verified+ == fused_ctx.workflow_verification_evidence.block_verified+ == ["open", "search"]+ )++ # Neither the split seam (new, new) nor the fused seam (prior, new) reuses the+ # edited block as verified.+ split_labels, _s, _sf = _plan_frontier(split_ctx, ["open", "search", "extract"], new, new)+ fused_labels, _f, _ff = _plan_frontier(fused_ctx, ["open", "search", "extract"], prior, new)+ assert "extract" in split_labels+ assert "extract" in fused_labels+++def test_parameter_value_change_resets_verified_trust() -> None:+ prior = _wf_def(+ ("search", "navigation", {"prompt": "search {{ term }}"}),+ ("extract", "extraction", {"prompt": "grab"}),+ params=[_FakeParameter("term", "cats")],+ )+ new = _wf_def(+ ("search", "navigation", {"prompt": "search {{ term }}"}),+ ("extract", "extraction", {"prompt": "grab"}),+ params=[_FakeParameter("term", "dogs")],+ )+ ctx = _make_ctx()+ _seed_verified(ctx, ["search", "extract"], current_url="https://example.com/r", full=True)++ _invalidate_verified_state_on_edit(ctx, prior, new)++ assert ctx.verified_prefix_labels == []+ assert ctx.verified_block_outputs == {}+ assert ctx.workflow_verification_evidence.block_verified == []+ assert ctx.workflow_verification_evidence.full_workflow_verified is False+ assert ctx.last_full_workflow_test_ok is False+++def test_parameter_addition_resets_verified_trust() -> None:+ # A block can reference a parameter by template without a config edit, so an+ # added key may alter behavior the block-diff alone won't catch — fail closed.+ prior = _wf_def(+ ("search", "navigation", {"prompt": "search"}),+ params=[_FakeParameter("term", "cats")],+ )+ new = _wf_def(+ ("search", "navigation", {"prompt": "search"}),+ params=[_FakeParameter("term", "cats"), _FakeParameter("limit", 10)],+ )+ ctx = _make_ctx()+ _seed_verified(ctx, ["search"], current_url="https://example.com/s", full=True)++ _invalidate_verified_state_on_edit(ctx, prior, new)++ assert ctx.verified_prefix_labels == []+ assert ctx.verified_block_outputs == {}+ assert ctx.workflow_verification_evidence.block_verified == []+ assert ctx.workflow_verification_evidence.full_workflow_verified is False+ assert ctx.last_full_workflow_test_ok is False+++def test_parameter_removal_resets_verified_trust() -> None:+ prior = _wf_def(+ ("search", "navigation", {"prompt": "search {{ term }}"}),+ ("extract", "extraction", {"prompt": "grab"}),+ params=[_FakeParameter("term", "cats"), _FakeParameter("limit", 10)],+ )+ new = _wf_def(+ ("search", "navigation", {"prompt": "search {{ term }}"}),+ ("extract", "extraction", {"prompt": "grab"}),+ params=[_FakeParameter("term", "cats")],+ )+ ctx = _make_ctx()+ _seed_verified(ctx, ["search", "extract"], current_url="https://example.com/r", full=True)++ _invalidate_verified_state_on_edit(ctx, prior, new)++ assert ctx.verified_prefix_labels == []+ assert ctx.verified_block_outputs == {}+ assert ctx.workflow_verification_evidence.block_verified == []+ assert ctx.workflow_verification_evidence.full_workflow_verified is False+ assert ctx.last_full_workflow_test_ok is False+++def test_parameter_reorder_keeps_verified_trust() -> None:+ # Parameters are referenced by key, so pure reordering changes no behavior.+ prior = _wf_def(+ ("search", "navigation", {"prompt": "search"}),+ params=[_FakeParameter("term", "cats"), _FakeParameter("limit", 10)],+ )+ new = _wf_def(+ ("search", "navigation", {"prompt": "search"}),+ params=[_FakeParameter("limit", 10), _FakeParameter("term", "cats")],+ )+ ctx = _make_ctx()+ _seed_verified(ctx, ["search"], current_url="https://example.com/s", full=True)++ _invalidate_verified_state_on_edit(ctx, prior, new)++ assert ctx.verified_prefix_labels == ["search"]+ assert ctx.workflow_verification_evidence.full_workflow_verified is True+ assert ctx.last_full_workflow_test_ok is True+++def test_reorder_resets_verified_trust() -> None:+ prior = _wf_def(+ ("a", "goto_url", {"url": "https://example.com"}),+ ("b", "navigation", {"prompt": "b"}),+ )+ new = _wf_def(+ ("b", "navigation", {"prompt": "b"}),+ ("a", "goto_url", {"url": "https://example.com"}),+ ("c", "extraction", {"prompt": "c"}),+ )+ ctx = _make_ctx()+ _seed_verified(ctx, ["a", "b"], current_url="https://example.com/b", full=True)++ _invalidate_verified_state_on_edit(ctx, prior, new)++ assert ctx.verified_prefix_labels == []+ assert ctx.verified_block_outputs == {}+ assert ctx.workflow_verification_evidence.full_workflow_verified is False+ assert ctx.last_full_workflow_test_ok is False++if __name__ == "__main__":pytest.main([__file__, "-v"])