1
0
Files
DiAL/openspec/changes/archive/2026-05-10-enhance-expect-rules/tasks.md

54 lines
2.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
## 1. 依赖安装
- [x] 1.1 安装 cheerio、xpath、@xmldom/xmldom 依赖
## 2. 类型定义
- [x] 2.1 在 types.ts 中定义 ExpectOperator、BodyExpectConfig 接口
- [x] 2.2 更新 ExpectConfig 接口,新增 headers 字段,将 bodyContains 替换为 body 分组
- [x] 2.3 新增 CssExpect 类型ExpectValue | ExpectOperator & { attr?: string }
- [x] 2.4 导出 ExpectValue 联合类型
## 3. Body 校验核心实现
- [x] 3.1 实现简易 JSONPath 求值函数 evaluateJsonPath支持 $.a.b、$.a[0].b 等基本路径)
- [x] 3.2 实现操作符比较函数 applyOperatorequals/contains/match/empty/exists/gte/lte/gt/lt
- [x] 3.3 实现 checkExpectValue 函数:标量 → equals对象 → 遍历操作符
- [x] 3.4 实现 checkBodyContainsbody.includes 包装
- [x] 3.5 实现 checkBodyRegexnew RegExp().test 包装
- [x] 3.6 实现 checkBodyJsonJSON.parse + evaluateJsonPath + applyOperator
- [x] 3.7 实现 checkBodyCsscheerio.load + 选择器查询 + text/attr 提取 + applyOperator
- [x] 3.8 实现 checkBodyXpathxmldom 解析 + xpath 引擎 evaluate + applyOperator
## 4. Expect 校验重构
- [x] 4.1 重构 checkExpect 函数,新增 headers 检查逻辑
- [x] 4.2 将 bodyContains 检查替换为 checkBodyExpect 调用,按需分发到五种子方法
- [x] 4.3 实现 checkBodyExpect 主入口:按 contains → regex → json → css → xpath 顺序 AND 短路执行
## 5. 配置加载
- [x] 5.1 确认 config-loader 中 expect 透传逻辑对新结构的兼容性,更新类型引用
## 6. 数据存储兼容
- [x] 6.1 验证 store.ts 中 expect JSON 序列化对新结构的兼容性,必要时调整
## 7. 测试
- [x] 7.1 为 evaluateJsonPath 编写单元测试(嵌套对象、数组索引、不存在路径、边界情况)
- [x] 7.2 为 applyOperator 编写单元测试9 种操作符各至少 2 个 case
- [x] 7.3 为 checkBodyContains/checkBodyRegex 编写单元测试
- [x] 7.4 为 checkBodyJson 编写单元测试等值匹配、操作符匹配、JSON 解析失败、路径不存在)
- [x] 7.5 为 checkBodyCss 编写单元测试text 提取、attr 提取、无匹配元素)
- [x] 7.6 为 checkBodyXpath 编写单元测试节点文本、属性值、无匹配节点、XML 解析失败)
- [x] 7.7 为 checkExpect 新增测试用例headers 校验、body 多种方法 AND 组合、全量规则)
- [x] 7.8 更新 config-loader 测试用例(新 expect 格式解析、向后兼容验证)
- [x] 7.9 端到端模拟测试:构造完整 expect 配置并验证 checkExpect 整体行为
## 8. 文档与示例
- [x] 8.1 更新 probes.example.yaml展示 headers 和 body 分组全部用法示例
- [x] 8.2 更新 README.md 配置说明章节,补充 expect.body 和 headers 的文档
- [x] 8.3 更新 README.md 依赖列表(如有需要)