Skip to content

feat(ads-client): add contract tests to validate types against MARS#7263

Draft
Almaju wants to merge 5 commits intomozilla:mainfrom
Almaju:ads-client-contract-validation
Draft

feat(ads-client): add contract tests to validate types against MARS#7263
Almaju wants to merge 5 commits intomozilla:mainfrom
Almaju:ads-client-contract-validation

Conversation

@Almaju
Copy link
Contributor

@Almaju Almaju commented Mar 9, 2026

Add two layers of contract validation:

  1. Unit contract tests (run on every cargo test, zero cost):

    • ad_response.rs: spec-accurate JSON fixtures for Image, Spoc, and Tile deserialization, including tests that document intentional deviations (click/impression required by us but optional in spec; attributions field not modelled but silently ignored)
    • ad_request.rs: serialization shape tests and taxonomy string validation
  2. Integration contract tests against staging (ignored by default):

    • Three new #[ignore] tests in integration_test.rs that hit ads.allizom.org and assert all required spec fields are present and non-empty for each ad type (Image, Spoc, Tile)
    • Run with: cargo test -p ads-client --test integration_test -- --ignored

Pull Request checklist

  • Breaking changes: This PR follows our breaking change policy
    • This PR follows the breaking change policy:
      • This PR has no breaking API changes, or
      • There are corresponding PRs for our consumer applications that resolve the breaking changes and have been approved
  • Quality: This PR builds and tests run cleanly
    • Note:
      • For changes that need extra cross-platform testing, consider adding [ci full] to the PR title.
      • If this pull request includes a breaking change, consider cutting a new release after merging.
  • Tests: This PR includes thorough tests or an explanation of why it does not
  • Changelog: This PR includes a changelog entry in CHANGELOG.md or an explanation of why it does not need one
    • Any breaking changes to Swift or Kotlin binding APIs are noted explicitly
  • Dependencies: This PR follows our dependency management guidelines
    • Any new dependencies are accompanied by a summary of the due diligence applied in selecting them.

Almaju and others added 5 commits March 9, 2026 15:00
…penAPI spec

Add two layers of contract validation:

1. Unit contract tests (run on every cargo test, zero cost):
   - ad_response.rs: spec-accurate JSON fixtures for Image, Spoc, and Tile
     deserialization, including tests that document intentional deviations
     (click/impression required by us but optional in spec; attributions field
     not modelled but silently ignored)
   - ad_request.rs: serialization shape tests and taxonomy string validation

2. Integration contract tests against staging (ignored by default):
   - Three new #[ignore] tests in integration_test.rs that hit ads.allizom.org
     and assert all required spec fields are present and non-empty for each
     ad type (Image, Spoc, Tile)
   - Run with: cargo test -p ads-client --test integration_test -- --ignored
…napi.json

Load schemas from the checked-in openapi.json with recursive $ref
resolution instead of hardcoding them. Add skip_serializing_if for
optional content field. Add GitHub Actions workflow for integration
tests on ads-client changes.
Versions 0.44+ have a CompactFormatter: Default compile error with
the current serde_json version.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

1 participant