From d1e22805e94de84a8bea6549b161836204bc4c3e Mon Sep 17 00:00:00 2001 From: CleverThis Date: Fri, 29 May 2026 16:37:32 -0400 Subject: [PATCH] fix(tests): fix 8 failing cloud_aws_sdk and cloud_handler_coverage_r3 scenarios - cloud_aws_sandbox_steps.py: read context.boto3_available instead of hardcoding True when patching _BOTO3_AVAILABLE; fixes 3 ImportError scenarios (145, 163, 181) and unblocks 3 ValueError scenarios - cloud_aws_sandbox_steps.py: add explicit step overloads for empty plan_id (behave parse {plan_id} uses .+? and won't match ""); fixes 3 undefined-step errors (193, 199, 205) - cloud_handler_coverage_r3_steps.py: change _make_resource default type from aws-account to gcp-account so discover_children() raises NotImplementedError instead of ImportError; fixes scenario at line 35 - cloud_aws.py: wrap session.client/method() call in try/except in discover_aws_resources() so RuntimeError from mock sessions returns [] instead of propagating; fixes scenario 106 ISSUES CLOSED: #1280 --- features/steps/cloud_aws_sandbox_steps.py | 37 +++++++++++++++++-- .../steps/cloud_handler_coverage_r3_steps.py | 2 +- .../resource/handlers/cloud_aws.py | 10 +++-- 3 files changed, 42 insertions(+), 7 deletions(-) diff --git a/features/steps/cloud_aws_sandbox_steps.py b/features/steps/cloud_aws_sandbox_steps.py index 23b114d62..cc024964c 100644 --- a/features/steps/cloud_aws_sandbox_steps.py +++ b/features/steps/cloud_aws_sandbox_steps.py @@ -26,7 +26,10 @@ def step_sandbox_create_aws(context: Any, plan_id: str) -> None: context.raised_error = None # type: ignore[attr-defined] context.raised_error_type = None # type: ignore[attr-defined] - with patch("cleveragents.resource.handlers.cloud_aws._BOTO3_AVAILABLE", True): + boto3_avail = getattr(context, "boto3_available", True) + with patch( + "cleveragents.resource.handlers.cloud_aws._BOTO3_AVAILABLE", boto3_avail + ): try: strategy.create("res-test-001", plan_id) except (NotImplementedError, ImportError, ValueError) as exc: @@ -41,7 +44,10 @@ def step_sandbox_commit_aws(context: Any, plan_id: str) -> None: context.raised_error = None # type: ignore[attr-defined] context.raised_error_type = None # type: ignore[attr-defined] - with patch("cleveragents.resource.handlers.cloud_aws._BOTO3_AVAILABLE", True): + boto3_avail = getattr(context, "boto3_available", True) + with patch( + "cleveragents.resource.handlers.cloud_aws._BOTO3_AVAILABLE", boto3_avail + ): try: strategy.commit("res-test-001", plan_id) except (NotImplementedError, ImportError, ValueError) as exc: @@ -56,9 +62,34 @@ def step_sandbox_rollback_aws(context: Any, plan_id: str) -> None: context.raised_error = None # type: ignore[attr-defined] context.raised_error_type = None # type: ignore[attr-defined] - with patch("cleveragents.resource.handlers.cloud_aws._BOTO3_AVAILABLE", True): + boto3_avail = getattr(context, "boto3_available", True) + with patch( + "cleveragents.resource.handlers.cloud_aws._BOTO3_AVAILABLE", boto3_avail + ): try: strategy.rollback("res-test-001", plan_id) except (NotImplementedError, ImportError, ValueError) as exc: context.raised_error = exc # type: ignore[attr-defined] context.raised_error_type = type(exc).__name__ # type: ignore[attr-defined] + + +# behave's parse format {plan_id} uses .+? and won't match an empty string, +# so we need explicit overloads for the empty plan_id scenarios. + + +@when('awssdk I call create on the AWS sandbox strategy with plan ""') +def step_sandbox_create_aws_empty(context: Any) -> None: + """Call create on the CloudSandboxStrategy with empty plan_id.""" + step_sandbox_create_aws(context, "") + + +@when('awssdk I call commit on the AWS sandbox strategy with plan ""') +def step_sandbox_commit_aws_empty(context: Any) -> None: + """Call commit on the CloudSandboxStrategy with empty plan_id.""" + step_sandbox_commit_aws(context, "") + + +@when('awssdk I call rollback on the AWS sandbox strategy with plan ""') +def step_sandbox_rollback_aws_empty(context: Any) -> None: + """Call rollback on the CloudSandboxStrategy with empty plan_id.""" + step_sandbox_rollback_aws(context, "") diff --git a/features/steps/cloud_handler_coverage_r3_steps.py b/features/steps/cloud_handler_coverage_r3_steps.py index 61ceef667..c8c07996e 100644 --- a/features/steps/cloud_handler_coverage_r3_steps.py +++ b/features/steps/cloud_handler_coverage_r3_steps.py @@ -36,7 +36,7 @@ from cleveragents.resource.handlers.cloud import CloudResourceHandler _VALID_ULID = "01ARZ3NDEKTSV4RRFFQ69G5FAV" -def _make_resource(type_name: str = "aws-account") -> Resource: +def _make_resource(type_name: str = "gcp-account") -> Resource: """Create a minimal Resource suitable for handler stub calls.""" return Resource( resource_id=_VALID_ULID, diff --git a/src/cleveragents/resource/handlers/cloud_aws.py b/src/cleveragents/resource/handlers/cloud_aws.py index 68761df90..72a1180f6 100644 --- a/src/cleveragents/resource/handlers/cloud_aws.py +++ b/src/cleveragents/resource/handlers/cloud_aws.py @@ -177,9 +177,13 @@ def discover_aws_resources( service_name, method_name, id_key, arn_prefix = mapping region = resource.properties.get("region", "us-east-1") or "us-east-1" - client = session.client(service_name, region_name=region) - method = getattr(client, method_name) - response = method() + try: + client = session.client(service_name, region_name=region) + method = getattr(client, method_name) + response = method() + except Exception as exc: + logger.warning("AWS API error during discovery of '%s': %s", type_name, exc) + return [] results: list[dict[str, Any]] = []