Skip to content

fix(preprocess): derive UcpMetadata union from $defs to include catalog - #58

Merged
damaz91 merged 3 commits into
Universal-Commerce-Protocol:mainfrom
XiaolongZhang-TT:fix/ucp-metadata-union-catalog
Jul 31, 2026
Merged

fix(preprocess): derive UcpMetadata union from $defs to include catalog#58
damaz91 merged 3 commits into
Universal-Commerce-Protocol:mainfrom
XiaolongZhang-TT:fix/ucp-metadata-union-catalog

Conversation

@XiaolongZhang-TT

@XiaolongZhang-TT XiaolongZhang-TT commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Description

normalize_metadata_schemas hardcoded the UcpMetadata root union as five members — platform_schema, business_schema, response_{checkout,order,cart}_schema — and so silently omitted response_catalog_schema, which is defined in ucp.json at the 2026-04-08 release this SDK targets (0.4.x). response_catalog_schema is a live metadata type, referenced by shopping/catalog_lookup.json and shopping/catalog_search.json; the generated UcpMetadata (src/ucp_sdk/models/schemas/ucp.py) therefore lacked ResponseCatalogSchema (the class was generated from the $def, but the union omitted it), so a UCP message carrying catalog-response metadata would fail validation against the unified ucp field type.

This derives the union members from ucp.json's $defs instead: the discovery profiles (platform/business) plus every response_*_schema. It fixes the missing catalog entry and keeps the union complete as the protocol adds response types — the same data-driven approach used for minProperties in #55. Output order follows $defs insertion order, so the existing members are unchanged and catalog is appended.

The generated UcpMetadata in ucp.py is updated by a single union line — exactly the change generate_models.sh produces for this fix. A full regeneration is intentionally not bundled: the tracked generated tree predates the current ruff toolchain and regenerating adds unrelated formatting churn (45 files reformatted). See Screenshots / Logs for verification.

Category (Required)

Please select one or more categories that apply to this change.

  • Core Protocol: Changes to the base communication layer, global context, or breaking refactors. (Requires Technical Council approval)
  • Governance/Contributing: Updates to GOVERNANCE.md, CONTRIBUTING.md, or CODEOWNERS. (Requires Governance Council approval)
  • Capability: New schemas (Discovery, Cart, etc.) or extensions. (Requires Maintainer approval)
  • Documentation: Updates to README, or documentations regarding schema or capabilities. (Requires Maintainer approval)
  • Infrastructure: CI/CD, Linters, or build scripts. (Requires DevOps Maintainer approval)
  • Maintenance: Version bumps, lockfile updates, or minor bug fixes. (Requires DevOps Maintainer approval)
  • SDK: Language-specific SDK updates and releases. (Requires DevOps Maintainer approval)
  • Samples / Conformance: Maintaining samples and the conformance suite. (Requires Maintainer approval)
  • UCP Schema: Changes to the ucp-schema tool (resolver, linter, validator). (Requires Maintainer approval)
  • Community Health (.github): Updates to templates, workflows, or org-level configs. (Requires DevOps Maintainer approval)

Related Issues

None. (Spotted during an audit of the SDK code-generation pipeline against release/2026-04-08.)

Checklist

  • I have followed the Contributing Guide (including Conventional Commits title requirements and ! for breaking changes).
  • I have updated the documentation (if applicable).
  • My changes pass all local linting and formatting checks.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.
  • (For Core/Capability) I have included/updated the relevant JSON schemas.
  • I have regenerated Python Pydantic models by running generate_models.sh under python_sdk.

Screenshots / Logs (if applicable)

BeforeUcpMetadata union (5 members, catalog missing):

PlatformSchema | BusinessSchema | ResponseCheckoutSchema | ResponseOrderSchema | ResponseCartSchema

AfterUcpMetadata union (6 members, catalog included):

PlatformSchema | BusinessSchema | ResponseCheckoutSchema | ResponseOrderSchema | ResponseCartSchema | ResponseCatalogSchema

metadata_union_members derived from the real release/2026-04-08 ucp.json:

['platform_schema', 'business_schema', 'response_checkout_schema',
 'response_order_schema', 'response_cart_schema', 'response_catalog_schema']

Full suite green as CI runs it (python -m unittest discover -s tests -p "test_*.py"): 27 passed, 0 failed. ruff (--ignore D,E501, matching the pre-commit hook), ruff format, and codespell are clean.

@google-cla

google-cla Bot commented Jul 30, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

normalize_metadata_schemas hardcoded the UcpMetadata root union as five
members (platform, business, response_{checkout,order,cart}) and so
silently omitted response_catalog_schema, which is defined in ucp.json at
the 2026-04-08 release the SDK targets. The generated UcpMetadata
(src/ucp_sdk/models/schemas/ucp.py) therefore lacked ResponseCatalogSchema
(the class was generated from the $def, but the union omitted it), so a
UCP message carrying catalog-response metadata failed validation against
every model's `ucp` field.

Derive the union members from ucp.json's $defs instead: the discovery
profiles (platform/business) plus every response_*_schema. This fixes the
missing catalog entry and keeps the union complete as the protocol adds
response types, matching the data-driven approach used for minProperties
(Universal-Commerce-Protocol#55). Output order follows $defs insertion order, so existing members are
unchanged and catalog is appended.

Update the generated UcpMetadata in ucp.py accordingly. A full regeneration
is intentionally not bundled here: the tracked generated tree predates the
current ruff toolchain and regenerating adds unrelated formatting churn, so
only the one union line is edited — exactly what regeneration produces for
this fix.

Add MetadataUnionTest covering the derivation (profiles + all response
schemas, automatic pickup of new response types, exclusion of non-schema
defs such as request_schema, empty $defs) and update the existing
normalize_metadata_schemas test to assert the six-member union.
@XiaolongZhang-TT
XiaolongZhang-TT force-pushed the fix/ucp-metadata-union-catalog branch from 67897d7 to 6fe9262 Compare July 30, 2026 07:49
@XiaolongZhang-TT
XiaolongZhang-TT marked this pull request as ready for review July 30, 2026 07:54
@damaz91 damaz91 added status:needs-triage Signal that the PR is ready for human triage status:under-review and removed status:needs-triage Signal that the PR is ready for human triage labels Jul 30, 2026
@damaz91

damaz91 commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Thanks! Also added the regenerated/linted classes!

@damaz91
damaz91 merged commit a763549 into Universal-Commerce-Protocol:main Jul 31, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants