- Introduced dynamic testing capabilities, allowing for multi-turn conversations with checkpoints through the new `DynamicRunner`. - Enhanced the `runSingleTest` method to support dynamic mode, including the execution of before/after scripts and detailed output for dynamic test results. - Added new output methods in `output.go` for dynamic test start, turns, checkpoints, and results, improving console feedback during testing. - Updated `DESIGN_V2.md` and `TODO_V2.md` to reflect the new dynamic mode features, including simulator configurations and checkpoint definitions. - Revised the `Case` struct in `types.go` to include fields for dynamic testing, such as `Simulator`, `Checkpoints`, and `MaxTurns`.
4.7 KiB
4.7 KiB
Agent Test Framework V2 - TODO
详细实施计划见 UPGRADE_PLAN.md
Format Rules
| Context | Format | Example |
|---|---|---|
-i flag (CLI) |
Prefix required | agents:workers.test.gen, scripts:tests.gen |
JSONL assertion use |
Prefix required | "use": "agents:workers.test.validator" |
JSONL simulator.use |
No prefix (agent only) | "use": "workers.test.user-simulator" |
--simulator flag |
No prefix (agent only) | --simulator workers.test.user-simulator |
t.assert.Agent() |
No prefix (method-bound) | t.assert.Agent(resp, "workers.test.val") |
JSONL before/after |
No prefix (in src/) | "before": "env_test.Before" |
--before/--after |
No prefix (in src/) | --before env_test.BeforeAll |
Phase 1: Before/After Scripts ✅
新增文件: script_hooks.go
types.go: 添加Before,After字段到Casetypes.go: 添加BeforeAll,AfterAll字段到Optionsscript_hooks.go: 实现HookExecutorscript_hooks.go: 通过 V8 直接执行*_test.ts脚本runner.go: 集成 before/after 到runSingleTestrunner.go: 集成 beforeAll/afterAll 到RunTestscmd/agent/test.go: 添加--before,--afterflagstest/utils.go: 添加LoadAgentTestScripts()通用函数- 创建示例脚本
assistants/tests/hooks-test/src/env_test.ts - 创建单元测试
script_hooks_test.go(黑盒测试)
Phase 2: Agent-Driven Assertions ✅
修改文件: assert.go, script_assert.go
types.go: 添加Use,Options字段到Assertionassert.go: 实现assertAgent方法assert.go: 在evaluateAssertion添加agent类型assert.go: 使用goutext.ExtractJSON容错解析 LLM 响应script_assert.go: 添加assertAgentMethod到newAssertObject- 创建示例 validator agent (
assistants/tests/validator-agent) - 创建单元测试
assert_agent_test.go(JSONL 断言 + JSAPI 断言)
Phase 3: Agent-Driven Input ✅
新增文件: input_source.go
用 Agent 生成测试用例,生成后使用标准模式执行。相对简单。
准备工作:
- 创建 generator agent (
yao-dev-app/assistants/tests/generator-agent) - 编写 generator agent 的 prompts.yml
实现:
input_source.go: 实现ParseInputSourceinput_source.go: 实现GenerateTestCasesloader.go: 添加LoadFromAgent方法loader.go: 添加LoadFromScript方法runner.go: 在RunTests支持不同输入源cmd/agent/test.go: 添加--dry-runflag
测试:
- 创建单元测试
input_source_test.go
Phase 4: Dynamic Mode (Simulator + Checkpoints) ✅
新增文件: dynamic_runner.go, dynamic_types.go
运行时使用 Simulator Agent 动态生成对话,需要多轮循环和 checkpoint 匹配。依赖 Phase 3 的 Agent 调用经验。
准备工作:
- 创建 simulator agent (
yao-dev-app/assistants/tests/simulator-agent) - 编写 simulator agent 的 prompts.yml (模拟用户行为)
实现:
types.go: 添加Simulator,Checkpoints字段到Casedynamic_types.go: 定义Checkpoint,DynamicResult等类型dynamic_runner.go: 实现DynamicRunnerdynamic_runner.go: 实现 checkpoint 匹配逻辑dynamic_runner.go: 实现终止条件判断runner.go: 在runSingleTest判断并调用动态模式
测试:
- 创建单元测试
dynamic_runner_test.go
Phase 5: Console Output Optimization ✅
修改文件: output.go
output.go: 添加DynamicTestStart方法output.go: 添加DynamicTurn方法output.go: 添加DynamicCheckpoint方法output.go: 添加DynamicTestResult方法- 动态模式输出效果已验证
Already Implemented ✅
- Message history support (
inputas array) - File attachments (
file://protocol) --parallelflag--fail-fastflag-vverbose mode- Script testing (
*_test.ts) - Before/After hooks (Phase 1)
- Agent-driven assertions (Phase 2)
- Agent-driven input (Phase 3)
--dry-runflag- Dynamic mode (Phase 4)
--simulatorflag- Console output optimization (Phase 5)
Open Questions
- Message Generation: 是否提供 helper 从脚本生成 message history?
- Snapshot Testing: 是否支持 "golden file" 对比?
- Retry Logic: 测试失败是否支持自动重试?