- Updated DESIGN_V2.md to reflect changes in the handling of before/after scripts, removing the `scripts:` prefix and clarifying their usage in JSONL test cases. - Enhanced runner.go to integrate global before/after hooks, ensuring they execute correctly before and after test cases. - Revised types.go to include new fields for before/after scripts in test case and options structures. - Improved TODO_V2.md to track the implementation progress of before/after script functionality and related tasks. - Added utility function LoadAgentTestScripts to facilitate loading of test scripts from the agent's src directory.
3.7 KiB
3.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类型script_assert.go: 添加AssertAgent方法到TestingT- 创建示例 validator agent
Phase 3: Dynamic Mode (Simulator + Checkpoints)
新增文件: dynamic_runner.go, dynamic_types.go
types.go: 添加Simulator,Checkpoints字段到Casedynamic_types.go: 定义Checkpoint,DynamicResult等类型dynamic_runner.go: 实现DynamicRunnerdynamic_runner.go: 实现 checkpoint 匹配逻辑dynamic_runner.go: 实现终止条件判断runner.go: 在runSingleTest判断并调用动态模式- 创建示例 simulator agent
Phase 4: Agent-Driven Input
新增文件: input_source.go
input_source.go: 实现ParseInputSourceinput_source.go: 实现GenerateTestCasesloader.go: 添加LoadFromAgent方法loader.go: 添加LoadFromScript方法runner.go: 在RunTests支持不同输入源cmd/agent/agent.go: 添加--dry-runflag- 创建示例 generator agent
Phase 5: Console Output Optimization
修改文件: output.go
output.go: 添加DynamicTestStart方法output.go: 添加DynamicTurn方法output.go: 添加DynamicTestResult方法output.go: 添加ParallelResults方法- 测试并行模式输出效果
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)
Open Questions
- Message Generation: 是否提供 helper 从脚本生成 message history?
- Snapshot Testing: 是否支持 "golden file" 对比?
- Retry Logic: 测试失败是否支持自动重试?