feat: agent-mock package for deterministic E2E testing (#33) #44

Merged
xiaomo merged 2 commits from test/33-mock-agent into main 2026-06-04 08:38:51 +00:00
Owner

What

新增 @united-workforce/agent-mockuwf-mock CLI),确定性 E2E 测试用的 mock agent。

Why

E2E test 层需要不碰 LLM 的确定性 agent 来验证 uwf 引擎(moderator → spawn → extract → CAS)。

How

  • --mock-data <path> 指定的 YAML 文件,按 step index 输出预设内容
  • 通过 ctx.steps.length 计数已有步骤确定当前 step
  • 校验 role 匹配(发现 moderator 路由 bug)
  • 复用 createAgent 框架,存 minimal detail 到 CAS
  • 零 LLM,毫秒级返回

Changes

  • packages/agent-mock/ — 全新 package(309 行,6 测试)
  • proman.yaml — 注册 agent-mock
  • tsconfig.json — 项目引用
  • 725 tests passing

Ref

Refs #33

## What 新增 `@united-workforce/agent-mock`(`uwf-mock` CLI),确定性 E2E 测试用的 mock agent。 ## Why E2E test 层需要不碰 LLM 的确定性 agent 来验证 uwf 引擎(moderator → spawn → extract → CAS)。 ## How - 读 `--mock-data <path>` 指定的 YAML 文件,按 step index 输出预设内容 - 通过 `ctx.steps.length` 计数已有步骤确定当前 step - 校验 role 匹配(发现 moderator 路由 bug) - 复用 `createAgent` 框架,存 minimal detail 到 CAS - 零 LLM,毫秒级返回 ## Changes - `packages/agent-mock/` — 全新 package(309 行,6 测试) - `proman.yaml` — 注册 agent-mock - `tsconfig.json` — 项目引用 - 725 tests passing ## Ref Refs #33
xiaomo reviewed 2026-06-04 07:59:43 +00:00
xiaomo left a comment
Owner

整体 LGTM,mock agent 设计干净,E2E 三个场景覆盖了线性、循环、错误检测,很好。

⚠️ 需要 rebase:与 PR #45 冲突

这个分支基于 #45 合并前的代码,E2E 测试用了 已被 #45 删除的 API

import { findHistoryEntry, getThread } from "../store.js";

// 测试里断言 completed thread 不在 active index:
expect(getThread(uwf.varStore, threadId)).toBeNull();
const hist = findHistoryEntry(uwf.varStore, threadId);

PR #45 统一存储后:

  • findHistoryEntry 已删除
  • completed thread 留在 @uwf/thread/*getThread 会返回带 status: "completed" 的 entry,不再返回 null

修复:rebase 到 main,E2E 里改成:

const entry = getThread(uwf.varStore, threadId);
expect(entry).not.toBeNull();
expect(entry!.status).toBe("completed");
expect(entry!.head).toBe(step2.head);

其他部分

  • mock agent:parseScenario 验证严格,selectMockStep role 校验能在 E2E 层暴露 moderator routing bug 👍
  • storeMockDetail 写 minimal CAS node 保证 chain 完整性
  • E2E 场景设计:线性流、循环流(4步 developer↔reviewer)、role mismatch 检测
  • beforeAll 按需 build agent-mock,自包含
整体 LGTM,mock agent 设计干净,E2E 三个场景覆盖了线性、循环、错误检测,很好。 ## ⚠️ 需要 rebase:与 PR #45 冲突 这个分支基于 #45 合并前的代码,E2E 测试用了 **已被 #45 删除的 API**: ```ts import { findHistoryEntry, getThread } from "../store.js"; // 测试里断言 completed thread 不在 active index: expect(getThread(uwf.varStore, threadId)).toBeNull(); const hist = findHistoryEntry(uwf.varStore, threadId); ``` PR #45 统一存储后: - `findHistoryEntry` 已删除 - completed thread 留在 `@uwf/thread/*`,`getThread` 会返回带 `status: "completed"` 的 entry,不再返回 null **修复**:rebase 到 main,E2E 里改成: ```ts const entry = getThread(uwf.varStore, threadId); expect(entry).not.toBeNull(); expect(entry!.status).toBe("completed"); expect(entry!.head).toBe(step2.head); ``` ## ✅ 其他部分 - mock agent:`parseScenario` 验证严格,`selectMockStep` role 校验能在 E2E 层暴露 moderator routing bug 👍 - `storeMockDetail` 写 minimal CAS node 保证 chain 完整性 ✅ - E2E 场景设计:线性流、循环流(4步 developer↔reviewer)、role mismatch 检测 ✅ - `beforeAll` 按需 build agent-mock,自包含 ✅
xiaoju added 2 commits 2026-06-04 08:06:31 +00:00
New package @united-workforce/agent-mock (uwf-mock CLI):
- Reads pre-scripted outputs from a YAML mock data file (--mock-data)
- Counts existing CAS chain steps to determine step index
- Validates expected role matches actual moderator routing
- Stores minimal detail node in CAS for valid step refs
- Zero LLM, instant execution, 100% deterministic

Usage in config.yaml:
  agents:
    mock:
      command: uwf-mock
      args: ["--mock-data", "./fixtures/scenario.yaml"]

Refs #33
test: E2E integration tests with uwf-mock agent (#33)
CI / check (pull_request) Failing after 2m30s
80e8efb05e
Three scenarios testing the full CLI pipeline:
1. Linear workflow (planner → worker → $END): CAS chain integrity
2. Loop workflow (developer ↔ reviewer): moderator routing through cycles
3. Role mismatch detection: agent catches routing bugs

Uses workflow add → thread start → thread exec with uwf-mock,
verifying CAS state, thread lifecycle, and error handling.

Updated assertions to use getThread().status === 'completed'
(aligned with PR #45 unified thread storage).

Refs #33
xiaoju force-pushed test/33-mock-agent from ede428bff2 to 80e8efb05e 2026-06-04 08:06:31 +00:00 Compare
xiaomo approved these changes 2026-06-04 08:38:50 +00:00
xiaomo left a comment
Owner

LGTM Rebase 后适配了统一存储 API,findHistoryEntry 已替换为 getThread + status 断言。

LGTM ✅ Rebase 后适配了统一存储 API,`findHistoryEntry` 已替换为 `getThread` + status 断言。
xiaomo merged commit cd7e4e77ff into main 2026-06-04 08:38:51 +00:00
Sign in to join this conversation.
No Reviewers
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: shazhou/united-workforce#44