Skip to content

REST CONTRACT_MAP missing 42 SDK models — promote test_contract_map_completeness to hard-fail #171

Description

@TexasCoding

From the v2.2.0 spec-drift hardening (#157). The WS contract map is now exhaustive and test_contract_map_completeness hard-fails on the WS side. The REST side leaves 42 SDK response/request models unmapped, with the test warn-only.

This is the same regression class that hid Balance.balance_dollars for five review rounds in v2.1.0 — an unmapped model is invisible to drift checks, so additive spec changes slide through silently.

Unmapped models

Reproduce with pytest tests/test_contracts.py::TestSpecDrift::test_contract_map_completeness -W error::Warning.

  • kalshi.models.markets (4): BidAskDistribution, Candlestick, OrderbookLevel, PriceDistribution
  • kalshi.models.orders (19): AmendOrderRequest, AmendOrderV2Request, AmendOrderV2Response, BatchCancelOrdersRequest, BatchCancelOrdersRequestOrder, BatchCancelOrdersV2Request, BatchCancelOrdersV2RequestOrder, BatchCancelOrdersV2Response, BatchCancelOrdersV2ResponseEntry, BatchCreateOrdersRequest, BatchCreateOrdersV2Request, BatchCreateOrdersV2Response, BatchCreateOrdersV2ResponseEntry, CancelOrderV2Response, CreateOrderV2Request, CreateOrderV2Response, DecreaseOrderRequest, DecreaseOrderV2Request, DecreaseOrderV2Response
  • kalshi.models.events (2): MarketMetadata, SettlementSource
  • kalshi.models.exchange (4): DailySchedule, MaintenanceWindow, Schedule, WeeklySchedule
  • kalshi.models.portfolio (4): Deposit, IndexedBalance, PositionsResponse, Withdrawal
  • kalshi.models.series (3): EventCandlesticks, ForecastPercentilesPoint, PercentilePoint
  • kalshi.models.multivariate (6): AssociatedEvent, CreateMarketInMultivariateEventCollectionRequest, CreateMarketResponse, LookupPoint, LookupTickersForMarketInMultivariateEventCollectionRequest, LookupTickersResponse

Work

  1. Add a ContractEntry to kalshi/_contract_map.py for each model, with the matching spec_schema lookup name from specs/openapi.yaml.
  2. The V2 orders family clusters around the *OrderV2* request/response pairs and is the largest sub-batch (~12 entries). Suitable for a self-contained first PR.
  3. Once mapped, drift on these models flows through test_additive_drift and test_required_drift. test_additive_drift is hard-fail post-Harden response-side spec drift: promote additive warnings to hard-fail #157, so any new spec field surfaces immediately.
  4. Promote test_contract_map_completeness from warnings.warn to pytest.fail so the next unmapped model fails CI.

Acceptance

  • len(CONTRACT_MAP) increases from 49 to ~91 (final number depends on whether nested sub-models get folded into their parent entries).
  • pytest tests/test_contracts.py -W error::Warning -k test_contract_map_completeness passes.
  • The test body's warnings.warn(...) is replaced with pytest.fail(...).
  • No regression in test_additive_drift (any new failures must be addressed before flipping the gate).

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    polishCode-quality and DX improvements; non-functionaltestingTest coverage

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions