Skip to content

test(cloudwatch): a botocore-driven check for the JSON path (#757) - #792

Merged
scttfrdmn merged 1 commit into
mainfrom
feat/757-botocore-cloudwatch-check
Sep 11, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
feat/757-botocore-cloudwatch-check

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

#757's last acceptance criterion had two halves:

  • test/e2e gains a CloudWatch journey, and a botocore-driven check exists for the path aws-sdk-go-v2 does not take.

PR #791 shipped the journey. This is the other half, and without it the issue cannot close.

Closes #757.

Why a Go test cannot cover this

aws-sdk-go-v2 resolves CloudWatch to Smithy RPC v2 CBOR. So do all of substrate's Go tests
that speak a real protocol — the unit tests, the httptest tiers, and the new test/e2e
journey. Every one of them exercises CBOR and none exercises awsJson1_0, which is the
protocol botocore picks. That is not a thin gap; it is exactly how substrate shipped a
CloudWatch that answered XML to the AWS CLI while its own suite was green, and the failure mode
was silence: the call returned HTTP 200, botocore's JSON parser found no members, and
aws cloudwatch list-metrics printed nothing at all rather than failing.

A manual aws invocation proved the fix in PR #791; nothing automated guards it.

Fail-before, pass-after

Same test file, two binaries, substrate_isolated starting a real process per test:

SUBSTRATE_BINARY=<ae8d706>   5 failed
SUBSTRATE_BINARY=<0c3e7d9>   5 passed

At ae8d706 the JSON request body was never parsed, so set_alarm_state on a
never-created alarm reported InvalidParameterValue (AlarmName missing) rather than the
ResourceNotFoundException the test asserts — a good illustration of the class of bug this
tier catches and the CBOR tier cannot.

The pre-fix binary was built from a detached worktree at ae8d706, not from a mutated tree.

What the five tests assert

  • test_put_metric_data_body_is_parsed — a JSON MetricData array reaches state, so
    ListMetrics reports both points. This is the input half: the handler reads
    MetricData.member.1.MetricName, botocore sends an array.
  • test_list_metrics_honours_the_metric_name_filter — the filter is applied, not ignored.
  • test_alarm_round_trip_keeps_modeled_types — Threshold reads back 80.5, not 80; a
    renderer writing every number as an integer would pass a round-trip test against itself.
    Also EvaluationPeriods == 2, Period == 300, ActionsEnabled is True, StateReasonData
    (stored but never returned before CloudWatch emulation doesn't speak rpc-v2-cbor — current aws-sdk-go-v2 clients fail to deserialize responses #785), "OKActions" not in alarm (absent, not empty),
    "NextToken" not in for_metric, disable/enable, and delete leaving MetricAlarms == [].
  • test_get_metric_data_reports_no_results_rather_than_nothing — both lists present and
    empty, which is the distinction a bare 200 with an unparseable body destroyed.
  • test_a_refusal_reports_its_code_and_message — ClientError with
    Code == "ResourceNotFoundException", the alarm name in the message, HTTP 404. Shaped as
    REST/JSON the code went into a header botocore's JSON parser never reads, so a refusal
    surfaced as An error occurred (404) and a consumer's except branch keyed on the code was
    unreachable.

The dependency, deliberately an extra

boto3 is a test extra, not a dependency — the plugin does not need it, and a consumer
installing pytest-substrate should not inherit an AWS SDK to use a server fixture. The wheel
metadata confirms the split:

Requires-Dist: pytest>=9.0.3
Provides-Extra: test
Requires-Dist: boto3>=1.35; extra == "test"

The CI install therefore becomes pip install -e './python[test]'. Without that change the
tests would importorskip and pass vacuously
, which is a worse outcome than not writing them:
the gap would look closed. The guard is pytest.importorskip rather than a bare import so a
contributor without boto3 gets a skip instead of a collection error.

This is the first Python test that launches a substrate process rather than exercising a
mock; all 459 previous lines were mocks. Verified it starts and tears down cleanly, including
under repeated runs, before pushing.

Verification

ruff check python/src python/tests        All checks passed
pytest python/tests -v                   37 passed (5 new)  — against HEAD
pytest tests/test_cloudwatch_botocore.py 5 failed           — against ae8d706
python -m build --wheel                  0; extra present, boto3 not in the base deps
.github/workflows/ci.yml                 parses; the install step is the only change

No Go files change in this PR.

aws-sdk-go-v2 resolves CloudWatch to Smithy RPC v2 CBOR, so every Go test —
unit, httptest and the test/e2e journey alike — exercises CBOR and none
exercises awsJson1_0. That is the gap that let substrate ship a CloudWatch
answering XML to the AWS CLI while its own suite stayed green, and the failure
mode was silence: HTTP 200, no members found by botocore's JSON parser, and
`aws cloudwatch list-metrics` printing nothing at all.

python/tests/test_cloudwatch_botocore.py drives boto3 against a real substrate
process over five behaviours: a JSON MetricData array reaching state, the
MetricName filter, an alarm keeping its modeled types (Threshold reads back
80.5, not 80), GetMetricData's two present-and-empty lists, and a refusal
arriving as a ClientError whose Code is ResourceNotFoundException at HTTP 404.
All five fail against ae8d706 and pass on 0c3e7d9.

They live in the Python suite because that is where a non-Go client already
runs: the CI job builds the binary and exports SUBSTRATE_BINARY today. boto3
becomes a `test` extra rather than a dependency, since the plugin itself does
not need it, and the CI install becomes `pip install -e './python[test]'` —
without it the tests importorskip and the gap reopens silently. This is the
first Python test that launches a substrate process rather than a mock.
@scttfrdmn scttfrdmn added this to the v0.110.0 milestone Sep 11, 2026
@codecov

codecov Bot commented Sep 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit bbb7f75 into main Sep 11, 2026
22 of 23 checks passed
@scttfrdmn
scttfrdmn deleted the feat/757-botocore-cloudwatch-check branch September 11, 2026 00:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CloudWatch answers XML to the JSON-RPC body every AWS CLI and boto3 caller sends

1 participant