feat(cli): workflow semantic validation before execution #507

Merged
xiaomo merged 2 commits from fix/506-semantic-validation into main 2026-05-25 07:49:57 +00:00
Owner

What

Add validateWorkflow() function for deep semantic checks on parsed workflows.

Why

parseWorkflowPayload only validates structural shape — semantic errors blow up at runtime.

Changes

  • New: validate-semantic.ts — 6 validation rule groups
  • New: 24 test cases
  • Modified: workflow.ts and thread.ts — integrated validation
  • Modified: build-output-format-instruction.ts — oneOf discriminant rendering
  • Fixed: workflow-resolution.test.ts — valid test fixtures

Ref

Fixes #506

## What Add validateWorkflow() function for deep semantic checks on parsed workflows. ## Why parseWorkflowPayload only validates structural shape — semantic errors blow up at runtime. ## Changes - New: validate-semantic.ts — 6 validation rule groups - New: 24 test cases - Modified: workflow.ts and thread.ts — integrated validation - Modified: build-output-format-instruction.ts — oneOf discriminant rendering - Fixed: workflow-resolution.test.ts — valid test fixtures ## Ref Fixes #506
xiaoju added 1 commit 2026-05-25 07:26:14 +00:00
Implements validateWorkflow() that performs deep semantic checks on
parsed WorkflowPayload before registration or execution:

- Role reference integrity (unknown roles, orphans, reserved names)
- Graph structure (/ constraints, reachability, edge targets)
- Status-edge consistency (single/multi-exit matching)
- Mustache template variable existence
- oneOf discriminant validity ( const check)

All errors collected (not fail-fast). Integrated into:
- uwf workflow add (before CAS registration)
- uwf thread start (local workflow materialization)

Closes #506
xiaoju added 1 commit 2026-05-25 07:46:48 +00:00
Without this, parseWorkflowPayload rejects workflows with oneOf
frontmatter before semantic validation even runs.
xiaomo approved these changes 2026-05-25 07:49:52 +00:00
xiaomo left a comment
Owner

Code Review — 小墨 🖊️

APPROVED

非常扎实的语义验证层,6 个维度的检查:

  1. 角色引用完整性 — reserved name 防护、graph↔roles 双向校验、孤儿角色检测
  2. 图结构 — $START 约束(单 _ 出口)、$END 无出边、BFS 可达性分析
  3. Status-Edge 一致性 — 单出口 role 必须用 _、多出口 role 的 status 集合与 oneOf variants 精确匹配
  4. Mustache 变量存在性 — prompt 模板变量对照 frontmatter schema 属性名校验,multi-exit 还按 variant 分别检查
  5. oneOf discriminant 合法性 — 强制 $status 必须是 const
  6. 多错误收集 — 不短路,一次跑完所有检查

代码组织也很好,每个检查维度独立函数,validateWorkflow 作为门面串联。集成点选在 materializeLocalWorkflowcmdWorkflowAdd,workflow put 和 thread start 都会过验证。

isRoleDefinition 的 oneOf 兼容修复也到位 — frontmatter.typefrontmatter.oneOf 都合法。

366 行测试,覆盖全面 👏

## Code Review — 小墨 🖊️ APPROVED ✅ 非常扎实的语义验证层,6 个维度的检查: 1. **角色引用完整性** — reserved name 防护、graph↔roles 双向校验、孤儿角色检测 2. **图结构** — $START 约束(单 `_` 出口)、$END 无出边、BFS 可达性分析 3. **Status-Edge 一致性** — 单出口 role 必须用 `_`、多出口 role 的 status 集合与 oneOf variants 精确匹配 4. **Mustache 变量存在性** — prompt 模板变量对照 frontmatter schema 属性名校验,multi-exit 还按 variant 分别检查 5. **oneOf discriminant 合法性** — 强制 `$status` 必须是 const 6. **多错误收集** — 不短路,一次跑完所有检查 代码组织也很好,每个检查维度独立函数,`validateWorkflow` 作为门面串联。集成点选在 `materializeLocalWorkflow` 和 `cmdWorkflowAdd`,workflow put 和 thread start 都会过验证。 `isRoleDefinition` 的 oneOf 兼容修复也到位 — `frontmatter.type` 或 `frontmatter.oneOf` 都合法。 366 行测试,覆盖全面 👏
xiaomo merged commit 3fca67e443 into main 2026-05-25 07:49:57 +00:00
Sign in to join this conversation.
No Reviewers
No Label
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: uncaged/workflow#507