Automate browser based workflows with AI
Python aiapiautomationbrowserbrowser-automationcomputergptllmplaywrightpowerautomatepuppeteerpythonrpaseleniumvisionworkflow
Reconcile the strict synthesis partition at one accounting point (SKY-13207) (#7909)
Andrew Neilsond999952e59ef
diff --git a/skyvern/forge/sdk/copilot/code_block_synthesis.py b/skyvern/forge/sdk/copilot/code_block_synthesis.pyindex 6eb82b8ad..760604d0a 100644--- a/skyvern/forge/sdk/copilot/code_block_synthesis.py+++ b/skyvern/forge/sdk/copilot/code_block_synthesis.py@@ -1814,6 +1814,14 @@ def _locator_expr(return _get_by_role_expr(role, name)notes.append("dropped an interaction with no selector and no role/name")+ if diagnostics is not None:+ diagnostics.dropped_interactions.append(+ {+ "trajectory_index": trajectory_index if trajectory_index is not None else -1,+ "tool_name": tool_name,+ "reason_code": "missing_selector_and_role_name",+ }+ )return ""@@ -2300,6 +2308,12 @@ def synthesize_code_block(record["lane"] = lanediagnostics.emitted_interactions.append(record)+ def already_recorded(trajectory_index: int) -> bool:+ return any(+ record.get("trajectory_index") == trajectory_index+ for record in (*diagnostics.emitted_interactions, *diagnostics.dropped_interactions)+ )+entry_url = ""entry_index = -1entry_replay_condition_active = False@@ -2519,17 +2533,15 @@ def synthesize_code_block(diagnostics.grounded_submit_binding_fingerprints.append(parameter_binding_snapshot.fingerprint)snapshot_recovery_emitted = True+ truncated_at_index = len(trajectory)for trajectory_index, interaction in enumerate(trajectory):if emitted >= _MAX_STEPS:diagnostics.truncated = Truenotes.append(f"trajectory truncated at {_MAX_STEPS} steps")+ truncated_at_index = trajectory_indexbreakif entry_replay_start_index and trajectory_index < entry_replay_start_index:- already_recorded = any(- record.get("trajectory_index") == trajectory_index- for record in (*diagnostics.emitted_interactions, *diagnostics.dropped_interactions)- )- if not already_recorded:+ if not already_recorded(trajectory_index):diagnostics.forgiven_interactions.append({"trajectory_index": trajectory_index,@@ -2567,13 +2579,14 @@ def synthesize_code_block(record_emission(trajectory_index, tool_name, "press", locator, line_start=line_start)else:if strict_selectors:- diagnostics.dropped_interactions.append(- {- "trajectory_index": trajectory_index,- "tool_name": tool_name,- "reason_code": "missing_selector",- }- )+ if not already_recorded(trajectory_index):+ diagnostics.dropped_interactions.append(+ {+ "trajectory_index": trajectory_index,+ "tool_name": tool_name,+ "reason_code": "missing_selector",+ }+ )continuelines.append(f"{action_indent}await page.keyboard.press({_py_str(key)})")record_emission(trajectory_index, tool_name, "press", "page.keyboard", line_start=line_start)@@ -2602,6 +2615,7 @@ def synthesize_code_block(lines.append(f"{action_indent}{_INDENT}await page.wait_for_timeout(1000)")lines.append(f"{action_indent}{_INDENT}{variable} = await page.evaluate({expression!r})")read_bindings.append((output_path, variable))+ record_emission(trajectory_index, tool_name, "evaluate", "page", line_start=line_start, lane="page_read")append_step(f"Read {output_path.removeprefix('output.')}", "read", line_start)emitted += 1continue@@ -2618,6 +2632,9 @@ def synthesize_code_block(continueline_start = len(lines) + 1lines.append(f"{action_indent}await page.wait_for_timeout({duration_ms})")+ record_emission(+ trajectory_index, tool_name, "wait_for_timeout", "page", line_start=line_start, lane="page_wait"+ )append_step(f"Wait {max(duration_ms // 1000, 1)}s", "wait", line_start)emitted += 1continue@@ -2773,6 +2790,9 @@ def synthesize_code_block(# Non-strict only: recording trajectories carry deliberate hovers; the# strict-imposition envelope keeps treating hover as unsupported.lines.append(f"{action_indent}await {locator}.hover()")+ record_emission(+ trajectory_index, tool_name, "hover", locator, line_start=line_start, lane="recording_hover"+ )append_step(f"Hover over {_step_target(interaction)}", "hover", line_start)else:notes.append(f"skipped unsupported interaction tool_name={tool_name!r}")@@ -2854,6 +2874,22 @@ def synthesize_code_block(lane="readonly_skip",)+ # Single reconciliation point for the retained manifest: a branch that neither emits, drops, nor forgives+ # its index lands here as a drop. The post-truncation tail is unvisited, so the truncation finding owns it.+ laned_indices = _recorded_partition_indices(diagnostics)+ for trajectory_index in diagnostics.retained_trajectory_indices:+ if trajectory_index >= truncated_at_index or trajectory_index in laned_indices:+ continue+ unaccounted = trajectory[trajectory_index]+ diagnostics.dropped_interactions.append(+ {+ "trajectory_index": trajectory_index,+ "tool_name": str(unaccounted.get("tool_name") or ""),+ "selector": str(unaccounted.get("selector") or "").strip(),+ "reason_code": "unaccounted_branch",+ }+ )+if compile_download_target and reached_download_target is not None:# The download affordance is observed in nav_targets, not necessarily a trajectory click, so the# download is an appended terminal step compiled from the typed target — never an in-place click upgrade.@@ -3189,7 +3225,8 @@ def spine_partition_findings() -> list[ObligationFinding]:"""Partition-exhaustiveness obligation over the full retained-index manifest: an uncovered requiredrung, a dropped interaction the allowlist does not forgive, a retained index in no record lane, or a- truncation are each a typed under-build finding. Forgiveness names the reason; it never absolves."""+ truncation are each a typed under-build finding. Forgiveness names the reason; it never absolves.+ Truncation supersedes the per-index lane check — the tail was never visited, so it reports once."""findings: list[ObligationFinding] = []for record in uncovered_required_emitted_interactions(diagnostics.emitted_interactions, draft_calls):index = record.get("trajectory_index")@@ -3212,12 +3249,13 @@ def spine_partition_findings(trajectory_index=index if isinstance(index, int) else None,))+ if diagnostics.truncated:+ findings.append(ObligationFinding(kind=TRUNCATED_FINDING))+ return findingsrecorded = _recorded_partition_indices(diagnostics)for index in diagnostics.retained_trajectory_indices:if index not in recorded:findings.append(ObligationFinding(kind=UNRECORDED_INDEX_FINDING, trajectory_index=index))- if diagnostics.truncated:- findings.append(ObligationFinding(kind=TRUNCATED_FINDING))return findingsdiff --git a/tests/unit/test_copilot_code_block_persist_seam.py b/tests/unit/test_copilot_code_block_persist_seam.pyindex cc28dfddc..c80fed235 100644--- a/tests/unit/test_copilot_code_block_persist_seam.py+++ b/tests/unit/test_copilot_code_block_persist_seam.py@@ -5974,6 +5974,88 @@ class TestCompiledAuthoringImposition:assert 'records = [{"number": "REC-001", "status": "credentialed"}]' in output_codeassert 'return {"records": records}' in output_code+ def _login_otp_ctx(self) -> CopilotContext:+ login_url = "https://example.com/login"+ ctx = _code_only_ctx()+ _enable_imposition(ctx)+ ctx.scout_trajectory = [+ _credential_fill_interaction("username", credential_id="cred_1", source_url=login_url),+ _credential_fill_interaction("password", credential_id="cred_1", source_url=login_url),+ {+ "tool_name": "click",+ "selector": ".btn-login",+ "source_url": login_url,+ "role": "button",+ "accessible_name": "Log in",+ },+ {+ "tool_name": "press_key",+ "selector": "input[type='password']",+ "key": "Enter",+ "source_url": login_url,+ },+ {+ "tool_name": "read_value",+ "read_expression": 'document.querySelector("#otp-hint").innerText',+ "read_output_path": "output.otp_hint",+ "source_url": login_url,+ },+ _credential_fill_interaction("totp", credential_id="cred_1", source_url=login_url),+ {+ "tool_name": "click",+ "selector": ".btn-primary-submit",+ "source_url": login_url,+ "role": "button",+ "accessible_name": "Login",+ },+ ]+ return ctx++ _INVENTED_SUBMIT_NAME_YAML = _credential_code_yaml(+ credential_id="cred_1",+ code="""+ await page.locator("#email").fill(login_credential.username)+ await page.locator("input[type='password']").fill(login_credential.password)+ await page.locator(".btn-login").click()+ await page.locator("#totpmfa").fill(await login_credential.otp())+ await page.get_by_role("button", name="Continue", exact=True).click()+ """,+ )++ @pytest.mark.asyncio+ async def test_login_otp_persist_imposes_demonstrated_submit_over_invented_role_name(+ self, monkeypatch: pytest.MonkeyPatch+ ) -> None:+ _stub_successful_update(monkeypatch)+ ctx = self._login_otp_ctx()++ result = await _update_workflow(+ {"workflow_yaml": self._INVENTED_SUBMIT_NAME_YAML}, ctx, allow_missing_credentials=True+ )++ assert result["ok"] is True+ assert result["data"]["imposed_substitutions"] is not None+ parsed = parse_workflow_yaml(ctx.workflow_yaml)+ assert isinstance(parsed, dict)+ code = str(_single_code_block(parsed)["code"])+ assert 'await page.locator(".btn-primary-submit").click()' in code+ assert "Continue" not in code++ @pytest.mark.asyncio+ async def test_login_otp_persist_retains_the_captured_output_read(self, monkeypatch: pytest.MonkeyPatch) -> None:+ _stub_successful_update(monkeypatch)+ ctx = self._login_otp_ctx()++ result = await _update_workflow(+ {"workflow_yaml": self._INVENTED_SUBMIT_NAME_YAML}, ctx, allow_missing_credentials=True+ )++ assert result["ok"] is True+ parsed = parse_workflow_yaml(ctx.workflow_yaml)+ assert isinstance(parsed, dict)+ code = str(_single_code_block(parsed)["code"])+ assert "await page.evaluate('document.querySelector(\"#otp-hint\").innerText')" in code+def _download_ctx(self) -> CopilotContext:from skyvern.forge.sdk.copilot.reached_download_target import ReachedDownloadTarget@@ -9845,6 +9927,16 @@ class TestBrowserSurfaceRejectionProvenance:assert provenance.nearest_selector == "#gone"assert not any("never_captured" in violation for violation in validation.violations)+ def test_unaccounted_branch_drop_does_not_relabel_an_unrelated_mutation(self) -> None:+ diagnostics = _spine_emission_diagnostics()+ diagnostics.dropped_interactions.append(+ {"trajectory_index": 2, "tool_name": "click", "selector": "#skipped", "reason_code": "unaccounted_branch"}+ )++ validation = _gate_validation('await page.locator("#hallucinated").click()\n', diagnostics)++ assert [provenance.kind for provenance in validation.provenance] == ["never_captured"]+def test_locator_form_divergence_matches_emitted_record(self) -> None:diagnostics = SynthesisDiagnostics(emitted_interaction_count=1,@@ -10184,6 +10276,48 @@ class TestScoutedSpineUnderBuild:assert events[0]["required_rung_count"] == 2assert events[0]["covered_rung_count"] == 1+ def test_retained_index_in_no_lane_still_declines_imposition(self, monkeypatch: pytest.MonkeyPatch) -> None:+ diagnostics = _spine_emission_diagnostics()+ diagnostics.retained_trajectory_indices = [0, 1, 2]+ monkeypatch.setattr(+ workflow_update_module,+ "synthesize_code_block",+ lambda *a, **k: _fake_spine_synthesized(diagnostics=diagnostics),+ )+ ctx = _quote_ctx()++ with capture_logs() as logs:+ result = workflow_update_module._maybe_impose_synthesized_code_block(+ _records_block_yaml(_SPINE_SYNTH_CODE), ctx+ )++ assert result.substitutions is None+ assert any("scouted_spine_unrecorded_index" in violation for violation in result.violations)+ assert result.repair_context is not None+ assert result.repair_context.reason_code == "scouted_spine_unrecorded_index"+ events = [log for log in logs if log["event"] == "copilot_scouted_spine_under_build"]+ assert [event["reason_code"] for event in events] == ["scouted_spine_unrecorded_index"]++ def test_unaccounted_branch_drop_still_declines_imposition(self, monkeypatch: pytest.MonkeyPatch) -> None:+ diagnostics = _spine_emission_diagnostics()+ diagnostics.retained_trajectory_indices = [0, 1, 2]+ diagnostics.dropped_interactions.append(+ {"trajectory_index": 2, "tool_name": "click", "selector": "#gone", "reason_code": "unaccounted_branch"}+ )+ monkeypatch.setattr(+ workflow_update_module,+ "synthesize_code_block",+ lambda *a, **k: _fake_spine_synthesized(diagnostics=diagnostics),+ )+ ctx = _quote_ctx()++ result = workflow_update_module._maybe_impose_synthesized_code_block(+ _records_block_yaml(_SPINE_SYNTH_CODE), ctx+ )++ assert result.substitutions is None+ assert any("unaccounted_branch" in violation for violation in result.violations)+def test_lane_flagged_emissions_do_not_trigger_under_build(self, monkeypatch: pytest.MonkeyPatch) -> None:diagnostics = SynthesisDiagnostics(emitted_interaction_count=4,@@ -11443,6 +11577,25 @@ class TestAdmittedImpositionOwnsSpineCoverage:events = [log for log in logs if log["event"] == "copilot_scouted_spine_under_build"]assert events and events[0]["site"] == "pre_persist"+ def test_pre_persist_observation_is_gated_on_the_repeated_omission_latch(self) -> None:+ ctx = _records_spine_ctx()+ ctx.update_workflow_called = True+ under_built = _records_block_yaml('await page.locator("#stage-a").click()')++ with capture_logs() as unlatched_logs:+ assert workflow_update_module._current_draft_repeats_prior_scouted_spine_omission(under_built, ctx) is False+ assert not [log for log in unlatched_logs if log["event"] == "copilot_scouted_spine_under_build"]++ probe = workflow_update_module._pre_persist_scouted_spine_result(under_built, ctx)+ assert probe is not None+ ctx.scouted_spine_repeated_identical_missing_steps = True+ ctx.scouted_spine_previous_omission_digest = probe.omission_digest++ with capture_logs() as latched_logs:+ assert workflow_update_module._current_draft_repeats_prior_scouted_spine_omission(under_built, ctx) is True+ events = [log for log in latched_logs if log["event"] == "copilot_scouted_spine_under_build"]+ assert [event["site"] for event in events] == ["pre_persist"]+def test_ungrounded_sibling_mixing_ambiguous_and_concrete_calls_is_replaced_by_the_spine(self) -> None:ctx = _quote_ctx()ctx.update_workflow_called = Truediff --git a/tests/unit/test_copilot_code_block_synthesis.py b/tests/unit/test_copilot_code_block_synthesis.pyindex 3f4173737..7b5c397eb 100644--- a/tests/unit/test_copilot_code_block_synthesis.py+++ b/tests/unit/test_copilot_code_block_synthesis.py@@ -12,6 +12,8 @@ import keywordimport reimport sysimport textwrap+from collections import Counter+from collections.abc import Mappingfrom dataclasses import replacefrom types import ModuleType, SimpleNamespacefrom typing import Any@@ -19,6 +21,7 @@ from typing import Anyimport pytestfrom structlog.testing import capture_logs+from skyvern.forge.sdk.copilot import code_block_synthesis as code_block_synthesis_modulefrom skyvern.forge.sdk.copilot.authoring_parameter_binding import (_SELECTION_MATCH_BASES,AuthoringParameterBindingCandidate,@@ -50,7 +53,6 @@ from skyvern.forge.sdk.copilot.code_block_synthesis import (SCOUTED_SPINE_TRUNCATED_REASON_CODE,TRUNCATED_FINDING,UNFORGIVEN_DROP_FINDING,- UNRECORDED_INDEX_FINDING,ProducedStaticReturnEnvelope,SynthesisDiagnostics,_get_by_role_expr_strict,@@ -3826,6 +3828,107 @@ class TestEmittedInteractionPartition:{"tool_name": "press_key", "selector": "#name", "key": "Enter"},]+ def _login_otp_trajectory(self) -> list[dict[str, Any]]:+ login_url = "https://example.com/login"+ return [+ _interaction(+ CREDENTIAL_FILL_TOOL_NAME,+ selector="#username",+ source_url=login_url,+ credential_id="cred_1",+ credential_field="username",+ typed_length=20,+ ),+ _interaction(+ CREDENTIAL_FILL_TOOL_NAME,+ selector="#password",+ source_url=login_url,+ credential_id="cred_1",+ credential_field="password",+ typed_length=14,+ ),+ _interaction("click", selector=".btn-login", role="button", accessible_name="Log in"),+ _interaction("press_key", selector="button", key="Enter"),+ _interaction(+ "read_value",+ read_expression='document.querySelector("#otp-hint").innerText',+ read_output_path="output.otp_hint",+ ),+ _interaction(+ CREDENTIAL_FILL_TOOL_NAME,+ selector="#totp",+ credential_id="cred_1",+ credential_field="totp",+ typed_length=6,+ ),+ _interaction("click", selector=".btn-primary-submit", role="button", accessible_name="Login"),+ ]++ def _lane_index_counts(self, diagnostics: SynthesisDiagnostics) -> Counter[int]:+ return Counter(+ record["trajectory_index"]+ for group in (+ diagnostics.emitted_interactions,+ diagnostics.dropped_interactions,+ diagnostics.forgiven_interactions,+ )+ for record in group+ )++ def test_login_otp_trajectory_puts_every_retained_index_in_exactly_one_lane(self) -> None:+ trajectory = self._login_otp_trajectory()++ result = synthesize_code_block(trajectory, strict_selectors=True)++ assert result is not None+ diagnostics = result.diagnostics+ assert diagnostics.truncated is False+ emitted = {record["trajectory_index"] for record in diagnostics.emitted_interactions}+ dropped = {record["trajectory_index"] for record in diagnostics.dropped_interactions}+ forgiven = {record["trajectory_index"] for record in diagnostics.forgiven_interactions}+ assert emitted | dropped | forgiven == set(range(len(trajectory)))+ assert emitted & dropped == set()+ assert emitted & forgiven == set()+ assert dropped & forgiven == set()+ assert set(self._lane_index_counts(diagnostics).values()) == {1}++ def test_captured_read_and_wait_records_carry_a_lane(self) -> None:+ trajectory = self._login_otp_trajectory()+ trajectory.insert(5, _interaction("wait", duration_ms=2000))++ result = synthesize_code_block(trajectory, strict_selectors=True)++ assert result is not None+ by_index = {record["trajectory_index"]: record for record in result.diagnostics.emitted_interactions}+ assert by_index[4]["method"] == "evaluate"+ assert by_index[4]["lane"] == "page_read"+ assert by_index[5]["method"] == "wait_for_timeout"+ assert by_index[5]["lane"] == "page_wait"+ assert set(self._lane_index_counts(result.diagnostics).values()) == {1}+ uncovered = uncovered_required_emitted_interactions(result.diagnostics.emitted_interactions, [])+ assert {record["trajectory_index"] for record in uncovered}.isdisjoint({4, 5})++ def test_non_strict_hover_and_anchorless_interaction_stay_in_exactly_one_lane(self) -> None:+ trajectory = [+ _interaction("click", selector="#open", source_url="https://example.com/start"),+ _interaction("hover", selector="#menu"),+ _interaction("click"),+ ]++ result = synthesize_code_block(trajectory, strict_selectors=False)++ assert result is not None+ diagnostics = result.diagnostics+ hover_record = next(record for record in diagnostics.emitted_interactions if record["trajectory_index"] == 1)+ assert hover_record["method"] == "hover"+ assert hover_record["lane"] == "recording_hover"+ dropped_reasons = {+ record["trajectory_index"]: record["reason_code"] for record in diagnostics.dropped_interactions+ }+ assert dropped_reasons[2] == "missing_selector_and_role_name"+ assert set(self._lane_index_counts(diagnostics)) == set(diagnostics.retained_trajectory_indices)+ assert set(self._lane_index_counts(diagnostics).values()) == {1}+def test_every_retained_index_in_exactly_one_partition(self) -> None:trajectory = self._mixed_trajectory()@@ -3907,6 +4010,58 @@ class TestEmittedInteractionPartition:{"trajectory_index": 1, "tool_name": "click", "lane": "entry_replay_prefix"}]+ def test_deferred_readonly_index_lands_in_exactly_one_lane(self) -> None:+ trajectory = [+ {"tool_name": "click", "selector": "#stage-a", "source_url": "https://example.com/records"},+ _readonly_type(control_readonly=True, control_value_satisfied=False),+ ]++ result = synthesize_code_block(trajectory, strict_selectors=True)++ assert result is not None+ assert self._lane_index_counts(result.diagnostics) == Counter({0: 1, 1: 1})+ by_index = {record["trajectory_index"]: record for record in result.diagnostics.emitted_interactions}+ assert by_index[1]["lane"] == "readonly_skip"++ def test_branch_yielding_no_locator_without_a_record_still_lands_in_one_lane(+ self, monkeypatch: pytest.MonkeyPatch+ ) -> None:+ trajectory = [+ {"tool_name": "click", "selector": "#stage-a", "source_url": "https://example.com/records"},+ {"tool_name": "click", "selector": "#stage-b"},+ ]++ def forgetful_locator_expr(+ interaction: Mapping[str, Any],+ notes: list[str],+ *,+ diagnostics: SynthesisDiagnostics | None = None,+ trajectory_index: int | None = None,+ tool_name: str = "",+ strict_selectors: bool = False,+ ) -> str:+ selector = str(interaction.get("selector") or "")+ return "" if selector == "#stage-b" else f'page.locator("{selector}")'++ monkeypatch.setattr(code_block_synthesis_module, "_locator_expr", forgetful_locator_expr)++ result = synthesize_code_block(trajectory, strict_selectors=True)++ assert result is not None+ diagnostics = result.diagnostics+ assert self._lane_index_counts(diagnostics) == Counter({0: 1, 1: 1})+ assert diagnostics.dropped_interactions == [+ {+ "trajectory_index": 1,+ "tool_name": "click",+ "selector": "#stage-b",+ "reason_code": "unaccounted_branch",+ }+ ]+ findings = spine_partition_findings(diagnostics, _covering_draft_calls(diagnostics), trajectory)+ assert [finding.kind for finding in findings] == [UNFORGIVEN_DROP_FINDING]+ assert obligation_finding_reason_code(findings[0]) == SCOUTED_SPINE_DROPPED_UNFORGIVEN_REASON_CODE+def _covering_draft_calls(diagnostics: SynthesisDiagnostics) -> list[tuple[str, str]]:return [@@ -3941,6 +4096,16 @@ class TestSpinePartitionFindings:draft_calls = _covering_draft_calls(result.diagnostics)assert spine_partition_findings(result.diagnostics, draft_calls, self._spine_trajectory()) == []+ def test_deferred_readonly_trajectory_has_no_findings(self) -> None:+ trajectory = [+ {"tool_name": "click", "selector": "#stage-a", "source_url": "https://example.com/records"},+ _readonly_type(control_readonly=True, control_value_satisfied=False),+ ]+ result = synthesize_code_block(trajectory, strict_selectors=True)+ assert result is not None+ draft_calls = _covering_draft_calls(result.diagnostics)+ assert spine_partition_findings(result.diagnostics, draft_calls, trajectory) == []+def test_omitted_demonstrated_totp_fill_is_an_uncovered_rung_finding(self) -> None:login_url = "https://example.com/login"trajectory = [@@ -3999,7 +4164,7 @@ class TestSpinePartitionFindings:findings = spine_partition_findings(result.diagnostics, draft_calls, trajectory)assert all(finding.kind != UNFORGIVEN_DROP_FINDING for finding in findings)- def test_truncation_leaves_post_break_indices_in_manifest_only(self) -> None:+ def test_truncation_reports_once_and_leaves_the_tail_unlaned(self) -> None:trajectory = [{"tool_name": "click", "selector": f"#stage-{index}", "source_url": "https://example.com/records"}for index in range(_MAX_STEPS + 3)@@ -4010,14 +4175,11 @@ class TestSpinePartitionFindings:assert diagnostics.truncated is Trueassert diagnostics.retained_trajectory_indices == list(range(len(trajectory)))recorded = {record["trajectory_index"] for record in diagnostics.emitted_interactions}- post_break = set(diagnostics.retained_trajectory_indices) - recorded- assert post_break+ assert set(diagnostics.retained_trajectory_indices) - recorded+ assert diagnostics.dropped_interactions == []findings = spine_partition_findings(diagnostics, _covering_draft_calls(diagnostics), trajectory)- kinds = {finding.kind for finding in findings}- assert TRUNCATED_FINDING in kinds- assert UNRECORDED_INDEX_FINDING in kinds- truncated_finding = next(finding for finding in findings if finding.kind == TRUNCATED_FINDING)- assert obligation_finding_reason_code(truncated_finding) == SCOUTED_SPINE_TRUNCATED_REASON_CODE+ assert [finding.kind for finding in findings] == [TRUNCATED_FINDING]+ assert obligation_finding_reason_code(findings[0]) == SCOUTED_SPINE_TRUNCATED_REASON_CODE_STRUCTURAL_BUTTON_XPATH = 'xpath=/*[name()="body"][1]/*[name()="button"][3]'