test(server): refactor spec_compat tests to use public API (#653)#657
Merged
Conversation
Closes #653. The previous tests in tests/test_spec_compat_hooks.py reached into private helpers (_hook_get_products, _make_sync_creatives_hook, _coerce_asset, _infer_asset_type) and asserted on internal shapes, which hid a class of bugs the public surface would expose. Changes: - All tests now exercise spec_compat_hooks() and the returned dict only. No private imports. - Add four model_validate() proofs that hook output is actually 4.4-valid: one for get_products (buying_mode default), three for sync_creatives (format_id wrap, asset_type inference, image→url demotion). Failure here means the hook is producing dicts that pass our internal asserts but fail at the dispatcher boundary. - Expand the create_tool_caller integration suite from one buying_mode smoke test to four end-to-end paths: get_products default, sync_creatives format_id wrap, asset_type inference, image→url demotion. - spec_compat_hooks(exclude={...}) now emits a UserWarning for unknown hook names (typos like "sync_creative" used to silently leave the hook active). Document the behaviour in the factory's exclude= section. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #653.
The tests in
tests/test_spec_compat_hooks.py(added in #648) reached into private helpers (_hook_get_products,_make_sync_creatives_hook,_coerce_asset,_infer_asset_type) and asserted on internal shapes. Per CLAUDE.md the testing contract is to call the public API and validate against the generated Pydantic schemas — the previous tests passed but would not catch a regression where the hook produced dicts that failed at the dispatcher boundary.What changed
spec_compat_hooks()and the returned dict — no private imports.model_validate()tests prove the hook output is actually 4.4-spec-valid:test_get_products_hook_output_passes_pydantic_validationtest_sync_creatives_hook_output_passes_pydantic_validation_format_id_wraptest_sync_creatives_hook_output_passes_pydantic_validation_inference_pathtest_sync_creatives_hook_output_passes_pydantic_validation_demotion_pathcreate_tool_callerintegration suite went from onebuying_modesmoke test to four end-to-end paths (get_products default, sync_creatives format_id wrap, asset_type inference, image→url demotion).exclude=names.spec_compat_hooks(exclude={"sync_creative"})(typo) now emits aUserWarninginstead of silently leaving the hook active.Test plan
pytest tests/test_spec_compat_hooks.py— 40 passedruff check src/adcp/server/spec_compat.py tests/test_spec_compat_hooks.pymypy src/adcp/server/spec_compat.pyadcp.server.spec_compatmodel_validate()test callsSyncCreativesRequest.model_validate()/GetProductsRequest.model_validate()on the hook's output🤖 Generated with Claude Code