Skip to content

fix(web_core): check v1.0 catalogs read from JSON against the v1.0 common types - #4349

Open
retz8 wants to merge 8 commits into
a2ui-project:mainfrom
retz8:fix/web-core-fromjson-v1-common-types
Open

retz8 wants to merge 8 commits into
a2ui-project:mainfrom
retz8:fix/web-core-fromjson-v1-common-types

Conversation

@retz8

@retz8 retz8 commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

Problem

In web_core, a v1.0 catalog loaded with Catalog.fromJson resolves its common_types.json references in the runtime superset of v0.9 and v1.0. So it accepts a check rule whose condition is a literal boolean, or that has a key CheckRule does not define, which the built-in v1.0 basic catalog rejects. @a2ui/agent builds every catalog with Catalog.fromJson, so its validatePayload accepts these rules, while the Python agent SDK's validate_payload rejects them. #4348 has the mechanism.

With this PR, a v1.0 catalog read from JSON is checked against the v1.0 common types, as the built-in catalog is. A v1.0 producer that writes such a check rule, or a function call with a key other than @call, catalogId and args, now gets a validation error, so the CHANGELOG entry marks this as breaking.

Stacked on #4347, because the function call change edits the v1.0 generator next to #4347's change. The first commit is #4347's and the second is this change. Once #4347 merges, the diff is only the second commit. On top of #4347, a v1.0 catalog read from JSON also rejects v0.9's bare path and call, which #4346 left open.

Fixes #4348. Part of #4346.

Changes

@a2ui/web_core:

  • src/catalog/schema_loader.ts: for a v1.0 catalog, parseCatalogSchema records the v1.0 common types (src/v1_0/schema/common-types.ts), and resolveProtocolRef looks references up there. This covers a property's $ref and an allOf mixin such as Checkable. The record is a WeakMap keyed by the parsed document, which every converter already receives as rootDoc, so no converter's signature changes. componentCommonMixinProperties takes the v1.0 ComponentCommon for a v1.0 catalog. v0.9 catalogs keep the superset.
  • src/v1_0/scripts/generate-schemas.mjs: the v1.0 FunctionCall rejects any key other than @call, catalogId and args.
    • The spec closes FunctionCall's allOf: [FunctionCommon, <catalog function>] with unevaluatedProperties: false, which jsonSchemaToZod drops, so the generated schema took any key.
    • The allowed keys are read from the spec: FunctionCommon's properties, and FunctionCallValidationSchema in catalog_definition.json, which limits a catalog function's properties to @call and args. @a2ui/agent checks a callRendererFunction against the same three keys (CALL_KEYS in src/utils/renderer-state.ts).
    • Without this, the loader change fails test_v10_published_basic_catalog_rejects_function_call_extra_key. The superset's strict FunctionCall was what rejected the extra key for a catalog read from JSON, and the built-in catalog accepted it.
    • The check is a superRefine that reports the extra keys as unrecognized_keys, as .strict() does, so the message is the one the superset gave ("Unrecognized key(s) in object: 'bogus'"). A .strict() object would also give the exported FunctionCall type, which infers as any today, a precise shape, and tsc then rejects 28 places that rely on the loose type, mostly test fixtures. With superRefine the type stays as it was. src/v1_0/schema/common-types.ts is regenerated.

Unchanged:

  • The superset in src/types/common-types.ts. v0.9 catalogs read from JSON still use it, and so does PayloadValidator's check of the accessibility and metadata mixins.
  • The legacy bare checks and accessibility on a v1.0 component are still read. A bare checks counts as @checks when the component declares @checks, as in the built-in catalog.

