Phase 2 Testing: JSONata moderator engine #295

Closed
opened 2026-05-18 02:03:00 +00:00 by xiaoju · 0 comments
Owner

验证目标

实现基于 JSONata 的 moderator 求值器,替代 JS 函数。

工作内容

workflow-protocol 中新增 JSONata moderator:

  • 新增 jsonata-moderator.ts
  • 实现 evaluateModerator(rules, context) → role name | __end__
  • rules: [{ from: string, to: string, when: string | null }]
  • when: null = FALLBACK(always matches)
  • context 结构与现有 ModeratorContext 兼容:{ threadId, depth, bundleHash, start, steps }
  • JSONata 表达式在 { steps, start, threadId, depth } 上求值

测试步骤

  • Step 1: 线性流程(solve-issue)

    rules = [
      { from: "__start__", to: "preparer", when: null },
      { from: "preparer", to: "developer", when: null },
      { from: "developer", to: "submitter", when: null },
      { from: "submitter", to: "__end__", when: null }
    ]
    

    验证:空 steps → preparer, 1 step(preparer) → developer, ...

  • Step 2: 条件分支 — plannerAborted

    { from: "planner", to: "__end__", when: "$steps[role='planner'].meta.status = 'aborted'" }
    

    验证:planner meta.status='aborted' → END, meta.status='planned' → 下一条规则

  • Step 3: 条件分支 — reviewApproved

    { from: "reviewer", to: "tester", when: "$steps[-1].meta.status = 'approved'" }
    { from: "reviewer", to: "coder", when: null }
    

    验证:approved → tester, 非 approved → coder (fallback)

  • Step 4: 条件分支 — allPhasesComplete
    JSONata 表达 coder 完成所有 planner phases 的逻辑
    验证:全部 phase 完成 → reviewer, 未完成 → coder (repeat)

  • Step 5: FALLBACK 和无匹配
    when: null 是 fallback,always matches
    无任何规则匹配 → 返回 __end__

  • Step 6: 非法 JSONata 表达式
    传入语法错误的 when → 抛出明确错误

  • Step 7: 完整 develop workflow 端到端
    用 JSONata 重写整个 develop moderator table,跑完整路径:
    __start__ → planner → coder (repeat) → reviewer → tester → committer → __end__

验证完成标准

所有 checkbox 打勾
bun test 全过
biome check 无 error

Ref: #294

## 验证目标 实现基于 JSONata 的 moderator 求值器,替代 JS 函数。 ## 工作内容 在 `workflow-protocol` 中新增 JSONata moderator: - 新增 `jsonata-moderator.ts` - 实现 `evaluateModerator(rules, context)` → role name | `__end__` - rules: `[{ from: string, to: string, when: string | null }]` - `when: null` = FALLBACK(always matches) - context 结构与现有 `ModeratorContext` 兼容:`{ threadId, depth, bundleHash, start, steps }` - JSONata 表达式在 `{ steps, start, threadId, depth }` 上求值 ## 测试步骤 - [ ] **Step 1: 线性流程(solve-issue)** ``` rules = [ { from: "__start__", to: "preparer", when: null }, { from: "preparer", to: "developer", when: null }, { from: "developer", to: "submitter", when: null }, { from: "submitter", to: "__end__", when: null } ] ``` 验证:空 steps → preparer, 1 step(preparer) → developer, ... - [ ] **Step 2: 条件分支 — plannerAborted** ``` { from: "planner", to: "__end__", when: "$steps[role='planner'].meta.status = 'aborted'" } ``` 验证:planner meta.status='aborted' → END, meta.status='planned' → 下一条规则 - [ ] **Step 3: 条件分支 — reviewApproved** ``` { from: "reviewer", to: "tester", when: "$steps[-1].meta.status = 'approved'" } { from: "reviewer", to: "coder", when: null } ``` 验证:approved → tester, 非 approved → coder (fallback) - [ ] **Step 4: 条件分支 — allPhasesComplete** JSONata 表达 coder 完成所有 planner phases 的逻辑 验证:全部 phase 完成 → reviewer, 未完成 → coder (repeat) - [ ] **Step 5: FALLBACK 和无匹配** `when: null` 是 fallback,always matches 无任何规则匹配 → 返回 `__end__` - [ ] **Step 6: 非法 JSONata 表达式** 传入语法错误的 when → 抛出明确错误 - [ ] **Step 7: 完整 develop workflow 端到端** 用 JSONata 重写整个 develop moderator table,跑完整路径: `__start__ → planner → coder (repeat) → reviewer → tester → committer → __end__` ## 验证完成标准 ✅ 所有 checkbox 打勾 ✅ `bun test` 全过 ✅ biome check 无 error Ref: #294
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: uncaged/workflow#295