Skip to content

Feature/dataset contract tests - #1089

Merged
Cedarich merged 10 commits into
Pulsefy:mainfrom
martinshub-tech:feature/dataset-contract-tests
Jul 23, 2026
Merged

Feature/dataset contract tests#1089
Cedarich merged 10 commits into
Pulsefy:mainfrom
martinshub-tech:feature/dataset-contract-tests

Conversation

@martinshub-tech

Copy link
Copy Markdown
Contributor

Closes #1052

Goal
Validate that derived datasets consumed by backend services maintain a stable database schema, JSON shape, and semantic meaning across pipeline changes.

Acceptance Criteria Met
Contract tests exist for at least one backend-consumed dataset: Implemented tests checking both the backend-consumed analytics_records and contract_events datasets.
Breaking shape or semantics changes produce a clear failure:
Database schema checks detect missing/added/modified columns, type mismatches, and nullability modifications statically.
Data shape checks inspect JSON structure keys and type correctness.
Semantic checks enforce mathematical consistency of calculations (e.g. change_percentage matches value/previous_value, trend matches threshold, positive ledgers/amounts, valid status/types).
Test fixtures are easy for contributors to update intentionally: Added --update-contracts CLI flag and UPDATE_CONTRACTS=1 environment variable support to automatically regenerate reference fixtures on the fly.
Coverage includes at least one analytics and one ingestion-derived output: Cover analytics_records (analytics-derived output) and contract_events (ingestion-derived output).
Changes

  1. Pytest Configuration Options
    apps/data-processing/tests/conftest.py: Added command line parser option --update-contracts and its respective fixture to allow updating contract schemas.
  2. Contract Test Suite
    apps/data-processing/tests/test_dataset_contracts.py: A new test suite that:
    Validates SQLAlchemy database mapping schema statically using inspection (no live DB connection required).
    Validates pipeline-generated mock outputs for both analytics and ingestion.
    Performs semantic calculations checks and trend checks.
    apps/data-processing/tests/fixtures/contracts/: Directory containing the saved JSON reference contracts representing the stable database schema and data shape expectations.

@drips-wave

drips-wave Bot commented Jul 23, 2026

Copy link
Copy Markdown

@martinshub-tech Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@Cedarich Cedarich left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kindly fix failing pytest

@martinshub-tech
martinshub-tech force-pushed the feature/dataset-contract-tests branch from b767cb8 to c8f19ca Compare July 23, 2026 18:32
@martinshub-tech
martinshub-tech requested a review from Cedarich July 23, 2026 18:33
@martinshub-tech
martinshub-tech force-pushed the feature/dataset-contract-tests branch from c8f19ca to f005178 Compare July 23, 2026 18:38
@Cedarich

Copy link
Copy Markdown
Contributor

@martinshub-tech

@Cedarich
Cedarich merged commit 0479fcf into Pulsefy:main Jul 23, 2026
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.

Data-processing: Backend consumer data contract tests for derived datasets

2 participants