Changed tests. Each relied on what this PR changes:

  • web_core catalog/schema_loader.test.ts:
    • Two fixtures with a literal boolean condition in a v1.0 check rule move to @path bindings.
    • resolves an external mixin written as a relative reference expected the v1.0 Checkable to add a bare checks. It now expects @checks.
    • lets a component override a property its mixins and local definitions declare listed the bare checks and accessibility among the mixin keys. The v1.0 mixins declare only @checks and @accessibility, so the component's own checks now comes after its other properties.
  • web_core processing/message-processor.test.ts (three tests) and validation/payload-validator.test.ts (two tests): v1.0 check rules with condition: true or false move to @path bindings. The test that evaluates a rule binds /valid to false in the data model.
  • @a2ui/agent utils/renderer-function-call-validation.test.ts: a callFunction with an extra key is now refused by the message schema ("Unrecognized key(s) in object: 'bogus' at 'callRendererFunction.callFunction'") before the agent's own check ("has unrecognized field 'bogus' on callFunction"). The case expects the schema's message.

The moved fixtures pass without this PR's source changes too. Of the changed tests, only the key list fails without them.

Tests

  • New: checks a v1.0 catalog's check rules against the v1.0 common types in catalog/schema_loader.test.ts. Without the loader change it fails with Missing expected exception (A2uiValidationError): expected {"condition":true} to be rejected. Its last part checks that a v0.9 catalog read from JSON still accepts a literal boolean condition.
  • New: PayloadValidator rejects a v1.0 function call holding a key no function declares in catalogs/basic/v1/basic_catalog_elements.test.ts. Without the generator change it fails with Missing expected exception., and conformance fails test_v10_published_basic_catalog_rejects_function_call_extra_key.
  • With the issue's reproduction, both catalogs reject the two check rules and the function call with bogus, and accept the counter-cases. The v0.9 line is unchanged. @a2ui/agent's validatePayload rejects the two check rules and accepts the valid one.

On this branch:

  • @a2ui/web_core: test 1661/1661; tests/conformance/conformance_test.mjs 830/830 passed, 1072 skipped; ESLint 0 errors and 822 warnings, as on main
  • @a2ui/agent: 2070 passed, 441 skipped
  • @a2ui/catalog-mcp: test:node 196/196, test:karma 227/227, test:types
  • @a2ui/react: test:unit 540 passed, 1 skipped
  • @a2ui/lit: test:unit 161 passed
  • @a2ui/catalog-vegachart, @a2ui/markdown-it, widget-builder, @a2ui/lit-explorer, @a2ui/react-explorer: test passes
  • ./scripts/fix_format.sh --check: Prettier and pyink pass. Its Dart step fails on main too, since fix(dart/core): report unknown envelope keys at their paths #4197, in dart/a2ui_core/lib/src/processing/processor.dart and test/processor_test.dart, which this PR does not touch.

Not run: @a2ui/angular, whose Angular 22 CLI needs a newer Node than the one here; scripts/e2e_test.sh; and fix_licenses.py (no new files).

Pre-launch Checklist

One time:

For this PR:

  • I have updated the relevant CHANGELOG.md file.
  • I updated/added relevant documentation.
  • My code changes (if any) have tests.
  • If my branch is on a fork, I have verified that scripts/e2e_test.sh passes.

If you need help, consider asking for advice on the discussion board.

The v1.0 schema generator replaced the common types' DataBinding,
FunctionCommon and IndexSystemFunction with hand-written schemas that
took v0.9's bare `path` or `call` beside `@path` or `@call`. The v1.0
common types allow only the `@` keys, and DataContext reads only them at
v1.0, so a v1.0 payload written with `{"path": ...}` or `{"call": ...}`
passed PayloadValidator and MessageProcessor, in strict mode too, and
was then drawn as the literal object.

The generator now emits the three definitions from the v1.0 common
types as written: `@path` and `@call` are required, and a DataBinding
takes no other key. The literal branch of DynamicValue excludes only
`@path` and `@call`, as the common types define it, so a plain object
with `path` or `call` keys stays a literal.

Catalogs loaded with Catalog.fromJson resolve their common type
references in the cross-version superset in types/common-types.ts, which
still takes both spellings; that is left for its own change.

