Skip to content

fix(validate): unify GenUI runtime schema validation - #106

Merged
wang-kaopu merged 3 commits into
omdsh-dev:mainfrom
wang-kaopu:main
Sep 5, 2026
Merged

fix(validate): unify GenUI runtime schema validation#106
wang-kaopu merged 3 commits into
omdsh-dev:mainfrom
wang-kaopu:main

Conversation

@wang-kaopu

Copy link
Copy Markdown
Collaborator

Summary

修复 #102validate_dsh_ui 与实际 GenUI 渲染语义不一致的问题,并进一步统一 GenUI 的 runtime schema、字段归一化、校验与 renderability 判断,避免字段名或字段类型错误在 repair 阶段被静默丢弃后仍通过校验或渲染空壳组件。

Closes #102

问题

此前 GenUI 的协议规则分散在 validator、repair、renderer 和 tool 中,导致部分输入存在以下情况:

  • card.label/contenttable.headers/datacallout.kindsteps.items 等字段无法被统一识别;
  • validate_dsh_ui 可能返回 ✅,但 renderer repair 后静默删除字段;
  • 某些非法字段值或 nested record 会在 repair 时被丢弃,但 validation 无法提前发现;
  • native node 与 custom node 混合时,节点丢弃计数可能被掩盖;
  • render_ui、fence renderer、presentation meta 对同一 spec 的 renderability 判断可能不完全一致。

改动

1. 引入统一的 GenUI runtime schema

新增并扩展 component schema registry,集中描述:

  • canonical fields;
  • required fields;
  • compatibility aliases;
  • primitive field types;
  • enum domains;
  • nested record schemas;
  • one-of / conditional required rules。

同时从 schema registry 派生 native component type 集合,减少协议定义漂移。

2. 统一字段 alias normalization

将常见模型输出兼容字段归一化为 canonical schema,包括:

  • card.label -> title
  • card.content -> items
  • table.headers -> columns
  • table.data -> rows
  • callout.kind -> tone
  • steps.items -> steps
  • 保留现有 text.textbadge.text/valuetabs[].content 等兼容行为。

canonical 字段与 alias 同时存在时优先保留 canonical,并输出明确 warning。

3. 补齐 runtime validation

runtime schema 现在会参与实际校验,包括:

  • required field;
  • primitive type;
  • enum domain;
  • nested record required/type/enum;
  • root spec field validation。

例如此前可能被 repair 静默删除的:

  • card.title = 123
  • 非法 callout.tone
  • steps[].title 类型错误
  • plot.series[].kind 非法值

现在会在 render 前直接报告错误。

4. 统一 chart semantic validation

将 chart renderability 规则收口到 guard 的共享实现中,chart-contract.ts 仅保留兼容 API,避免 plugin 与 renderer 分别维护 chart 协议。

5. 统一 renderability 判断

新增共享 isRenderableProcess(),并用于:

  • render_ui.execute
  • render_ui.presentationMeta
  • tool presentation
  • dsh-ui fence renderer

避免同一个 spec 在不同入口出现“一个认为合法、另一个仍然渲染”的情况。

6. 修复 native node drop detection

拆分:

  • declaredNativeCount
  • renderedNativeCount
  • renderedTotalCount

native drop detection 仅比较 native/native,避免 opaque custom node 或 file-tree data 掩盖被 repair 删除的 native component。

7. 增强字段诊断

对 native component、root spec 以及部分 nested records 增加 unknown-field diagnostics,同时继续保持 custom renderer payload opaque,不检查或重写插件自定义数据。

测试

新增/更新测试覆盖:

@wang-kaopu
wang-kaopu merged commit 02a7264 into omdsh-dev:main Sep 5, 2026
4 checks passed
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.

validate_dsh_ui 未接线 guard 现成的 validateGenuiSpec:字段名错误静默通过校验,渲染空壳卡

1 participant