Skip to content

tests: check that client and server schemas match#1192

Open
HirenGajjar wants to merge 1 commit into
mlco2:masterfrom
HirenGajjar:tests/schema-compatibility-check
Open

tests: check that client and server schemas match#1192
HirenGajjar wants to merge 1 commit into
mlco2:masterfrom
HirenGajjar:tests/schema-compatibility-check

Conversation

@HirenGajjar
Copy link
Copy Markdown

@HirenGajjar HirenGajjar commented May 13, 2026

Description

Adds a test suite that verifies the client (codecarbon/core/schemas.py) and server (carbonserver/carbonserver/api/schemas.py) schemas stay compatible, addressing #1190.

What it checks

For each shared model pair (EmissionBase, RunBase, ExperimentBase, ProjectBase, OrganizationBase) — 15 parametrized tests total:

  1. Field presence — every client field exists in the server schema
  2. Required fields — every required server field exists in the client schema
  3. Type compatibility — shared fields have wire-compatible types

Why ast instead of imports

The client and server live in separate uv environments. Using Python's ast module to parse schema files as source avoids any import or path issues — the test runs in the existing client test environment with zero extra dependencies.

Regression proof

This test catches the exact bug fixed in #1189. Temporarily changing on_cloud: Optional[bool] to Optional[str] on the server produces:

FAILED test_shared_field_types_are_compatible[ExperimentBase-...]
AssertionError: [ExperimentBase] Incompatible types between client and server schemas:
  on_cloud: client='bool'  server='Optional[str]'

Related Issue

Closes #1190

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

AI Usage Disclosure

  • 🟥 AI-vibecoded: You cannot explain the logic.
  • 🟠 AI-generated: Car analogy: the car drives itself, you are inside and give instructions.
  • ⭐ AI-assisted. Car analogy: you drive the car, AI helps you find your way.
  • ♻️ No AI used.

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the contributing.md document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Add 15 parametrized tests across EmissionBase, RunBase, ExperimentBase,
ProjectBase and OrganizationBase that verify the client (codecarbon/core/schemas.py)
and server (carbonserver/carbonserver/api/schemas.py) schemas are compatible.

Tests check:
- All client fields exist in the server schema
- All required server fields exist in the client schema
- Shared fields have wire-compatible types

Uses ast to parse schema files without importing either module,
so the test runs in the client test environment with no extra deps.

This would have caught the on_cloud: str vs bool mismatch fixed in mlco2#1189.

Closes mlco2#1190
@HirenGajjar HirenGajjar requested a review from a team as a code owner May 13, 2026 05:25
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.

tests: check that client and server schemas match

1 participant