Tests that sent a v1.0 message with the bare keys move to the `@` keys:
web_core's callRendererFunction fixtures, the Angular v1.0 rendering
spec, and two catalog-mcp callMcpTool tests, one of which now calls the
tool through a v1.0 DataContext. The comment above callMcpTool's
imports no longer says the v1.0 schemas take the v0.9 keys. The
@a2ui/agent case for a callFunction written with `call` expects the
message schema's error, which now reports it before the agent's own
check.
…mmon types

Catalog.fromJson resolved every common_types.json reference in
types/common-types.ts, the runtime superset of v0.9 and v1.0, whatever
the catalog's version. Its CheckRule takes v0.9's literal boolean
condition and any key, so a v1.0 catalog read from JSON, which is how
@a2ui/agent builds every catalog, accepted check rules that the built-in
v1.0 basic catalog and the v1.0 common types refuse.

The loader now resolves a v1.0 catalog's references, and the
ComponentCommon its components compose, in v1_0/schema/common-types.ts.
Other catalogs keep the superset.

The superset's FunctionCall was strict, and the v1.0 one took any key,
since jsonSchemaToZod drops the unevaluatedProperties: false that closes
FunctionCommon and the catalog function. The v1.0 generator now refuses
any key other than those two declare: @call and catalogId from
FunctionCommon, and @call and args, which catalog_definition.json limits
a catalog function's properties to. This keeps
test_v10_published_basic_catalog_rejects_function_call_extra_key passing,
and the built-in catalog refuses those keys too. The FunctionCall type is
unchanged.

Tests that wrote a v1.0 check rule with a literal boolean condition move
to a @path binding. Two schema_loader tests expected a v1.0 catalog's
components to declare the bare checks and accessibility. They now expect
@Checks and @accessibility, and the bare keys are still read as the
legacy mixins. In @a2ui/agent, a callFunction with an extra key is now
refused by the message schema before the agent's own check, so the case
expects the schema's message.

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request introduces breaking changes to strictly align v1.0 schemas (such as DataBinding, FunctionCommon, IndexSystemFunction, and FunctionCall) with the v1.0 common types specification. Support for legacy v0.9 keys (path and call) has been removed in v1.0 contexts, enforcing the use of @path and @call. Additionally, strict validation has been added to reject unrecognized keys in function calls and literal boolean conditions in check rules. The schema loader, payload validator, message processor, and corresponding tests have been updated to enforce these new validation constraints. I have no feedback to provide as there are no review comments.

@github-actions github-actions Bot added the status: needs-triage auto-managed: https://github.com/a2ui-project/a2ui/blob/main/scripts/triage.mjs label Nov 21, 2026
@Varun-S10 Varun-S10 self-assigned this Nov 23, 2026
@github-actions github-actions Bot removed the status: needs-triage auto-managed: https://github.com/a2ui-project/a2ui/blob/main/scripts/triage.mjs label Nov 23, 2026
@Varun-S10

Copy link
Copy Markdown
Collaborator

Hi @retz8, Thank you for raising the issue. We have reproduced the issue and we appreciate you have raised pr to fix the issue. The pr will be reviewed. Thank you for your patience and understanding.
Hi @gspencergoog, could you please take a look?

…e-path-call

# Conflicts:
#	typescript/core/web_core/CHANGELOG.md
…on-v1-common-types

# Conflicts:
#	typescript/core/web_core/CHANGELOG.md
retz8 added 4 commits December 3, 2026 19:07
…e-path-call

# Conflicts:
#	typescript/core/web_core/CHANGELOG.md
…son-v1-common-types

# Conflicts:
#	typescript/core/web_core/CHANGELOG.md
#	typescript/core/web_core/src/catalog/schema_loader.ts

This branch has not been deployed

No deployments
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.

[BUG]: web_core's Catalog.fromJson accepts v1.0 check rules with a literal boolean condition or an extra key

2 participants